From 2cebf4d6a1ff54503aa8a977ea372ad0de48e86f Mon Sep 17 00:00:00 2001 From: Lyka Labrada Date: Mon, 23 Oct 2023 10:01:11 +0800 Subject: [PATCH 1/2] fix(core): skip eth provider for transfer domain --- .../app/api/transaction/transfer_domain.ts | 25 ++++++++++--------- .../app/contexts/CustomServiceProvider.tsx | 2 +- .../screens/SendConfirmationScreen.tsx | 11 +------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index c5ed0e4409..277b3f79d8 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -13,6 +13,8 @@ import { fromAddress, Eth } from "@defichain/jellyfish-address"; import { NetworkName } from "@defichain/jellyfish-network"; import { ConvertDirection } from "@screens/enum"; import TransferDomainV1 from "@shared-contracts/TransferDomainV1.json"; +import { getEthRpcUrl } from "@contexts/CustomServiceProvider"; +import { SecuredStoreAPI } from "@api/secured"; const TD_CONTRACT_ADDR = "0xdf00000000000000000000000000000000000001"; @@ -36,9 +38,7 @@ interface TransferDomainSigner { convertDirection: ConvertDirection; dvmAddress: string; evmAddress: string; - chainId?: number; networkName: NetworkName; - nonce: number; } export async function transferDomainSigner({ @@ -49,9 +49,7 @@ export async function transferDomainSigner({ convertDirection, dvmAddress, evmAddress, - chainId, networkName, - nonce, }: TransferDomainSigner): Promise { const dvmScript = fromAddress(dvmAddress, networkName)?.script as Script; const evmScript = Eth.fromAddress(evmAddress) as Script; @@ -67,6 +65,15 @@ export async function transferDomainSigner({ ? [TRANSFER_DOMAIN_TYPE.EVM, TRANSFER_DOMAIN_TYPE.DVM] : [TRANSFER_DOMAIN_TYPE.DVM, TRANSFER_DOMAIN_TYPE.EVM]; + const privateKey = await account.privateKey(); + const accountEvmAddress = await account.getEvmAddress(); + + // TODO (lyka): Check android issue with null eth provider + const network = await SecuredStoreAPI.getNetwork(); + const ethRpc = new providers.JsonRpcProvider(getEthRpcUrl(network)); + const nonce = await ethRpc.getTransactionCount(accountEvmAddress); + const chainId = (await ethRpc.getNetwork()).chainId; + const signedEvmTxData = await createSignedEvmTx({ isEvmToDvm, sourceTokenId: stripEvmSuffixFromTokenId(sourceTokenId).toString(), @@ -74,8 +81,8 @@ export async function transferDomainSigner({ amount, dvmAddress, evmAddress, - accountEvmAddress: await account.getEvmAddress(), - privateKey: await account.privateKey(), + accountEvmAddress, + privateKey, chainId, nonce, }); @@ -152,11 +159,9 @@ export function transferDomainCrafter({ networkName, onBroadcast, onConfirmation, - chainId, submitButtonLabel, dvmAddress, evmAddress, - nonce, }: { amount: BigNumber; convertDirection: ConvertDirection; @@ -165,11 +170,9 @@ export function transferDomainCrafter({ networkName: NetworkName; onBroadcast: () => any; onConfirmation: () => void; - chainId?: number; submitButtonLabel?: string; dvmAddress: string; evmAddress: string; - nonce: number; }): DfTxSigner { if ( ![ConvertDirection.evmToDvm, ConvertDirection.dvmToEvm].includes( @@ -201,8 +204,6 @@ export function transferDomainCrafter({ targetTokenId: targetToken.tokenId, dvmAddress, evmAddress, - chainId, - nonce, }), title: translate( "screens/ConvertConfirmScreen", diff --git a/mobile-app/app/contexts/CustomServiceProvider.tsx b/mobile-app/app/contexts/CustomServiceProvider.tsx index fecf28aa72..9a085b9fb4 100644 --- a/mobile-app/app/contexts/CustomServiceProvider.tsx +++ b/mobile-app/app/contexts/CustomServiceProvider.tsx @@ -102,7 +102,7 @@ function getBlockscoutUrl(network: EnvironmentNetwork) { } } -function getEthRpcUrl(network: EnvironmentNetwork) { +export function getEthRpcUrl(network: EnvironmentNetwork) { // TODO: Add proper ethereum RPC URLs for each network switch (network) { case EnvironmentNetwork.LocalPlayground: diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx index e2ecddfc61..144cecee2b 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -50,7 +50,6 @@ import { AddressType as JellyfishAddressType, } from "@waveshq/walletkit-core"; import { DomainType, useDomainContext } from "@contexts/DomainContext"; -import { useEVMProvider } from "@contexts/EVMProvider"; import { PortfolioParamList } from "../PortfolioNavigator"; type Props = StackScreenProps; @@ -81,7 +80,6 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { hasOceanTXQueued(state.ocean), ); const dispatch = useAppDispatch(); - const { provider, chainId } = useEVMProvider(); const [isSubmitting, setIsSubmitting] = useState(false); const navigation = useNavigation>(); const [isOnPage, setIsOnPage] = useState(true); @@ -101,15 +99,12 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { return; } setIsSubmitting(true); - const nonce = provider ? await provider.getTransactionCount(evmAddress) : 0; await send( { address: destination, token, amount, domain, - chainId, - nonce, networkName: network.networkName, }, dispatch, @@ -364,13 +359,11 @@ interface SendForm { address: string; token: WalletToken; domain: DomainType; - nonce: number; - chainId?: number; networkName: NetworkName; } async function send( - { address, token, amount, domain, networkName, nonce, chainId }: SendForm, + { address, token, amount, domain, networkName }: SendForm, dispatch: Dispatch, onBroadcast: () => void, logger: NativeLoggingProps, @@ -424,8 +417,6 @@ async function send( dvmAddress, evmAddress, networkName, - nonce, - chainId, convertDirection: sendDirection, }); } From e515785c5d8153d4f5537b1144f5068d6ae5c142 Mon Sep 17 00:00:00 2001 From: Lyka Labrada Date: Mon, 23 Oct 2023 10:16:21 +0800 Subject: [PATCH 2/2] fix lint error --- .../Portfolio/screens/ConvertConfirmationScreen.tsx | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx index b4cba246ab..1ece2dc920 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -33,7 +33,6 @@ import { } from "@api/transaction/transfer_domain"; import { useNetworkContext } from "@waveshq/walletkit-ui"; import { NetworkName } from "@defichain/jellyfish-network"; -import { useEVMProvider } from "@contexts/EVMProvider"; import { PortfolioParamList } from "../PortfolioNavigator"; type Props = StackScreenProps; @@ -49,7 +48,6 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { } = route.params; const { networkName } = useNetworkContext(); const { address, evmAddress } = useWalletContext(); - const { provider, chainId } = useEVMProvider(); const addressLabel = useAddressLabel(address); const hasPendingJob = useSelector((state: RootState) => hasTxQueued(state.transactionQueue), @@ -122,9 +120,6 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { logger, ); } else { - const nonce = provider - ? await provider.getTransactionCount(evmAddress) - : 0; await constructSignedTransferDomain( { amount, @@ -132,8 +127,6 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { sourceToken, targetToken, networkName, - chainId, - nonce, evmAddress, dvmAddress: address, }, @@ -355,20 +348,16 @@ async function constructSignedTransferDomain( sourceToken, targetToken, networkName, - chainId, dvmAddress, evmAddress, - nonce, }: { convertDirection: ConvertDirection; sourceToken: TransferDomainToken; targetToken: TransferDomainToken; amount: BigNumber; networkName: NetworkName; - chainId?: number; dvmAddress: string; evmAddress: string; - nonce: number; }, dispatch: Dispatch, onBroadcast: () => void, @@ -385,10 +374,8 @@ async function constructSignedTransferDomain( networkName, onBroadcast, onConfirmation: () => {}, - chainId, dvmAddress, evmAddress, - nonce, }), ), );