Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crashing after bridge tx in Firefox #29631

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/scripts/controllers/bridge-status/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions shared/types/bridge-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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'
Expand Down
13 changes: 7 additions & 6 deletions ui/ducks/bridge-status/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
StartPollingForBridgeTxStatusArgs,
BridgeStatusAction,
StartPollingForBridgeTxStatusArgsSerialized,
} from '../../../shared/types/bridge-status';
import { forceUpdateMetamaskState } from '../../store/actions';
import { submitRequestToBackground } from '../../store/background-connection';
Expand All @@ -17,14 +17,15 @@ const callBridgeStatusControllerMethod = <T extends unknown[]>(
};

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,
]),
);
};
};
10 changes: 9 additions & 1 deletion ui/pages/bridge/hooks/useSubmitBridgeTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
Loading