Skip to content

Commit

Permalink
feat: multichain send action adds solana
Browse files Browse the repository at this point in the history
  • Loading branch information
aganglada committed Nov 26, 2024
1 parent be2b439 commit d16127a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
27 changes: 21 additions & 6 deletions ui/components/app/wallet-overview/coin-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -315,7 +327,7 @@ const CoinButtons = ({
(approval) => {
return (
approval.type === 'snap_dialog' &&
approval.origin === BITCOIN_WALLET_SNAP_ID
Object.values(multichainAccountTypeToSnapId).includes(approval.origin)
);
},
);
Expand Down Expand Up @@ -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).
Expand Down
9 changes: 7 additions & 2 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d16127a

Please sign in to comment.