diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/ExchangeSelection')
4 files changed, 26 insertions, 17 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts index bdbd36596..3f37dda77 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/example.ts @@ -15,7 +15,7 @@ */ import { - ExchangeFullDetailsListItem, + ExchangeFullDetails, ExchangeListItem, } from "@gnu-taler/taler-util"; @@ -24,7 +24,7 @@ import { * @author Sebastian Javier Marchano (sebasjm) */ -export const bitcoinExchanges: ExchangeFullDetailsListItem[] = [ +export const bitcoinExchanges: ExchangeFullDetails[] = [ { exchangeBaseUrl: "https://bitcoin1.ice.bfh.ch/", currency: "BITCOINBTC", @@ -11781,7 +11781,7 @@ export const bitcoinExchanges: ExchangeFullDetailsListItem[] = [ }, ] as any; -export const kudosExchanges: ExchangeFullDetailsListItem[] = [ +export const kudosExchanges: ExchangeFullDetails[] = [ { exchangeBaseUrl: "https://exchange1.demo.taler.net/", currency: "KUDOS", diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts index 0dec00b09..061c94ad7 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { AbsoluteTime, AmountJson, ExchangeFullDetailsListItem } from "@gnu-taler/taler-util"; +import { AbsoluteTime, AmountJson, ExchangeFullDetails } from "@gnu-taler/taler-util"; import { Loading } from "../../components/Loading.js"; import { HookError } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js"; @@ -52,7 +52,7 @@ export namespace State { export interface BaseInfo { exchanges: SelectFieldHandler; - selected: ExchangeFullDetailsListItem; + selected: ExchangeFullDetails; nextFeeUpdate: AbsoluteTime; error: undefined; } diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts index eda755e96..28d34578a 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts @@ -25,11 +25,21 @@ export function useComponentState( { onCancel, onSelection, currency }: Props, api: typeof wxApi, ): State { - const hook = useAsyncAsHook(api.listExchangesDetailled); - const initialValue = 0 const [value, setValue] = useState(String(initialValue)); + const hook = useAsyncAsHook(async () => { + const { exchanges } = await api.listExchanges() + + const selectedIdx = parseInt(value, 10) + const selectedExchange = exchanges.length == 0 ? undefined : exchanges[selectedIdx] + const selected = !selectedExchange ? undefined : await api.getExchangeDetailedInfo(selectedExchange.exchangeBaseUrl) + + const initialExchange = selectedIdx === initialValue ? undefined : exchanges[initialValue] + const original = !initialExchange ? undefined : await api.getExchangeDetailedInfo(initialExchange.exchangeBaseUrl) + return { exchanges, selected, original } + }); + if (!hook) { return { status: "loading", @@ -43,18 +53,16 @@ export function useComponentState( }; } - const exchanges = hook.response.exchanges; + const { exchanges, selected, original } = hook.response; - if (exchanges.length === 0) { + if (!selected) { + //!selected <=> exchanges.length === 0 return { status: "no-exchanges", error: undefined } } - const original = exchanges[initialValue]; - const selected = exchanges[Number(value)]; - let nextFeeUpdate = TalerProtocolTimestamp.never(); nextFeeUpdate = Object.values(selected.wireInfo.feesForType).reduce( @@ -97,7 +105,8 @@ export function useComponentState( const exchangeMap = exchanges.reduce((prev, cur, idx) => ({ ...prev, [cur.exchangeBaseUrl]: String(idx) }), {} as Record<string, string>) - if (original === selected) { + if (!original) { + // !original <=> selected == original return { status: "ready", exchanges: { diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx index 094087517..cb4cc7c69 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/stories.tsx @@ -19,7 +19,7 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { ExchangeFullDetailsListItem, ExchangeListItem } from "@gnu-taler/taler-util"; +import { ExchangeFullDetails, ExchangeListItem } from "@gnu-taler/taler-util"; import { createExample } from "../../test-utils.js"; import { bitcoinExchanges, kudosExchanges } from "./example.js"; import { FeeDescription, FeeDescriptionPair, OperationMap } from "./index.js"; @@ -34,7 +34,7 @@ export default { }; function timelineForExchange( - ex: ExchangeFullDetailsListItem, + ex: ExchangeFullDetails, ): OperationMap<FeeDescription[]> { return { deposit: createDenominationTimeline( @@ -61,8 +61,8 @@ function timelineForExchange( } function timelinePairForExchange( - ex1: ExchangeFullDetailsListItem, - ex2: ExchangeFullDetailsListItem, + ex1: ExchangeFullDetails, + ex2: ExchangeFullDetails, ): OperationMap<FeeDescriptionPair[]> { const om1 = timelineForExchange(ex1); const om2 = timelineForExchange(ex2); |