Skip to content

Commit

Permalink
fix(core): handle auto-conversion of utxo to dfi token (#4082)
Browse files Browse the repository at this point in the history
* fix(core): handle auto-conversion of utxo to dfi token

* update getinputtokentype if-condition

* updated getInputTokenType condition for send token

---------

Co-authored-by: Harsh <[email protected]>
  • Loading branch information
lykalabrada and fullstackninja864 authored Oct 20, 2023
1 parent 04a830c commit 2422423
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AddressType>();

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;
Expand All @@ -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";
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2422423

Please sign in to comment.