summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta/Withdraw/state.ts')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/state.ts49
1 files changed, 43 insertions, 6 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
index 7bff13e51..bf460834d 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
@@ -21,11 +21,12 @@ import {
ExchangeFullDetails,
ExchangeListItem,
ExchangeTosStatus,
+ NotificationType,
TalerError,
parseWithdrawExchangeUri,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
-import { useEffect, useState } from "preact/hooks";
+import { useEffect, useState, useMemo, useCallback } from "preact/hooks";
import { alertFromError, useAlertContext } from "../../context/alert.js";
import { useBackendContext } from "../../context/backend.js";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
@@ -208,17 +209,40 @@ export function useComponentStateFromURI({
WalletApiOperation.GetWithdrawalDetailsForUri,
{
talerWithdrawUri,
+ notifyChangeFromPendingTimeoutMs: 30 * 1000
},
);
- const { amount, defaultExchangeBaseUrl, possibleExchanges } = uriInfo;
+ const { amount, defaultExchangeBaseUrl, possibleExchanges, operationId, confirmTransferUrl, status } = uriInfo;
+ const transaction = await api.wallet.call(
+ WalletApiOperation.GetWithdrawalTransactionByUri,
+ { talerWithdrawUri },
+ );
return {
talerWithdrawUri,
+ operationId,
+ status,
+ transaction,
+ confirmTransferUrl,
amount: Amounts.parseOrThrow(amount),
thisExchange: defaultExchangeBaseUrl,
exchanges: possibleExchanges,
};
});
+ const readyToListen = uriInfoHook && !uriInfoHook.hasError
+
+ useEffect(() => {
+ if (!uriInfoHook) {
+ return;
+ }
+ return api.listener.onUpdateNotification(
+ [NotificationType.WithdrawalOperationTransition],
+ () => {
+ uriInfoHook.retry()
+ },
+ );
+ }, [readyToListen]);
+
if (!uriInfoHook) return { status: "loading", error: undefined };
if (uriInfoHook.hasError) {
@@ -257,8 +281,20 @@ export function useComponentStateFromURI({
};
}
- return () =>
- exchangeSelectionState(
+ if (uriInfoHook.response.status !== "pending") {
+ if (uriInfoHook.response.transaction) {
+ onSuccess(uriInfoHook.response.transaction.transactionId)
+ }
+ return {
+ status: "already-completed",
+ operationState: uriInfoHook.response.status,
+ confirmTransferUrl: uriInfoHook.response.confirmTransferUrl,
+ error: undefined,
+ }
+ }
+
+ return useCallback(() => {
+ return exchangeSelectionState(
doManagedWithdraw,
cancel,
onSuccess,
@@ -267,6 +303,7 @@ export function useComponentStateFromURI({
exchangeList,
defaultExchange,
);
+ }, [])
}
type ManualOrManagedWithdrawFunction = (
@@ -294,7 +331,7 @@ function exchangeSelectionState(
return selectedExchange;
}
- return (): State.Success | State.LoadingUriError | State.Loading => {
+ return useCallback((): State.Success | State.LoadingUriError | State.Loading => {
const { i18n } = useTranslationContext();
const { pushAlertOnError } = useAlertContext();
const [ageRestricted, setAgeRestricted] = useState(0);
@@ -428,5 +465,5 @@ function exchangeSelectionState(
},
cancel,
};
- };
+ }, []);
}