Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle auto-conversion of utxo to dfi token #4082

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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