From 060de638f91397638989809cab02c30bf1cc76b8 Mon Sep 17 00:00:00 2001 From: BenRey <44082144+Ben-Rey@users.noreply.github.com> Date: Tue, 27 Aug 2024 09:51:48 +0200 Subject: [PATCH] Update Massa-web3 and fix build (#478) --- package-lock.json | 17 ++++----- .../components/ConnectMassaWallet.tsx | 36 +++++++++---------- .../components/SelectMassaWallet.tsx | 8 ++--- .../ConnectMassaWallets/store/accountStore.ts | 6 ++-- src/lib/massa-react/const.ts | 5 --- 5 files changed, 33 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index d7e1aaf6..c710b02f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3977,9 +3977,9 @@ } }, "node_modules/@massalabs/massa-web3": { - "version": "5.0.0-next.20240812191059", - "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-5.0.0-next.20240812191059.tgz", - "integrity": "sha512-kZ84eIgbRKaENG8cDACKYuY7QkaUBRxFwNX9qJpZ+0LbmjMGP5UOyKGvEwB0SK6l/L7uhZpcAzQGbBZYzcnUtQ==", + "version": "5.0.0-next.20240826165639", + "resolved": "https://registry.npmjs.org/@massalabs/massa-web3/-/massa-web3-5.0.0-next.20240826165639.tgz", + "integrity": "sha512-w8n2wWX72HOybr6QETP3JQQHAHdcWyBHKcXuZWaT+wZMem54zmN3Ajd/fLHfCHB7v+Sw7xetnoonQK10l8HW3A==", "dependencies": { "@noble/ed25519": "^1.7.3", "@noble/hashes": "^1.2.0", @@ -3989,6 +3989,7 @@ "bs58check": "^4.0.0", "decimal.js": "^10.4.3", "dotenv": "^16.0.3", + "eventemitter3": "^5.0.1", "lodash.isequal": "^4.5.0", "secure-random": "^1.1.2", "string_decoder": "^1.3.0", @@ -4010,15 +4011,16 @@ } }, "node_modules/@massalabs/wallet-provider": { - "version": "3.0.0-next.20240801111008", - "resolved": "https://registry.npmjs.org/@massalabs/wallet-provider/-/wallet-provider-3.0.0-next.20240801111008.tgz", - "integrity": "sha512-JjL7Pu95YM9DtsCr0VMXOSRT0+WP59tAsdCpjQD2kKP8vFfcjk7YLaw4tfX02bq99Byiyt215M+mkfesDorDRg==", + "version": "3.0.0-next.20240826165834", + "resolved": "https://registry.npmjs.org/@massalabs/wallet-provider/-/wallet-provider-3.0.0-next.20240826165834.tgz", + "integrity": "sha512-w2xXV3rEESiFUadA77GJ+3qvgexTHTMi/4AGkWeWeKOKBQNDJkWH/Mto4E0f9dEa6SdTWEO2MOTXiTtrO+qCSg==", "dependencies": { "@hicaru/bearby.js": "^0.5.8", "@massalabs/massa-web3": "^5.0.0-next", "axios": "^0.28.0", "bs58check": "^4.0.0", "buffer": "^6.0.3", + "eventemitter3": "^5.0.1", "uid": "^2.0.1" }, "optionalDependencies": { @@ -12575,8 +12577,7 @@ "node_modules/eventemitter3": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", - "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==", - "dev": true + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" }, "node_modules/events": { "version": "3.3.0", diff --git a/src/lib/ConnectMassaWallets/components/ConnectMassaWallet.tsx b/src/lib/ConnectMassaWallets/components/ConnectMassaWallet.tsx index b55d347b..ae79c40b 100644 --- a/src/lib/ConnectMassaWallets/components/ConnectMassaWallet.tsx +++ b/src/lib/ConnectMassaWallets/components/ConnectMassaWallet.tsx @@ -13,28 +13,28 @@ import SwitchWalletButton from './SwitchWalletButton'; import Intl from '../i18n'; import { useAccountStore } from '../store'; import { MassaWallet, Tooltip } from '../../../components'; -import { SUPPORTED_MASSA_WALLETS } from '../../massa-react/const'; +import { WalletName } from '@massalabs/wallet-provider'; export const ConnectMassaWallet = () => { const { currentWallet, wallets, setCurrentWallet, isFetching } = useAccountStore(); - const [selectedProvider, setSelectedProvider] = useState< - SUPPORTED_MASSA_WALLETS | undefined - >(currentWallet?.name() as SUPPORTED_MASSA_WALLETS); + const [selectedWallet, setSelectedWallet] = useState( + currentWallet?.name(), + ); useEffect(() => { - const provider = wallets.find((p) => p.name() === selectedProvider); + const provider = wallets.find((p) => p.name() === selectedWallet); if (provider && !currentWallet) { setCurrentWallet(provider); } - }, [wallets, selectedProvider, currentWallet, setCurrentWallet]); + }, [wallets, selectedWallet, currentWallet, setCurrentWallet]); function renderWallet() { - switch (selectedProvider) { - case SUPPORTED_MASSA_WALLETS.MASSASTATION: + switch (selectedWallet) { + case WalletName.MassaStation: return ; - case SUPPORTED_MASSA_WALLETS.BEARBY: + case WalletName.Bearby: return ; default: // Should not happen @@ -43,31 +43,31 @@ export const ConnectMassaWallet = () => { } function renderSelectedWallet() { - switch (selectedProvider) { - case SUPPORTED_MASSA_WALLETS.MASSASTATION: + switch (selectedWallet) { + case WalletName.MassaStation: return ( <> - {Intl.t(`connect-wallet.${SUPPORTED_MASSA_WALLETS.MASSASTATION}`)} + {Intl.t(`connect-wallet.${WalletName.MassaStation}`)} ); - case SUPPORTED_MASSA_WALLETS.BEARBY: + case WalletName.Bearby: return ( <> - {Intl.t(`connect-wallet.${SUPPORTED_MASSA_WALLETS.BEARBY}`)} + {Intl.t(`connect-wallet.${WalletName.Bearby}`)} ); } } - const noWalletSelected = !selectedProvider || isFetching; + const noWalletSelected = !selectedWallet || isFetching; function renderNoWalletSelected() { return ( { - setSelectedProvider(providerName); + setSelectedWallet(providerName); const provider = wallets.find((p) => p.name() === providerName); if (provider) { setCurrentWallet(provider); @@ -90,7 +90,7 @@ export const ConnectMassaWallet = () => {
{renderSelectedWallet()} - {selectedProvider === SUPPORTED_MASSA_WALLETS.BEARBY && ( + {selectedWallet === WalletName.Bearby && ( {
{ - setSelectedProvider(undefined); + setSelectedWallet(undefined); setCurrentWallet(); }} /> diff --git a/src/lib/ConnectMassaWallets/components/SelectMassaWallet.tsx b/src/lib/ConnectMassaWallets/components/SelectMassaWallet.tsx index dfa59f0b..3db6b545 100644 --- a/src/lib/ConnectMassaWallets/components/SelectMassaWallet.tsx +++ b/src/lib/ConnectMassaWallets/components/SelectMassaWallet.tsx @@ -6,21 +6,21 @@ import { BearbySvg } from './BearbySvg'; import { Disconnected } from './Status/Disconnected'; import Intl from '../i18n'; import { Dropdown, MassaWallet } from '../../../components'; -import { SUPPORTED_MASSA_WALLETS } from '../../massa-react/const'; +import { WalletName } from '@massalabs/wallet-provider'; const walletList = [ { - name: SUPPORTED_MASSA_WALLETS.MASSASTATION, + name: WalletName.MassaStation, icon: , }, { - name: SUPPORTED_MASSA_WALLETS.BEARBY, + name: WalletName.Bearby, icon: , }, ]; interface SelectMassaWalletProps { - onClick: (providerName: SUPPORTED_MASSA_WALLETS) => void; + onClick: (providerName: WalletName) => void; } const SelectMassaWallet = ({ onClick }: SelectMassaWalletProps) => { diff --git a/src/lib/ConnectMassaWallets/store/accountStore.ts b/src/lib/ConnectMassaWallets/store/accountStore.ts index 6d9b0b1b..d5c0acb7 100644 --- a/src/lib/ConnectMassaWallets/store/accountStore.ts +++ b/src/lib/ConnectMassaWallets/store/accountStore.ts @@ -1,8 +1,6 @@ import { Provider } from '@massalabs/massa-web3'; import { create } from 'zustand'; - -import { SUPPORTED_MASSA_WALLETS } from '../../massa-react/const'; -import { Wallet } from '@massalabs/wallet-provider'; +import { Wallet, WalletName } from '@massalabs/wallet-provider'; async function handleBearbyAccountChange( newAddress: string, @@ -82,7 +80,7 @@ export const useAccountStore = create((set, get) => ({ set({ networkObserver }); } - if (currentWallet?.name() === SUPPORTED_MASSA_WALLETS.BEARBY) { + if (currentWallet?.name() === WalletName.Bearby) { currentWallet .connect() .then(() => { diff --git a/src/lib/massa-react/const.ts b/src/lib/massa-react/const.ts index c2af6836..478d8281 100644 --- a/src/lib/massa-react/const.ts +++ b/src/lib/massa-react/const.ts @@ -8,11 +8,6 @@ export const MASSA_WALLET_CREATE_ACCOUNT = 'http://station.massa/plugin/massa-labs/massa-wallet/web-app/account-create'; export const massaToken = 'MAS'; export const BEARBY_INSTALL = 'https://bearby.io'; -export enum SUPPORTED_MASSA_WALLETS { - MASSASTATION = 'MASSASTATION', - BEARBY = 'BEARBY', -} - export const MASSA_EXPLO_URL = 'https://massexplo.io/tx/'; export const MASSA_EXPLO_EXTENSION = '?network=buildnet'; export const MASSA_EXPLORER_URL =