From 65e6a8caa0de98632ad99cca35bf98bffe663dff Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Apr 2022 22:37:41 -0300 Subject: useAsync new API --- .../taler-wallet-webextension/src/popup/BalancePage.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'packages/taler-wallet-webextension/src/popup') diff --git a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx index 37000bd38..d67e44346 100644 --- a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx +++ b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx @@ -16,7 +16,7 @@ import { Amounts, Balance, NotificationType } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useEffect, useState } from "preact/hooks"; import { BalanceTable } from "../components/BalanceTable.js"; import { JustInDevMode } from "../components/JustInDevMode.js"; import { Loading } from "../components/Loading.js"; @@ -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 { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; +import { useAsyncAsHook2 } from "../hooks/useAsyncAsHook.js"; import { AddNewActionView } from "../wallet/AddNewActionView.js"; import * as wxApi from "../wxApi.js"; import { NoBalanceHelp } from "./NoBalanceHelp.js"; @@ -41,9 +41,14 @@ export function BalancePage({ }: Props): VNode { const { i18n } = useTranslationContext(); const [addingAction, setAddingAction] = useState(false); - const state = useAsyncAsHook(wxApi.getBalance, [ - NotificationType.WithdrawGroupFinished, - ]); + const state = useAsyncAsHook2(wxApi.getBalance); + + useEffect(() => { + wxApi.onUpdateNotification([NotificationType.WithdrawGroupFinished], () => { + state?.retry(); + }); + }); + const balances = !state || state.hasError ? [] : state.response.balances; if (!state) { -- cgit v1.2.3