From 78b056a0b1613ef19d1d72c17fd256c2e86e6774 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 9 Jun 2022 14:16:28 -0300 Subject: [PATCH] remove listener on unload --- .../src/components/PendingTransactions.tsx | 9 ++++++--- .../taler-wallet-webextension/src/popup/BalancePage.tsx | 9 ++++++--- .../src/wallet/DeveloperPage.tsx | 2 +- .../taler-wallet-webextension/src/wallet/History.tsx | 9 ++++++--- .../src/wallet/ManualWithdrawPage.tsx | 2 +- .../taler-wallet-webextension/src/wallet/Transaction.tsx | 9 ++++++--- packages/taler-wallet-webextension/src/wxApi.ts | 4 +++- 7 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx index 126c82f88..05995395b 100644 --- a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx +++ b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx @@ -36,9 +36,12 @@ export function PendingTransactions({ goToTransaction }: Props): VNode { const state = useAsyncAsHook(wxApi.getTransactions); useEffect(() => { - wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { - state?.retry(); - }); + return wxApi.onUpdateNotification( + [NotificationType.WithdrawGroupFinished], + () => { + state?.retry(); + }, + ); }); const transactions = diff --git a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx index 6a31fe238..cdf507cb5 100644 --- a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx +++ b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx @@ -44,9 +44,12 @@ export function BalancePage({ const state = useAsyncAsHook(wxApi.getBalance); useEffect(() => { - wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { - state?.retry(); - }); + return wxApi.onUpdateNotification( + [NotificationType.WithdrawGroupFinished], + () => { + state?.retry(); + }, + ); }); const balances = !state || state.hasError ? [] : state.response.balances; diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx index 644d19798..3406b04ef 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx @@ -54,7 +54,7 @@ export function DeveloperPage(): VNode { }); useEffect(() => { - wxApi.onUpdateNotification(listenAllEvents, () => { + return wxApi.onUpdateNotification(listenAllEvents, () => { response?.retry(); }); }); diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx index 3aa4baeb4..c192b2ba7 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.tsx @@ -56,9 +56,12 @@ export function HistoryPage({ })); useEffect(() => { - wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { - state?.retry(); - }); + return wxApi.onUpdateNotification( + [NotificationType.WithdrawGroupFinished], + () => { + state?.retry(); + }, + ); }); if (!state) { diff --git a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx index b1e5cf3d0..a45daa6b1 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManualWithdrawPage.tsx @@ -52,7 +52,7 @@ export function ManualWithdrawPage({ currency, onCancel }: Props): VNode { const state = useAsyncAsHook(wxApi.listExchanges); useEffect(() => { - wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => { + return wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => { state?.retry(); }); }); diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index 1f195a2bf..c42bf7066 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -84,9 +84,12 @@ export function TransactionPage({ tid, goToWalletHistory }: Props): VNode { const state = useAsyncAsHook(() => getTransaction(tid), [tid]); useEffect(() => { - wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { - state?.retry(); - }); + return wxApi.onUpdateNotification( + [NotificationType.WithdrawGroupFinished], + () => { + state?.retry(); + }, + ); }); if (!state) { diff --git a/packages/taler-wallet-webextension/src/wxApi.ts b/packages/taler-wallet-webextension/src/wxApi.ts index 9d704e6e2..7ee14261a 100644 --- a/packages/taler-wallet-webextension/src/wxApi.ts +++ b/packages/taler-wallet-webextension/src/wxApi.ts @@ -42,6 +42,7 @@ import { GetFeeForDepositRequest, GetWithdrawalDetailsForUriRequest, KnownBankAccounts, + Logger, NotificationType, PrepareDepositRequest, PrepareDepositResponse, @@ -76,6 +77,7 @@ import { platform, MessageFromBackend } from "./platform/api.js"; export interface ExtendedPermissionsResponse { newValue: boolean; } +const logger = new Logger("wxApi"); /** * Response with information about available version upgrades. @@ -106,7 +108,7 @@ async function callBackend(operation: string, payload: any): Promise { console.log("Error calling backend"); throw new Error(`Error contacting backend: ${e}`); } - console.log("got response", response); + logger.info("got response", response); if (response.type === "error") { throw TalerError.fromUncheckedDetail(response.error); }