diff --git a/web/massastation/src/custom/hooks/useUpdatePlugin.ts b/web/massastation/src/custom/hooks/useUpdatePlugin.ts new file mode 100644 index 000000000..a121ad050 --- /dev/null +++ b/web/massastation/src/custom/hooks/useUpdatePlugin.ts @@ -0,0 +1,18 @@ +import { PluginExecuteRequest } from '@/pages/Store/StationSection/StationPlugin'; +import { usePost } from '../api'; + +export function useUpdatePlugin(id: string | undefined) { + const { + mutate: mutateExecute, + isSuccess: isExecuteSuccess, + isLoading: isExecuteLoading, + } = usePost(`plugin-manager/${id}/execute`); + + function updatePluginState(command: string) { + if (isExecuteLoading) return; + const payload = { command } as PluginExecuteRequest; + mutateExecute({ payload }); + } + + return { isExecuteSuccess, isExecuteLoading, updatePluginState }; +} diff --git a/web/massastation/src/pages/Index/Dashboard/MassaWallet.tsx b/web/massastation/src/pages/Index/Dashboard/MassaWallet.tsx index ed8ed6e32..8bd3d338a 100644 --- a/web/massastation/src/pages/Index/Dashboard/MassaWallet.tsx +++ b/web/massastation/src/pages/Index/Dashboard/MassaWallet.tsx @@ -34,7 +34,7 @@ export function ActivePlugin(props: MSPluginProps) { return ( <>
{iconActive}
-
+

{title} @@ -56,7 +56,7 @@ export function Updateplugin(props: MSPluginProps) { return ( <>

{iconActive}
-
+

{title} @@ -112,7 +112,7 @@ export function CrashedPlugin(props: MSPluginProps) { return ( <> {iconActive} -

+

{`${title} can’t be opened. Reinstall it from the Module store.`}

diff --git a/web/massastation/src/pages/Index/DashboardStation.tsx b/web/massastation/src/pages/Index/DashboardStation.tsx index 81d5c4fec..2b2069a74 100644 --- a/web/massastation/src/pages/Index/DashboardStation.tsx +++ b/web/massastation/src/pages/Index/DashboardStation.tsx @@ -10,9 +10,8 @@ import { Dusa } from './Dashboard/Dusa'; import { MASSA_WALLET, PLUGIN_UPDATE } from '@/const'; import { MassaPluginModel } from '@/models'; import { MassaWallet } from './Dashboard/MassaWallet'; -import { PluginExecuteRequest } from '../Store/StationSection/StationPlugin'; -import { usePost } from '@/custom/api'; import { useEffect, useState } from 'react'; +import { useUpdatePlugin } from '@/custom/hooks/useUpdatePlugin'; export interface IDashboardStationProps { massaPlugins?: MassaPluginModel[] | undefined; @@ -48,11 +47,8 @@ export function DashboardStation(props: IDashboardStationProps) { const [walletState, setWalletState] = useState(); - const { - mutate: mutateExecute, - isSuccess: isExecuteSuccess, - isLoading: isExecuteLoading, - } = usePost(`plugin-manager/${id}/execute`); + const { isExecuteSuccess, isExecuteLoading, updatePluginState } = + useUpdatePlugin(id); useEffect(() => { if (pluginWalletIsInstalled && !isUpdatable) { @@ -70,18 +66,12 @@ export function DashboardStation(props: IDashboardStationProps) { } }, [isExecuteSuccess]); - function updatePluginState(command: string) { - if (isExecuteLoading) return; - const payload = { command } as PluginExecuteRequest; - mutateExecute({ payload }); - } - return (
-
+