Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/_locales/en/messages.json

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

6 changes: 6 additions & 0 deletions app/_locales/en_GB/messages.json

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

2 changes: 2 additions & 0 deletions ui/ducks/bridge/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe('Ducks - Bridge', () => {
"isVerified": undefined,
"name": "SYMBOL",
"rwaData": undefined,
"securityData": undefined,
"symbol": "SYMBOL",
"tokenFiatAmount": undefined,
}
Expand Down Expand Up @@ -210,6 +211,7 @@ describe('Ducks - Bridge', () => {
chainId: 'eip155:10',
rwaData: undefined,
isVerified: undefined,
securityData: undefined,
iconUrl:
'https://static.cx.metamask.io/api/v2/tokenIcons/assets/eip155/10/erc20/0x13341431.png',
});
Expand Down
4 changes: 4 additions & 0 deletions ui/ducks/bridge/selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ describe('Bridge selectors', () => {
tokenFiatAmount: undefined,
rwaData: undefined,
isVerified: undefined,
securityData: undefined,
});
});
});
Expand Down Expand Up @@ -647,6 +648,7 @@ describe('Bridge selectors', () => {
"isVerified": undefined,
"name": "DEST",
"rwaData": undefined,
"securityData": undefined,
"symbol": "DEST",
"tokenFiatAmount": undefined,
}
Expand Down Expand Up @@ -680,6 +682,7 @@ describe('Bridge selectors', () => {
tokenFiatAmount: undefined,
rwaData: undefined,
isVerified: undefined,
securityData: undefined,
});
});

Expand Down Expand Up @@ -748,6 +751,7 @@ describe('Bridge selectors', () => {
tokenFiatAmount: undefined,
rwaData: undefined,
isVerified: undefined,
securityData: undefined,
});
});
});
Expand Down
80 changes: 80 additions & 0 deletions ui/ducks/bridge/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type CaipAssetType } from '@metamask/utils';
import { MultichainNetworks } from '../../../shared/constants/multichain/networks';
import { CHAIN_IDS } from '../../../shared/constants/network';
import { BridgeAssetSecurityDataType } from '../../pages/bridge/utils/tokens';
import { isSupportedBridgeChain, toBridgeToken } from './utils';

const BASE_PAYLOAD = {
Expand Down Expand Up @@ -56,6 +57,39 @@ describe('isSupportedBridgeChain', () => {
});

describe('toBridgeToken', () => {
describe('securityData', () => {
it('passes securityData from the payload when tokenMetadata has no securityData', () => {
const token = toBridgeToken(
{
...BASE_PAYLOAD,
securityData: { type: BridgeAssetSecurityDataType.MALICIOUS },
},
{ balance: '10' },
);
expect(token.securityData).toStrictEqual({
type: BridgeAssetSecurityDataType.MALICIOUS,
});
});

it('tokenMetadata.securityData takes precedence over payload.securityData', () => {
const token = toBridgeToken(
{
...BASE_PAYLOAD,
securityData: { type: BridgeAssetSecurityDataType.SPAM },
},
{ securityData: { type: BridgeAssetSecurityDataType.VERIFIED } },
);
expect(token.securityData).toStrictEqual({
type: BridgeAssetSecurityDataType.VERIFIED,
});
});

it('securityData is undefined when absent from both payload and tokenMetadata', () => {
const token = toBridgeToken(BASE_PAYLOAD, { balance: '10' });
expect(token.securityData).toBeUndefined();
});
});

describe('isVerified', () => {
it('includes isVerified: true from the payload', () => {
const token = toBridgeToken({ ...BASE_PAYLOAD, isVerified: true });
Expand Down Expand Up @@ -87,5 +121,51 @@ describe('toBridgeToken', () => {
);
expect(token.isVerified).toBe(true);
});

describe('securityData', () => {
it('returns true when tokenMetadata.securityData.type is VERIFIED', () => {
const token = toBridgeToken(BASE_PAYLOAD, {
securityData: { type: BridgeAssetSecurityDataType.VERIFIED },
});
expect(token.isVerified).toBe(true);
});

it('returns true when tokenMetadata.securityData.type is VERIFIED even if tokenMetadata.isVerified is false', () => {
const token = toBridgeToken(BASE_PAYLOAD, {
isVerified: false,
securityData: { type: BridgeAssetSecurityDataType.VERIFIED },
});
expect(token.isVerified).toBe(true);
});

it('falls back to tokenMetadata.isVerified when securityData.type is not VERIFIED', () => {
const token = toBridgeToken(BASE_PAYLOAD, {
isVerified: true,
securityData: { type: BridgeAssetSecurityDataType.WARNING },
});
expect(token.isVerified).toBe(true);
});

it('falls back to payload isVerified when securityData.type is not VERIFIED and tokenMetadata.isVerified is absent', () => {
const token = toBridgeToken(
{ ...BASE_PAYLOAD, isVerified: true },
{ securityData: { type: BridgeAssetSecurityDataType.BENIGN } },
);
expect(token.isVerified).toBe(true);
});

it('returns false when securityData.type is not VERIFIED and tokenMetadata.isVerified is false', () => {
const token = toBridgeToken(BASE_PAYLOAD, {
isVerified: false,
securityData: { type: BridgeAssetSecurityDataType.SPAM },
});
expect(token.isVerified).toBe(false);
});

it('returns undefined when no securityData and no isVerified in either payload or tokenMetadata', () => {
const token = toBridgeToken(BASE_PAYLOAD, { balance: '50' });
expect(token.isVerified).toBeUndefined();
});
});
});
});
9 changes: 8 additions & 1 deletion ui/ducks/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
BRIDGE_CHAINID_COMMON_TOKEN_PAIR,
} from '../../../shared/constants/bridge';
import { getAssetImageUrl } from '../../../shared/lib/asset-utils';
import { BridgeAssetSecurityDataType } from '../../pages/bridge/utils/tokens';
import type { TokenPayload, BridgeToken } from './types';

// Re-export isNonEvmChainId from bridge-controller for backward compatibility
Expand Down Expand Up @@ -212,6 +213,7 @@ export const toBridgeToken = (
accountType,
rwaData,
isVerified,
securityData,
} = payload;
const { chainId } = parseCaipAssetType(assetId);
return {
Expand All @@ -225,7 +227,12 @@ export const toBridgeToken = (
tokenFiatAmount: tokenMetadata?.tokenFiatAmount ?? tokenFiatAmount,
accountType: tokenMetadata?.accountType ?? accountType,
rwaData: tokenMetadata?.rwaData ?? rwaData,
isVerified: tokenMetadata?.isVerified ?? isVerified,
isVerified:
(tokenMetadata?.securityData?.type ===
BridgeAssetSecurityDataType.VERIFIED ||
tokenMetadata?.isVerified) ??
isVerified,
securityData: tokenMetadata?.securityData ?? securityData,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ exports[`usePrefillFromSearchQuery should only set dest token 1`] = `
"isVerified": undefined,
"name": "USDC",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -50,6 +51,7 @@ exports[`usePrefillFromSearchQuery should only set src token and amount 1`] = `
"isVerified": undefined,
"name": "USDC",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -71,6 +73,7 @@ exports[`usePrefillFromSearchQuery should set evm bridge params 1`] = `
"isVerified": undefined,
"name": "USDC",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -86,6 +89,7 @@ exports[`usePrefillFromSearchQuery should set evm bridge params 1`] = `
"isVerified": undefined,
"name": "Solana",
"rwaData": undefined,
"securityData": undefined,
"symbol": "SOL",
"tokenFiatAmount": undefined,
},
Expand All @@ -104,6 +108,7 @@ exports[`usePrefillFromSearchQuery should set solana swap params 1`] = `
"isVerified": undefined,
"name": "Solana",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -118,6 +123,7 @@ exports[`usePrefillFromSearchQuery should set solana swap params 1`] = `
"isVerified": undefined,
"name": "Solana",
"rwaData": undefined,
"securityData": undefined,
"symbol": "SOL",
"tokenFiatAmount": undefined,
},
Expand All @@ -136,6 +142,7 @@ exports[`usePrefillFromSearchQuery should set src token after navigating from ER
"isVerified": undefined,
"name": "USDC",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -156,6 +163,7 @@ exports[`usePrefillFromSearchQuery should set src token after navigating from na
"isVerified": undefined,
"name": "Ethereum",
"rwaData": undefined,
"securityData": undefined,
"symbol": "ETH",
"tokenFiatAmount": undefined,
},
Expand Down
3 changes: 3 additions & 0 deletions ui/hooks/bridge/usePrefillFromBridgeState.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ describe('usePrefillFromBridgeState', () => {
"isVerified": undefined,
"name": "USDC",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand Down Expand Up @@ -154,6 +155,7 @@ describe('usePrefillFromBridgeState', () => {
"isVerified": undefined,
"name": "USD Coin",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand All @@ -168,6 +170,7 @@ describe('usePrefillFromBridgeState', () => {
"isVerified": undefined,
"name": "Native USD Coin (POS)",
"rwaData": undefined,
"securityData": undefined,
"symbol": "USDC",
"tokenFiatAmount": undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ exports[`BridgeInputGroup should render popular tokens 2`] = `
"isVerified": undefined,
"name": "Ether",
"rwaData": undefined,
"securityData": undefined,
"symbol": "ETH",
"tokenFiatAmount": 25.242128065034784,
},
Expand All @@ -384,6 +385,7 @@ exports[`BridgeInputGroup should render popular tokens 2`] = `
"isVerified": undefined,
"name": "Uniswap",
"rwaData": undefined,
"securityData": undefined,
"symbol": "UNI",
"tokenFiatAmount": 0.0010728914112762384,
},
Expand All @@ -397,6 +399,7 @@ exports[`BridgeInputGroup should render popular tokens 2`] = `
"isVerified": undefined,
"name": "Link",
"rwaData": undefined,
"securityData": undefined,
"symbol": "LINK",
"tokenFiatAmount": 0.0000030290553678041743,
},
Expand Down Expand Up @@ -1067,6 +1070,7 @@ exports[`BridgeInputGroup should search for tokens 4`] = `
"isVerified": undefined,
"name": "Ether",
"rwaData": undefined,
"securityData": undefined,
"symbol": "ETH",
"tokenFiatAmount": 25.242128065034784,
},
Expand All @@ -1080,6 +1084,7 @@ exports[`BridgeInputGroup should search for tokens 4`] = `
"isVerified": undefined,
"name": "Uniswap",
"rwaData": undefined,
"securityData": undefined,
"symbol": "UNI",
"tokenFiatAmount": 0.0010728914112762384,
},
Expand All @@ -1093,6 +1098,7 @@ exports[`BridgeInputGroup should search for tokens 4`] = `
"isVerified": undefined,
"name": "Link",
"rwaData": undefined,
"securityData": undefined,
"symbol": "LINK",
"tokenFiatAmount": 0.0000030290553678041743,
},
Expand Down Expand Up @@ -1520,6 +1526,7 @@ exports[`BridgeInputGroup should search for tokens with hasNextPage 3`] = `
"isVerified": undefined,
"name": "Ether",
"rwaData": undefined,
"securityData": undefined,
"symbol": "ETH",
"tokenFiatAmount": 25.242128065034784,
},
Expand All @@ -1533,6 +1540,7 @@ exports[`BridgeInputGroup should search for tokens with hasNextPage 3`] = `
"isVerified": undefined,
"name": "Uniswap",
"rwaData": undefined,
"securityData": undefined,
"symbol": "UNI",
"tokenFiatAmount": 0.0010728914112762384,
},
Expand All @@ -1546,6 +1554,7 @@ exports[`BridgeInputGroup should search for tokens with hasNextPage 3`] = `
"isVerified": undefined,
"name": "Link",
"rwaData": undefined,
"securityData": undefined,
"symbol": "LINK",
"tokenFiatAmount": 0.0000030290553678041743,
},
Expand Down
Loading
Loading