diff options
author | Sebastian <sebasjm@gmail.com> | 2022-03-30 14:22:42 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-03-30 14:23:28 -0300 |
commit | 8642f8edcd1aa8fe18c50d534f485debf1df01c9 (patch) | |
tree | 03c8d62706e7d3e0b6f38e4ddf8c643582bfad63 /packages/taler-wallet-webextension/src/cta | |
parent | bbd6ccf1c7c0baea44234863967e640f5cb10a3a (diff) | |
download | wallet-core-8642f8edcd1aa8fe18c50d534f485debf1df01c9.tar.xz |
fix loop rendering
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Deposit.tsx | 3 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Pay.tsx | 2 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/cta/Withdraw.tsx | 79 |
3 files changed, 53 insertions, 31 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Deposit.tsx b/packages/taler-wallet-webextension/src/cta/Deposit.tsx index 7ade50e2c..541bc733b 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit.tsx +++ b/packages/taler-wallet-webextension/src/cta/Deposit.tsx @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* This file is part of TALER (C) 2015 GNUnet e.V. @@ -197,7 +198,7 @@ export function PaymentRequestView({ payStatus, payResult, }: PaymentRequestViewProps): VNode { - let totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw); + const totalFees: AmountJson = Amounts.getZero(payStatus.amountRaw); const contractTerms: ContractTerms = payStatus.contractTerms; const { i18n } = useTranslationContext(); diff --git a/packages/taler-wallet-webextension/src/cta/Pay.tsx b/packages/taler-wallet-webextension/src/cta/Pay.tsx index c2f352661..13fb69853 100644 --- a/packages/taler-wallet-webextension/src/cta/Pay.tsx +++ b/packages/taler-wallet-webextension/src/cta/Pay.tsx @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @typescript-eslint/no-non-null-assertion */ /* This file is part of TALER (C) 2015 GNUnet e.V. diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx index 67a910397..64a0c2586 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx @@ -28,7 +28,7 @@ import { WithdrawUriInfoResponse, } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useCallback, useMemo, useState } from "preact/hooks"; import { Loading } from "../components/Loading.js"; import { LoadingError } from "../components/LoadingError.js"; import { ErrorTalerOperation } from "../components/ErrorTalerOperation.js"; @@ -247,37 +247,52 @@ export function WithdrawPageWithParsedURI({ const [reviewing, setReviewing] = useState<boolean>(false); const [reviewed, setReviewed] = useState<boolean>(false); - const knownExchangesHook = useAsyncAsHook(() => wxApi.listExchanges()); + const knownExchangesHook = useAsyncAsHook( + useCallback(() => wxApi.listExchanges(), []), + ); - const knownExchanges = - !knownExchangesHook || knownExchangesHook.hasError - ? [] - : knownExchangesHook.response.exchanges; - const withdrawAmount = Amounts.parseOrThrow(uriInfo.amount); - const thisCurrencyExchanges = knownExchanges.filter( - (ex) => ex.currency === withdrawAmount.currency, + const knownExchanges = useMemo( + () => + !knownExchangesHook || knownExchangesHook.hasError + ? [] + : knownExchangesHook.response.exchanges, + [knownExchangesHook], + ); + const withdrawAmount = useMemo( + () => Amounts.parseOrThrow(uriInfo.amount), + [uriInfo.amount], + ); + const thisCurrencyExchanges = useMemo( + () => + knownExchanges.filter((ex) => ex.currency === withdrawAmount.currency), + [knownExchanges, withdrawAmount.currency], ); - const exchange: string | undefined = - customExchange ?? - uriInfo.defaultExchangeBaseUrl ?? - (thisCurrencyExchanges[0] - ? thisCurrencyExchanges[0].exchangeBaseUrl - : undefined); + const exchange: string | undefined = useMemo( + () => + customExchange ?? + uriInfo.defaultExchangeBaseUrl ?? + (thisCurrencyExchanges[0] + ? thisCurrencyExchanges[0].exchangeBaseUrl + : undefined), + [customExchange, thisCurrencyExchanges, uriInfo.defaultExchangeBaseUrl], + ); - const detailsHook = useAsyncAsHook(async () => { - if (!exchange) throw Error("no default exchange"); - const tos = await wxApi.getExchangeTos(exchange, ["text/xml"]); + const detailsHook = useAsyncAsHook( + useCallback(async () => { + if (!exchange) throw Error("no default exchange"); + const tos = await wxApi.getExchangeTos(exchange, ["text/xml"]); - const tosState = buildTermsOfServiceState(tos); + const tosState = buildTermsOfServiceState(tos); - const info = await wxApi.getExchangeWithdrawalInfo({ - exchangeBaseUrl: exchange, - amount: withdrawAmount, - tosAcceptedFormat: ["text/xml"], - }); - return { tos: tosState, info }; - }); + const info = await wxApi.getExchangeWithdrawalInfo({ + exchangeBaseUrl: exchange, + amount: withdrawAmount, + tosAcceptedFormat: ["text/xml"], + }); + return { tos: tosState, info }; + }, [exchange, withdrawAmount]), + ); if (!detailsHook) { return <Loading />; @@ -342,10 +357,14 @@ export function WithdrawPageWithParsedURI({ } export function WithdrawPage({ talerWithdrawUri }: Props): VNode { const { i18n } = useTranslationContext(); - const uriInfoHook = useAsyncAsHook(() => - !talerWithdrawUri - ? Promise.reject(undefined) - : wxApi.getWithdrawalDetailsForUri({ talerWithdrawUri }), + const uriInfoHook = useAsyncAsHook( + useCallback( + () => + !talerWithdrawUri + ? Promise.reject(undefined) + : wxApi.getWithdrawalDetailsForUri({ talerWithdrawUri }), + [talerWithdrawUri], + ), ); if (!talerWithdrawUri) { |