From 8f18a7a1d4fce809625f6022f892a57aa086649b Mon Sep 17 00:00:00 2001 From: Jongsun Suh Date: Mon, 6 Jan 2025 13:11:42 -0500 Subject: [PATCH] Upstream type fixes --- app/scripts/controllers/swaps/swaps.types.ts | 10 ++++------ app/scripts/lib/ppom/ppom-middleware.ts | 2 +- shared/constants/multichain/assets.ts | 4 ++-- shared/modules/selectors/smart-transactions.ts | 4 +--- ui/helpers/utils/util.js | 6 ++++++ ui/pages/bridge/utils/quote.ts | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/scripts/controllers/swaps/swaps.types.ts b/app/scripts/controllers/swaps/swaps.types.ts index fca608629a8a..11ba9725f6b8 100644 --- a/app/scripts/controllers/swaps/swaps.types.ts +++ b/app/scripts/controllers/swaps/swaps.types.ts @@ -52,12 +52,10 @@ export type SwapsControllerState = { swapsStxGetTransactionsRefreshTime: number; swapsStxMaxFeeMultiplier: number; swapsFeatureFlags: - | ({ - smartTransactions?: Partial; - } & { - [networkName: string]: { smartTransactions?: Partial }; - }) - | Record; + | Partial + | { + [networkName: string]: Partial; + }; }; }; diff --git a/app/scripts/lib/ppom/ppom-middleware.ts b/app/scripts/lib/ppom/ppom-middleware.ts index f99cf675f534..d3d9fc7f7611 100644 --- a/app/scripts/lib/ppom/ppom-middleware.ts +++ b/app/scripts/lib/ppom/ppom-middleware.ts @@ -74,7 +74,7 @@ export function createPPOMMiddleware< const { chainId } = getProviderConfig({ - metamask: networkController.state, + metamask: { NetworkController: networkController.state }, }) ?? {}; if (!chainId) { return; diff --git a/shared/constants/multichain/assets.ts b/shared/constants/multichain/assets.ts index 58e0869ff045..c467687b6f1f 100644 --- a/shared/constants/multichain/assets.ts +++ b/shared/constants/multichain/assets.ts @@ -1,5 +1,5 @@ import { CaipAssetType } from '@metamask/keyring-api'; -import { MultichainNetworks } from './networks'; +import { MultichainNetworkIds, MultichainNetworks } from './networks'; export const MULTICHAIN_NATIVE_CURRENCY_TO_CAIP19 = { BTC: `${MultichainNetworks.BITCOIN}/slip44:0`, @@ -20,7 +20,7 @@ export enum MultichainNativeAssets { * Each network is mapped to an array containing its native asset for consistency. */ export const MULTICHAIN_NETWORK_TO_ASSET_TYPES: Record< - MultichainNetworks, + MultichainNetworkIds, CaipAssetType[] > = { [MultichainNetworks.SOLANA]: [MultichainNativeAssets.SOLANA], diff --git a/shared/modules/selectors/smart-transactions.ts b/shared/modules/selectors/smart-transactions.ts index 5487d2e86178..83437b1214de 100644 --- a/shared/modules/selectors/smart-transactions.ts +++ b/shared/modules/selectors/smart-transactions.ts @@ -47,7 +47,6 @@ export const getSmartTransactionsOptInStatusInternal = createSelector( * @returns true if the user has explicitly opted in, false if they have opted out, * or null if they have not explicitly opted in or out. */ -// @ts-expect-error TODO: Fix types for `getSmartTransactionsOptInStatusInternal` once `getPreferences is converted to TypeScript export const getSmartTransactionsOptInStatusForMetrics = createSelector( getSmartTransactionsOptInStatusInternal, (optInStatus: boolean): boolean => optInStatus, @@ -60,7 +59,6 @@ export const getSmartTransactionsOptInStatusForMetrics = createSelector( * @param state * @returns */ -// @ts-expect-error TODO: Fix types for `getSmartTransactionsOptInStatusInternal` once `getPreferences is converted to TypeScript export const getSmartTransactionsPreferenceEnabled = createSelector( getSmartTransactionsOptInStatusInternal, (optInStatus: boolean): boolean => { @@ -100,7 +98,7 @@ export const getSmartTransactionsEnabled = ( // TODO: Create a new proxy service only for MM feature flags. const smartTransactionsFeatureFlagEnabled = state.metamask.SwapsController.swapsState?.swapsFeatureFlags - ?.smartTransactions?.extensionActive; + ?.extensionActive; const smartTransactionsLiveness = state.metamask.SmartTransactionsController.smartTransactionsState?.liveness; return Boolean( diff --git a/ui/helpers/utils/util.js b/ui/helpers/utils/util.js index d687d9b82338..3c2e805d8b5b 100644 --- a/ui/helpers/utils/util.js +++ b/ui/helpers/utils/util.js @@ -299,6 +299,12 @@ export function shortenAddress(address = '') { }); } +/** + * + * @param {(import('@metamask/keyring-internal-api').InternalAccount | import('../../selectors/selectors.types').InternalAccountWithBalance)[]} accounts - The internal accounts list. + * @param {string} targetAddress + * @returns {import('@metamask/keyring-internal-api').InternalAccount | import('../../selectors/selectors.types').InternalAccountWithBalance | undefined} + */ export function getAccountByAddress(accounts = [], targetAddress) { return accounts.find(({ address }) => address === targetAddress); } diff --git a/ui/pages/bridge/utils/quote.ts b/ui/pages/bridge/utils/quote.ts index ee78e055698d..0ba821b121c9 100644 --- a/ui/pages/bridge/utils/quote.ts +++ b/ui/pages/bridge/utils/quote.ts @@ -95,7 +95,7 @@ const calcTotalGasFee = ({ bridgeQuote: QuoteResponse & L1GasFees; feePerGasInDecGwei: string; priorityFeePerGasInDecGwei: string; - nativeExchangeRate?: number; + nativeExchangeRate?: number | null; }) => { const { approval, trade, l1GasFeesInHexWei } = bridgeQuote; @@ -139,7 +139,7 @@ export const calcEstimatedAndMaxTotalGasFee = ({ estimatedBaseFeeInDecGwei: string; maxFeePerGasInDecGwei: string; maxPriorityFeePerGasInDecGwei: string; - nativeExchangeRate?: number; + nativeExchangeRate?: number | null; }) => { const { amount, valueInCurrency } = calcTotalGasFee({ bridgeQuote,