commit fe65e2c97b2f4ed95bf4cdf6c4e8c1104ce0846a
parent 654d6203e774a7fe62fb9cb93e78ae629b43c30d
Author: Sebastian <sebasjm@taler-systems.com>
Date: Wed, 5 Aug 2026 18:13:13 -0300
do not unload when deps change, unload when the component is unmounted
Diffstat:
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/state.ts b/packages/taler-wallet-webextension/src/cta/Deposit/state.ts
@@ -31,10 +31,12 @@ export function useComponentState({
}: Props): State {
const api = useBackendContext();
const { pushAlertOnError } = useAlertContext();
- const [amount, setAmount] = useState(Amounts.zeroOfCurrency(scope.currency));
+ const zero = Amounts.zeroOfCurrency(scope.currency);
+ const [amount, setAmount] = useState(zero);
const amountStr = Amounts.stringify(amount);
const hook = useAsyncAsHook(async () => {
+ if (Amounts.isZero(amount)) return undefined
const deposit = await api.wallet.call(WalletApiOperation.CheckDeposit, {
amount: amountStr,
depositPaytoUri: Paytos.toFullString(account),
@@ -56,14 +58,14 @@ export function useComponentState({
// }
const debitAmount =
- !hook || hook.hasError
- ? Amounts.zeroOfCurrency(scope.currency)
+ !hook || hook.hasError || !hook.response
+ ? zero
: Amounts.parseOrThrow(hook.response.effectiveDepositAmount);
const toBeReceived =
- !hook || hook.hasError
- ? Amounts.zeroOfCurrency(scope.currency)
+ !hook || hook.hasError || !hook.response
+ ? zero
: Amounts.parseOrThrow(hook.response.totalDepositCost);
- // const { deposit, uri, amount } = hook.response;
+
async function doDeposit(): Promise<void> {
const resp = await api.wallet.call(WalletApiOperation.CreateDepositGroup, {
amount: amountStr,
diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
@@ -52,14 +52,15 @@ export function useAsyncAsHook<T>(
): HookResponseWithRetry<T> {
const [result, setHookResponse] = useState<HookResponse<T>>(undefined);
const unload = useRef(false);
+
async function doAsync(): Promise<void> {
try {
const response = await fn();
if (response === false || unload.current) return;
setHookResponse({ hasError: false, response });
} catch (e) {
- console.log(e)
- if (unload.current) return
+ console.log(e);
+ if (unload.current) return;
if (e instanceof TalerError) {
setHookResponse({
hasError: true,
@@ -86,11 +87,14 @@ export function useAsyncAsHook<T>(
useEffect(() => {
doAsync();
- return () => {
- unload.current = true
- }
}, deps ?? []);
+ useEffect(() => {
+ return () => {
+ unload.current = true;
+ };
+ }, []);
+
if (!result) return undefined;
return { ...result, retry: doAsync };
}