From 65e6a8caa0de98632ad99cca35bf98bffe663dff Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Apr 2022 22:37:41 -0300 Subject: useAsync new API --- .../taler-wallet-webextension/src/cta/Withdraw.tsx | 60 ++++++++++------------ 1 file changed, 28 insertions(+), 32 deletions(-) (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw.tsx') 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(false); const [reviewed, setReviewed] = useState(false); -- cgit v1.2.3