Skip to content

Commit

Permalink
Fix E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwalsh0 committed Dec 20, 2024
1 parent 1fd24ac commit 507a418
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import {
TransactionMeta,
TransactionType,
} from '@metamask/transaction-controller';
import { renderHookWithConfirmContextProvider } from '../../../../../../../test/lib/confirmations/render-helpers';
import { getMockConfirmStateForTransaction } from '../../../../../../../test/data/confirmations/helper';
import { genUnapprovedContractInteractionConfirmation } from '../../../../../../../test/data/confirmations/contract-interaction';
import { genUnapprovedTokenTransferConfirmation } from '../../../../../../../test/data/confirmations/token-transfer';
import { useTransferRecipient } from './useTransferRecipient';

const ADDRESS_MOCK = '0x2e0D7E8c45221FcA00d74a3609A0f7097035d09B';
const ADDRESS_2_MOCK = '0x2e0D7E8c45221FcA00d74a3609A0f7097035d09C';

const TRANSACTION_METADATA_MOCK =
genUnapprovedContractInteractionConfirmation() as TransactionMeta;
Expand All @@ -28,10 +32,11 @@ describe('useTransferRecipient', () => {
expect(runHook()).toBeUndefined();
});

it('returns transaction to address if no token data', () => {
it('returns parameter to address if simple send', () => {
expect(
runHook({
...TRANSACTION_METADATA_MOCK,
type: TransactionType.simpleSend,
txParams: {
...TRANSACTION_METADATA_MOCK.txParams,
to: ADDRESS_MOCK,
Expand All @@ -40,16 +45,30 @@ describe('useTransferRecipient', () => {
).toBe(ADDRESS_MOCK);
});

it('returns transaction data to address if token transfer', () => {
it('returns data to address if token data', () => {
expect(
runHook({
...TRANSACTION_METADATA_MOCK,
txParams: {
...TRANSACTION_METADATA_MOCK.txParams,
to: '0x123',
to: ADDRESS_2_MOCK,
data: genUnapprovedTokenTransferConfirmation().txParams.data,
},
}),
).toBe(ADDRESS_MOCK);
});

it('returns parameter to address if token data but type is simple send', () => {
expect(
runHook({
...TRANSACTION_METADATA_MOCK,
type: TransactionType.simpleSend,
txParams: {
...TRANSACTION_METADATA_MOCK.txParams,
to: ADDRESS_2_MOCK,
data: genUnapprovedTokenTransferConfirmation().txParams.data,
},
}),
).toBe(ADDRESS_2_MOCK);
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TransactionMeta } from '@metamask/transaction-controller';
import {
TransactionMeta,
TransactionType,
} from '@metamask/transaction-controller';
import { useConfirmContext } from '../../../../context/confirm';
import { useTokenTransactionData } from './useTokenTransactionData';

Expand All @@ -7,8 +10,11 @@ export function useTransferRecipient() {
useConfirmContext<TransactionMeta>();

const transactionData = useTokenTransactionData();
const transactionType = transactionMetadata?.type;
const transactionTo = transactionMetadata?.txParams?.to;
const transferTo = transactionData?.args?._to as string | undefined;

return transferTo || transactionTo;
return transactionType == TransactionType.simpleSend
? transactionTo
: transferTo;
}

0 comments on commit 507a418

Please sign in to comment.