aboutsummaryrefslogtreecommitdiff
path: root/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bank-ui/src/pages/PaytoWireTransferForm.tsx')
-rw-r--r--packages/bank-ui/src/pages/PaytoWireTransferForm.tsx28
1 files changed, 21 insertions, 7 deletions
diff --git a/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx b/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx
index 90b41d331..0fb8c0ac1 100644
--- a/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx
+++ b/packages/bank-ui/src/pages/PaytoWireTransferForm.tsx
@@ -79,6 +79,7 @@ export function PaytoWireTransferForm({
routeHere,
onAuthorizationRequired,
limit,
+ balance,
}: Props): VNode {
const [inputType, setInputType] = useState<"form" | "payto" | "qr">("form");
const isRawPayto = inputType !== "form";
@@ -116,6 +117,11 @@ export function PaytoWireTransferForm({
? Amounts.zeroOfCurrency(config.currency)
: Amounts.parseOrThrow(config.wire_transfer_fees);
+ const limitWithFee =
+ Amounts.cmp(limit, wireFee) === 1
+ ? Amounts.sub(limit, wireFee).amount
+ : Amounts.zeroOfAmount(limit);
+
const errorsWire = undefinedIfEmpty({
account: !account
? i18n.str`Required`
@@ -129,7 +135,7 @@ export function PaytoWireTransferForm({
? i18n.str`Required`
: !parsedAmount
? i18n.str`Not valid`
- : validateAmount(parsedAmount, limit, wireFee, i18n),
+ : validateAmount(parsedAmount, limitWithFee, i18n),
});
const parsed = !rawPaytoInput ? undefined : parsePaytoUri(rawPaytoInput);
@@ -139,7 +145,7 @@ export function PaytoWireTransferForm({
? i18n.str`Required`
: !parsed
? i18n.str`Does not follow the pattern`
- : validateRawPayto(parsed, limit, wireFee, url.host, i18n, paytoType),
+ : validateRawPayto(parsed, limitWithFee, url.host, i18n, paytoType),
});
async function doSend() {
@@ -627,6 +633,17 @@ export function PaytoWireTransferForm({
</div>
</div>
)}
+ {Amounts.cmp(limitWithFee, balance) > 0 ? (
+ <p class="mt-2 text-sm text-gray-900">
+ <i18n.Translate>
+ You can transfer{" "}
+ <RenderAmount
+ value={limitWithFee}
+ spec={config.currency_specification}
+ />
+ </i18n.Translate>
+ </p>
+ ) : undefined}
</div>
{Amounts.isZero(wireFee) ? undefined : (
<div class="px-4 my-4">
@@ -800,7 +817,6 @@ export function RenderAmount({
function validateRawPayto(
parsed: PaytoUri,
limit: AmountJson,
- fee: AmountJson,
host: string,
i18n: InternationalizationAPI,
type: "iban" | "x-taler-bank",
@@ -844,7 +860,7 @@ function validateRawPayto(
if (!amount) {
return i18n.str`The "amount" parameter is not valid`;
}
- result = validateAmount(amount, limit, fee, i18n);
+ result = validateAmount(amount, limit, i18n);
if (result) return result;
if (!parsed.params.message) {
@@ -860,7 +876,6 @@ function validateRawPayto(
function validateAmount(
amount: AmountJson,
limit: AmountJson,
- fee: AmountJson,
i18n: InternationalizationAPI,
): TranslatedString | undefined {
if (amount.currency !== limit.currency) {
@@ -869,8 +884,7 @@ function validateAmount(
if (Amounts.isZero(amount)) {
return i18n.str`Can't transfer zero amount`;
}
- const amountWithFee = Amounts.add(amount, fee).amount;
- if (Amounts.cmp(limit, amountWithFee) === -1) {
+ if (Amounts.cmp(limit, amount) === -1) {
return i18n.str`Balance is not enough`;
}
return undefined;