From 76e664c9432822c4f5ba717af7f421b7cd015bf3 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 4 May 2020 18:52:54 +0530 Subject: update withdrawal page when something changes --- src/webex/pages/popup.tsx | 15 ++------------- src/webex/pages/withdraw.tsx | 16 ++++++++++++---- src/webex/wxApi.ts | 12 ++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index a6c4651df..450aae4ce 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -45,17 +45,6 @@ import { PermissionsCheckbox } from "./welcome"; // FIXME: move to newer react functions /* eslint-disable react/no-deprecated */ -function onUpdateNotification(f: () => void): () => void { - const port = chrome.runtime.connect({ name: "notifications" }); - const listener = (): void => { - f(); - }; - port.onMessage.addListener(listener); - return () => { - port.onMessage.removeListener(listener); - }; -} - class Router extends React.Component { static setRoute(s: string): void { window.location.hash = s; @@ -190,7 +179,7 @@ class WalletBalanceView extends React.Component { private unmount = false; componentWillMount(): void { - this.canceler = onUpdateNotification(() => this.updateBalance()); + this.canceler = wxApi.onUpdateNotification(() => this.updateBalance()); this.updateBalance(); } @@ -651,7 +640,7 @@ class WalletHistory extends React.Component { componentWillMount(): void { this.update(); this.setState({ filter: true }); - onUpdateNotification(() => this.update()); + wxApi.onUpdateNotification(() => this.update()); } componentWillUnmount(): void { diff --git a/src/webex/pages/withdraw.tsx b/src/webex/pages/withdraw.tsx index 1647a7065..5ef4376f7 100644 --- a/src/webex/pages/withdraw.tsx +++ b/src/webex/pages/withdraw.tsx @@ -28,9 +28,9 @@ import { WithdrawDetails } from "../../types/walletTypes"; import { WithdrawDetailView, renderAmount } from "../renderHtml"; import React, { useState, useEffect } from "react"; -import { getWithdrawDetails, acceptWithdrawal } from "../wxApi"; +import { getWithdrawDetails, acceptWithdrawal, onUpdateNotification } from "../wxApi"; -function NewExchangeSelection(props: { +function WithdrawalDialog(props: { talerWithdrawUri: string; }): JSX.Element { const [details, setDetails] = useState(); @@ -42,6 +42,14 @@ function NewExchangeSelection(props: { const [selecting, setSelecting] = useState(false); const [customUrl, setCustomUrl] = useState(""); const [errMsg, setErrMsg] = useState(""); + const [updateCounter, setUpdateCounter] = useState(1); + + useEffect(() => { + return onUpdateNotification(() => { + setUpdateCounter(updateCounter + 1); + }); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) useEffect(() => { const fetchData = async (): Promise => { @@ -65,7 +73,7 @@ function NewExchangeSelection(props: { setDetails(d); }; fetchData(); - }, [selectedExchange, errMsg, selecting, talerWithdrawUri]); + }, [selectedExchange, errMsg, selecting, talerWithdrawUri, updateCounter]); if (errMsg) { return ( @@ -214,5 +222,5 @@ export function createWithdrawPage(): JSX.Element { if (!talerWithdrawUri) { throw Error("withdraw URI required"); } - return ; + return ; } diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index 128041e57..0bd444856 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -339,3 +339,15 @@ export function setExtendedPermissions(value: boolean): Promise { return callBackend("get-extended-permissions", {}); } + + +export function onUpdateNotification(f: () => void): () => void { + const port = chrome.runtime.connect({ name: "notifications" }); + const listener = (): void => { + f(); + }; + port.onMessage.addListener(listener); + return () => { + port.onMessage.removeListener(listener); + }; +} \ No newline at end of file -- cgit v1.2.3