aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-04-25 23:07:31 -0300
committerSebastian <sebasjm@gmail.com>2022-04-26 11:48:29 -0300
commit41ab855736815d33f5fdbebc896b167c71482eee (patch)
treeb1c61f37f107f8118215483c4945bc942ee45b7a /packages
parent65e6a8caa0de98632ad99cca35bf98bffe663dff (diff)
remove old async hook
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-webextension/manifest-v2.json2
-rw-r--r--packages/taler-wallet-webextension/src/components/PendingTransactions.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/cta/Pay.tsx9
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.test.ts5
-rw-r--r--packages/taler-wallet-webextension/src/cta/Withdraw.tsx12
-rw-r--r--packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts44
-rw-r--r--packages/taler-wallet-webextension/src/popup/BalancePage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/BackupPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DepositPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/History.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/Settings.tsx4
-rw-r--r--packages/taler-wallet-webextension/src/wallet/Transaction.tsx4
17 files changed, 35 insertions, 85 deletions
diff --git a/packages/taler-wallet-webextension/manifest-v2.json b/packages/taler-wallet-webextension/manifest-v2.json
index 8f705d197..e92217b98 100644
--- a/packages/taler-wallet-webextension/manifest-v2.json
+++ b/packages/taler-wallet-webextension/manifest-v2.json
@@ -7,7 +7,7 @@
"version_name": "0.9.0-dev.9",
"minimum_chrome_version": "51",
"minimum_opera_version": "36",
- "applications": {
+ "browser_specific_settings": {
"gecko": {
"id": "wallet@taler.net",
"strict_min_version": "57.0"
diff --git a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx
index 0f1806fbf..2fc2d2d38 100644
--- a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx
+++ b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx
@@ -6,7 +6,7 @@ import {
} from "@gnu-taler/taler-util";
import { Fragment, h, JSX, VNode } from "preact";
import { useEffect } from "preact/hooks";
-import { useAsyncAsHook, useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { Avatar } from "../mui/Avatar.js";
import { Typography } from "../mui/Typography.js";
import * as wxApi from "../wxApi.js";
@@ -18,7 +18,7 @@ interface Props extends JSX.HTMLAttributes {
}
export function PendingTransactions({ goToTransaction }: Props): VNode {
- const state = useAsyncAsHook2(wxApi.getTransactions);
+ const state = useAsyncAsHook(wxApi.getTransactions);
useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => {
diff --git a/packages/taler-wallet-webextension/src/cta/Pay.tsx b/packages/taler-wallet-webextension/src/cta/Pay.tsx
index 9b7f7862f..3e9e34fe6 100644
--- a/packages/taler-wallet-webextension/src/cta/Pay.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Pay.tsx
@@ -29,7 +29,6 @@ import {
AmountJson,
Amounts,
ConfirmPayResult,
- ConfirmPayResultDone,
ConfirmPayResultType,
ContractTerms,
NotificationType,
@@ -60,11 +59,7 @@ import {
WarningBox,
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import {
- HookError,
- useAsyncAsHook,
- useAsyncAsHook2,
-} from "../hooks/useAsyncAsHook.js";
+import { HookError, useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { ButtonHandler } from "../mui/handlers.js";
import * as wxApi from "../wxApi.js";
@@ -112,7 +107,7 @@ export function useComponentState(
);
const [payErrMsg, setPayErrMsg] = useState<TalerError | undefined>(undefined);
- const hook = useAsyncAsHook2(async () => {
+ const hook = useAsyncAsHook(async () => {
if (!talerPayUri) throw Error("ERROR_NO-URI-FOR-PAYMENT");
const payStatus = await api.preparePay(talerPayUri);
const balance = await api.getBalance();
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts
index 0301e321c..7f05870c1 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.test.ts
@@ -58,7 +58,10 @@ describe("Withdraw CTA states", () => {
const { status, hook } = getLastResultOrThrow()
expect(status).equals('loading-uri')
- expect(hook).deep.equals({ "hasError": true, "operational": false, "message": "ERROR_NO-URI-FOR-WITHDRAWAL" });
+ if (!hook) expect.fail();
+ if (!hook.hasError) expect.fail();
+ if (hook.operational) expect.fail();
+ expect(hook.message).eq("ERROR_NO-URI-FOR-WITHDRAWAL");
}
await assertNoPendingUpdate()
diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
index 56c64a6d7..3346512f7 100644
--- a/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
+++ b/packages/taler-wallet-webextension/src/cta/Withdraw.tsx
@@ -40,11 +40,7 @@ import {
WalletAction,
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import {
- HookError,
- useAsyncAsHook,
- useAsyncAsHook2,
-} from "../hooks/useAsyncAsHook.js";
+import { HookError, useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { buildTermsOfServiceState } from "../utils/index.js";
import { ButtonHandler, SelectFieldHandler } from "../mui/handlers.js";
import * as wxApi from "../wxApi.js";
@@ -103,7 +99,7 @@ export function useComponentState(
/**
* Ask the wallet about the withdraw URI
*/
- const uriInfoHook = useAsyncAsHook2(async () => {
+ const uriInfoHook = useAsyncAsHook(async () => {
if (!talerWithdrawUri) throw Error("ERROR_NO-URI-FOR-WITHDRAWAL");
const uriInfo = await api.getWithdrawalDetailsForUri({
@@ -151,7 +147,7 @@ export function useComponentState(
/**
* For the exchange selected, bring the status of the terms of service
*/
- const terms = useAsyncAsHook2(async () => {
+ const terms = useAsyncAsHook(async () => {
if (!thisExchange) return false;
const exchangeTos = await api.getExchangeTos(thisExchange, ["text/xml"]);
@@ -165,7 +161,7 @@ export function useComponentState(
* With the exchange and amount, ask the wallet the information
* about the withdrawal
*/
- const info = useAsyncAsHook2(async () => {
+ const info = useAsyncAsHook(async () => {
if (!thisExchange || !amount) return false;
const info = await api.getExchangeWithdrawalInfo({
diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
index d03455ff7..04a6dbb18 100644
--- a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
+++ b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts
@@ -48,50 +48,6 @@ export type HookResponseWithRetry<T> = ((HookOk<T> | HookError) & WithRetry) | u
export function useAsyncAsHook<T>(
fn: () => Promise<T | false>,
- updateOnNotification?: Array<NotificationType>,
- deps?: any[],
-): HookResponse<T> {
-
- const args = useMemo(() => ({
- fn, updateOnNotification
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }), deps || [])
- const [result, setHookResponse] = useState<HookResponse<T>>(undefined);
-
- useEffect(() => {
- async function doAsync(): Promise<void> {
- try {
- const response = await args.fn();
- if (response === false) return;
- setHookResponse({ hasError: false, response });
- } catch (e) {
- if (e instanceof TalerError) {
- setHookResponse({
- hasError: true,
- operational: true,
- details: e.errorDetail,
- });
- } else if (e instanceof Error) {
- setHookResponse({
- hasError: true,
- operational: false,
- message: e.message,
- });
- }
- }
- }
- doAsync();
- if (args.updateOnNotification && args.updateOnNotification.length > 0) {
- return wxApi.onUpdateNotification(args.updateOnNotification, () => {
- doAsync();
- });
- }
- }, [args]);
- return result;
-}
-
-export function useAsyncAsHook2<T>(
- fn: () => Promise<T | false>,
deps?: any[],
): HookResponseWithRetry<T> {
diff --git a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx
index d67e44346..966782bbe 100644
--- a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx
+++ b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx
@@ -24,7 +24,7 @@ import { LoadingError } from "../components/LoadingError.js";
import { MultiActionButton } from "../components/MultiActionButton.js";
import { ButtonBoxPrimary, ButtonPrimary } from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { AddNewActionView } from "../wallet/AddNewActionView.js";
import * as wxApi from "../wxApi.js";
import { NoBalanceHelp } from "./NoBalanceHelp.js";
@@ -41,7 +41,7 @@ export function BalancePage({
}: Props): VNode {
const { i18n } = useTranslationContext();
const [addingAction, setAddingAction] = useState(false);
- const state = useAsyncAsHook2(wxApi.getBalance);
+ const state = useAsyncAsHook(wxApi.getBalance);
useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => {
diff --git a/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx b/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx
index 00386b461..505aa600b 100644
--- a/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx
@@ -41,7 +41,7 @@ import {
SmallText,
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { Pages } from "../NavigationBar.js";
import * as wxApi from "../wxApi.js";
@@ -51,7 +51,7 @@ interface Props {
export function BackupPage({ onAddProvider }: Props): VNode {
const { i18n } = useTranslationContext();
- const status = useAsyncAsHook2(wxApi.getBackupInfo);
+ const status = useAsyncAsHook(wxApi.getBackupInfo);
if (!status) {
return <Loading />;
}
diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx b/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
index 2bbd9f2e9..9b8008175 100644
--- a/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/DepositPage.tsx
@@ -32,7 +32,7 @@ import {
WarningBox,
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
-import { HookError, useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { HookError, useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import {
ButtonHandler,
SelectFieldHandler,
@@ -98,7 +98,7 @@ export function useComponentState(
onSuccess: (currency: string) => void,
api: typeof wxApi,
): State {
- const hook = useAsyncAsHook2(async () => {
+ const hook = useAsyncAsHook(async () => {
const { balances } = await api.getBalance();
const { accounts } = await api.listKnownBankAccounts(currency);
const defaultSelectedAccount =
diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
index c70850c6d..e371775f4 100644
--- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx
@@ -28,7 +28,7 @@ import { Diagnostics } from "../components/Diagnostics.js";
import { NotifyUpdateFadeOut } from "../components/styled/index.js";
import { Time } from "../components/Time.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { useDiagnostics } from "../hooks/useDiagnostics.js";
import * as wxApi from "../wxApi.js";
@@ -38,7 +38,7 @@ export function DeveloperPage(): VNode {
const listenAllEvents = Array.from<NotificationType>({ length: 1 });
listenAllEvents.includes = () => true; // includes every event
- const response = useAsyncAsHook2(async () => {
+ const response = useAsyncAsHook(async () => {
const op = await wxApi.getPendingOperations();
const c = await wxApi.dumpCoins();
const ex = await wxApi.listExchanges();
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
index a9e12505d..135cf68d8 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx
@@ -8,7 +8,7 @@ import {
} from "../components/styled/index.js";
import { useTranslationContext } from "../context/translation.js";
import { TermsOfServiceSection } from "../cta/TermsOfServiceSection.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { buildTermsOfServiceState, TermsState } from "../utils/index.js";
import * as wxApi from "../wxApi.js";
@@ -23,7 +23,7 @@ export function ExchangeAddConfirmPage({
onCancel,
onConfirm,
}: Props): VNode {
- const detailsHook = useAsyncAsHook2(async () => {
+ const detailsHook = useAsyncAsHook(async () => {
const tos = await wxApi.getExchangeTos(url, ["text/xml"]);
const tosState = buildTermsOfServiceState(tos);
diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
index 2cf8ac647..df423bb2b 100644
--- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddPage.tsx
@@ -20,7 +20,7 @@ import {
} from "@gnu-taler/taler-util";
import { h, VNode } from "preact";
import { useState } from "preact/hooks";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { queryToSlashKeys } from "../utils/index.js";
import * as wxApi from "../wxApi.js";
import { ExchangeAddConfirmPage } from "./ExchangeAddConfirm.js";
@@ -36,7 +36,7 @@ export function ExchangeAddPage({ currency, onBack }: Props): VNode {
{ url: string; config: TalerConfigResponse } | undefined
>(undefined);
- const knownExchangesResponse = useAsyncAsHook2(wxApi.listExchanges);
+ const knownExchangesResponse = useAsyncAsHook(wxApi.listExchanges);
const knownExchanges = !knownExchangesResponse
? []
: knownExchangesResponse.hasError
diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx
index cc99a8d0b..4a435d0cf 100644
--- a/packages/taler-wallet-webextension/src/wallet/History.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/History.tsx
@@ -35,7 +35,7 @@ import {
import { Time } from "../components/Time.js";
import { TransactionItem } from "../components/TransactionItem.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { NoBalanceHelp } from "../popup/NoBalanceHelp.js";
import * as wxApi from "../wxApi.js";
@@ -50,7 +50,7 @@ export function HistoryPage({
goToWalletDeposit,
}: Props): VNode {
const { i18n } = useTranslationContext();
- const state = useAsyncAsHook2(async () => ({
+ const state = useAsyncAsHook(async () => ({
b: await wxApi.getBalance(),
tx: await wxApi.getTransactions(),
}));
diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
index 1d0e81e01..daa46086e 100644
--- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx
@@ -27,7 +27,7 @@ import { useEffect, useState } from "preact/hooks";
import { Loading } from "../components/Loading.js";
import { LoadingError } from "../components/LoadingError.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook, useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import * as wxApi from "../wxApi.js";
import { CreateManualWithdraw } from "./CreateManualWithdraw.js";
import { ReserveCreated } from "./ReserveCreated.js";
@@ -50,7 +50,7 @@ export function ManualWithdrawPage({ currency, onCancel }: Props): VNode {
>(undefined);
const [error, setError] = useState<string | undefined>(undefined);
- const state = useAsyncAsHook2(wxApi.listExchanges);
+ const state = useAsyncAsHook(wxApi.listExchanges);
useEffect(() => {
wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => {
state?.retry();
diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx
index 1228c7951..bf9f55b10 100644
--- a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx
@@ -34,7 +34,7 @@ import {
} from "../components/styled/index.js";
import { Time } from "../components/Time.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import * as wxApi from "../wxApi.js";
interface Props {
@@ -54,7 +54,7 @@ export function ProviderDetailPage({ pid: providerURL, onBack }: Props): VNode {
return providers.length ? providers[0] : null;
}
- const state = useAsyncAsHook2(getProviderInfo);
+ const state = useAsyncAsHook(getProviderInfo);
if (!state) {
return <Loading />;
diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
index eefa5f385..5a9c776fd 100644
--- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx
@@ -29,7 +29,7 @@ import {
} from "../components/styled/index.js";
import { useDevContext } from "../context/devContext.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { useBackupDeviceName } from "../hooks/useBackupDeviceName.js";
import { useExtendedPermissions } from "../hooks/useExtendedPermissions.js";
import { Pages } from "../NavigationBar.js";
@@ -41,7 +41,7 @@ export function SettingsPage(): VNode {
const { devMode, toggleDevMode } = useDevContext();
const { name, update } = useBackupDeviceName();
- const exchangesHook = useAsyncAsHook2(wxApi.listExchanges);
+ const exchangesHook = useAsyncAsHook(wxApi.listExchanges);
return (
<SettingsView
diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
index cf87089b1..584fe427b 100644
--- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx
@@ -48,7 +48,7 @@ import {
} from "../components/styled/index.js";
import { Time } from "../components/Time.js";
import { useTranslationContext } from "../context/translation.js";
-import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js";
+import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import * as wxApi from "../wxApi.js";
interface Props {
@@ -69,7 +69,7 @@ async function getTransaction(tid: string): Promise<Transaction> {
export function TransactionPage({ tid, goToWalletHistory }: Props): VNode {
const { i18n } = useTranslationContext();
- const state = useAsyncAsHook2(() => getTransaction(tid));
+ const state = useAsyncAsHook(() => getTransaction(tid));
useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => {