Skip to content

Commit

Permalink
Enable dashboard plugin update (#1351)
Browse files Browse the repository at this point in the history
* Enable dashboard plugin update

* Add update frontend

* clean and add useUpdatePLugin hook

* add i18n

* Review Changes

* Add Store Update ToolTip

* Revamp and Animate MW Plugin

* Homogenize scaling

* Add MW i18n

* try fix ci

* try fix ci

* try fix ci

---------

Co-authored-by: Nathan Seva <[email protected]>
  • Loading branch information
pivilartisant and Thykof authored Apr 24, 2024
1 parent 08e0e14 commit ba149a9
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .github/actions/install/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ runs:
if: startsWith(inputs.os, 'ubuntu-')
shell: bash
run: |
# sudo sed -i 's/^deb/#deb/g' /etc/apt/sources.list.d/microsoft-prod.list
sudo rm /etc/apt/sources.list.d/microsoft-prod.list
curl https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -o packages-microsoft-prod.deb
sudo dpkg -i --force-confnew packages-microsoft-prod.deb
sudo apt update
sudo apt install -y libgl1-mesa-dev xorg-dev gcc-mingw-w64-x86-64 p7zip
Expand Down
6 changes: 3 additions & 3 deletions web/massastation/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions web/massastation/src/assets/dashboard/MassaWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions web/massastation/src/assets/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './BridgeOutline.svg';
export * from './MassaLabs.svg';
export * from './DusaWave.svg';
export * from './Explorer.svg';
export * from './MassaWallet.svg';
18 changes: 18 additions & 0 deletions web/massastation/src/custom/hooks/useUpdatePlugin.ts
Original file line number Diff line number Diff line change
@@ -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<PluginExecuteRequest>(`plugin-manager/${id}/execute`);

function updatePluginState(command: string) {
if (isExecuteLoading) return;
const payload = { command } as PluginExecuteRequest;
mutateExecute({ payload });
}

return { isExecuteSuccess, isExecuteLoading, updatePluginState };
}
17 changes: 15 additions & 2 deletions web/massastation/src/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mystation-banner": "My Station",
"store-banner": "Store",
"loading": "Loading...",
"update": "Update",
"massa-station-incompatible": "Available in Massa Station version: {version}",
"crashed-module": "The module is not working. Please delete it and then reinstall it.",
"mystation": {
Expand Down Expand Up @@ -43,14 +44,26 @@
"foundation-desc": "Learn about Massa ecosystem and initiatives.",
"massalabs-desc": "Unique Lab supporting Massa ecosystem and creating innovative solutions.",
"purrfect-desc": "Create, buy & sell NFTs on the Massa blockchain.",
"dusa-desc": "Fully decentralized exchange protocol."
"dusa-desc": "Advanced, customizable and fully decentralized trading protocol."
},
"modules": {
"bridge": "Massa Bridge",
"explorer": "Massa Explorer",
"foundation": "Massa Foundation",
"massalabs": "Massa Labs",
"purrfect": "Purrfect Universe",
"dusa": "Dusa"
"dusa": "Dusa",
"massa-wallet": {
"title": "Massa Wallet",
"desc": "Official Massa Wallet",
"crash": "{title} can’t be opened. Reinstall it from the Module store.",
"installing": "{title} installation",
"launch": "Launch",
"install": "Install",
"update": "Update",
"updating": "Updating...",
"click": "Click here",
"no-update": " to launch it without update"
}
}
}
2 changes: 1 addition & 1 deletion web/massastation/src/pages/Index/Dashboard/Bridge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Intl from '@/i18n/i18n';

export function Bridge() {
return (
<motion.div className="h-full" whileHover={{ scale: 1.05 }}>
<motion.div className="h-full" whileHover={{ scale: 1.03 }}>
<RedirectTile
url="https://bridge.massa.net"
size="cs"
Expand Down
2 changes: 1 addition & 1 deletion web/massastation/src/pages/Index/Dashboard/Dusa.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Intl from '@/i18n/i18n';

export function Dusa() {
return (
<motion.div className="h-full" whileHover={{ scale: 1.05 }}>
<motion.div className="h-full" whileHover={{ scale: 1.03 }}>
<RedirectTile
size="cs"
customSize="h-full"
Expand Down
6 changes: 3 additions & 3 deletions web/massastation/src/pages/Index/Dashboard/Foundation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { motion } from 'framer-motion';
import Intl from '@/i18n/i18n';
export function Foundation() {
return (
<motion.div whileHover={{ scale: 1.05 }}>
<motion.div whileHover={{ scale: 1.03 }}>
<RedirectTile
url="https://massa.foundation/"
className="bg-neutral text-primary rounded-md p-0 hover:bg-c-hover hover:cursor-pointer h-full"
Expand All @@ -15,8 +15,8 @@ export function Foundation() {
</div>
<div className="relative flex justify-end">
<img
width={140}
height={140}
width={160}
height={160}
src={foundation}
alt={Intl.t('modules.foundation')}
/>
Expand Down
267 changes: 267 additions & 0 deletions web/massastation/src/pages/Index/Dashboard/MassaWallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { Button, Spinner } from '@massalabs/react-ui-kit';
import Intl from '@/i18n/i18n';
import { useState } from 'react';
import { FiArrowUpRight, FiRefreshCw } from 'react-icons/fi';
import { WalletStates } from '../DashboardStation';
import { motion } from 'framer-motion';
import massaWallet from '../../../assets/dashboard/MassaWallet.svg';

export interface PluginWalletProps {
state?: string;
isLoading: boolean;
title: string;
status?: string;
isUpdating: boolean;
onClickActive: () => void;
onClickInactive: () => void;
onUpdateClick: () => void;
}

export interface MSPluginProps {
title: string;
onClickActive?: () => void;
onClickInactive?: () => void;
isUpdating?: boolean;
isHovered?: boolean;
}

export function ActivePlugin(props: MSPluginProps) {
const { title, onClickActive, isHovered } = props;

return (
<>
<div className={`w-full h-full rounded-t-md bg-brand`}>
<motion.img
initial={false}
animate={{
rotate: isHovered ? 180 : 0,
transition: { duration: 0.36 },
}}
src={massaWallet}
alt={Intl.t('modules.massa-wallet.title')}
className="w-full h-full p-4"
/>
</div>
<div className="w-full h-full text-f-primary bg-secondary flex flex-col gap-1 justify-evenly items-center pb-4">
<div className="mas-subtitle text-center">{title}</div>
<div className="mas-body2">{Intl.t('modules.massa-wallet.desc')}</div>
<div className="w-3/5">
<Button onClick={onClickActive} preIcon={<FiArrowUpRight />}>
{Intl.t('modules.massa-wallet.launch')}
</Button>
</div>
</div>
</>
);
}

export function Updateplugin(props: MSPluginProps) {
const { title, onClickActive, isUpdating, isHovered } = props;

return (
<>
<div className={`w-full h-full rounded-t-md bg-brand`}>
<motion.img
initial={false}
animate={{
rotate: isHovered ? 180 : 0,
transition: { duration: 0.36 },
}}
src={massaWallet}
alt={Intl.t('modules.massa-wallet.title')}
className="w-full h-full p-4"
/>
</div>
<div className="w-full h-full text-f-primary bg-secondary flex flex-col gap-1 pb-4 justify-evenly items-center">
<div className="mas-subtitle text-center">{title}</div>
<div className="flex flex-col gap-2">
<Button onClick={onClickActive}>
<div className="flex items-center gap-2">
<div className={isUpdating ? 'animate-spin' : 'none'}>
<FiRefreshCw className="text-primary" size={18} />
</div>
{isUpdating
? Intl.t('modules.massa-wallet.updating')
: Intl.t('modules.massa-wallet.update')}
</div>
</Button>
<div className="text-s-warning px-4 mas-caption">
<a
className="underline"
href="/plugin/massa-labs/massa-wallet/web-app/index"
target="_blank"
>
{Intl.t('modules.massa-wallet.click')}
</a>{' '}
{Intl.t('modules.massa-wallet.no-update')}
</div>
</div>
</div>
</>
);
}

export function InactivePlugin(props: MSPluginProps) {
const { title, onClickInactive, isHovered } = props;

return (
<>
<div className={`w-full h-full rounded-t-md bg-tertiary`}>
<motion.img
initial={false}
animate={{
rotate: isHovered ? 180 : 0,
transition: { duration: 0.36 },
}}
src={massaWallet}
alt={Intl.t('modules.massa-wallet.title')}
className="w-full h-full p-4"
/>
</div>
<div className="w-full h-full text-f-primary bg-secondary flex flex-col justify-center items-center rounded-b-md">
<div className="w-4/5 px-4 py-2 mas-buttons lg:h-14 flex items-center justify-center">
<p className="text-center">{`${title} is not installed in your station`}</p>
</div>
<div className="w-4/5 px-4 py-2">
<Button onClick={onClickInactive}>
{Intl.t('modules.massa-wallet.install')}
</Button>
</div>
</div>
</>
);
}

export function CrashedPlugin(props: MSPluginProps) {
const { title, isHovered } = props;

return (
<>
<div className={`w-full h-full rounded-t-md bg-brand`}>
<motion.img
initial={false}
animate={{
rotate: isHovered ? 180 : 0,
transition: { duration: 0.36 },
}}
src={massaWallet}
alt={Intl.t('modules.massa-wallet.title')}
className="w-full h-full p-4"
/>
</div>
<div className="w-full h-full py-6 text-f-primary bg-secondary flex flex-col items-center">
<div className="w-4/5 px-4 py-2 mas-buttons lg:h-14 flex items-center justify-center">
<p className="text-center">
{' '}
{Intl.t('modules.massa-wallet.crash', {
title: title,
})}
</p>
</div>
</div>
</>
);
}

export function LoadingPlugin(props: MSPluginProps) {
const { title, isHovered } = props;

return (
<>
<div className={`w-full h-full rounded-t-md bg-brand`}>
<motion.img
initial={false}
animate={{
rotate: isHovered ? 180 : 0,
transition: { duration: 0.36 },
}}
src={massaWallet}
alt={Intl.t('modules.massa-wallet.title')}
className="w-full h-full p-4"
/>
</div>
<div className="w-full text-f-primary bg-secondary flex flex-col items-center gap-4 py-4">
<div className="w-4/5 mas-buttons flex items-center justify-center">
<p className="text-center">
{Intl.t('modules.massa-wallet.installing', {
title: title,
})}
</p>
</div>
<div className="w-3/5">
<Button disabled={true}>
<Spinner />
</Button>
</div>
</div>
</>
);
}

export function MassaWallet(props: PluginWalletProps) {
const {
state,
isLoading,
status,
title,
onClickActive,
onClickInactive,
onUpdateClick,
isUpdating,
} = props;

const [isHovered, setIsHovered] = useState(false);

const displayPlugin = () => {
if (isLoading) {
return <LoadingPlugin title={title} isHovered={isHovered} />;
}
if (state === WalletStates.Updateable) {
return (
<Updateplugin
title={title}
onClickActive={onUpdateClick}
isUpdating={isUpdating}
isHovered={isHovered}
/>
);
}
if (state === WalletStates.Inactive) {
return (
<InactivePlugin
title={title}
onClickInactive={onClickInactive}
isHovered={isHovered}
/>
);
}
if (status && status === 'Crashed') {
return <CrashedPlugin title={title} isHovered={isHovered} />;
}
return (
<ActivePlugin
title={title}
onClickActive={onClickActive}
isHovered={isHovered}
/>
);
};

return (
<motion.div
onHoverStart={() => {
setIsHovered(true);
}}
onHoverEnd={() => {
setIsHovered(false);
}}
whileHover={{ scale: 1.03 }}
data-testid="plugin-wallet"
className="w-full h-full rounded-md flex flex-col"
>
{displayPlugin()}
</motion.div>
);
}
Loading

0 comments on commit ba149a9

Please sign in to comment.