Skip to content

Commit

Permalink
Update Massa-web3 and fix build (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey authored Aug 27, 2024
1 parent a174341 commit 060de63
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 39 deletions.
17 changes: 9 additions & 8 deletions package-lock.json

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

36 changes: 18 additions & 18 deletions src/lib/ConnectMassaWallets/components/ConnectMassaWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<WalletName | undefined>(
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 <StationWallet />;
case SUPPORTED_MASSA_WALLETS.BEARBY:
case WalletName.Bearby:
return <BearbyWallet />;
default:
// Should not happen
Expand All @@ -43,31 +43,31 @@ export const ConnectMassaWallet = () => {
}

function renderSelectedWallet() {
switch (selectedProvider) {
case SUPPORTED_MASSA_WALLETS.MASSASTATION:
switch (selectedWallet) {
case WalletName.MassaStation:
return (
<>
<MassaWallet size={28} />
{Intl.t(`connect-wallet.${SUPPORTED_MASSA_WALLETS.MASSASTATION}`)}
{Intl.t(`connect-wallet.${WalletName.MassaStation}`)}
</>
);
case SUPPORTED_MASSA_WALLETS.BEARBY:
case WalletName.Bearby:
return (
<>
<BearbySvg />
{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 (
<SelectMassaWallet
onClick={(providerName) => {
setSelectedProvider(providerName);
setSelectedWallet(providerName);
const provider = wallets.find((p) => p.name() === providerName);
if (provider) {
setCurrentWallet(provider);
Expand All @@ -90,7 +90,7 @@ export const ConnectMassaWallet = () => {
<div className="flex gap-2 items-center">
{renderSelectedWallet()}
<ChainStatus />
{selectedProvider === SUPPORTED_MASSA_WALLETS.BEARBY && (
{selectedWallet === WalletName.Bearby && (
<Tooltip
customClass="mas-caption w-fit whitespace-nowrap"
body={Intl.t(
Expand All @@ -101,7 +101,7 @@ export const ConnectMassaWallet = () => {
</div>
<SwitchWalletButton
onClick={() => {
setSelectedProvider(undefined);
setSelectedWallet(undefined);
setCurrentWallet();
}}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/lib/ConnectMassaWallets/components/SelectMassaWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: <MassaWallet size={32} />,
},
{
name: SUPPORTED_MASSA_WALLETS.BEARBY,
name: WalletName.Bearby,
icon: <BearbySvg />,
},
];

interface SelectMassaWalletProps {
onClick: (providerName: SUPPORTED_MASSA_WALLETS) => void;
onClick: (providerName: WalletName) => void;
}

const SelectMassaWallet = ({ onClick }: SelectMassaWalletProps) => {
Expand Down
6 changes: 2 additions & 4 deletions src/lib/ConnectMassaWallets/store/accountStore.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -82,7 +80,7 @@ export const useAccountStore = create<AccountStoreState>((set, get) => ({
set({ networkObserver });
}

if (currentWallet?.name() === SUPPORTED_MASSA_WALLETS.BEARBY) {
if (currentWallet?.name() === WalletName.Bearby) {
currentWallet
.connect()
.then(() => {
Expand Down
5 changes: 0 additions & 5 deletions src/lib/massa-react/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 060de63

Please sign in to comment.