From ae775d4b00011874ac13f2a9fdf96e99b547f977 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Tue, 15 Mar 2022 10:35:00 -0300
Subject: fix: update total balance on wallet page when WithdrawGroupFinished

---
 .../src/wallet/History.tsx                         | 25 +++++++++++-----------
 1 file changed, 12 insertions(+), 13 deletions(-)

(limited to 'packages/taler-wallet-webextension/src/wallet/History.tsx')

diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx
index ea6057d05..02fc0a76c 100644
--- a/packages/taler-wallet-webextension/src/wallet/History.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/History.tsx
@@ -52,20 +52,19 @@ export function HistoryPage({
   goToWalletDeposit,
 }: Props): VNode {
   const { i18n } = useTranslationContext();
-  const balance = useAsyncAsHook(wxApi.getBalance);
-  const balanceWithoutError = balance?.hasError
-    ? []
-    : balance?.response.balances || [];
-
-  const transactionQuery = useAsyncAsHook(wxApi.getTransactions, [
-    NotificationType.WithdrawGroupFinished,
-  ]);
+  const state = useAsyncAsHook(
+    async () => ({
+      b: await wxApi.getBalance(),
+      tx: await wxApi.getTransactions(),
+    }),
+    [NotificationType.WithdrawGroupFinished],
+  );
 
-  if (!transactionQuery || !balance) {
+  if (!state) {
     return <Loading />;
   }
 
-  if (transactionQuery.hasError) {
+  if (state.hasError) {
     return (
       <LoadingError
         title={
@@ -73,18 +72,18 @@ export function HistoryPage({
             Could not load the list of transactions
           </i18n.Translate>
         }
-        error={transactionQuery}
+        error={state}
       />
     );
   }
 
   return (
     <HistoryView
-      balances={balanceWithoutError}
+      balances={state.response.b.balances}
       defaultCurrency={currency}
       goToWalletManualWithdraw={goToWalletManualWithdraw}
       goToWalletDeposit={goToWalletDeposit}
-      transactions={[...transactionQuery.response.transactions].reverse()}
+      transactions={[...state.response.tx.transactions].reverse()}
     />
   );
 }
-- 
cgit v1.2.3

