aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts50
-rw-r--r--packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/index.ts17
-rw-r--r--packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/state.ts7
-rw-r--r--packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/test.ts7
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts29
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts86
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ExchangeSelection/test.ts5
7 files changed, 110 insertions, 91 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts
index 12a13bbdf..99bb547de 100644
--- a/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts
+++ b/packages/taler-wallet-webextension/src/wallet/DepositPage.test.ts
@@ -62,9 +62,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:0` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:0` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: {} }),
} as Partial<typeof wxApi> as any),
);
@@ -89,9 +89,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:1` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:1` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: {} }),
} as Partial<typeof wxApi> as any),
);
@@ -111,19 +111,21 @@ describe("DepositPage states", () => {
await assertNoPendingUpdate();
});
- const ibanPayto_str = "payto://iban/ES8877998399652238"
+ const ibanPayto_str = "payto://iban/ES8877998399652238";
const ibanPayto = { ibanPayto_str: parsePaytoUri(ibanPayto_str)! };
- const talerBankPayto_str = "payto://x-taler-bank/ES8877998399652238"
- const talerBankPayto = { talerBankPayto_str: parsePaytoUri(talerBankPayto_str)! };
+ const talerBankPayto_str = "payto://x-taler-bank/ES8877998399652238";
+ const talerBankPayto = {
+ talerBankPayto_str: parsePaytoUri(talerBankPayto_str)!,
+ };
it("should have status 'ready' but unable to deposit ", async () => {
const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } =
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:1` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:1` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: ibanPayto }),
} as Partial<typeof wxApi> as any),
);
@@ -153,9 +155,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:1` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:1` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: ibanPayto }),
getFeeForDeposit: withoutFee,
} as Partial<typeof wxApi> as any),
@@ -202,9 +204,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:1` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:1` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: ibanPayto }),
getFeeForDeposit: withSomeFee,
} as Partial<typeof wxApi> as any),
@@ -252,9 +254,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:1` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:1` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({
accounts: { ...ibanPayto, ...talerBankPayto },
}),
@@ -338,9 +340,9 @@ describe("DepositPage states", () => {
mountHook(() =>
useComponentState(currency, nullFunction, nullFunction, {
getBalance: async () =>
- ({
- balances: [{ available: `${currency}:15` }],
- } as Partial<BalancesResponse>),
+ ({
+ balances: [{ available: `${currency}:15` }],
+ } as Partial<BalancesResponse>),
listKnownBankAccounts: async () => ({ accounts: ibanPayto }),
getFeeForDeposit: withSomeFee,
} as Partial<typeof wxApi> as any),
diff --git a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/index.ts b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/index.ts
index 2773e66f7..fd82cde73 100644
--- a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/index.ts
+++ b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/index.ts
@@ -25,13 +25,9 @@ export interface Props {
p: string;
}
-export type State =
- | State.Loading
- | State.LoadingUriError
- | State.Ready;
+export type State = State.Loading | State.LoadingUriError | State.Ready;
export namespace State {
-
export interface Loading {
status: "loading";
error: undefined;
@@ -54,10 +50,11 @@ export namespace State {
const viewMapping: StateViewMap<State> = {
loading: Loading,
"loading-uri": LoadingUriView,
- "ready": ReadyView,
+ ready: ReadyView,
};
-
-export const ComponentName = compose("ComponentName", (p: Props) => useComponentState(p, wxApi), viewMapping)
-
-
+export const ComponentName = compose(
+ "ComponentName",
+ (p: Props) => useComponentState(p, wxApi),
+ viewMapping,
+);
diff --git a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/state.ts b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/state.ts
index 45b174063..2c5ac95c0 100644
--- a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/state.ts
+++ b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/state.ts
@@ -17,12 +17,9 @@
import * as wxApi from "../../wxApi.js";
import { Props, State } from "./index.js";
-export function useComponentState(
- { p }: Props,
- api: typeof wxApi,
-): State {
+export function useComponentState({ p }: Props, api: typeof wxApi): State {
return {
status: "ready",
error: undefined,
- }
+ };
}
diff --git a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/test.ts b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/test.ts
index 631e76d01..eae4d4ca2 100644
--- a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/test.ts
+++ b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/test.ts
@@ -22,10 +22,7 @@
import { expect } from "chai";
describe("test description", () => {
-
it("should assert", () => {
-
- expect([]).deep.equals([])
+ expect([]).deep.equals([]);
});
-})
-
+});
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts
index 16ab7ab16..3b2708eff 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/index.ts
@@ -14,16 +14,25 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-import { FeeDescription, FeeDescriptionPair, AbsoluteTime, ExchangeFullDetails, OperationMap } from "@gnu-taler/taler-util";
+import {
+ FeeDescription,
+ FeeDescriptionPair,
+ AbsoluteTime,
+ ExchangeFullDetails,
+ OperationMap,
+} from "@gnu-taler/taler-util";
import { Loading } from "../../components/Loading.js";
import { HookError } from "../../hooks/useAsyncAsHook.js";
import { ButtonHandler, SelectFieldHandler } from "../../mui/handlers.js";
import { compose, StateViewMap } from "../../utils/index.js";
import * as wxApi from "../../wxApi.js";
import { useComponentState } from "./state.js";
-import { ComparingView, LoadingUriView, NoExchangesView, ReadyView } from "./views.js";
-
-
+import {
+ ComparingView,
+ LoadingUriView,
+ NoExchangesView,
+ ReadyView,
+} from "./views.js";
export interface Props {
currency?: string;
@@ -39,7 +48,6 @@ export type State =
| State.NoExchanges;
export namespace State {
-
export interface Loading {
status: "loading";
error: undefined;
@@ -75,13 +83,16 @@ export namespace State {
}
}
-
const viewMapping: StateViewMap<State> = {
loading: Loading,
"loading-uri": LoadingUriView,
- "comparing": ComparingView,
+ comparing: ComparingView,
"no-exchanges": NoExchangesView,
- "ready": ReadyView,
+ ready: ReadyView,
};
-export const ExchangeSelectionPage = compose("ExchangeSelectionPage", (p: Props) => useComponentState(p, wxApi), viewMapping)
+export const ExchangeSelectionPage = compose(
+ "ExchangeSelectionPage",
+ (p: Props) => useComponentState(p, wxApi),
+ viewMapping,
+);
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts
index 352952da0..8c0c21486 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts
@@ -14,7 +14,6 @@
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-
import { FeeDescription, OperationMap } from "@gnu-taler/taler-util";
import { createDenominationPairTimeline } from "@gnu-taler/taler-wallet-core";
import { useState } from "preact/hooks";
@@ -26,26 +25,32 @@ export function useComponentState(
{ onCancel, onSelection, currency }: Props,
api: typeof wxApi,
): State {
- const initialValue = 0
+ 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 }
+ 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",
error: undefined,
- }
+ };
}
if (hook.hasError) {
return {
@@ -60,11 +65,14 @@ export function useComponentState(
//!selected <=> exchanges.length === 0
return {
status: "no-exchanges",
- error: undefined
- }
+ error: undefined,
+ };
}
- const exchangeMap = exchanges.reduce((prev, cur, idx) => ({ ...prev, [cur.exchangeBaseUrl]: String(idx) }), {} as Record<string, string>)
+ const exchangeMap = exchanges.reduce(
+ (prev, cur, idx) => ({ ...prev, [cur.exchangeBaseUrl]: String(idx) }),
+ {} as Record<string, string>,
+ );
if (!original) {
// !original <=> selected == original
@@ -74,24 +82,36 @@ export function useComponentState(
list: exchangeMap,
value: value,
onChange: async (v) => {
- setValue(v)
- }
+ setValue(v);
+ },
},
error: undefined,
onClose: {
- onClick: onCancel
+ onClick: onCancel,
},
selected,
- timeline: selected.feesDescription
- }
+ timeline: selected.feesDescription,
+ };
}
const pairTimeline: OperationMap<FeeDescription[]> = {
- deposit: createDenominationPairTimeline(selected.feesDescription.deposit, original.feesDescription.deposit),
- refresh: createDenominationPairTimeline(selected.feesDescription.refresh, original.feesDescription.refresh),
- refund: createDenominationPairTimeline(selected.feesDescription.refund, original.feesDescription.refund),
- withdraw: createDenominationPairTimeline(selected.feesDescription.withdraw, original.feesDescription.withdraw),
- }
+ deposit: createDenominationPairTimeline(
+ selected.feesDescription.deposit,
+ original.feesDescription.deposit,
+ ),
+ refresh: createDenominationPairTimeline(
+ selected.feesDescription.refresh,
+ original.feesDescription.refresh,
+ ),
+ refund: createDenominationPairTimeline(
+ selected.feesDescription.refund,
+ original.feesDescription.refund,
+ ),
+ withdraw: createDenominationPairTimeline(
+ selected.feesDescription.withdraw,
+ original.feesDescription.withdraw,
+ ),
+ };
return {
status: "comparing",
@@ -99,23 +119,21 @@ export function useComponentState(
list: exchangeMap,
value: value,
onChange: async (v) => {
- setValue(v)
- }
+ setValue(v);
+ },
},
error: undefined,
onReset: {
onClick: async () => {
- setValue(String(initialValue))
- }
+ setValue(String(initialValue));
+ },
},
onSelect: {
onClick: async () => {
- onSelection(selected.exchangeBaseUrl)
- }
+ onSelection(selected.exchangeBaseUrl);
+ },
},
selected,
pairTimeline,
- }
-
+ };
}
-
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/test.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/test.ts
index 61bc6425f..3c7235851 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/test.ts
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/test.ts
@@ -19,8 +19,5 @@
* @author Sebastian Javier Marchano (sebasjm)
*/
-import {
- AbsoluteTime,
- Amounts, DenominationInfo
-} from "@gnu-taler/taler-util";
+import { AbsoluteTime, Amounts, DenominationInfo } from "@gnu-taler/taler-util";
import { expect } from "chai";