Skip to content

Commit

Permalink
fix: token.icon possibly null, update validators and types (#29065)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29065?quickstart=1)

This PR fixes an issue where `token.icon` returned by the Bridge API
status endpoint could be `null`, which caused validation to fail. It
updates the types and the validation to match what the Bridge API
returns.

## **Related issues**

Related to #28899

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
infiniteflower authored Dec 11, 2024
1 parent 2693e6c commit 3d9db73
Showing 3 changed files with 47 additions and 4 deletions.
42 changes: 42 additions & 0 deletions app/scripts/controllers/bridge-status/validators.test.ts
Original file line number Diff line number Diff line change
@@ -162,6 +162,43 @@ const BridgeTxStatusResponses = {
},
},
},
STATUS_COMPLETE_VALID_MISSING_FIELDS_2: {
status: 'COMPLETE',
isExpectedToken: false,
bridge: 'across',
srcChain: {
chainId: 10,
txHash:
'0x4c57876fad21fb5149af5a58a4aba2ca9d6b212014505dd733b75667ca4f0f2b',
amount: '991250000000000',
token: {
chainId: 10,
address: '0x4200000000000000000000000000000000000006',
symbol: 'WETH',
name: 'Wrapped Ether',
decimals: 18,
icon: 'https://media.socket.tech/tokens/all/WETH',
// logoURI: 'https://media.socket.tech/tokens/all/WETH',
// chainAgnosticId: 'ETH',
},
},
destChain: {
chainId: 8453,
txHash:
'0x60c4cad7c3eb14c7b3ace40cd4015b90927dadacbdc8673f404bea6a5603844b',
amount: '988339336750062',
token: {
chainId: 8453,
address: '0x4200000000000000000000000000000000000006',
symbol: 'WETH',
name: 'Wrapped Ether',
decimals: 18,
icon: null,
// logoURI: null,
// chainAgnosticId: null,
},
},
},
STATUS_COMPLETE_INVALID_MISSING_FIELDS: {
status: 'COMPLETE',
isExpectedToken: true,
@@ -203,6 +240,11 @@ describe('validators', () => {
expected: false,
description: 'complete bridge status with missing fields',
},
{
input: BridgeTxStatusResponses.STATUS_COMPLETE_VALID_MISSING_FIELDS_2,
expected: true,
description: 'complete bridge status with missing fields 2',
},
{
input: BridgeTxStatusResponses.STATUS_COMPLETE_VALID_MISSING_FIELDS,
expected: true,
7 changes: 4 additions & 3 deletions app/scripts/controllers/bridge-status/validators.ts
Original file line number Diff line number Diff line change
@@ -54,9 +54,10 @@ const assetValidators = [
},
{
property: 'icon',
type: 'string|undefined',
validator: (v: unknown): v is string | undefined =>
v === undefined || typeof v === 'string',
// typeof null === 'object'
type: 'string|undefined|object',
validator: (v: unknown): v is string | undefined | object =>
v === undefined || v === null || typeof v === 'string',
},
];

2 changes: 1 addition & 1 deletion shared/types/bridge-status.ts
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ export type Asset = {
symbol: string;
name: string;
decimals: number;
icon?: string;
icon?: string | null;
};

export type SrcChainStatus = {

0 comments on commit 3d9db73

Please sign in to comment.