From 8fc0d07ea4b4d1b5102f8a9fd58f186328b7bf22 Mon Sep 17 00:00:00 2001 From: IF <139582705+infiniteflower@users.noreply.github.com> Date: Fri, 22 Nov 2024 13:44:46 -0500 Subject: [PATCH] chore: add dec to prefixed hex and consume --- .../bridge-status/bridge-status-controller.ts | 20 +++++++------------ shared/modules/conversion.utils.ts | 6 ++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/scripts/controllers/bridge-status/bridge-status-controller.ts b/app/scripts/controllers/bridge-status/bridge-status-controller.ts index 502077543c5d..18010ae0de3d 100644 --- a/app/scripts/controllers/bridge-status/bridge-status-controller.ts +++ b/app/scripts/controllers/bridge-status/bridge-status-controller.ts @@ -1,7 +1,6 @@ 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, @@ -9,6 +8,7 @@ import { StatusTypes, BridgeStatusControllerState, } from '../../../../shared/types/bridge-status'; +import { decimalToPrefixedHex } from '../../../../shared/modules/conversion.utils'; import { BRIDGE_STATUS_CONTROLLER_NAME, DEFAULT_BRIDGE_STATUS_CONTROLLER_STATE, @@ -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, @@ -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(); @@ -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 && diff --git a/shared/modules/conversion.utils.ts b/shared/modules/conversion.utils.ts index 75da336eb8e6..9e24a8427cce 100644 --- a/shared/modules/conversion.utils.ts +++ b/shared/modules/conversion.utils.ts @@ -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(); }