diff options
author | Sebastian <sebasjm@gmail.com> | 2022-09-20 20:26:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-09-20 20:26:47 -0300 |
commit | 859991a40c4a7757d874f9ae6e6db7b76145a3c3 (patch) | |
tree | 2d029521929fa63f731e0b62bd3342f6f70ad2f8 /packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts | |
parent | 7adaeff0a57bc2d0633dd6a2c750a91facc03c4d (diff) | |
download | wallet-core-859991a40c4a7757d874f9ae6e6db7b76145a3c3.tar.xz |
exchange selection for invoices and some fixes
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts b/packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts index d9085153e..7219c30d2 100644 --- a/packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts +++ b/packages/taler-wallet-webextension/src/hooks/useSelectedExchange.ts @@ -24,6 +24,7 @@ export namespace State { export interface NoExchange { status: "no-exchange" error: undefined; + currency: string | undefined; } export interface Ready { status: "ready", @@ -59,25 +60,27 @@ export function useSelectedExchange({ currency, defaultExchange, list }: Props): return { status: "no-exchange", error: undefined, + currency: undefined, } } - const firstByCurrency = list.find((e) => e.currency === currency) - if (!firstByCurrency) { + const listCurrency = list.filter((e) => e.currency === currency) + if (!listCurrency.length) { // there should be at least one exchange for this currency return { status: "no-exchange", error: undefined, + currency, } } if (isSelecting) { - const currentExchange = selectedExchange ?? defaultExchange ?? firstByCurrency.exchangeBaseUrl; + const currentExchange = selectedExchange ?? defaultExchange ?? listCurrency[0].exchangeBaseUrl; return { status: "selecting-exchange", error: undefined, - list, + list: listCurrency, currency, currentExchange: currentExchange, onSelection: async (exchangeBaseUrl: string) => { @@ -120,6 +123,6 @@ export function useSelectedExchange({ currency, defaultExchange, list }: Props): doSelect: { onClick: async () => setIsSelecting(true) }, - selected: firstByCurrency + selected: listCurrency[0] } } |