Skip to content

Commit

Permalink
chore: add dec to prefixed hex and consume
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteflower committed Nov 22, 2024
1 parent 0cd08cb commit 8fc0d07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 7 additions & 13 deletions app/scripts/controllers/bridge-status/bridge-status-controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { StateMetadata } from '@metamask/base-controller';
import { StaticIntervalPollingController } from '@metamask/polling-controller';
import { Hex } from '@metamask/utils';
import { Numeric } from '../../../../shared/modules/Numeric';
// eslint-disable-next-line import/no-restricted-paths
import {
StartPollingForBridgeTxStatusArgs,
StatusRequest,
StatusTypes,
BridgeStatusControllerState,
} from '../../../../shared/types/bridge-status';
import { decimalToPrefixedHex } from '../../../../shared/modules/conversion.utils';
import {
BRIDGE_STATUS_CONTROLLER_NAME,
DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE,
Expand Down Expand Up @@ -143,9 +143,7 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
refuel: Boolean(historyItem.quote.refuel),
};

const hexSourceChainId = new Numeric(statusRequest.srcChainId, 10)
.toPrefixedHexString()
.toLowerCase() as `0x${string}`;
const hexSourceChainId = decimalToPrefixedHex(statusRequest.srcChainId);
const networkClientId = this.messagingSystem.call(
'NetworkController:findNetworkClientIdByChainId',
hexSourceChainId,
Expand All @@ -171,9 +169,7 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
initialDestAssetBalance,
targetContractAddress,
} = startPollingForBridgeTxStatusArgs;
const hexSourceChainId = new Numeric(statusRequest.srcChainId, 10)
.toPrefixedHexString()
.toLowerCase() as `0x${string}`;
const hexSourceChainId = decimalToPrefixedHex(statusRequest.srcChainId);

const { bridgeStatusState } = this.state;
const { address: account } = this.#getSelectedAccount();
Expand Down Expand Up @@ -277,14 +273,12 @@ export default class BridgeStatusController extends StaticIntervalPollingControl
const bridgeHistoryItem =
this.state.bridgeStatusState.txHistory[sourceTxHash];

const hexSourceChainId = new Numeric(
const hexSourceChainId = decimalToPrefixedHex(
bridgeHistoryItem.quote.srcChainId,
10,
).toPrefixedHexString() as `0x${string}`;
const hexDestChainId = new Numeric(
);
const hexDestChainId = decimalToPrefixedHex(
bridgeHistoryItem.quote.destChainId,
10,
).toPrefixedHexString() as `0x${string}`;
);

return (
bridgeHistoryItem.account === address &&
Expand Down
6 changes: 6 additions & 0 deletions shared/modules/conversion.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ export function decimalToHex(decimal: number | string | BigNumber | BN) {
return new Numeric(decimal, 10).toBase(16).toString();
}

export function decimalToPrefixedHex(
decimal: number | string | BigNumber | BN,
): Hex {
return new Numeric(decimal, 10).toPrefixedHexString() as Hex;
}

export function hexToDecimal(hexValue: number | string | BigNumber | BN) {
return new Numeric(hexValue, 16).toBase(10).toString();
}

0 comments on commit 8fc0d07

Please sign in to comment.