remove listener on unload

This commit is contained in:
Sebastian 2022-06-09 14:16:28 -03:00
parent ff49e3477e
commit 78b056a0b1
No known key found for this signature in database
GPG Key ID: BE4FF68352439FC1
7 changed files with 29 additions and 15 deletions

View File

@ -36,9 +36,12 @@ export function PendingTransactions({ goToTransaction }: Props): VNode {
const state = useAsyncAsHook(wxApi.getTransactions); const state = useAsyncAsHook(wxApi.getTransactions);
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { return wxApi.onUpdateNotification(
[NotificationType.WithdrawGroupFinished],
() => {
state?.retry(); state?.retry();
}); },
);
}); });
const transactions = const transactions =

View File

@ -44,9 +44,12 @@ export function BalancePage({
const state = useAsyncAsHook(wxApi.getBalance); const state = useAsyncAsHook(wxApi.getBalance);
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { return wxApi.onUpdateNotification(
[NotificationType.WithdrawGroupFinished],
() => {
state?.retry(); state?.retry();
}); },
);
}); });
const balances = !state || state.hasError ? [] : state.response.balances; const balances = !state || state.hasError ? [] : state.response.balances;

View File

@ -54,7 +54,7 @@ export function DeveloperPage(): VNode {
}); });
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification(listenAllEvents, () => { return wxApi.onUpdateNotification(listenAllEvents, () => {
response?.retry(); response?.retry();
}); });
}); });

View File

@ -56,9 +56,12 @@ export function HistoryPage({
})); }));
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { return wxApi.onUpdateNotification(
[NotificationType.WithdrawGroupFinished],
() => {
state?.retry(); state?.retry();
}); },
);
}); });
if (!state) { if (!state) {

View File

@ -52,7 +52,7 @@ export function ManualWithdrawPage({ currency, onCancel }: Props): VNode {
const state = useAsyncAsHook(wxApi.listExchanges); const state = useAsyncAsHook(wxApi.listExchanges);
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => { return wxApi.onUpdateNotification([NotificationType.ExchangeAdded], () => {
state?.retry(); state?.retry();
}); });
}); });

View File

@ -84,9 +84,12 @@ export function TransactionPage({ tid, goToWalletHistory }: Props): VNode {
const state = useAsyncAsHook(() => getTransaction(tid), [tid]); const state = useAsyncAsHook(() => getTransaction(tid), [tid]);
useEffect(() => { useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { return wxApi.onUpdateNotification(
[NotificationType.WithdrawGroupFinished],
() => {
state?.retry(); state?.retry();
}); },
);
}); });
if (!state) { if (!state) {

View File

@ -42,6 +42,7 @@ import {
GetFeeForDepositRequest, GetFeeForDepositRequest,
GetWithdrawalDetailsForUriRequest, GetWithdrawalDetailsForUriRequest,
KnownBankAccounts, KnownBankAccounts,
Logger,
NotificationType, NotificationType,
PrepareDepositRequest, PrepareDepositRequest,
PrepareDepositResponse, PrepareDepositResponse,
@ -76,6 +77,7 @@ import { platform, MessageFromBackend } from "./platform/api.js";
export interface ExtendedPermissionsResponse { export interface ExtendedPermissionsResponse {
newValue: boolean; newValue: boolean;
} }
const logger = new Logger("wxApi");
/** /**
* Response with information about available version upgrades. * Response with information about available version upgrades.
@ -106,7 +108,7 @@ async function callBackend(operation: string, payload: any): Promise<any> {
console.log("Error calling backend"); console.log("Error calling backend");
throw new Error(`Error contacting backend: ${e}`); throw new Error(`Error contacting backend: ${e}`);
} }
console.log("got response", response); logger.info("got response", response);
if (response.type === "error") { if (response.type === "error") {
throw TalerError.fromUncheckedDetail(response.error); throw TalerError.fromUncheckedDetail(response.error);
} }