From 82cdf2287164333ec6bba97178c13b2e62c0e656 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 12 Oct 2023 13:30:27 +0530 Subject: [PATCH 01/12] refactore transferdomain provider --- mobile-app/app/api/transaction/transfer_domain.ts | 15 +++++++++------ .../screens/ConvertConfirmationScreen.tsx | 4 ++++ .../Portfolio/screens/SendConfirmationScreen.tsx | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index 96ae667d6a..ad97318224 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -12,8 +12,6 @@ import { fromAddress, Eth } from "@defichain/jellyfish-address"; import { NetworkName } from "@defichain/jellyfish-network"; import { ConvertDirection } from "@screens/enum"; import { parseUnits } from "ethers/lib/utils"; -import { getEthRpcUrl } from "@store/evm"; -import { SecuredStoreAPI } from "@api/secured"; import TransferDomainV1 from "@shared-contracts/TransferDomainV1.json"; const TD_CONTRACT_ADDR = "0xdf00000000000000000000000000000000000001"; @@ -38,6 +36,7 @@ interface TransferDomainSigner { convertDirection: ConvertDirection; dvmAddress: string; evmAddress: string; + provider: providers.JsonRpcProvider; networkName: NetworkName; } @@ -49,6 +48,7 @@ export async function transferDomainSigner({ convertDirection, dvmAddress, evmAddress, + provider, networkName, }: TransferDomainSigner): Promise { const dvmScript = fromAddress(dvmAddress, networkName)?.script as Script; @@ -74,6 +74,7 @@ export async function transferDomainSigner({ evmAddress, accountEvmAddress: await account.getEvmAddress(), privateKey: await account.privateKey(), + provider, }); const transferDomain: TransferDomain = { @@ -117,6 +118,7 @@ export function transferDomainCrafter( networkName: NetworkName, onBroadcast: () => any, onConfirmation: () => void, + provider: providers.JsonRpcProvider, submitButtonLabel?: string, ): DfTxSigner { if ( @@ -142,6 +144,7 @@ export function transferDomainCrafter( sourceTokenId: sourceToken.tokenId, targetTokenId: targetToken.tokenId, dvmAddress: await account.getAddress(), + provider, evmAddress: await account.getEvmAddress(), }), title: translate( @@ -192,6 +195,7 @@ interface EvmTxSigner { evmAddress: string; accountEvmAddress: string; privateKey: Buffer; + provider: providers.JsonRpcProvider; } async function createSignedEvmTx({ @@ -203,6 +207,7 @@ async function createSignedEvmTx({ evmAddress, accountEvmAddress, privateKey, + provider, }: EvmTxSigner): Promise { let data; const tdFace = new utils.Interface(TransferDomainV1.abi); @@ -223,15 +228,13 @@ async function createSignedEvmTx({ const transferDST20 = [contractAddress, from, to, parsedAmount, vmAddress]; data = tdFace.encodeFunctionData("transferDST20", transferDST20); } - const network = await SecuredStoreAPI.getNetwork(); - const ethRpc = new providers.JsonRpcProvider(getEthRpcUrl(network)); const wallet = new ethers.Wallet(privateKey); /* TODO: Figure out CORS issue when using the ethRpc */ const tx: providers.TransactionRequest = { to: TD_CONTRACT_ADDR, - nonce: await ethRpc.getTransactionCount(accountEvmAddress), - chainId: (await ethRpc.getNetwork()).chainId, + nonce: await provider.getTransactionCount(accountEvmAddress), + chainId: (await provider.getNetwork()).chainId, data: data, value: 0, gasLimit: 0, 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 f1a168083e..42285ab7b0 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -33,6 +33,7 @@ import { } from "@api/transaction/transfer_domain"; import { useNetworkContext } from "@waveshq/walletkit-ui"; import { NetworkName } from "@defichain/jellyfish-network"; +import { providers } from "ethers"; import { PortfolioParamList } from "../PortfolioNavigator"; type Props = StackScreenProps; @@ -342,12 +343,14 @@ async function constructSignedTransferDomain( sourceToken, targetToken, networkName, + provider, }: { convertDirection: ConvertDirection; sourceToken: TransferDomainToken; targetToken: TransferDomainToken; amount: BigNumber; networkName: NetworkName; + provider: providers.JsonRpcProvider; }, dispatch: Dispatch, onBroadcast: () => void, @@ -364,6 +367,7 @@ async function constructSignedTransferDomain( networkName, onBroadcast, () => {}, + provider, ), ), ); 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 e9097b515b..d25f01b00a 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -50,6 +50,8 @@ import { AddressType as JellyfishAddressType, } 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; @@ -79,6 +81,7 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { hasOceanTXQueued(state.ocean), ); const dispatch = useAppDispatch(); + const { provider } = useEVMProvider(); const [isSubmitting, setIsSubmitting] = useState(false); const navigation = useNavigation>(); const [isOnPage, setIsOnPage] = useState(true); @@ -104,6 +107,7 @@ export function SendConfirmationScreen({ route }: Props): JSX.Element { token, amount, domain, + provider, networkName: network.networkName, }, dispatch, @@ -357,11 +361,12 @@ interface SendForm { address: string; token: WalletToken; domain: DomainType; + provider: providers.JsonRpcProvider; networkName: NetworkName; } async function send( - { address, token, amount, domain, networkName }: SendForm, + { address, token, amount, domain, networkName, provider }: SendForm, dispatch: Dispatch, onBroadcast: () => void, logger: NativeLoggingProps, @@ -407,6 +412,7 @@ async function send( dvmAddress, evmAddress, networkName, + provider, convertDirection: sendDirection, }); } From 58b999c02a33a5bd2b90943389c28dbab4f69501 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 12 Oct 2023 13:33:15 +0530 Subject: [PATCH 02/12] fix(ui-ux): fixed icon for evm DFI on swap token listing --- .../screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx index e830eb6972..faf5634b07 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx @@ -32,6 +32,7 @@ export interface SelectionToken { name: string; displaySymbol: string; displayTextSymbol?: string; + domainType?: DomainType; symbol: string; isLPS?: boolean; }; @@ -228,7 +229,7 @@ function TokenItem({ displaySymbol: item.token.displaySymbol, }} size={36} - isEvmToken={isEvmDomain} + isEvmToken={isEvmDomain || item.token.domainType === DomainType.EVM} /> Date: Thu, 12 Oct 2023 14:58:01 +0530 Subject: [PATCH 03/12] fix convert screen provider issue --- .../screens/Portfolio/screens/ConvertConfirmationScreen.tsx | 3 +++ 1 file changed, 3 insertions(+) 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 42285ab7b0..ba85176dbb 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -34,6 +34,7 @@ import { 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"; type Props = StackScreenProps; @@ -49,6 +50,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { } = route.params; const { networkName } = useNetworkContext(); const { address } = useWalletContext(); + const { provider } = useEVMProvider(); const addressLabel = useAddressLabel(address); const hasPendingJob = useSelector((state: RootState) => hasTxQueued(state.transactionQueue), @@ -128,6 +130,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { sourceToken, targetToken, networkName, + provider, }, dispatch, () => { From 9dd7f725dd4d624203aa3e0b37af7ad6a62045f1 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 12 Oct 2023 16:00:17 +0530 Subject: [PATCH 04/12] added chainId in evm provider --- .../app/api/transaction/transfer_domain.ts | 42 +++++++++++++------ mobile-app/app/contexts/EVMProvider.tsx | 16 +++++-- .../screens/ConvertConfirmationScreen.tsx | 12 ++++-- .../screens/SendConfirmationScreen.tsx | 7 +++- 4 files changed, 56 insertions(+), 21 deletions(-) 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, }); } From edf6f5ac97ddffd342e71bf902adaaafc85437d0 Mon Sep 17 00:00:00 2001 From: Harsh Date: Thu, 12 Oct 2023 19:33:33 +0530 Subject: [PATCH 05/12] added nonce in td request --- .../app/api/transaction/transfer_domain.ts | 27 ++++++++++--------- .../screens/ConvertConfirmationScreen.tsx | 20 +++++++++----- .../screens/SendConfirmationScreen.tsx | 12 ++++----- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index c9a45b83d1..d93db2fd46 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -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({ @@ -50,8 +50,8 @@ export async function transferDomainSigner({ dvmAddress, evmAddress, chainId, - provider, networkName, + nonce, }: TransferDomainSigner): Promise { const dvmScript = fromAddress(dvmAddress, networkName)?.script as Script; const evmScript = Eth.fromAddress(evmAddress) as Script; @@ -76,8 +76,8 @@ export async function transferDomainSigner({ evmAddress, accountEvmAddress: await account.getEvmAddress(), privateKey: await account.privateKey(), - provider, chainId, + nonce, }); const transferDomain: TransferDomain = { @@ -122,8 +122,10 @@ export function transferDomainCrafter({ onBroadcast, onConfirmation, chainId, - provider, submitButtonLabel, + dvmAddress, + evmAddress, + nonce, }: { amount: BigNumber; convertDirection: ConvertDirection; @@ -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( @@ -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", @@ -211,8 +215,8 @@ interface EvmTxSigner { evmAddress: string; accountEvmAddress: string; privateKey: Buffer; - provider: providers.JsonRpcProvider; chainId?: number; + nonce: number; } async function createSignedEvmTx({ @@ -222,10 +226,9 @@ async function createSignedEvmTx({ amount, dvmAddress, evmAddress, - accountEvmAddress, privateKey, - provider, chainId, + nonce, }: EvmTxSigner): Promise { let data; const tdFace = new utils.Interface(TransferDomainV1.abi); @@ -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, 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 9788377a42..5672609761 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 { providers } from "ethers"; import { useEVMProvider } from "@contexts/EVMProvider"; import { PortfolioParamList } from "../PortfolioNavigator"; @@ -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) => @@ -123,6 +122,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { logger, ); } else { + const nonce = await provider.getTransactionCount(evmAddress); await constructSignedTransferDomain( { amount, @@ -130,8 +130,10 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { sourceToken, targetToken, networkName, - provider, chainId, + nonce, + evmAddress, + dvmAddress: address, }, dispatch, () => { @@ -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, onBroadcast: () => void, @@ -374,7 +380,9 @@ async function constructSignedTransferDomain( onBroadcast, onConfirmation: () => {}, chainId, - provider, + dvmAddress, + evmAddress, + nonce, }), ), ); 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 e27f091670..6b1cd49b9d 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -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; 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 { @@ -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, @@ -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, onBroadcast: () => void, logger: NativeLoggingProps, @@ -414,7 +414,7 @@ async function send( dvmAddress, evmAddress, networkName, - provider, + nonce, chainId, convertDirection: sendDirection, }); From b33f0f17d80641602f2781cc62a227afc632e752 Mon Sep 17 00:00:00 2001 From: Harsh Date: Fri, 13 Oct 2023 10:32:13 +0530 Subject: [PATCH 06/12] fix(chore): updated evm tokenId and fixed DFI evm icon and balance inconsistancy --- .../app/api/transaction/transfer_domain.ts | 8 +++---- .../app/components/icons/assets/index.ts | 1 + .../Portfolio/components/ActionButtons.tsx | 8 +++---- .../Portfolio/components/DFIBalanceCard.tsx | 14 +++++++++++-- .../Portfolio/hooks/EvmTokenBalances.ts | 8 +++---- .../screens/ConvertConfirmationScreen.tsx | 6 +++--- .../Portfolio/screens/ConvertScreen.tsx | 21 +++++++++++-------- .../screens/SendConfirmationScreen.tsx | 4 ++-- .../Portfolio/screens/TokenDetailScreen.tsx | 20 ++++-------------- 9 files changed, 46 insertions(+), 44 deletions(-) diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index d93db2fd46..de56517c6b 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -150,8 +150,8 @@ export function transferDomainCrafter({ const [symbolA, symbolB] = convertDirection === ConvertDirection.dvmToEvm - ? [sourceToken.displayTextSymbol, `${targetToken.displayTextSymbol}-EVM`] - : [`${targetToken.displayTextSymbol}-EVM`, sourceToken.displayTextSymbol]; + ? [sourceToken.displayTextSymbol, `${targetToken.displayTextSymbol}_evm`] + : [`${targetToken.displayTextSymbol}_evm`, sourceToken.displayTextSymbol]; return { sign: async (account: WhaleWalletAccount) => @@ -267,8 +267,8 @@ async function createSignedEvmTx({ } function stripEvmSuffixFromTokenId(tokenId: string) { - if (tokenId.includes("-EVM")) { - return Number(tokenId.replace("-EVM", "")); + if (tokenId.includes("_evm")) { + return Number(tokenId.replace("_evm", "")); } return Number(tokenId); } diff --git a/mobile-app/app/components/icons/assets/index.ts b/mobile-app/app/components/icons/assets/index.ts index 52e3c8da64..7429981566 100644 --- a/mobile-app/app/components/icons/assets/index.ts +++ b/mobile-app/app/components/icons/assets/index.ts @@ -27,6 +27,7 @@ const mapping: Record JSX.Element> = { _UTXO: DFI, DFI: DFI, "DFI (UTXO)": DFI, + "DFI (EVM)": EvmDFI, "DFI (Token)": DFI, BTC: BTC, DOT: DOT, diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/ActionButtons.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/ActionButtons.tsx index 9330b5049b..eb57683c9d 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/ActionButtons.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/ActionButtons.tsx @@ -87,8 +87,8 @@ export function ActionButtons(): JSX.Element { const defaultTargetToken = { tokenId: domain === DomainType.DVM - ? `${item.tokenId}-EVM` - : item.tokenId.replace("-EVM", ""), + ? `${item.tokenId}_evm` + : item.tokenId.replace("_evm", ""), available: new BigNumber(0), token: { ...item.token, @@ -111,13 +111,13 @@ export function ActionButtons(): JSX.Element { // If EVM -> choose DVM equivalent targetToken = dvmTokens.find( - (token) => token.tokenId === item.tokenId.replace("-EVM", ""), + (token) => token.tokenId === item.tokenId.replace("_evm", ""), ) ?? defaultTargetToken; } else if (domain === DomainType.DVM) { // If DVM -> choose EVM equivalent targetToken = evmTokens.find( - (token) => token.tokenId === `${item.tokenId}-EVM`, + (token) => token.tokenId === `${item.tokenId}_evm`, ) ?? defaultTargetToken; } diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx index 02be14c2ab..894fa68746 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx @@ -30,7 +30,7 @@ export function DFIBalanceCard({ }: DFIBalaceCardProps): JSX.Element { const { domain } = useDomainContext(); const { evmTokens } = useEvmTokenBalances(); - const evmDFIToken = evmTokens.find(({ id }) => id === "0-EVM"); + const evmDFIToken = evmTokens.find(({ id }) => id === "0_evm"); const navigation = useNavigation>(); const DFIToken = useSelector((state: RootState) => DFITokenSelector(state.wallet), @@ -69,7 +69,17 @@ export function DFIBalanceCard({ onPress={() => navigation.navigate({ name: "TokenDetailScreen", - params: { token: DFIUnified, usdAmount }, + params: { + token: { + ...DFIUnified, + amount: tokenAmount, + usdAmount, + ...(isEvmDomain && { + displaySymbol: "DFI (EVM)", + id: "0_evm", + }), + }, + }, merge: true, }) } diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts index 311365e467..6aa26e79c1 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts @@ -42,7 +42,7 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { const getEvmTokens = async () => { const dfiToken: WalletToken = { - id: "0-EVM", + id: "0_evm", symbol: "DFI", symbolKey: "DFI", isDAT: true, @@ -50,8 +50,8 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { isLoanToken: false, amount: "0", name: "DeFiChain for EVM", - displaySymbol: "EvmDFI", - avatarSymbol: "EvmDFI", + displaySymbol: "DFI (EVM)", + avatarSymbol: "DFI (EVM)", }; try { const evmDfiBalance = formatEther( @@ -67,7 +67,7 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { return [ ...current, { - id: `${tokenDetails.id}-EVM`, + id: `${tokenDetails.id}_evm`, symbol: tokenDetails.symbol, symbolKey: tokenDetails.symbolKey, isDAT: tokenDetails.isDAT, 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 5672609761..cbe890c954 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -186,7 +186,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm ? "-EVM" : "" + convertDirection === ConvertDirection.dvmToEvm ? "_evm" : "" }`, ), }, @@ -246,7 +246,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${sourceToken.displayTextSymbol}${ - convertDirection !== ConvertDirection.evmToDvm ? "" : "-EVM" + convertDirection !== ConvertDirection.evmToDvm ? "" : "_evm" }`, testID: "resulting_tokens_value", themedProps: { @@ -288,7 +288,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm ? "-EVM" : "" + convertDirection === ConvertDirection.dvmToEvm ? "_evm" : "" }`, testID: "resulting_utxo_value", themedProps: { diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx index 5234605a29..08e683b041 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx @@ -202,7 +202,7 @@ export function ConvertScreen(props: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${sourceToken.token.displayTextSymbol}${ - domain === DomainType.EVM ? "-EVM" : "" + domain === DomainType.EVM ? "_evm" : "" }`, ), percent: type, @@ -225,11 +225,14 @@ export function ConvertScreen(props: Props): JSX.Element { function getListByDomain(listType: TokenListType): DomainToken[] { if (listType === TokenListType.To) { + const evmDFIToken = evmTokens.find(({ tokenId }) => tokenId === "0_evm"); const defaultEvmTargetToken = { - tokenId: `${sourceToken.tokenId}-EVM`, - available: new BigNumber(0), + tokenId: `${sourceToken.tokenId}_evm`, + available: new BigNumber(evmDFIToken?.available ?? 0), token: { ...sourceToken.token, + displaySymbol: "DFI (EVM)", + displayTextSymbol: "DFI (EVM)", name: `${sourceToken.token.name} for EVM`, domainType: DomainType.EVM, }, @@ -250,7 +253,7 @@ export function ConvertScreen(props: Props): JSX.Element { } else if (domain === DomainType.DVM) { // Display EVM equivalent return [defaultEvmTargetToken]; - } else if (domain === DomainType.EVM && sourceToken.tokenId === "0-EVM") { + } else if (domain === DomainType.EVM && sourceToken.tokenId === "0_evm") { // Display DFI (DVM) return dvmTokens.filter((token) => token.tokenId === "0"); } @@ -281,8 +284,8 @@ export function ConvertScreen(props: Props): JSX.Element { const defaultTargetToken = { tokenId: domain === DomainType.DVM - ? `${item.tokenId}-EVM` - : item.tokenId.replace("-EVM", ""), + ? `${item.tokenId}_evm` + : item.tokenId.replace("_evm", ""), available: new BigNumber(0), token: { ...item.token, @@ -308,12 +311,12 @@ export function ConvertScreen(props: Props): JSX.Element { // If EVM -> choose DVM equivalent updatedTargetToken = dvmTokens.find( - (token) => token.tokenId === item.tokenId.replace("-EVM", ""), + (token) => token.tokenId === item.tokenId.replace("_evm", ""), ) ?? defaultTargetToken; } else if (domain === DomainType.DVM) { // If DVM -> choose EVM equivalent updatedTargetToken = - evmTokens.find((token) => token.tokenId === `${item.tokenId}-EVM`) ?? + evmTokens.find((token) => token.tokenId === `${item.tokenId}_evm`) ?? defaultTargetToken; } /* End of what will be moved into a hook */ @@ -369,7 +372,7 @@ export function ConvertScreen(props: Props): JSX.Element { : "", token: convertDirection === ConvertDirection.evmToDvm - ? `${sourceToken.token.displayTextSymbol}-EVM` + ? `${sourceToken.token.displayTextSymbol}_evm` : sourceToken.token.displayTextSymbol, }, )} 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 6b1cd49b9d..16440b483d 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -397,8 +397,8 @@ async function send( : ConvertDirection.evmToDvm; const isEvmToDvm = sendDirection === ConvertDirection.evmToDvm; const tokenId = token.id === "0_unified" ? "0" : token.id; - const sourceTokenId = isEvmToDvm ? `${tokenId}-EVM` : tokenId; - const targetTokenId = isEvmToDvm ? tokenId : `${tokenId}-EVM`; + const sourceTokenId = isEvmToDvm ? `${tokenId}_evm` : tokenId; + const targetTokenId = isEvmToDvm ? tokenId : `${tokenId}_evm`; const dvmAddress = isEvmToDvm ? address : await account.getAddress(); diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx index 05d7c46cbe..d232320ba2 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx @@ -407,23 +407,15 @@ function TokenSummary(props: { const { getTokenUrl } = useDeFiScanContext(); const onTokenUrlPressed = async (): Promise => { const id = - props.token.id === "0_utxo" || props.token.id === "0_unified" + props.token.id === "0_utxo" || + props.token.id === "0_unified" || + props.token.id === "0_evm" ? 0 : props.token.id; const url = getTokenUrl(id); await Linking.openURL(url); }; - const DFIUnified = useSelector((state: RootState) => - unifiedDFISelector(state.wallet), - ); - const { getTokenPrice } = useTokenPrice(denominationCurrency); // input based on selected denomination from portfolio tab - const dfiUsdAmount = getTokenPrice( - DFIUnified.symbol, - new BigNumber(DFIUnified.amount), - DFIUnified.isLPS, - ); - return ( )} thousandSeparator - value={ - props.token.symbol === "DFI" - ? getPrecisedTokenValue(dfiUsdAmount) - : getPrecisedTokenValue(props.usdAmount) - } + value={getPrecisedTokenValue(props.usdAmount)} /> )} From 591f9045b3ddd7f46200eed1125d6e3090bac36e Mon Sep 17 00:00:00 2001 From: Harsh Date: Fri, 13 Oct 2023 10:59:57 +0530 Subject: [PATCH 07/12] updated dfi name --- .../AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx index 894fa68746..35af174925 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx @@ -75,6 +75,7 @@ export function DFIBalanceCard({ amount: tokenAmount, usdAmount, ...(isEvmDomain && { + name: `${DFIUnified.name} for EVM`, displaySymbol: "DFI (EVM)", id: "0_evm", }), From 927a728042dd16c42ac290446ab69eb50f6d9f36 Mon Sep 17 00:00:00 2001 From: Harsh Date: Fri, 13 Oct 2023 15:30:50 +0530 Subject: [PATCH 08/12] updated EVM suffix names --- mobile-app/app/api/transaction/transfer_domain.ts | 10 ++++++++-- .../Portfolio/components/DFIBalanceCard.tsx | 2 +- .../screens/ConvertConfirmationScreen.tsx | 15 ++++++++++++--- .../screens/Portfolio/screens/ConvertScreen.tsx | 14 ++++++++++---- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index de56517c6b..ae55f94154 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -150,8 +150,14 @@ export function transferDomainCrafter({ const [symbolA, symbolB] = convertDirection === ConvertDirection.dvmToEvm - ? [sourceToken.displayTextSymbol, `${targetToken.displayTextSymbol}_evm`] - : [`${targetToken.displayTextSymbol}_evm`, sourceToken.displayTextSymbol]; + ? [ + sourceToken.displayTextSymbol, + `${targetToken.displayTextSymbol} (EVM)`, + ] + : [ + `${targetToken.displayTextSymbol} (EVM)`, + sourceToken.displayTextSymbol, + ]; return { sign: async (account: WhaleWalletAccount) => diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx index 35af174925..645c7643fc 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/DFIBalanceCard.tsx @@ -94,7 +94,7 @@ export function DFIBalanceCard({ )} 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 cbe890c954..16ed17a17c 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -186,7 +186,10 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm ? "_evm" : "" + convertDirection === ConvertDirection.dvmToEvm && + targetToken.tokenId !== "0_evm" + ? "(EVM)" + : "" }`, ), }, @@ -246,7 +249,10 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${sourceToken.displayTextSymbol}${ - convertDirection !== ConvertDirection.evmToDvm ? "" : "_evm" + convertDirection !== ConvertDirection.evmToDvm && + sourceToken.tokenId !== "0_evm" + ? "" + : "(EVM)" }`, testID: "resulting_tokens_value", themedProps: { @@ -288,7 +294,10 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm ? "_evm" : "" + convertDirection === ConvertDirection.dvmToEvm && + targetToken.tokenId !== "0_evm" + ? "(EVM)" + : "" }`, testID: "resulting_utxo_value", themedProps: { diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx index 08e683b041..0fda1f790c 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx @@ -202,7 +202,9 @@ export function ConvertScreen(props: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${sourceToken.token.displayTextSymbol}${ - domain === DomainType.EVM ? "_evm" : "" + domain === DomainType.EVM && sourceToken.tokenId !== "0_evm" + ? "(EVM)" + : "" }`, ), percent: type, @@ -371,8 +373,9 @@ export function ConvertScreen(props: Props): JSX.Element { ? BigNumber(sourceToken.available).toFixed(8) : "", token: - convertDirection === ConvertDirection.evmToDvm - ? `${sourceToken.token.displayTextSymbol}_evm` + convertDirection === ConvertDirection.evmToDvm && + sourceToken.tokenId !== "0_evm" + ? `${sourceToken.token.displayTextSymbol} (EVM)` : sourceToken.token.displayTextSymbol, }, )} @@ -577,7 +580,10 @@ export function ConvertScreen(props: Props): JSX.Element { Date: Fri, 13 Oct 2023 16:01:33 +0530 Subject: [PATCH 09/12] chore --- .../screens/Portfolio/screens/ConvertConfirmationScreen.tsx | 6 +++--- .../screens/Portfolio/screens/ConvertScreen.tsx | 2 +- 2 files changed, 4 insertions(+), 4 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 16ed17a17c..9c0b28c2f0 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -188,7 +188,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { `${targetToken.displayTextSymbol}${ convertDirection === ConvertDirection.dvmToEvm && targetToken.tokenId !== "0_evm" - ? "(EVM)" + ? " (EVM)" : "" }`, ), @@ -252,7 +252,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { convertDirection !== ConvertDirection.evmToDvm && sourceToken.tokenId !== "0_evm" ? "" - : "(EVM)" + : " (EVM)" }`, testID: "resulting_tokens_value", themedProps: { @@ -296,7 +296,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { suffix: ` ${targetToken.displayTextSymbol}${ convertDirection === ConvertDirection.dvmToEvm && targetToken.tokenId !== "0_evm" - ? "(EVM)" + ? " (EVM)" : "" }`, testID: "resulting_utxo_value", diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx index 0fda1f790c..cd0201bb12 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx @@ -203,7 +203,7 @@ export function ConvertScreen(props: Props): JSX.Element { "screens/ConvertScreen", `${sourceToken.token.displayTextSymbol}${ domain === DomainType.EVM && sourceToken.tokenId !== "0_evm" - ? "(EVM)" + ? " (EVM)" : "" }`, ), From 3e58e25074b8733966684e5f4aef9a50388fc7cf Mon Sep 17 00:00:00 2001 From: Harsh Date: Fri, 13 Oct 2023 20:32:28 +0530 Subject: [PATCH 10/12] removed (EVM) for DFI token --- .../app/components/TokenDropdownButton.tsx | 7 +- .../Auctions/screens/PlaceBidScreen.tsx | 39 ++++----- .../Dex/CompositeSwap/CompositeSwapScreen.tsx | 2 + .../SwapTokenSelectionScreen.tsx | 1 + .../components/BottomSheetLoanTokensList.tsx | 23 +++--- .../screens/AddOrRemoveCollateralScreen.tsx | 1 + .../Loans/screens/BorrowLoanTokenScreen.tsx | 81 ++++++++++--------- .../Loans/screens/PaybackLoanScreen.tsx | 59 +++++++------- .../Portfolio/components/DFIBalanceCard.tsx | 4 +- .../Portfolio/components/TokenIcon.tsx | 6 +- .../Portfolio/hooks/EvmTokenBalances.ts | 4 +- .../screens/ConvertConfirmationScreen.tsx | 21 ++--- .../Portfolio/screens/ConvertScreen.tsx | 18 ++--- .../screens/Portfolio/screens/SendScreen.tsx | 1 + .../Portfolio/screens/TokenDetailScreen.tsx | 1 + .../screens/TokenSelectionScreen.tsx | 1 + 16 files changed, 141 insertions(+), 128 deletions(-) diff --git a/mobile-app/app/components/TokenDropdownButton.tsx b/mobile-app/app/components/TokenDropdownButton.tsx index 292b58d951..5fcba32749 100644 --- a/mobile-app/app/components/TokenDropdownButton.tsx +++ b/mobile-app/app/components/TokenDropdownButton.tsx @@ -16,6 +16,7 @@ export enum TokenDropdownButtonStatus { } export function TokenDropdownButton(props: { + tokenId?: string; symbol?: string; displayedTextSymbol?: string; testID: string; @@ -24,7 +25,11 @@ export function TokenDropdownButton(props: { isEvmToken?: boolean; }): JSX.Element { const Icon = - props.symbol !== undefined ? getNativeIcon(props.symbol) : undefined; + props.symbol !== undefined + ? props.tokenId === "0_evm" + ? getNativeIcon("DFI (EVM)") + : getNativeIcon(props.symbol) + : undefined; return ( ; export function PlaceBidScreen(props: Props): JSX.Element { const { batch, vault } = props.route.params; const tokens = useSelector((state: RootState) => - tokensSelector(state.wallet) + tokensSelector(state.wallet), ); const ownedToken = tokens.find((token) => token.id === batch.loan.id); const { minNextBidInToken, totalCollateralsValueInUSD } = useAuctionBidValue( batch, - vault.liquidationPenalty + vault.liquidationPenalty, ); const [fee, setFee] = useState(new BigNumber(0.0001)); const { bottomSheetRef, containerRef, isModalDisplayed, bottomSheetScreen } = @@ -61,15 +61,15 @@ export function PlaceBidScreen(props: Props): JSX.Element { const navigation = useNavigation>(); const hasPendingJob = useSelector((state: RootState) => - hasTxQueued(state.transactionQueue) + hasTxQueued(state.transactionQueue), ); const hasPendingBroadcastJob = useSelector((state: RootState) => - hasOceanTXQueued(state.ocean) + hasOceanTXQueued(state.ocean), ); const blockCount = useSelector((state: RootState) => state.block.count) ?? 0; const { blocksRemaining } = useAuctionTime( vault.liquidationHeight, - blockCount + blockCount, ); const logger = useLogger(); const client = useWhaleApiClient(); @@ -100,7 +100,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { async function onBidPercentagePress( amount: BigNumber, - type: BidAmountButtonTypes + type: BidAmountButtonTypes, ): Promise { setValue("bidAmount", amount.toFixed(8)); await trigger("bidAmount"); @@ -117,7 +117,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { type: "wallet_toast", placement: "top", duration: TOAST_DURATION, - } + }, ); } @@ -137,7 +137,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { const ownedTokenAmount = ownedToken === undefined ? "0" : ownedToken.amount; const displayHigherBidWarning = getAmountInUSDValue(bidAmount).gte( - totalCollateralsValueInUSD.times(1.2) + totalCollateralsValueInUSD.times(1.2), ); const displayMinBidError = formState.errors.bidAmount?.type === "min"; const displayMinBidMessage = @@ -149,7 +149,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { @@ -165,12 +165,12 @@ export function PlaceBidScreen(props: Props): JSX.Element { { ownedAmount: ownedToken?.amount ?? "0.00", symbol: batch.loan.displaySymbol, - } + }, )} @@ -207,6 +207,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { {}} status={TokenDropdownButtonStatus.Locked} @@ -216,7 +217,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { light={tailwind("bg-mono-light-v2-00")} dark={tailwind("bg-mono-dark-v2-00")} style={tailwind( - "flex flex-row justify-around items-center py-3 mt-6 mx-1 rounded-xl-v2 font-normal-v2" + "flex flex-row justify-around items-center py-3 mt-6 mx-1 rounded-xl-v2 font-normal-v2", )} > {Object.values(BidAmountButtonTypes).map( @@ -230,7 +231,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { hasBorder={length - 1 !== index} /> ); - } + }, )} @@ -251,7 +252,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { { amount: minNextBidInToken.toFixed(8), symbol: batch.loan.symbol, - } + }, )} )} @@ -271,13 +272,13 @@ export function PlaceBidScreen(props: Props): JSX.Element { renderText={(value: string) => ( {translate( "components/QuickBid", "Your bid is higher than the auction's collateral value of {{currency}}{{amount}}", - { amount: value, currency: "$" } + { amount: value, currency: "$" }, )} )} @@ -291,7 +292,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { dark={tailwind("border-gray-700")} light={tailwind("border-gray-300")} style={tailwind( - "p-5 border-0.5 rounded-lg-v2 mx-1 my-6 font-normal-v2" + "p-5 border-0.5 rounded-lg-v2 mx-1 my-6 font-normal-v2", )} > {translate("screens/PlaceBidScreen", "Auction timeout")} @@ -332,7 +333,7 @@ export function PlaceBidScreen(props: Props): JSX.Element { > {translate( "screens/PlaceBidScreen", - "Review full details in the next screen" + "Review full details in the next screen", )} navigateToTokenSelectionScreen(TokenListType.From) @@ -1103,6 +1104,7 @@ export function CompositeSwapScreen({ route }: Props): JSX.Element { )} navigateToTokenSelectionScreen(TokenListType.To) diff --git a/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx index be3a69dab9..6f0f66ffe3 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Dex/CompositeSwap/SwapTokenSelectionScreen.tsx @@ -223,6 +223,7 @@ function TokenItem({ token={{ isLPS: item.token.isLPS, displaySymbol: item.token.displaySymbol, + id: item.tokenId, }} size={36} isEvmToken={item.token.domainType === DomainType.EVM} diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/components/BottomSheetLoanTokensList.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/components/BottomSheetLoanTokensList.tsx index 4b4901a8b0..3194daa6e4 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/components/BottomSheetLoanTokensList.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/components/BottomSheetLoanTokensList.tsx @@ -40,7 +40,7 @@ export const BottomSheetLoanTokensList = ({ return filterLoanTokensBySearchTerm( loanTokens, debouncedSearchTerm, - isSearchFocus + isSearchFocus, ); }, [debouncedSearchTerm, isSearchFocus]); @@ -64,12 +64,12 @@ export const BottomSheetLoanTokensList = ({ keyExtractor={(item) => item.tokenId} renderItem={({ item }: ListRenderItemInfo): JSX.Element => { const currentPrice = getPrecisedTokenValue( - getActivePrice(item.token.symbol, item.activePrice) + getActivePrice(item.token.symbol, item.activePrice), ); return ( @@ -101,7 +102,7 @@ export const BottomSheetLoanTokensList = ({ renderText={(value) => ( @@ -117,7 +118,7 @@ export const BottomSheetLoanTokensList = ({ renderText={(value) => ( @@ -145,7 +146,7 @@ export const BottomSheetLoanTokensList = ({ showClearButton={searchString !== ""} placeholder={translate( "components/BottomSheetLoanTokensList", - "Search with token name" + "Search with token name", )} containerStyle={tailwind([ "border-0.5", @@ -184,12 +185,12 @@ export const BottomSheetLoanTokensList = ({ {searchString.trim() === "" ? translate( "components/BottomSheetLoanTokensList", - "Search with token name" + "Search with token name", ) : translate( "components/BottomSheetLoanTokensList", "Search results for “{{searchTerm}}”", - { searchTerm: searchString } + { searchTerm: searchString }, )} @@ -210,14 +211,14 @@ export const BottomSheetLoanTokensList = ({ function filterLoanTokensBySearchTerm( loanTokens: LoanToken[], searchTerm: string, - isFocused: boolean + isFocused: boolean, ): LoanToken[] { if (searchTerm === "") { return isFocused ? [] : loanTokens; } return loanTokens.filter((t) => { return [t.token.displaySymbol].some((searchItem) => - searchItem.toLowerCase().includes(searchTerm.trim().toLowerCase()) + searchItem.toLowerCase().includes(searchTerm.trim().toLowerCase()), ); }); } diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/screens/AddOrRemoveCollateralScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/screens/AddOrRemoveCollateralScreen.tsx index 89adcb46ca..000c61b98a 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/screens/AddOrRemoveCollateralScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/screens/AddOrRemoveCollateralScreen.tsx @@ -516,6 +516,7 @@ export function AddOrRemoveCollateralScreen({ route }: Props): JSX.Element { { setBottomSheetScreen([ diff --git a/mobile-app/app/screens/AppNavigator/screens/Loans/screens/BorrowLoanTokenScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Loans/screens/BorrowLoanTokenScreen.tsx index 4c2bf5f580..3dca96f01f 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Loans/screens/BorrowLoanTokenScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Loans/screens/BorrowLoanTokenScreen.tsx @@ -80,23 +80,23 @@ export function BorrowLoanTokenScreen({ const blockCount = useSelector((state: RootState) => state.block.count); const vaults = useSelector((state: RootState) => vaultsSelector(state.loans)); const loanTokens = useSelector((state: RootState) => - loanTokensSelector(state.loans) + loanTokensSelector(state.loans), ); const [vault, setVault] = useState(route.params.vault); const [loanToken, setLoanToken] = useState(route.params.loanToken); const [totalAnnualInterest, setTotalAnnualInterest] = useState( - new BigNumber(NaN) + new BigNumber(NaN), ); const [fee, setFee] = useState(new BigNumber(0.0001)); const interestPerBlock = useInterestPerBlock( new BigNumber(vault.loanScheme.interestRate ?? NaN), - new BigNumber(loanToken.interest) + new BigNumber(loanToken.interest), ); const { requiredTokensShare } = useValidCollateralRatio( vault.collateralAmounts, new BigNumber(vault.collateralValue), - new BigNumber(vault.loanValue) + new BigNumber(vault.loanValue), ); const maxLoanAmount = useMaxLoan({ @@ -105,16 +105,16 @@ export function BorrowLoanTokenScreen({ existingLoanValue: new BigNumber(vault.loanValue), minColRatio: new BigNumber(vault.loanScheme.minColRatio), loanActivePrice: new BigNumber( - getActivePrice(loanToken.token.symbol, loanToken.activePrice) + getActivePrice(loanToken.token.symbol, loanToken.activePrice), ), interestPerBlock: interestPerBlock, }); const blocksPerDay = useBlocksPerDay(); const hasPendingJob = useSelector((state: RootState) => - hasTxQueued(state.transactionQueue) + hasTxQueued(state.transactionQueue), ); const hasPendingBroadcastJob = useSelector((state: RootState) => - hasOceanTXQueued(state.ocean) + hasOceanTXQueued(state.ocean), ); // Form Input @@ -129,9 +129,9 @@ export function BorrowLoanTokenScreen({ ? new BigNumber(0) : new BigNumber(borrowAmount), new BigNumber( - getActivePrice(loanToken.token.symbol, loanToken.activePrice) + getActivePrice(loanToken.token.symbol, loanToken.activePrice), ), - interestPerBlock + interestPerBlock, ); const [disableContinue, setDisableContinue] = useState(false); const { isDFILessThanHalfOfRequiredCollateral } = @@ -142,13 +142,13 @@ export function BorrowLoanTokenScreen({ loanValue: new BigNumber(vault.loanValue).plus( new BigNumber(borrowAmount).isNaN() ? new BigNumber(0) - : new BigNumber(borrowAmount) + : new BigNumber(borrowAmount), ), loanToken: loanToken, minColRatio: vault.loanScheme.minColRatio, }); const { atRiskThreshold } = useColRatioThreshold( - new BigNumber(vault.loanScheme.minColRatio) + new BigNumber(vault.loanScheme.minColRatio), ); // Bottom sheet @@ -172,7 +172,7 @@ export function BorrowLoanTokenScreen({ @@ -201,7 +201,7 @@ export function BorrowLoanTokenScreen({ @@ -233,7 +233,7 @@ export function BorrowLoanTokenScreen({ async function onPercentagePress( amount: string, - type: AmountButtonTypes + type: AmountButtonTypes, ): Promise { setValue("borrowAmount", amount); await trigger("borrowAmount"); @@ -259,14 +259,14 @@ export function BorrowLoanTokenScreen({ type: "wallet_toast", placement: "top", duration: TOAST_DURATION, - } + }, ); } const updateInterestAmount = (): void => { const loanTokenPrice = getActivePrice( loanToken.token.symbol, - loanToken.activePrice + loanToken.activePrice, ); if (borrowAmount === undefined || loanTokenPrice === "0") { return; @@ -336,14 +336,14 @@ export function BorrowLoanTokenScreen({ fetchVaults({ address, client, - }) + }), ); } }, [blockCount, address, isFocused]); useEffect(() => { const updatedVault = vaults.find( - (v) => v.vaultId === vault.vaultId + (v) => v.vaultId === vault.vaultId, ) as LoanVaultActive; setVault(updatedVault); }, [vaults]); @@ -358,7 +358,7 @@ export function BorrowLoanTokenScreen({ resultingColRatio.isLessThan(vault.loanScheme.minColRatio) || hasPendingJob || hasPendingBroadcastJob || - !formState.isValid + !formState.isValid, ); }, [ resultingColRatio, @@ -379,7 +379,7 @@ export function BorrowLoanTokenScreen({ @@ -411,7 +411,7 @@ export function BorrowLoanTokenScreen({ > @@ -436,7 +436,7 @@ export function BorrowLoanTokenScreen({ }} placeholder="0.00" placeholderTextColor={getColor( - isLight ? "mono-light-v2-500" : "mono-dark-v2-500" + isLight ? "mono-light-v2-500" : "mono-dark-v2-500", )} testID="text_input_borrow_amount" /> @@ -448,7 +448,7 @@ export function BorrowLoanTokenScreen({ validate: { greaterThanZero: (value: string) => new BigNumber( - value !== undefined && value !== "" ? value : 0 + value !== undefined && value !== "" ? value : 0, ).isGreaterThan(0), hasDFIandDUSDCollateral: () => requiredTokensShare.isGreaterThan(0), // need >0 DFI and or DUSD to take loan @@ -461,12 +461,12 @@ export function BorrowLoanTokenScreen({ price={new BigNumber( typeof borrowAmount === "string" && borrowAmount.length > 0 ? borrowAmount - : 0 + : 0, ).multipliedBy( getActivePrice( loanToken.token.symbol, - loanToken.activePrice - ) + loanToken.activePrice, + ), )} style={tailwind("text-sm")} testId="borrow_amount_in_usd" @@ -476,6 +476,7 @@ export function BorrowLoanTokenScreen({ { setBottomSheetScreen(bottomSheetLoanTokenList); @@ -494,7 +495,7 @@ export function BorrowLoanTokenScreen({ > {translate( "screens/BorrowLoanTokenScreen", - "Amount entered will result in vault liquidation" + "Amount entered will result in vault liquidation", )} )} @@ -536,7 +537,7 @@ export function BorrowLoanTokenScreen({ > {translate( "screens/BorrowLoanTokenScreen", - inputValidationMessage.message + inputValidationMessage.message, )} ) : ( @@ -549,7 +550,7 @@ export function BorrowLoanTokenScreen({ > {translate( "screens/BorrowLoanTokenScreen", - "Review full details in the next screen" + "Review full details in the next screen", )} ) @@ -611,7 +612,7 @@ function VaultInput(props: VaultInputProps): JSX.Element { /> - activeVaultsSelector(state.loans) + activeVaultsSelector(state.loans), ); useEffect(() => { @@ -72,7 +72,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { }, []); const collateralTokens = useSelector( - (state: RootState) => state.loans.collateralTokens + (state: RootState) => state.loans.collateralTokens, ); useEffect(() => { @@ -81,7 +81,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { setVault(vault); } const loanTokenAmount = vault?.loanAmounts.find( - (l: LoanVaultTokenAmount) => l.id === routeParams.loanTokenAmount.id + (l: LoanVaultTokenAmount) => l.id === routeParams.loanTokenAmount.id, ); if (loanTokenAmount !== undefined) { setLoanTokenAmount(loanTokenAmount); @@ -89,7 +89,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { }, [vaults]); const tokens = useSelector((state: RootState) => - tokensSelector(state.wallet) + tokensSelector(state.wallet), ); const toast = useToast(); const TOAST_DURATION = 2000; @@ -102,7 +102,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { }); } const loanToken = useSelector((state: RootState) => - loanTokenByTokenId(state.loans, loanTokenAmount.id) + loanTokenByTokenId(state.loans, loanTokenAmount.id), ); const { isLight } = useThemeContext(); const canUseOperations = useLoanOperations(vault?.state); @@ -112,7 +112,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { }); const { amountToPay } = watch(); const collateralDUSD = vault?.collateralAmounts?.find( - ({ symbol }) => symbol === "DUSD" + ({ symbol }) => symbol === "DUSD", ); const collateralDUSDAmount = collateralDUSD?.amount ?? "0"; const [fee, setFee] = useState(new BigNumber(0.0001)); @@ -129,14 +129,14 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { if (routeParams.isPaybackDUSDUsingCollateral) { setValue( "amountToPay", - BigNumber.min(collateralDUSDAmount, loanTokenAmount.amount).toFixed(8) + BigNumber.min(collateralDUSDAmount, loanTokenAmount.amount).toFixed(8), ); } }, [loanTokenAmount, collateralDUSDAmount]); const interestPerBlock = useInterestPerBlock( new BigNumber(vault?.loanScheme.interestRate ?? NaN), - new BigNumber(loanToken?.interest ?? NaN) + new BigNumber(loanToken?.interest ?? NaN), ); const token = tokens?.find((t) => t.id === loanTokenAmount.id); const tokenBalance = @@ -152,21 +152,23 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { ? collateralFactor : undefined, undefined, - routeParams.isPaybackDUSDUsingCollateral === true ? "COLLATERAL" : undefined + routeParams.isPaybackDUSDUsingCollateral === true + ? "COLLATERAL" + : undefined, ); const hasPendingJob = useSelector((state: RootState) => - hasTxQueued(state.transactionQueue) + hasTxQueued(state.transactionQueue), ); const hasPendingBroadcastJob = useSelector((state: RootState) => - hasOceanTXQueued(state.ocean) + hasOceanTXQueued(state.ocean), ); const getCollateralValue = (collateralValue: string) => { if (routeParams.isPaybackDUSDUsingCollateral) { // In case of DUSD payment using collateral return new BigNumber(collateralValue).minus( - new BigNumber(amountToPay).multipliedBy(loanTokenActivePriceInUSD) + new BigNumber(amountToPay).multipliedBy(loanTokenActivePriceInUSD), ); } return new BigNumber(collateralValue); @@ -177,10 +179,10 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { new BigNumber(vault?.loanValue ?? NaN), BigNumber.min( new BigNumber(amountToPay).isNaN() ? "0" : amountToPay, - loanTokenAmount.amount + loanTokenAmount.amount, ).multipliedBy(-1), new BigNumber(loanTokenActivePriceInUSD), - interestPerBlock + interestPerBlock, ); const navigateToConfirmScreen = async (): Promise => { @@ -202,7 +204,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { const onChangeFromAmount = async ( amount: string, - type: AmountButtonTypes + type: AmountButtonTypes, ): Promise => { const isMax = type === AmountButtonTypes.Max; const toastMessage = isMax @@ -214,7 +216,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { percent: type, }; showToast( - translate("screens/PaybackLoanScreen", toastMessage, toastOption) + translate("screens/PaybackLoanScreen", toastMessage, toastOption), ); await trigger("amountToPay"); }; @@ -238,7 +240,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { "screens/PaybackLoanScreen", routeParams.isPaybackDUSDUsingCollateral ? "I WANT TO PAY WITH DUSD COLLATERAL" - : "I WANT TO PAY" + : "I WANT TO PAY", )} @@ -266,7 +268,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { > @@ -276,7 +278,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { routeParams.isPaybackDUSDUsingCollateral ? BigNumber.min( collateralDUSDAmount, - loanTokenAmount.amount + loanTokenAmount.amount, ).toFixed(8) : "" } @@ -309,7 +311,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { }} placeholder="0.00" placeholderTextColor={getColor( - isLight ? "mono-light-v2-500" : "mono-dark-v2-500" + isLight ? "mono-light-v2-500" : "mono-dark-v2-500", )} testID="payback_input_text" editable={amountToPay !== undefined} @@ -323,7 +325,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { validate: { greaterThanZero: (value: string) => new BigNumber( - value !== undefined && value !== "" ? value : 0 + value !== undefined && value !== "" ? value : 0, ).isGreaterThan(0), notSufficientFunds: (value) => new BigNumber(tokenBalance).gte(value), @@ -335,7 +337,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { new BigNumber(amountToPay).isNaN() ? new BigNumber(0) : new BigNumber(amountToPay).multipliedBy( - loanTokenActivePriceInUSD + loanTokenActivePriceInUSD, ) } style={tailwind("text-sm")} @@ -344,6 +346,7 @@ export function PaybackLoanScreen({ navigation, route }: Props): JSX.Element { /> )} @@ -467,7 +470,7 @@ function TransactionDetailsSection({ }; const loanRemaining = BigNumber.max( new BigNumber(outstandingBalance).minus(amountToPay), - 0 + 0, ); return ( )} diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenIcon.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenIcon.tsx index 5ef5bdf923..af3442d63b 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenIcon.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenIcon.tsx @@ -7,6 +7,7 @@ interface TokenIconProps { testID?: string; token: { isLPS?: boolean; + id: string; displaySymbol: string; }; size: number; @@ -28,7 +29,10 @@ export function TokenIcon(props: TokenIconProps): JSX.Element { /> ); } - const Icon = getNativeIcon(token.displaySymbol); + const Icon = + token.id === "0_evm" + ? getNativeIcon("DFI (EVM)") + : getNativeIcon(token.displaySymbol); const evmIconSize = isEvmToken ? size - 4 : size; return ( diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts index 6aa26e79c1..36d88172eb 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/hooks/EvmTokenBalances.ts @@ -50,8 +50,8 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } { isLoanToken: false, amount: "0", name: "DeFiChain for EVM", - displaySymbol: "DFI (EVM)", - avatarSymbol: "DFI (EVM)", + displaySymbol: "DFI", + avatarSymbol: "DFI", }; try { const evmDfiBalance = formatEther( 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 9c0b28c2f0..d2c3ed6a06 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertConfirmationScreen.tsx @@ -186,17 +186,18 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm && - targetToken.tokenId !== "0_evm" - ? " (EVM)" - : "" + convertDirection === ConvertDirection.dvmToEvm ? " (EVM)" : "" }`, ), }, )} amount={amount} testID="text_convert_amount" - iconA={targetToken.displaySymbol} + iconA={ + targetToken.tokenId === "0_evm" + ? "DFI (EVM)" + : targetToken.displaySymbol + } fromAddress={address} fromAddressLabel={addressLabel} isEvmToken={convertDirection === ConvertDirection.dvmToEvm} @@ -249,10 +250,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${sourceToken.displayTextSymbol}${ - convertDirection !== ConvertDirection.evmToDvm && - sourceToken.tokenId !== "0_evm" - ? "" - : " (EVM)" + convertDirection !== ConvertDirection.evmToDvm ? "" : " (EVM)" }`, testID: "resulting_tokens_value", themedProps: { @@ -294,10 +292,7 @@ export function ConvertConfirmationScreen({ route }: Props): JSX.Element { fee, }), suffix: ` ${targetToken.displayTextSymbol}${ - convertDirection === ConvertDirection.dvmToEvm && - targetToken.tokenId !== "0_evm" - ? " (EVM)" - : "" + convertDirection === ConvertDirection.dvmToEvm ? " (EVM)" : "" }`, testID: "resulting_utxo_value", themedProps: { diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx index cd0201bb12..d7d6dc0d49 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx @@ -202,9 +202,7 @@ export function ConvertScreen(props: Props): JSX.Element { unit: translate( "screens/ConvertScreen", `${sourceToken.token.displayTextSymbol}${ - domain === DomainType.EVM && sourceToken.tokenId !== "0_evm" - ? " (EVM)" - : "" + domain === DomainType.EVM ? " (EVM)" : "" }`, ), percent: type, @@ -233,8 +231,8 @@ export function ConvertScreen(props: Props): JSX.Element { available: new BigNumber(evmDFIToken?.available ?? 0), token: { ...sourceToken.token, - displaySymbol: "DFI (EVM)", - displayTextSymbol: "DFI (EVM)", + displaySymbol: "DFI", + displayTextSymbol: "DFI", name: `${sourceToken.token.name} for EVM`, domainType: DomainType.EVM, }, @@ -373,8 +371,7 @@ export function ConvertScreen(props: Props): JSX.Element { ? BigNumber(sourceToken.available).toFixed(8) : "", token: - convertDirection === ConvertDirection.evmToDvm && - sourceToken.tokenId !== "0_evm" + convertDirection === ConvertDirection.evmToDvm ? `${sourceToken.token.displayTextSymbol} (EVM)` : sourceToken.token.displayTextSymbol, }, @@ -436,6 +433,7 @@ export function ConvertScreen(props: Props): JSX.Element { From 1b9554537def5d3d0ce7a534baf7aa272a169b75 Mon Sep 17 00:00:00 2001 From: Harsh Date: Mon, 16 Oct 2023 09:58:43 +0530 Subject: [PATCH 11/12] Balance details screen for EVM token --- .../components/TokenBreakdownDetailsV2.tsx | 27 ++++++++++--------- .../Portfolio/screens/TokenDetailScreen.tsx | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenBreakdownDetailsV2.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenBreakdownDetailsV2.tsx index 84c7882388..7534d70bdd 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenBreakdownDetailsV2.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/components/TokenBreakdownDetailsV2.tsx @@ -34,7 +34,7 @@ interface TokenBreakdownDetailProps { } export function TokenBreakdownDetailsV2( - props: TokenBreakdownDetailProps + props: TokenBreakdownDetailProps, ): JSX.Element { const { denominationCurrency } = useDenominationCurrency(); const lockedToken = (useTokenLockedBalance({ @@ -46,17 +46,17 @@ export function TokenBreakdownDetailsV2( }; const loanTokens = useSelector((state: RootState) => state.loans.loanTokens); const collateralTokens = useSelector( - (state: RootState) => state.loans.collateralTokens + (state: RootState) => state.loans.collateralTokens, ); const hasLockedBalance = useMemo((): boolean => { return ( collateralTokens.some( (collateralToken) => - collateralToken.token.displaySymbol === props.token.displaySymbol + collateralToken.token.displaySymbol === props.token.displaySymbol, ) || loanTokens.some( (loanToken) => - loanToken.token.displaySymbol === props.token.displaySymbol + loanToken.token.displaySymbol === props.token.displaySymbol, ) ); }, [props.token]); @@ -65,7 +65,7 @@ export function TokenBreakdownDetailsV2( // LP token calculations const { poolpairs: pairs } = useSelector((state: RootState) => state.wallet); const poolPairData = pairs.find( - (pr) => pr.data.symbol === (props.token as AddressToken).symbol + (pr) => pr.data.symbol === (props.token as AddressToken).symbol, ); const mappedPair = poolPairData?.data; const toRemove = new BigNumber(1) @@ -81,7 +81,7 @@ export function TokenBreakdownDetailsV2( const getUSDValue = ( amount: BigNumber, symbol: string, - isLPs: boolean = false + isLPs: boolean = false, ): BigNumber => { return getTokenPrice(symbol, amount, isLPs); }; @@ -166,6 +166,7 @@ export function TokenBreakdownDetailsV2( {/* To display options for DFI UTXO and Token */} {props.token.displaySymbol === "DFI" && + props.token.id !== "0_evm" && props.dfiUtxo !== undefined && props.dfiToken !== undefined && ( @@ -211,8 +212,8 @@ export function TokenBreakdownDetailsV2( getTokenPrice( props.token.symbol, new BigNumber(props.token.amount), - true - ) + true, + ), )} label="" hasFetchedToken={props.hasFetchedToken} @@ -233,7 +234,7 @@ export function TokenBreakdownDetailsV2( label={translate( "components/DFIBalanceCard", "Tokens in {{token}}", - { token: props.pair.tokenA.displaySymbol } + { token: props.pair.tokenA.displaySymbol }, )} hasFetchedToken={props.hasFetchedToken} /> @@ -242,8 +243,8 @@ export function TokenBreakdownDetailsV2( amount={getPrecisedCurrencyValue( getUSDValue( new BigNumber(tokenATotal), - props.pair.tokenA.symbol - ) + props.pair.tokenA.symbol, + ), )} label="" hasFetchedToken={props.hasFetchedToken} @@ -263,14 +264,14 @@ export function TokenBreakdownDetailsV2( label={translate( "components/DFIBalanceCard", "Tokens in {{token}}", - { token: props.pair.tokenB.displaySymbol } + { token: props.pair.tokenB.displaySymbol }, )} hasFetchedToken={props.hasFetchedToken} /> - {token.symbol === "DFI" && ( + {token.symbol === "DFI" && token.id !== "0_evm" && ( Date: Mon, 16 Oct 2023 11:12:49 +0530 Subject: [PATCH 12/12] fixed evm dif related bugs --- .../Portfolio/screens/ConvertScreen.tsx | 7 +++ .../screens/SendConfirmationScreen.tsx | 10 +++- .../Portfolio/screens/TokenDetailScreen.tsx | 46 +++++++++++++++++-- 3 files changed, 58 insertions(+), 5 deletions(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx index d7d6dc0d49..25c1b54c25 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/ConvertScreen.tsx @@ -278,6 +278,12 @@ export function ConvertScreen(props: Props): JSX.Element { ) { // If from:DFI-UTXO -> to: utxosToAccount updatedConvertDirection = ConvertDirection.utxosToAccount; + } else if ( + sourceToken.tokenId === "0" && + listType === TokenListType.To && + item.tokenId === "0_evm" + ) { + updatedConvertDirection = ConvertDirection.dvmToEvm; } let updatedTargetToken: SelectionToken | undefined; @@ -331,6 +337,7 @@ export function ConvertScreen(props: Props): JSX.Element { targetToken: updatedTargetToken, convertDirection: updatedConvertDirection, }, + key: updatedTargetToken?.tokenId, merge: true, }); } 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 16440b483d..2c5488cd6f 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendConfirmationScreen.tsx @@ -397,8 +397,14 @@ async function send( : ConvertDirection.evmToDvm; const isEvmToDvm = sendDirection === ConvertDirection.evmToDvm; const tokenId = token.id === "0_unified" ? "0" : token.id; - const sourceTokenId = isEvmToDvm ? `${tokenId}_evm` : tokenId; - const targetTokenId = isEvmToDvm ? tokenId : `${tokenId}_evm`; + const sourceTokenId = + isEvmToDvm && !tokenId.includes("_evm") + ? `${tokenId}_evm` + : tokenId; + const targetTokenId = + !isEvmToDvm && !tokenId.includes("_evm") + ? `${tokenId}_evm` + : tokenId; const dvmAddress = isEvmToDvm ? address : await account.getAddress(); diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx index 38d3604626..1b25bd3d90 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenDetailScreen.tsx @@ -127,7 +127,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element { route.params.token, ); - const { dvmTokens } = useTokenBalance(); + const { dvmTokens, evmTokens } = useTokenBalance(); // usdAmount for crypto tokens, undefined for DFI token const { usdAmount } = route.params.token; @@ -267,7 +267,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element { )} - {token.symbol === "DFI" && ( + {token.symbol === "DFI" && token.id !== "0_evm" && ( + )} + + {token.id === "0_evm" && ( + { + const convertDirection: ConvertDirection = + domain === DomainType.DVM + ? ConvertDirection.dvmToEvm + : ConvertDirection.evmToDvm; + + const evmToken = evmTokens.find( + (token) => token.tokenId === "0_evm", + ); + const dfiToken = dvmTokens.find( + (token) => token.tokenId === "0", + ); + const [sourceToken, targetToken] = + convertDirection === ConvertDirection.evmToDvm + ? [evmToken, dfiToken] + : [dfiToken, evmToken]; + + navigation.navigate({ + name: "ConvertScreen", + params: { + sourceToken, + targetToken, + convertDirection, + }, + merge: true, + }); + }} + testID="convert_button" + title={translate( + "screens/TokenDetailScreen", + "Convert to {{symbol}}", + { symbol: "Token" }, )} /> )}