From 732e764b376dff6b0262b869b29dbdee0c455a0e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 28 Jul 2020 23:17:12 +0530 Subject: new balances API, remove defunct 'return funds to own account' implementation --- src/webex/pages/popup.tsx | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'src/webex/pages/popup.tsx') diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index e4eea4d9e..8a99a6d90 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -29,8 +29,6 @@ import * as i18n from "../i18n"; import { AmountJson } from "../../util/amounts"; import * as Amounts from "../../util/amounts"; -import { WalletBalance, WalletBalanceEntry } from "../../types/walletTypes"; - import { abbrev, renderAmount, PageLink } from "../renderHtml"; import * as wxApi from "../wxApi"; @@ -40,6 +38,7 @@ import moment from "moment"; import { Timestamp } from "../../util/time"; import { classifyTalerUri, TalerUriType } from "../../util/taleruri"; import { PermissionsCheckbox } from "./welcome"; +import { BalancesResponse, Balance } from "../../types/walletTypes"; // FIXME: move to newer react functions /* eslint-disable react/no-deprecated */ @@ -172,7 +171,7 @@ function EmptyBalanceView(): JSX.Element { } class WalletBalanceView extends React.Component { - private balance: WalletBalance; + private balance: BalancesResponse; private gotError = false; private canceler: (() => void) | undefined = undefined; private unmount = false; @@ -196,7 +195,7 @@ class WalletBalanceView extends React.Component { return; } this.updateBalanceRunning = true; - let balance: WalletBalance; + let balance: BalancesResponse; try { balance = await wxApi.getBalance(); } catch (e) { @@ -219,10 +218,14 @@ class WalletBalanceView extends React.Component { this.setState({}); } - formatPending(entry: WalletBalanceEntry): JSX.Element { + formatPending(entry: Balance): JSX.Element { let incoming: JSX.Element | undefined; let payment: JSX.Element | undefined; + const available = Amounts.parseOrThrow(entry.available); + const pendingIncoming = Amounts.parseOrThrow(entry.pendingIncoming); + const pendingOutgoing = Amounts.parseOrThrow(entry.pendingOutgoing); + console.log( "available: ", entry.pendingIncoming ? renderAmount(entry.available) : null, @@ -232,7 +235,7 @@ class WalletBalanceView extends React.Component { entry.pendingIncoming ? renderAmount(entry.pendingIncoming) : null, ); - if (Amounts.isNonZero(entry.pendingIncoming)) { + if (Amounts.isNonZero(pendingIncoming)) { incoming = ( @@ -244,18 +247,6 @@ class WalletBalanceView extends React.Component { ); } - if (Amounts.isNonZero(entry.pendingPayment)) { - payment = ( - - - {"-"} - {renderAmount(entry.pendingPayment)} - {" "} - being spent - - ); - } - const l = [incoming, payment].filter((x) => x !== undefined); if (l.length === 0) { return ; @@ -288,11 +279,11 @@ class WalletBalanceView extends React.Component { return ; } console.log(wallet); - const listing = Object.keys(wallet.byCurrency).map((key) => { - const entry: WalletBalanceEntry = wallet.byCurrency[key]; + const listing = wallet.balances.map((entry) => { + const av = Amounts.parseOrThrow(entry.available); return ( -

- {bigAmount(entry.available)} {this.formatPending(entry)} +

+ {bigAmount(av)} {this.formatPending(entry)}

); }); @@ -314,7 +305,6 @@ function formatAndCapitalize(text: string): string { return text; } - const HistoryComponent = (props: any): JSX.Element => { return TBD; }; @@ -330,7 +320,6 @@ class WalletSettings extends React.Component { } } - function reload(): void { try { chrome.runtime.reload(); -- cgit v1.2.3