aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-12-15 17:12:03 -0300
committerSebastian <sebasjm@gmail.com>2022-12-15 17:12:03 -0300
commitf1f8f818dbe631fbeeba64af9dfcae1aa7842615 (patch)
tree856d3b443556ce271c3e9fdab6aed7ae7728ab65 /packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts
parentf93bd51499ed34844b666bf6d333227adf4368bf (diff)
downloadwallet-core-f1f8f818dbe631fbeeba64af9dfcae1aa7842615.tar.xz
pretty
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts
index 5ad0841dc..02e85a1c7 100644
--- a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts
+++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts
@@ -21,7 +21,7 @@ import {
KnownBankAccountsInfo,
parsePaytoUri,
PaytoUri,
- stringifyPaytoUri
+ stringifyPaytoUri,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { useState } from "preact/hooks";
@@ -29,10 +29,13 @@ import { useBackendContext } from "../../context/backend.js";
import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js";
import { Props, State } from "./index.js";
-export function useComponentState(
- { amount: amountStr, currency: currencyStr, onCancel, onSuccess }: Props,
-): State {
- const api = useBackendContext()
+export function useComponentState({
+ amount: amountStr,
+ currency: currencyStr,
+ onCancel,
+ onSuccess,
+}: Props): State {
+ const api = useBackendContext();
const parsed = amountStr === undefined ? undefined : Amounts.parse(amountStr);
const currency = parsed !== undefined ? parsed.currency : currencyStr;
@@ -55,8 +58,8 @@ export function useComponentState(
parsed !== undefined
? parsed
: currency !== undefined
- ? Amounts.zeroOfCurrency(currency)
- : undefined;
+ ? Amounts.zeroOfCurrency(currency)
+ : undefined;
// const [accountIdx, setAccountIdx] = useState<number>(0);
const [amount, setAmount] = useState<AmountJson>(initialValue ?? ({} as any));
const [selectedAccount, setSelectedAccount] = useState<PaytoUri>();
@@ -162,7 +165,11 @@ export function useComponentState(
async function updateAmount(newAmount: AmountJson): Promise<void> {
// const parsed = Amounts.parse(`${currency}:${numStr}`);
try {
- const result = await getFeeForAmount(currentAccount, newAmount, api.wallet);
+ const result = await getFeeForAmount(
+ currentAccount,
+ newAmount,
+ api.wallet,
+ );
setAmount(newAmount);
setFee(result);
} catch (e) {
@@ -185,8 +192,8 @@ export function useComponentState(
const amountError = !isDirty
? undefined
: Amounts.cmp(balance, amount) === -1
- ? `Too much, your current balance is ${Amounts.stringifyValue(balance)}`
- : undefined;
+ ? `Too much, your current balance is ${Amounts.stringifyValue(balance)}`
+ : undefined;
const unableToDeposit =
Amounts.isZero(totalToDeposit) || //deposit may be zero because of fee