Skip to content

Commit

Permalink
fix(core): skip eth provider for transfer domain
Browse files Browse the repository at this point in the history
  • Loading branch information
lykalabrada committed Oct 23, 2023
1 parent 5a5fb80 commit 2cebf4d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
25 changes: 13 additions & 12 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -36,9 +38,7 @@ interface TransferDomainSigner {
convertDirection: ConvertDirection;
dvmAddress: string;
evmAddress: string;
chainId?: number;
networkName: NetworkName;
nonce: number;
}

export async function transferDomainSigner({
Expand All @@ -49,9 +49,7 @@ export async function transferDomainSigner({
convertDirection,
dvmAddress,
evmAddress,
chainId,
networkName,
nonce,
}: TransferDomainSigner): Promise<CTransactionSegWit> {
const dvmScript = fromAddress(dvmAddress, networkName)?.script as Script;
const evmScript = Eth.fromAddress(evmAddress) as Script;
Expand All @@ -67,15 +65,24 @@ 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(),
targetTokenId: stripEvmSuffixFromTokenId(targetTokenId).toString(),
amount,
dvmAddress,
evmAddress,
accountEvmAddress: await account.getEvmAddress(),
privateKey: await account.privateKey(),
accountEvmAddress,
privateKey,
chainId,
nonce,
});
Expand Down Expand Up @@ -152,11 +159,9 @@ export function transferDomainCrafter({
networkName,
onBroadcast,
onConfirmation,
chainId,
submitButtonLabel,
dvmAddress,
evmAddress,
nonce,
}: {
amount: BigNumber;
convertDirection: ConvertDirection;
Expand All @@ -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(
Expand Down Expand Up @@ -201,8 +204,6 @@ export function transferDomainCrafter({
targetTokenId: targetToken.tokenId,
dvmAddress,
evmAddress,
chainId,
nonce,
}),
title: translate(
"screens/ConvertConfirmScreen",
Expand Down
2 changes: 1 addition & 1 deletion mobile-app/app/contexts/CustomServiceProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PortfolioParamList, "SendConfirmationScreen">;
Expand Down Expand Up @@ -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<NavigationProp<PortfolioParamList>>();
const [isOnPage, setIsOnPage] = useState<boolean>(true);
Expand All @@ -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,
Expand Down Expand Up @@ -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<any>,
onBroadcast: () => void,
logger: NativeLoggingProps,
Expand Down Expand Up @@ -424,8 +417,6 @@ async function send(
dvmAddress,
evmAddress,
networkName,
nonce,
chainId,
convertDirection: sendDirection,
});
}
Expand Down

0 comments on commit 2cebf4d

Please sign in to comment.