Skip to content

Commit

Permalink
fix: crashing after bridge tx in Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Jan 10, 2025
1 parent 3ff4aba commit cdca73e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
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

0 comments on commit cdca73e

Please sign in to comment.