diff options
author | Sebastian <sebasjm@gmail.com> | 2022-12-15 17:11:24 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-12-15 17:11:24 -0300 |
commit | f93bd51499ed34844b666bf6d333227adf4368bf (patch) | |
tree | ed3cf0c38b7db54276436d1743a6085c94f71977 /packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts | |
parent | 8d8d71807df6b775e5b0335eb1b2526a56d42ac6 (diff) | |
download | wallet-core-f93bd51499ed34844b666bf6d333227adf4368bf.tar.xz |
wxApi from context and using the new testing sdk
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts index bbf2c2771..5ad0841dc 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts @@ -21,18 +21,18 @@ import { KnownBankAccountsInfo, parsePaytoUri, PaytoUri, - stringifyPaytoUri, + stringifyPaytoUri } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; +import { useBackendContext } from "../../context/backend.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; -import { wxApi } from "../../wxApi.js"; import { Props, State } from "./index.js"; export function useComponentState( { amount: amountStr, currency: currencyStr, onCancel, onSuccess }: Props, - api: typeof wxApi, ): State { + const api = useBackendContext() const parsed = amountStr === undefined ? undefined : Amounts.parse(amountStr); const currency = parsed !== undefined ? parsed.currency : currencyStr; @@ -55,8 +55,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>(); @@ -134,7 +134,7 @@ export function useComponentState( const currentAccount = !selectedAccount ? firstAccount : selectedAccount; if (fee === undefined) { - getFeeForAmount(currentAccount, amount, api).then((initialFee) => { + getFeeForAmount(currentAccount, amount, api.wallet).then((initialFee) => { setFee(initialFee); }); return { @@ -149,7 +149,7 @@ export function useComponentState( const uri = !accountStr ? undefined : parsePaytoUri(accountStr); if (uri) { try { - const result = await getFeeForAmount(uri, amount, api); + const result = await getFeeForAmount(uri, amount, api.wallet); setSelectedAccount(uri); setFee(result); } catch (e) { @@ -162,7 +162,7 @@ export function useComponentState( async function updateAmount(newAmount: AmountJson): Promise<void> { // const parsed = Amounts.parse(`${currency}:${numStr}`); try { - const result = await getFeeForAmount(currentAccount, newAmount, api); + const result = await getFeeForAmount(currentAccount, newAmount, api.wallet); setAmount(newAmount); setFee(result); } catch (e) { @@ -185,8 +185,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 @@ -243,11 +243,11 @@ export function useComponentState( async function getFeeForAmount( p: PaytoUri, a: AmountJson, - api: typeof wxApi, + wallet: ReturnType<typeof useBackendContext>["wallet"], ): Promise<DepositGroupFees> { const depositPaytoUri = `payto://${p.targetType}/${p.targetPath}`; const amount = Amounts.stringify(a); - return await api.wallet.call(WalletApiOperation.GetFeeForDeposit, { + return await wallet.call(WalletApiOperation.GetFeeForDeposit, { amount, depositPaytoUri, }); |