From e120c1698eda825b64bc93bbbfe2cbc86381d53d Mon Sep 17 00:00:00 2001 From: jinchung Date: Thu, 17 Oct 2024 12:03:29 -0400 Subject: [PATCH] Use getNetworkNativeAsset in SignTransactionSheet --- src/screens/SignTransactionSheet.tsx | 23 +++-------------------- src/utils/ethereumUtils.ts | 2 +- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/screens/SignTransactionSheet.tsx b/src/screens/SignTransactionSheet.tsx index 4cd27255b32..b81f5f92afe 100644 --- a/src/screens/SignTransactionSheet.tsx +++ b/src/screens/SignTransactionSheet.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useMemo } from 'react'; import { AnimatePresence, MotiView } from 'moti'; import * as i18n from '@/languages'; import { Image, InteractionManager, PixelRatio, ScrollView } from 'react-native'; @@ -8,7 +8,7 @@ import { Transaction } from '@ethersproject/transactions'; import { ChainImage } from '@/components/coin-icon/ChainImage'; import { SheetActionButton } from '@/components/sheet'; import { Bleed, Box, Columns, Inline, Inset, Stack, Text, globalColors, useBackgroundColor, useForegroundColor } from '@/design-system'; -import { NewTransaction, ParsedAddressAsset, TransactionStatus } from '@/entities'; +import { NewTransaction, TransactionStatus } from '@/entities'; import { useNavigation } from '@/navigation'; import { useTheme } from '@/theme'; @@ -42,7 +42,6 @@ import { parseGasParamsForTransaction } from '@/parsers/gas'; import { loadWallet, sendTransaction, signPersonalMessage, signTransaction, signTypedDataMessage } from '@/model/wallet'; import { analyticsV2 as analytics } from '@/analytics'; -import { getOnchainAssetBalance } from '@/handlers/assets'; import { maybeSignUri } from '@/handlers/imgix'; import { isAddress } from '@ethersproject/address'; import { hexToNumber, isHex } from 'viem'; @@ -108,7 +107,7 @@ export const SignTransactionSheet = () => { const addressToUse = specifiedAddress ?? accountAddress; const provider = getProvider({ chainId }); - const [nativeAsset, setNativeAsset] = useState(null); + const nativeAsset = ethereumUtils.getNetworkNativeAsset({ chainId }); const isMessageRequest = isMessageDisplayType(transactionDetails.payload.method); const isPersonalSignRequest = isPersonalSign(transactionDetails.payload.method); @@ -116,22 +115,6 @@ export const SignTransactionSheet = () => { const label = useForegroundColor('label'); const surfacePrimary = useBackgroundColor('surfacePrimary'); - useEffect(() => { - const fetchNativeAsset = async () => { - const asset = await ethereumUtils.getNativeAssetForNetwork({ chainId, address: addressToUse }); - if (asset) { - const balance = await getOnchainAssetBalance(asset, addressToUse, chainId, provider); - if (balance) { - const assetWithOnchainBalance: ParsedAddressAsset = { ...asset, balance }; - setNativeAsset(assetWithOnchainBalance); - } else { - setNativeAsset(asset); - } - } - }; - fetchNativeAsset(); - }, [addressToUse, chainId, provider]); - const formattedDappUrl = useMemo(() => { try { const { hostname } = new URL(transactionDetails?.dappUrl); diff --git a/src/utils/ethereumUtils.ts b/src/utils/ethereumUtils.ts index 89549ce63f2..0998a83fb8d 100644 --- a/src/utils/ethereumUtils.ts +++ b/src/utils/ethereumUtils.ts @@ -1,5 +1,5 @@ import { BigNumberish } from '@ethersproject/bignumber'; -import { Provider, StaticJsonRpcProvider, TransactionRequest } from '@ethersproject/providers'; +import { StaticJsonRpcProvider, TransactionRequest } from '@ethersproject/providers'; import { serialize } from '@ethersproject/transactions'; import { RainbowAddressAssets } from '@/resources/assets/types'; import { userAssetsQueryKey } from '@/resources/assets/UserAssetsQuery';