diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-20 16:04:51 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-20 16:05:59 -0300 |
commit | 52ec740c825d4e94fd59ef0a5cd8e8b73f4dfc06 (patch) | |
tree | dd65f9852005097c2cd8975b14ccbd198bef57e8 /packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts | |
parent | a5525eab1e96d5b08fbb6442275b1e92f7f8d806 (diff) | |
download | wallet-core-52ec740c825d4e94fd59ef0a5cd8e8b73f4dfc06.tar.xz |
new compose feature: sub-states
implemented in withdraw page, WIP
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts index 8c0c21486..db6138f8e 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts @@ -22,14 +22,17 @@ import * as wxApi from "../../wxApi.js"; import { Props, State } from "./index.js"; export function useComponentState( - { onCancel, onSelection, currency }: Props, + { onCancel, onSelection, list: exchanges, currentExchange }: Props, api: typeof wxApi, ): State { - const initialValue = 0; + const initialValue = exchanges.findIndex(e => e.exchangeBaseUrl === currentExchange); + if (initialValue === -1) { + throw Error(`wrong usage of ExchangeSelection component, currentExchange '${currentExchange}' is not in the list of exchanges`) + } const [value, setValue] = useState(String(initialValue)); const hook = useAsyncAsHook(async () => { - const { exchanges } = await api.listExchanges(); + // const { exchanges } = await api.listExchanges(); const selectedIdx = parseInt(value, 10); const selectedExchange = @@ -54,12 +57,12 @@ export function useComponentState( } if (hook.hasError) { return { - status: "loading-uri", + status: "error-loading", error: hook, }; } - const { exchanges, selected, original } = hook.response; + const { selected, original } = hook.response; if (!selected) { //!selected <=> exchanges.length === 0 |