Skip to content

Commit

Permalink
chore: adds call to the multichain transactions controller
Browse files Browse the repository at this point in the history
  • Loading branch information
zone-live committed Feb 17, 2025
1 parent 8c81e3a commit 67113a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4069,6 +4069,12 @@ export default class MetamaskController extends EventEmitter {
// MultichainBalancesController
multichainUpdateBalance: (accountId) =>
this.multichainBalancesController.updateBalance(accountId),

// MultichainTransactionsController
multichainUpdateTransactions: (accountId) =>
this.multichainTransactionsController.updateTransactionsForAccount(
accountId,
),
///: END:ONLY_INCLUDE_IF
// Transaction Decode
decodeTransactionData: (request) =>
Expand Down
18 changes: 18 additions & 0 deletions ui/hooks/accounts/useMultichainWalletSnapClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { SOLANA_WALLET_SNAP_ID } from '../../../shared/lib/accounts/solana-walle
import {
handleSnapRequest,
multichainUpdateBalance,
multichainUpdateTransactions,
} from '../../store/actions';
import {
useMultichainWalletSnapClient,
Expand All @@ -23,10 +24,13 @@ import {
jest.mock('../../store/actions', () => ({
handleSnapRequest: jest.fn(),
multichainUpdateBalance: jest.fn(),
multichainUpdateTransactions: jest.fn(),
}));

const mockHandleSnapRequest = handleSnapRequest as jest.Mock;
const mockMultichainUpdateBalance = multichainUpdateBalance as jest.Mock;
const mockMultichainUpdateTransactions =
multichainUpdateTransactions as jest.Mock;

describe('useMultichainWalletSnapClient', () => {
beforeEach(() => {
Expand Down Expand Up @@ -91,5 +95,19 @@ describe('useMultichainWalletSnapClient', () => {
await multichainWalletSnapClient.createAccount(network);
expect(mockMultichainUpdateBalance).toHaveBeenCalledWith(mockAccount.id);
});

it(`force fetches the transactions after creating a ${clientType} account`, async () => {
const { result } = renderHook(() =>
useMultichainWalletSnapClient(clientType),
);
const multichainWalletSnapClient = result.current;

mockHandleSnapRequest.mockResolvedValue(mockAccount);

await multichainWalletSnapClient.createAccount(network);
expect(mockMultichainUpdateTransactions).toHaveBeenCalledWith(
mockAccount.id,
);
});
});
});
3 changes: 3 additions & 0 deletions ui/hooks/accounts/useMultichainWalletSnapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMemo } from 'react';
import {
handleSnapRequest,
multichainUpdateBalance,
multichainUpdateTransactions,
} from '../../store/actions';
import { BITCOIN_WALLET_SNAP_ID } from '../../../shared/lib/accounts/bitcoin-wallet-snap';
import { SOLANA_WALLET_SNAP_ID } from '../../../shared/lib/accounts/solana-wallet-snap';
Expand Down Expand Up @@ -62,6 +63,8 @@ export class MultichainWalletSnapClient {
// However, the balance won't be fetched right away. To workaround this, we trigger the
// fetch explicitly here (since we are already in a `async` call) and wait for it to be updated!
await multichainUpdateBalance(account.id);

await multichainUpdateTransactions(account.id);
}
}

Expand Down
8 changes: 8 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5913,6 +5913,14 @@ export async function multichainUpdateBalance(
]);
}

export async function multichainUpdateTransactions(
accountId: string,
): Promise<void> {
return await submitRequestToBackground<void>('multichainUpdateTransactions', [
accountId,
]);
}

export async function getLastInteractedConfirmationInfo(): Promise<
LastInteractedConfirmationInfo | undefined
> {
Expand Down

0 comments on commit 67113a8

Please sign in to comment.