diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/components/PaymentButtons.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/components/PaymentButtons.tsx | 90 |
1 files changed, 80 insertions, 10 deletions
diff --git a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx index 30c2ef833..f8983b995 100644 --- a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx +++ b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx @@ -17,6 +17,7 @@ import { AmountJson, Amounts, + PayMerchantInsufficientBalanceDetails, PreparePayResult, PreparePayResultType, TranslatedString, @@ -35,7 +36,6 @@ import { assertUnreachable } from "../utils/index.js"; interface Props { payStatus: PreparePayResult; payHandler: ButtonHandler | undefined; - balance: AmountJson | undefined; uri: string; amount: AmountJson; goToWalletManualWithdraw: (currency: string) => Promise<void>; @@ -45,7 +45,6 @@ export function PaymentButtons({ payStatus, uri, payHandler, - balance, amount, goToWalletManualWithdraw, }: Props): VNode { @@ -73,16 +72,58 @@ export function PaymentButtons({ } if (payStatus.status === PreparePayResultType.InsufficientBalance) { + const reason = getReason(payStatus.balanceDetails); + let BalanceMessage = ""; - if (!balance) { - BalanceMessage = i18n.str`You have no balance for this currency. Withdraw digital cash first.`; - } else { - const balanceShouldBeEnough = Amounts.cmp(balance, amount) !== -1; - if (balanceShouldBeEnough) { - BalanceMessage = i18n.str`Could not find enough coins to pay. Even if you have enough ${balance.currency} some restriction may apply.`; - } else { - BalanceMessage = i18n.str`Your current balance is not enough.`; + switch (reason) { + case "age-acceptable": { + BalanceMessage = i18n.str`Balance is not enough because you have ${Amounts.stringifyValue( + payStatus.balanceDetails.balanceAgeAcceptable, + )} ${amount.currency} to pay for contracts restricted for age above ${ + payStatus.contractTerms.minimum_age + } years old`; + break; + } + case "available": { + BalanceMessage = i18n.str`Balance is not enough because you have ${Amounts.stringifyValue( + payStatus.balanceDetails.balanceAvailable, + )} ${amount.currency} available.`; + break; + } + case "merchant-acceptable": { + BalanceMessage = i18n.str`Balance is not enough because merchant will just accept ${Amounts.stringifyValue( + payStatus.balanceDetails.balanceMerchantAcceptable, + )} ${ + amount.currency + } . To know more you can check which exchange and auditors the merchant trust.`; + break; + } + case "merchant-depositable": { + BalanceMessage = i18n.str`Balance is not enough because merchant will just accept ${Amounts.stringifyValue( + payStatus.balanceDetails.balanceMerchantDepositable, + )} ${ + amount.currency + } . To know more you can check which wire methods the merchant accepts.`; + break; } + case "material": { + BalanceMessage = i18n.str`Balance is not enough because you have ${Amounts.stringifyValue( + payStatus.balanceDetails.balanceMaterial, + )} ${ + amount.currency + } to spend right know. There are some coins that need to be refreshed.`; + break; + } + case "fee-gap": { + BalanceMessage = i18n.str`Balance looks like it should be enough, but doesn't cover all fees requested by the merchant and payment processor. Please ensure there is at least ${Amounts.stringifyValue( + payStatus.balanceDetails.feeGapEstimate, + )} ${ + amount.currency + } more balance in your wallet or ask your merchant to cover more of the fees.`; + break; + } + default: + assertUnreachable(reason); } const uriPrivate = `${uri}&n=${payStatus.noncePriv}`; @@ -150,3 +191,32 @@ function PayWithMobile({ uri }: { uri: string }): VNode { </section> ); } + +type NoEnoughBalanceReason = + | "available" + | "material" + | "age-acceptable" + | "merchant-acceptable" + | "merchant-depositable" + | "fee-gap"; + +function getReason( + info: PayMerchantInsufficientBalanceDetails, +): NoEnoughBalanceReason { + if (Amounts.cmp(info.amountRequested, info.balanceAvailable)) { + return "available"; + } + if (Amounts.cmp(info.amountRequested, info.balanceMaterial)) { + return "material"; + } + if (Amounts.cmp(info.amountRequested, info.balanceAgeAcceptable)) { + return "age-acceptable"; + } + if (Amounts.cmp(info.amountRequested, info.balanceMerchantAcceptable)) { + return "merchant-acceptable"; + } + if (Amounts.cmp(info.amountRequested, info.balanceMerchantDepositable)) { + return "merchant-depositable"; + } + return "fee-gap"; +} |