diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-06 17:17:44 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-06 17:17:50 -0300 |
commit | 1e00724a0dcd0d65e6d786a1d8d7cdffc9fe2a85 (patch) | |
tree | 34eb327ac3370174cec4365ecc375309462d239b /packages/taler-wallet-webextension/src/cta | |
parent | 49c9279c1e06a90757b2bd3e75b4887e71345d1d (diff) | |
download | wallet-core-1e00724a0dcd0d65e6d786a1d8d7cdffc9fe2a85.tar.xz |
listExchangesDetailed to getExchangeDetailedInfo & ageRestriction taken from the denoms
Diffstat (limited to 'packages/taler-wallet-webextension/src/cta')
3 files changed, 18 insertions, 16 deletions
diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index bb0f0d1af..804d216eb 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -30,7 +30,7 @@ export function useComponentState( const [subject, setSubject] = useState(""); const [talerUri, setTalerUri] = useState("") - const hook = useAsyncAsHook(api.listExchangesDetailled); + const hook = useAsyncAsHook(api.listExchanges); const [exchangeIdx, setExchangeIdx] = useState("0") const [operationError, setOperationError] = useState<TalerErrorDetail | undefined>(undefined) diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 58d3cfedf..015c9aaca 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -30,7 +30,7 @@ export function useComponentStateFromParams( const [ageRestricted, setAgeRestricted] = useState(0); - const exchangeHook = useAsyncAsHook(api.listExchangesDetailled); + const exchangeHook = useAsyncAsHook(api.listExchanges); const exchangeHookDep = !exchangeHook || exchangeHook.hasError || !exchangeHook.response @@ -65,6 +65,7 @@ export function useComponentStateFromParams( exchangeBaseUrl: exchange.exchangeBaseUrl, amount: chosenAmount, tosAcceptedFormat: ["text/xml"], + ageRestricted, }); const withdrawAmount = { @@ -72,7 +73,7 @@ export function useComponentStateFromParams( effective: Amounts.parseOrThrow(info.withdrawalAmountEffective), } - return { amount: withdrawAmount }; + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions }; }, [exchangeHookDep]); const [reviewing, setReviewing] = useState<boolean>(false); @@ -172,16 +173,16 @@ export function useComponentStateFromParams( termsState !== undefined && (termsState.status === "changed" || termsState.status === "new"); - const ageRestrictionOptions: Record<string, string> | undefined = "6:12:18" - .split(":") - .reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {}); + const ageRestrictionOptions = amountHook.response. + ageRestrictionOptions?. + reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {} as Record<string, string>) - if (ageRestrictionOptions) { + const ageRestrictionEnabled = ageRestrictionOptions !== undefined + if (ageRestrictionEnabled) { ageRestrictionOptions["0"] = "Not restricted"; } //TODO: calculate based on exchange info - const ageRestrictionEnabled = false; const ageRestriction = ageRestrictionEnabled ? { list: ageRestrictionOptions, value: String(ageRestricted), @@ -269,6 +270,7 @@ export function useComponentStateFromURI( exchangeBaseUrl: uriHookDep?.thisExchange, amount: Amounts.parseOrThrow(uriHookDep.amount), tosAcceptedFormat: ["text/xml"], + ageRestricted, }); const withdrawAmount = { @@ -276,7 +278,7 @@ export function useComponentStateFromURI( effective: Amounts.parseOrThrow(info.withdrawalAmountEffective), } - return { amount: withdrawAmount }; + return { amount: withdrawAmount, ageRestrictionOptions: info.ageRestrictionOptions }; }, [uriHookDep]); const [reviewing, setReviewing] = useState<boolean>(false); @@ -385,16 +387,16 @@ export function useComponentStateFromURI( termsState !== undefined && (termsState.status === "changed" || termsState.status === "new"); - const ageRestrictionOptions: Record<string, string> | undefined = "6:12:18" - .split(":") - .reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {}); + const ageRestrictionOptions = amountHook.response. + ageRestrictionOptions?. + reduce((p, c) => ({ ...p, [c]: `under ${c}` }), {} as Record<string, string>) - if (ageRestrictionOptions) { + const ageRestrictionEnabled = ageRestrictionOptions !== undefined + if (ageRestrictionEnabled) { ageRestrictionOptions["0"] = "Not restricted"; } //TODO: calculate based on exchange info - const ageRestrictionEnabled = false; const ageRestriction = ageRestrictionEnabled ? { list: ageRestrictionOptions, value: String(ageRestricted), diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index 6c9e0c3ba..ce964f7f7 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -21,7 +21,7 @@ import { Amounts, - ExchangeFullDetailsListItem, + ExchangeFullDetails, ExchangeListItem, GetExchangeTosResult, } from "@gnu-taler/taler-util"; @@ -30,7 +30,7 @@ import { expect } from "chai"; import { mountHook } from "../../test-utils.js"; import { useComponentStateFromURI } from "./state.js"; -const exchanges: ExchangeFullDetailsListItem[] = [ +const exchanges: ExchangeFullDetails[] = [ { currency: "ARS", exchangeBaseUrl: "http://exchange.demo.taler.net", |