From d16127a98b28ed3e676807440fa07058cb5cece9 Mon Sep 17 00:00:00 2001 From: Alejandro Garcia Anglada Date: Tue, 26 Nov 2024 18:02:35 +0100 Subject: [PATCH] feat: multichain send action adds solana --- .../app/wallet-overview/coin-buttons.tsx | 27 ++++++++++++++----- ui/store/actions.ts | 9 +++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/ui/components/app/wallet-overview/coin-buttons.tsx b/ui/components/app/wallet-overview/coin-buttons.tsx index c3708eaef344..026bab844f1a 100644 --- a/ui/components/app/wallet-overview/coin-buttons.tsx +++ b/ui/components/app/wallet-overview/coin-buttons.tsx @@ -24,7 +24,11 @@ import { } from '@metamask/utils'; ///: BEGIN:ONLY_INCLUDE_IF(build-flask) -import { BtcAccountType, InternalAccount } from '@metamask/keyring-api'; +import { + BtcAccountType, + InternalAccount, + SolAccountType, +} from '@metamask/keyring-api'; ///: END:ONLY_INCLUDE_IF ///: BEGIN:ONLY_INCLUDE_IF(build-main,build-beta,build-flask) import { ChainId } from '../../../../shared/constants/network'; @@ -94,6 +98,7 @@ import { } from '../../../store/actions'; ///: BEGIN:ONLY_INCLUDE_IF(build-flask) import { BITCOIN_WALLET_SNAP_ID } from '../../../../shared/lib/accounts/bitcoin-wallet-snap'; +import { SOLANA_WALLET_SNAP_ID } from '../../../../shared/lib/accounts/solana-wallet-snap'; ///: END:ONLY_INCLUDE_IF import { getMultichainIsEvm, @@ -116,6 +121,13 @@ type CoinButtonsProps = { iconButtonClassName?: string; }; +///: BEGIN:ONLY_INCLUDE_IF(build-flask) +const multichainAccountTypeToSnapId = { + [BtcAccountType.P2wpkh]: BITCOIN_WALLET_SNAP_ID, + [SolAccountType.DataAccount]: SOLANA_WALLET_SNAP_ID, +}; +///: END:ONLY_INCLUDE_IF + const CoinButtons = ({ account, chainId, @@ -315,7 +327,7 @@ const CoinButtons = ({ (approval) => { return ( approval.type === 'snap_dialog' && - approval.origin === BITCOIN_WALLET_SNAP_ID + Object.values(multichainAccountTypeToSnapId).includes(approval.origin) ); }, ); @@ -356,15 +368,18 @@ const CoinButtons = ({ ); switch (account.type) { ///: BEGIN:ONLY_INCLUDE_IF(build-flask) - case BtcAccountType.P2wpkh: { + case BtcAccountType.P2wpkh: + case SolAccountType.DataAccount: { try { // FIXME: We switch the tab before starting the send flow (we // faced some inconsistencies when changing it after). await dispatch(setDefaultHomeActiveTabName('activity')); await sendMultichainTransaction( - BITCOIN_WALLET_SNAP_ID, - account.id, - chainId as CaipChainId, + multichainAccountTypeToSnapId[account.type], + { + account: account.id, + scope: chainId as CaipChainId, + }, ); } catch { // Restore the previous tab in case of any error (see FIXME comment above). diff --git a/ui/store/actions.ts b/ui/store/actions.ts index f3f4e712acf5..3812a83d1b5c 100644 --- a/ui/store/actions.ts +++ b/ui/store/actions.ts @@ -6011,8 +6011,13 @@ function applyPatches( export async function sendMultichainTransaction( snapId: string, - account: string, - scope: string, + { + account, + scope, + }: { + account: string; + scope: string; + }, ) { await handleSnapRequest({ snapId,