Skip to content

Commit

Permalink
added nonce in td request
Browse files Browse the repository at this point in the history
  • Loading branch information
fullstackninja864 committed Oct 12, 2023
1 parent 9dd7f72 commit edf6f5a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
27 changes: 15 additions & 12 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ interface TransferDomainSigner {
convertDirection: ConvertDirection;
dvmAddress: string;
evmAddress: string;
provider: providers.JsonRpcProvider;
chainId?: number;
networkName: NetworkName;
nonce: number;
}

export async function transferDomainSigner({
Expand All @@ -50,8 +50,8 @@ export async function transferDomainSigner({
dvmAddress,
evmAddress,
chainId,
provider,
networkName,
nonce,
}: TransferDomainSigner): Promise<CTransactionSegWit> {
const dvmScript = fromAddress(dvmAddress, networkName)?.script as Script;
const evmScript = Eth.fromAddress(evmAddress) as Script;
Expand All @@ -76,8 +76,8 @@ export async function transferDomainSigner({
evmAddress,
accountEvmAddress: await account.getEvmAddress(),
privateKey: await account.privateKey(),
provider,
chainId,
nonce,
});

const transferDomain: TransferDomain = {
Expand Down Expand Up @@ -122,8 +122,10 @@ export function transferDomainCrafter({
onBroadcast,
onConfirmation,
chainId,
provider,
submitButtonLabel,
dvmAddress,
evmAddress,
nonce,
}: {
amount: BigNumber;
convertDirection: ConvertDirection;
Expand All @@ -133,8 +135,10 @@ export function transferDomainCrafter({
onBroadcast: () => any;
onConfirmation: () => void;
chainId?: number;
provider: providers.JsonRpcProvider;
submitButtonLabel?: string;
dvmAddress: string;
evmAddress: string;
nonce: number;
}): DfTxSigner {
if (
![ConvertDirection.evmToDvm, ConvertDirection.dvmToEvm].includes(
Expand All @@ -158,10 +162,10 @@ export function transferDomainCrafter({
networkName,
sourceTokenId: sourceToken.tokenId,
targetTokenId: targetToken.tokenId,
dvmAddress: await account.getAddress(),
dvmAddress,
evmAddress,
chainId,
provider,
evmAddress: await account.getEvmAddress(),
nonce,
}),
title: translate(
"screens/ConvertConfirmScreen",
Expand Down Expand Up @@ -211,8 +215,8 @@ interface EvmTxSigner {
evmAddress: string;
accountEvmAddress: string;
privateKey: Buffer;
provider: providers.JsonRpcProvider;
chainId?: number;
nonce: number;
}

async function createSignedEvmTx({
Expand All @@ -222,10 +226,9 @@ async function createSignedEvmTx({
amount,
dvmAddress,
evmAddress,
accountEvmAddress,
privateKey,
provider,
chainId,
nonce,
}: EvmTxSigner): Promise<Uint8Array> {
let data;
const tdFace = new utils.Interface(TransferDomainV1.abi);
Expand All @@ -251,7 +254,7 @@ async function createSignedEvmTx({
/* TODO: Figure out CORS issue when using the ethRpc */
const tx: providers.TransactionRequest = {
to: TD_CONTRACT_ADDR,
nonce: await provider.getTransactionCount(accountEvmAddress),
nonce,
chainId,
data: data,
value: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
} from "@api/transaction/transfer_domain";
import { useNetworkContext } from "@waveshq/walletkit-ui";
import { NetworkName } from "@defichain/jellyfish-network";
import { providers } from "ethers";
import { useEVMProvider } from "@contexts/EVMProvider";
import { PortfolioParamList } from "../PortfolioNavigator";

Expand All @@ -49,7 +48,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element {
originScreen,
} = route.params;
const { networkName } = useNetworkContext();
const { address } = useWalletContext();
const { address, evmAddress } = useWalletContext();
const { provider, chainId } = useEVMProvider();
const addressLabel = useAddressLabel(address);
const hasPendingJob = useSelector((state: RootState) =>
Expand Down Expand Up @@ -123,15 +122,18 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element {
logger,
);
} else {
const nonce = await provider.getTransactionCount(evmAddress);
await constructSignedTransferDomain(
{
amount,
convertDirection,
sourceToken,
targetToken,
networkName,
provider,
chainId,
nonce,
evmAddress,
dvmAddress: address,
},
dispatch,
() => {
Expand Down Expand Up @@ -347,16 +349,20 @@ async function constructSignedTransferDomain(
sourceToken,
targetToken,
networkName,
provider,
chainId,
dvmAddress,
evmAddress,
nonce,
}: {
convertDirection: ConvertDirection;
sourceToken: TransferDomainToken;
targetToken: TransferDomainToken;
amount: BigNumber;
networkName: NetworkName;
provider: providers.JsonRpcProvider;
chainId?: number;
dvmAddress: string;
evmAddress: string;
nonce: number;
},
dispatch: Dispatch<any>,
onBroadcast: () => void,
Expand All @@ -374,7 +380,9 @@ async function constructSignedTransferDomain(
onBroadcast,
onConfirmation: () => {},
chainId,
provider,
dvmAddress,
evmAddress,
nonce,
}),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,13 @@ import {
} from "@waveshq/walletkit-core";
import { DomainType, useDomainContext } from "@contexts/DomainContext";
import { useEVMProvider } from "@contexts/EVMProvider";
import { providers } from "ethers";
import { PortfolioParamList } from "../PortfolioNavigator";

type Props = StackScreenProps<PortfolioParamList, "SendConfirmationScreen">;

export function SendConfirmationScreen({ route }: Props): JSX.Element {
const { domain } = useDomainContext();
const { address } = useWalletContext();
const { address, evmAddress } = useWalletContext();
const addressLabel = useAddressLabel(address);
const network = useNetworkContext();
const {
Expand Down Expand Up @@ -101,14 +100,15 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element {
return;
}
setIsSubmitting(true);
const nonce = await provider.getTransactionCount(evmAddress);
await send(
{
address: destination,
token,
amount,
domain,
provider,
chainId,
nonce,
networkName: network.networkName,
},
dispatch,
Expand Down Expand Up @@ -362,13 +362,13 @@ interface SendForm {
address: string;
token: WalletToken;
domain: DomainType;
provider: providers.JsonRpcProvider;
nonce: number;
chainId?: number;
networkName: NetworkName;
}

async function send(
{ address, token, amount, domain, networkName, provider, chainId }: SendForm,
{ address, token, amount, domain, networkName, nonce, chainId }: SendForm,
dispatch: Dispatch<any>,
onBroadcast: () => void,
logger: NativeLoggingProps,
Expand Down Expand Up @@ -414,7 +414,7 @@ async function send(
dvmAddress,
evmAddress,
networkName,
provider,
nonce,
chainId,
convertDirection: sendDirection,
});
Expand Down

0 comments on commit edf6f5a

Please sign in to comment.