From cdca73e474779b28210c33cf03a723468bc269e7 Mon Sep 17 00:00:00 2001 From: IF <139582705+infiniteflower@users.noreply.github.com> Date: Fri, 10 Jan 2025 10:51:01 -0500 Subject: [PATCH 1/3] fix: crashing after bridge tx in Firefox --- shared/types/bridge-status.ts | 8 ++++++-- ui/ducks/bridge-status/actions.ts | 13 +++++++------ ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts | 10 +++++++++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/shared/types/bridge-status.ts b/shared/types/bridge-status.ts index 3e81f6e74f1d..bd892eac82dc 100644 --- a/shared/types/bridge-status.ts +++ b/shared/types/bridge-status.ts @@ -146,9 +146,8 @@ export enum BridgeStatusAction { GET_STATE = 'getState', } -// The BigNumber values are serialized to strings export type QuoteMetadataSerialized = { - sentAmount: { amount: string; fiat: string | null }; + sentAmount: { amount: string; valueInCurrency: string | null }; }; export type StartPollingForBridgeTxStatusArgs = { @@ -161,6 +160,11 @@ export type StartPollingForBridgeTxStatusArgs = { targetContractAddress?: BridgeHistoryItem['targetContractAddress']; }; +/** + * Chrome: The BigNumber values are automatically serialized to strings when sent to the background + * Firefox: The BigNumber values are not serialized to strings when sent to the background, + * so we force the ui to do it manually, by using StartPollingForBridgeTxStatusArgsSerialized type on the startPollingForBridgeTxStatus action + */ export type StartPollingForBridgeTxStatusArgsSerialized = Omit< StartPollingForBridgeTxStatusArgs, 'quoteResponse' diff --git a/ui/ducks/bridge-status/actions.ts b/ui/ducks/bridge-status/actions.ts index e9198914966c..dd5de256fe61 100644 --- a/ui/ducks/bridge-status/actions.ts +++ b/ui/ducks/bridge-status/actions.ts @@ -1,6 +1,6 @@ import { - StartPollingForBridgeTxStatusArgs, BridgeStatusAction, + StartPollingForBridgeTxStatusArgsSerialized, } from '../../../shared/types/bridge-status'; import { forceUpdateMetamaskState } from '../../store/actions'; import { submitRequestToBackground } from '../../store/background-connection'; @@ -17,14 +17,15 @@ const callBridgeStatusControllerMethod = ( }; export const startPollingForBridgeTxStatus = ( - startPollingForBridgeTxStatusArgs: StartPollingForBridgeTxStatusArgs, + startPollingForBridgeTxStatusArgs: StartPollingForBridgeTxStatusArgsSerialized, ) => { return async (dispatch: MetaMaskReduxDispatch) => { return dispatch( - callBridgeStatusControllerMethod<[StartPollingForBridgeTxStatusArgs]>( - BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS, - [startPollingForBridgeTxStatusArgs], - ), + callBridgeStatusControllerMethod< + [StartPollingForBridgeTxStatusArgsSerialized] + >(BridgeStatusAction.START_POLLING_FOR_BRIDGE_TX_STATUS, [ + startPollingForBridgeTxStatusArgs, + ]), ); }; }; diff --git a/ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts b/ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts index dee7139a623f..1fb44fa4b2bc 100644 --- a/ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts +++ b/ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts @@ -137,7 +137,15 @@ export default function useSubmitBridgeTransaction() { startPollingForBridgeTxStatus({ bridgeTxMeta, statusRequest, - quoteResponse, + quoteResponse: { + ...quoteResponse, + sentAmount: { + amount: quoteResponse.sentAmount.amount.toString(), + valueInCurrency: quoteResponse.sentAmount.valueInCurrency + ? quoteResponse.sentAmount.valueInCurrency.toString() + : null, + }, + }, slippagePercentage: slippage ?? 0, startTime: bridgeTxMeta.time, }), From 7cf80a0630696c7474c6866f70ac7d8ec38e8934 Mon Sep 17 00:00:00 2001 From: IF <139582705+infiniteflower@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:14:20 -0500 Subject: [PATCH 2/3] fix: lint error --- app/scripts/controllers/bridge-status/mocks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scripts/controllers/bridge-status/mocks.ts b/app/scripts/controllers/bridge-status/mocks.ts index 1507af5830ec..0292fc7ecf9a 100644 --- a/app/scripts/controllers/bridge-status/mocks.ts +++ b/app/scripts/controllers/bridge-status/mocks.ts @@ -236,7 +236,7 @@ export const getMockStartPollingForBridgeTxStatusArgs = ({ }, approval: null, estimatedProcessingTimeInSeconds: 15, - sentAmount: { amount: '1.234', fiat: null }, + sentAmount: { amount: '1.234', valueInCurrency: null }, }, startTime: 1729964825189, slippagePercentage: 0, From e11652dc51a79e048a9da02814b87d9014aeb9f1 Mon Sep 17 00:00:00 2001 From: IF <139582705+infiniteflower@users.noreply.github.com> Date: Fri, 10 Jan 2025 11:44:31 -0500 Subject: [PATCH 3/3] fix: broken tests --- test/data/bridge/dummy-quotes.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/data/bridge/dummy-quotes.ts b/test/data/bridge/dummy-quotes.ts index 3328960a9b73..8b3e907d7df2 100644 --- a/test/data/bridge/dummy-quotes.ts +++ b/test/data/bridge/dummy-quotes.ts @@ -1,6 +1,10 @@ export const DummyQuotesNoApproval = { OP_0_005_ETH_TO_ARB: [ { + sentAmount: { + amount: '0.005', + valueInCurrency: null, + }, quote: { requestId: 'be448070-7849-4d14-bb35-8dcdaf7a4d69', srcChainId: 10, @@ -392,6 +396,10 @@ export const DummyQuotesNoApproval = { export const DummyQuotesWithApproval = { ETH_11_USDC_TO_ARB: [ { + sentAmount: { + amount: '1.0903750', + valueInCurrency: null, + }, quote: { requestId: '0cd5caf6-9844-465b-89ad-9c89b639f432', srcChainId: 1, @@ -812,6 +820,10 @@ export const DummyQuotesWithApproval = { ], ARB_11_USDC_TO_ETH: [ { + sentAmount: { + amount: '1.0903750', + valueInCurrency: null, + }, quote: { requestId: 'edbef62a-d3e6-4b33-aad5-9cdb81f85f53', srcChainId: 42161, @@ -911,6 +923,10 @@ export const DummyQuotesWithApproval = { ], ARB_11_USDC_TO_OP: [ { + sentAmount: { + amount: '1.0903750', + valueInCurrency: null, + }, quote: { requestId: 'dc63e7e6-dc9b-4aa8-80bb-714192ecd801', srcChainId: 42161, @@ -2461,6 +2477,10 @@ export const DummyQuotesWithApproval = { ], OP_11_USDC_TO_ARB: [ { + sentAmount: { + amount: '1.1000000', + valueInCurrency: null, + }, quote: { requestId: '01fa78fd-ed49-42b3-ab0e-94c7108feea9', srcChainId: 10,