From 24224234d1683db7297b6f745d72be76f1c65827 Mon Sep 17 00:00:00 2001 From: Lyka Labrada Date: Fri, 20 Oct 2023 08:58:49 +0800 Subject: [PATCH] fix(core): handle auto-conversion of utxo to dfi token (#4082) * fix(core): handle auto-conversion of utxo to dfi token * update getinputtokentype if-condition * updated getInputTokenType condition for send token --------- Co-authored-by: Harsh --- .../screens/Portfolio/screens/SendScreen.tsx | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendScreen.tsx index 181dea740c..72c924ae96 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/SendScreen.tsx @@ -115,14 +115,27 @@ export function SendScreen({ route, navigation }: Props): JSX.Element { }); const { address } = watch(); const amountToSend = getValues("amount"); + const isEvmAddress = + getAddressCategory(getValues("address"), networkName) === + AddressCategory.ETH; + const [addressType, setAddressType] = useState(); + const getInputTokenType = () => { + if (token?.id === "0_unified") { + if (isEvmAddress) { + return "token"; + } + return "utxo"; + } + return "others"; + }; const { isConversionRequired, conversionAmount } = useConversion({ inputToken: { - type: token?.id === "0_unified" ? "utxo" : "others", + type: getInputTokenType(), amount: new BigNumber(amountToSend), }, - deps: [amountToSend, JSON.stringify(token)], + deps: [amountToSend, JSON.stringify(token), isEvmAddress], }); const reservedDFI = 0.1; @@ -144,9 +157,6 @@ export function SendScreen({ route, navigation }: Props): JSX.Element { let infoText; let themedProps; let status = TransactionCardStatus.Default; - const isEvmAddress = - getAddressCategory(getValues("address"), networkName) === - AddressCategory.ETH; if (new BigNumber(amountToSend).isGreaterThan(token?.amount ?? 0)) { infoText = "Insufficient balance"; @@ -299,7 +309,9 @@ export function SendScreen({ route, navigation }: Props): JSX.Element { if (isConversionRequired) { queueConvertTransaction( { - mode: ConvertDirection.accountToUtxos, + mode: isEvmAddress + ? ConvertDirection.utxosToAccount + : ConvertDirection.accountToUtxos, amount: conversionAmount, }, dispatch,