Skip to content

Commit

Permalink
Use getNetworkNativeAsset in SignTransactionSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Oct 18, 2024
1 parent 67e7b09 commit e120c16
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 21 deletions.
23 changes: 3 additions & 20 deletions src/screens/SignTransactionSheet.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -108,30 +107,14 @@ export const SignTransactionSheet = () => {
const addressToUse = specifiedAddress ?? accountAddress;

const provider = getProvider({ chainId });
const [nativeAsset, setNativeAsset] = useState<ParsedAddressAsset | null>(null);
const nativeAsset = ethereumUtils.getNetworkNativeAsset({ chainId });

const isMessageRequest = isMessageDisplayType(transactionDetails.payload.method);
const isPersonalSignRequest = isPersonalSign(transactionDetails.payload.method);

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);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ethereumUtils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit e120c16

Please sign in to comment.