aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/BusinessAccount.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-03-11 18:19:38 -0300
committerSebastian <sebasjm@gmail.com>2023-03-11 18:20:16 -0300
commitc67d94c56e154be4b2cf91572cdc2d8d2da7f8e4 (patch)
treefbb9444857d4e11f348c051b9c470e9295990096 /packages/demobank-ui/src/pages/BusinessAccount.tsx
parentb72729f06535f12af974035b141a30320e75575c (diff)
downloadwallet-core-c67d94c56e154be4b2cf91572cdc2d8d2da7f8e4.tar.xz
fix: #7753
Diffstat (limited to 'packages/demobank-ui/src/pages/BusinessAccount.tsx')
-rw-r--r--packages/demobank-ui/src/pages/BusinessAccount.tsx20
1 files changed, 11 insertions, 9 deletions
diff --git a/packages/demobank-ui/src/pages/BusinessAccount.tsx b/packages/demobank-ui/src/pages/BusinessAccount.tsx
index 9bd799746..128b47114 100644
--- a/packages/demobank-ui/src/pages/BusinessAccount.tsx
+++ b/packages/demobank-ui/src/pages/BusinessAccount.tsx
@@ -212,8 +212,7 @@ function useRatiosAndFeeConfigWithChangeDetection(): HttpResponse<
oldResult.ratios_and_fees.sell_at_ratio ||
result.data.ratios_and_fees.sell_out_fee !==
oldResult.ratios_and_fees.sell_out_fee ||
- result.data.ratios_and_fees.fiat_currency !==
- oldResult.ratios_and_fees.fiat_currency);
+ result.data.fiat_currency !== oldResult.fiat_currency);
return {
...result,
@@ -238,16 +237,19 @@ function CreateCashout({
if (!result.ok) return onLoadNotOk(result);
if (!ratiosResult.ok) return onLoadNotOk(ratiosResult);
const config = ratiosResult.data;
- const maybeBalance = Amounts.parse(result.data.balance.amount);
- if (!maybeBalance) return <div>error</div>;
- const balance = maybeBalance;
+ const balance = Amounts.parseOrThrow(result.data.balance.amount);
+ const debitThreshold = Amounts.parseOrThrow(result.data.debitThreshold);
const zero = Amounts.zeroOfCurrency(balance.currency);
+ const balanceIsDebit = result.data.balance.credit_debit_indicator == "debit";
+ const limit = balanceIsDebit
+ ? Amounts.sub(debitThreshold, balance).amount
+ : Amounts.add(balance, debitThreshold).amount;
const sellRate = config.ratios_and_fees.sell_at_ratio;
const sellFee = !config.ratios_and_fees.sell_out_fee
? zero
: Amounts.fromFloat(config.ratios_and_fees.sell_out_fee, balance.currency);
- const fiatCurrency = config.ratios_and_fees.fiat_currency;
+ const fiatCurrency = config.fiat_currency;
if (!sellRate || sellRate < 0) return <div>error rate</div>;
@@ -278,12 +280,12 @@ function CreateCashout({
? i18n.str`required`
: !amount
? i18n.str`could not be parsed`
- : Amounts.cmp(balance, amount_debit) === -1
+ : Amounts.cmp(limit, amount_debit) === -1
? i18n.str`balance is not enough`
: Amounts.cmp(credit_before_fee, sellFee) === -1
- ? i18n.str`amount is not enough`
+ ? i18n.str`the total amount to transfer does not cover the fees`
: Amounts.isZero(amount_credit)
- ? i18n.str`amount is not enough`
+ ? i18n.str`the total transfer at destination will be zero`
: undefined,
channel: !form.channel ? i18n.str`required` : undefined,
});