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);
useEffect(() => {
wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => {
state?.retry();
});
return wxApi.onUpdateNotification(
[NotificationType.WithdrawGroupFinished],
() => {
state?.retry();
},
);
});
const transactions =

View File

@ -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;

View File

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

View File

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

View File

@ -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();
});
});

View File

@ -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) {

View File

@ -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<any> {
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);
}