diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index ad97318224..c9a45b83d1 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -37,6 +37,7 @@ interface TransferDomainSigner { dvmAddress: string; evmAddress: string; provider: providers.JsonRpcProvider; + chainId?: number; networkName: NetworkName; } @@ -48,6 +49,7 @@ export async function transferDomainSigner({ convertDirection, dvmAddress, evmAddress, + chainId, provider, networkName, }: TransferDomainSigner): Promise { @@ -75,6 +77,7 @@ export async function transferDomainSigner({ accountEvmAddress: await account.getEvmAddress(), privateKey: await account.privateKey(), provider, + chainId, }); const transferDomain: TransferDomain = { @@ -110,17 +113,29 @@ export async function transferDomainSigner({ return new CTransactionSegWit(signed); } -export function transferDomainCrafter( - amount: BigNumber, - convertDirection: ConvertDirection, - sourceToken: TransferDomainToken, - targetToken: TransferDomainToken, - networkName: NetworkName, - onBroadcast: () => any, - onConfirmation: () => void, - provider: providers.JsonRpcProvider, - submitButtonLabel?: string, -): DfTxSigner { +export function transferDomainCrafter({ + amount, + convertDirection, + sourceToken, + targetToken, + networkName, + onBroadcast, + onConfirmation, + chainId, + provider, + submitButtonLabel, +}: { + amount: BigNumber; + convertDirection: ConvertDirection; + sourceToken: TransferDomainToken; + targetToken: TransferDomainToken; + networkName: NetworkName; + onBroadcast: () => any; + onConfirmation: () => void; + chainId?: number; + provider: providers.JsonRpcProvider; + submitButtonLabel?: string; +}): DfTxSigner { if ( ![ConvertDirection.evmToDvm, ConvertDirection.dvmToEvm].includes( convertDirection, @@ -144,6 +159,7 @@ export function transferDomainCrafter( sourceTokenId: sourceToken.tokenId, targetTokenId: targetToken.tokenId, dvmAddress: await account.getAddress(), + chainId, provider, evmAddress: await account.getEvmAddress(), }), @@ -196,6 +212,7 @@ interface EvmTxSigner { accountEvmAddress: string; privateKey: Buffer; provider: providers.JsonRpcProvider; + chainId?: number; } async function createSignedEvmTx({ @@ -208,6 +225,7 @@ async function createSignedEvmTx({ accountEvmAddress, privateKey, provider, + chainId, }: EvmTxSigner): Promise { let data; const tdFace = new utils.Interface(TransferDomainV1.abi); @@ -234,7 +252,7 @@ async function createSignedEvmTx({ const tx: providers.TransactionRequest = { to: TD_CONTRACT_ADDR, nonce: await provider.getTransactionCount(accountEvmAddress), - chainId: (await provider.getNetwork()).chainId, + chainId, data: data, value: 0, gasLimit: 0, diff --git a/mobile-app/app/contexts/EVMProvider.tsx b/mobile-app/app/contexts/EVMProvider.tsx index 7ab54bc47d..7216ac2445 100644 --- a/mobile-app/app/contexts/EVMProvider.tsx +++ b/mobile-app/app/contexts/EVMProvider.tsx @@ -1,10 +1,11 @@ -import React, { createContext, useContext, useMemo } from "react"; +import React, { createContext, useContext, useMemo, useState } from "react"; import { providers } from "ethers"; import { useNetworkContext } from "@waveshq/walletkit-ui"; import { getEthRpcUrl } from "@store/evm"; interface EVMProviderContextI { provider: providers.JsonRpcProvider; + chainId?: number; } const EVMProviderContext = createContext(undefined as any); @@ -16,11 +17,20 @@ export function EVMProvider({ children, }: React.PropsWithChildren): JSX.Element | null { const { network } = useNetworkContext(); + const [chainId, setChainId] = useState(); + + const getProvider = () => { + const provider = new providers.JsonRpcProvider(getEthRpcUrl(network)); + provider.getNetwork().then(({ chainId }) => setChainId(chainId)); + return provider; + }; + const client = useMemo( () => ({ - provider: new providers.JsonRpcProvider(getEthRpcUrl(network)), + provider: getProvider(), + chainId, }), - [network], + [network, chainId], ); return ( 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 ba85176dbb..9788377a42 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -50,7 +50,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { } = route.params; const { networkName } = useNetworkContext(); const { address } = useWalletContext(); - const { provider } = useEVMProvider(); + const { provider, chainId } = useEVMProvider(); const addressLabel = useAddressLabel(address); const hasPendingJob = useSelector((state: RootState) => hasTxQueued(state.transactionQueue), @@ -131,6 +131,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { targetToken, networkName, provider, + chainId, }, dispatch, () => { @@ -347,6 +348,7 @@ async function constructSignedTransferDomain( targetToken, networkName, provider, + chainId, }: { convertDirection: ConvertDirection; sourceToken: TransferDomainToken; @@ -354,6 +356,7 @@ async function constructSignedTransferDomain( amount: BigNumber; networkName: NetworkName; provider: providers.JsonRpcProvider; + chainId?: number; }, dispatch: Dispatch, onBroadcast: () => void, @@ -362,16 +365,17 @@ async function constructSignedTransferDomain( try { dispatch( transactionQueue.actions.push( - transferDomainCrafter( + transferDomainCrafter({ amount, convertDirection, sourceToken, targetToken, networkName, onBroadcast, - () => {}, + onConfirmation: () => {}, + chainId, provider, - ), + }), ), ); } catch (e) { 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 d25f01b00a..e27f091670 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -81,7 +81,7 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { hasOceanTXQueued(state.ocean), ); const dispatch = useAppDispatch(); - const { provider } = useEVMProvider(); + const { provider, chainId } = useEVMProvider(); const [isSubmitting, setIsSubmitting] = useState(false); const navigation = useNavigation>(); const [isOnPage, setIsOnPage] = useState(true); @@ -108,6 +108,7 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { amount, domain, provider, + chainId, networkName: network.networkName, }, dispatch, @@ -362,11 +363,12 @@ interface SendForm { token: WalletToken; domain: DomainType; provider: providers.JsonRpcProvider; + chainId?: number; networkName: NetworkName; } async function send( - { address, token, amount, domain, networkName, provider }: SendForm, + { address, token, amount, domain, networkName, provider, chainId }: SendForm, dispatch: Dispatch, onBroadcast: () => void, logger: NativeLoggingProps, @@ -413,6 +415,7 @@ async function send( evmAddress, networkName, provider, + chainId, convertDirection: sendDirection, }); }