From 21c99d265c60dfd1fc2ea1506412c9d0e89ea53f Mon Sep 17 00:00:00 2001 From: Harsh R <53080940+fullstackninja864@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:07:37 +0530 Subject: [PATCH] fix(chore): bug fix for transferdomain (#4063) * refactore transferdomain provider * fix(ui-ux): fixed icon for evm DFI on swap token listing * fix convert screen provider issue * added chainId in evm provider * added nonce in td request * fix(chore): updated evm tokenId and fixed DFI evm icon and balance inconsistancy * updated dfi name * updated EVM suffix names * chore * removed (EVM) for DFI token * Balance details screen for EVM token * fixed evm dif related bugs --- .../components/TokenBreakdownDetailsV2.tsx | 27 ++++++----- .../Portfolio/screens/ConvertScreen.tsx | 7 +++ .../screens/SendConfirmationScreen.tsx | 10 +++- .../Portfolio/screens/TokenDetailScreen.tsx | 48 +++++++++++++++++-- 4 files changed, 73 insertions(+), 19 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} /> 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 ae7aefa45c..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; @@ -201,7 +201,7 @@ export function TokenDetailScreen({ route, navigation }: Props): JSX.Element { usdAmount={usdAmount ?? new BigNumber(0)} pair={pair} /> - {token.symbol === "DFI" && ( + {token.symbol === "DFI" && token.id !== "0_evm" && ( )} - {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" }, )} /> )}