summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-04-25 22:37:41 -0300
committerSebastian <sebasjm@gmail.com>2022-04-26 11:48:28 -0300
commit65e6a8caa0de98632ad99cca35bf98bffe663dff (patch)
tree53bd9ec1c376e9cb73c57ba4ce223899c0b0751e /packages/taler-wallet-webextension/src/cta/Withdraw.tsx
parent1e6b2dd150416d4acfac4cf4068c41edb036d5e0 (diff)
downloadwallet-core-65e6a8caa0de98632ad99cca35bf98bffe663dff.tar.gz
wallet-core-65e6a8caa0de98632ad99cca35bf98bffe663dff.tar.bz2
wallet-core-65e6a8caa0de98632ad99cca35bf98bffe663dff.zip
useAsync new API
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.tsx')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.tsx60
1 files changed, 28 insertions, 32 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index 21f98ec9a..56c64a6d7 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -40,7 +40,11 @@ import {
WalletAction,
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import { HookError, useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
+import {
+ HookError,
+ useAsyncAsHook,
+ useAsyncAsHook2,
+} from "../hooks/useAsyncAsHook.js";
import { buildTermsOfServiceState } from "../utils/index.js";
import { ButtonHandler, SelectFieldHandler } from "../mui/handlers.js";
import * as wxApi from "../wxApi.js";
@@ -99,7 +103,7 @@ export function useComponentState(
/**
* Ask the wallet about the withdraw URI
*/
- const uriInfoHook = useAsyncAsHook(async () => {
+ const uriInfoHook = useAsyncAsHook2(async () => {
if (!talerWithdrawUri) throw Error("ERROR_NO-URI-FOR-WITHDRAWAL");
const uriInfo = await api.getWithdrawalDetailsForUri({
@@ -147,44 +151,36 @@ export function useComponentState(
/**
* For the exchange selected, bring the status of the terms of service
*/
- const terms = useAsyncAsHook(
- async () => {
- if (!thisExchange) return false;
+ const terms = useAsyncAsHook2(async () => {
+ if (!thisExchange) return false;
- const exchangeTos = await api.getExchangeTos(thisExchange, ["text/xml"]);
+ const exchangeTos = await api.getExchangeTos(thisExchange, ["text/xml"]);
- const state = buildTermsOfServiceState(exchangeTos);
+ const state = buildTermsOfServiceState(exchangeTos);
- return { state };
- },
- [],
- [thisExchange],
- );
+ return { state };
+ }, [thisExchange]);
/**
* With the exchange and amount, ask the wallet the information
* about the withdrawal
*/
- const info = useAsyncAsHook(
- async () => {
- if (!thisExchange || !amount) return false;
-
- const info = await api.getExchangeWithdrawalInfo({
- exchangeBaseUrl: thisExchange,
- amount,
- tosAcceptedFormat: ["text/xml"],
- });
-
- const withdrawalFee = Amounts.sub(
- Amounts.parseOrThrow(info.withdrawalAmountRaw),
- Amounts.parseOrThrow(info.withdrawalAmountEffective),
- ).amount;
-
- return { info, withdrawalFee };
- },
- [],
- [thisExchange, amount],
- );
+ const info = useAsyncAsHook2(async () => {
+ if (!thisExchange || !amount) return false;
+
+ const info = await api.getExchangeWithdrawalInfo({
+ exchangeBaseUrl: thisExchange,
+ amount,
+ tosAcceptedFormat: ["text/xml"],
+ });
+
+ const withdrawalFee = Amounts.sub(
+ Amounts.parseOrThrow(info.withdrawalAmountRaw),
+ Amounts.parseOrThrow(info.withdrawalAmountEffective),
+ ).amount;
+
+ return { info, withdrawalFee };
+ }, [thisExchange, amount]);
const [reviewing, setReviewing] = useState<boolean>(false);
const [reviewed, setReviewed] = useState<boolean>(false);