summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/cta
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2024-02-27 15:46:45 +0100
committerFlorian Dold <florian@dold.me>2024-02-27 15:46:45 +0100
commit525a66bcca5ee58814573d3810c0fbc02e937883 (patch)
tree44b14f7b7cd8f61faad73ed0bc7c47aee9f9b2f0 /packages/taler-wallet-webextension/src/cta
parent11f36c77a1e5722cab5459fbf4ec6752781e84c8 (diff)
downloadwallet-core-525a66bcca5ee58814573d3810c0fbc02e937883.tar.gz
wallet-core-525a66bcca5ee58814573d3810c0fbc02e937883.tar.bz2
wallet-core-525a66bcca5ee58814573d3810c0fbc02e937883.zip
wallet-core: types for observability
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw/state.ts91
1 files changed, 57 insertions, 34 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
index 515c5765e..a49ad3d36 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts
@@ -22,7 +22,7 @@ import {
ExchangeListItem,
NotificationType,
TalerError,
- parseWithdrawExchangeUri
+ parseWithdrawExchangeUri,
} from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { useTranslationContext } from "@gnu-taler/web-util/browser";
@@ -140,8 +140,8 @@ export function useComponentStateFromParams({
confirm: {
onClick: isValid
? pushAlertOnError(async () => {
- onAmountChanged(Amounts.stringify(amount));
- })
+ onAmountChanged(Amounts.stringify(amount));
+ })
: undefined,
},
amount: {
@@ -208,10 +208,17 @@ export function useComponentStateFromURI({
WalletApiOperation.GetWithdrawalDetailsForUri,
{
talerWithdrawUri,
- notifyChangeFromPendingTimeoutMs: 30 * 1000
+ notifyChangeFromPendingTimeoutMs: 30 * 1000,
},
);
- const { amount, defaultExchangeBaseUrl, possibleExchanges, operationId, confirmTransferUrl, status } = uriInfo;
+ const {
+ amount,
+ defaultExchangeBaseUrl,
+ possibleExchanges,
+ operationId,
+ confirmTransferUrl,
+ status,
+ } = uriInfo;
const transaction = await api.wallet.call(
WalletApiOperation.GetWithdrawalTransactionByUri,
{ talerWithdrawUri },
@@ -228,16 +235,16 @@ export function useComponentStateFromURI({
};
});
- const readyToListen = uriInfoHook && !uriInfoHook.hasError
+ const readyToListen = uriInfoHook && !uriInfoHook.hasError;
useEffect(() => {
if (!uriInfoHook) {
return;
}
return api.listener.onUpdateNotification(
- [NotificationType.WithdrawalOperationTransition],
+ [NotificationType.TransactionStateTransition],
() => {
- uriInfoHook.retry()
+ uriInfoHook.retry();
},
);
}, [readyToListen]);
@@ -282,14 +289,14 @@ export function useComponentStateFromURI({
if (uriInfoHook.response.status !== "pending") {
if (uriInfoHook.response.transaction) {
- onSuccess(uriInfoHook.response.transaction.transactionId)
+ onSuccess(uriInfoHook.response.transaction.transactionId);
}
return {
status: "already-completed",
operationState: uriInfoHook.response.status,
confirmTransferUrl: uriInfoHook.response.confirmTransferUrl,
error: undefined,
- }
+ };
}
return useCallback(() => {
@@ -302,7 +309,7 @@ export function useComponentStateFromURI({
exchangeList,
defaultExchange,
);
- }, [])
+ }, []);
}
type ManualOrManagedWithdrawFunction = (
@@ -330,13 +337,18 @@ function exchangeSelectionState(
return selectedExchange;
}
- return useCallback((): 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);
const currentExchange = selectedExchange.selected;
- const [selectedCurrency, setSelectedCurrency] = useState<string>(chosenAmount.currency)
+ const [selectedCurrency, setSelectedCurrency] = useState<string>(
+ chosenAmount.currency,
+ );
/**
* With the exchange and amount, ask the wallet the information
* about the withdrawal
@@ -359,7 +371,7 @@ function exchangeSelectionState(
return {
amount: withdrawAmount,
ageRestrictionOptions: info.ageRestrictionOptions,
- accounts: info.withdrawalAccountsList
+ accounts: info.withdrawalAccountsList,
};
}, []);
@@ -424,23 +436,33 @@ function exchangeSelectionState(
//TODO: calculate based on exchange info
const ageRestriction = ageRestrictionEnabled
? {
- list: ageRestrictionOptions,
- value: String(ageRestricted),
- onChange: pushAlertOnError(async (v: string) =>
- setAgeRestricted(parseInt(v, 10)),
- ),
- }
+ list: ageRestrictionOptions,
+ value: String(ageRestricted),
+ onChange: pushAlertOnError(async (v: string) =>
+ setAgeRestricted(parseInt(v, 10)),
+ ),
+ }
: undefined;
- const altCurrencies = amountHook.response.accounts.filter(a => !!a.currencySpecification).map(a => a.currencySpecification!.name)
- const chooseCurrencies = altCurrencies.length === 0 ? [] : [toBeReceived.currency, ...altCurrencies]
- const convAccount = amountHook.response.accounts.find(c => {
- return c.currencySpecification && c.currencySpecification.name === selectedCurrency
- })
- const conversionInfo = !convAccount ? undefined : ({
- spec: convAccount.currencySpecification!,
- amount: Amounts.parseOrThrow(convAccount.transferAmount!)
- })
+ const altCurrencies = amountHook.response.accounts
+ .filter((a) => !!a.currencySpecification)
+ .map((a) => a.currencySpecification!.name);
+ const chooseCurrencies =
+ altCurrencies.length === 0
+ ? []
+ : [toBeReceived.currency, ...altCurrencies];
+ const convAccount = amountHook.response.accounts.find((c) => {
+ return (
+ c.currencySpecification &&
+ c.currencySpecification.name === selectedCurrency
+ );
+ });
+ const conversionInfo = !convAccount
+ ? undefined
+ : {
+ spec: convAccount.currencySpecification!,
+ amount: Amounts.parseOrThrow(convAccount.transferAmount!),
+ };
return {
status: "success",
@@ -450,17 +472,18 @@ function exchangeSelectionState(
toBeReceived,
chooseCurrencies,
selectedCurrency,
- changeCurrency: (s) => { setSelectedCurrency(s) },
+ changeCurrency: (s) => {
+ setSelectedCurrency(s);
+ },
conversionInfo,
withdrawalFee,
chosenAmount,
talerWithdrawUri,
ageRestriction,
doWithdrawal: {
- onClick:
- doingWithdraw
- ? undefined
- : pushAlertOnError(doWithdrawAndCheckError),
+ onClick: doingWithdraw
+ ? undefined
+ : pushAlertOnError(doWithdrawAndCheckError),
},
cancel,
};