From e9bb85a212dbd9b86875e89a0aca5d805e2ad61b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 13 Aug 2021 18:04:05 -0300 Subject: new wallet UI and more tests --- .../src/popup/History.tsx | 52 +++++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'packages/taler-wallet-webextension/src/popup/History.tsx') diff --git a/packages/taler-wallet-webextension/src/popup/History.tsx b/packages/taler-wallet-webextension/src/popup/History.tsx index 57fc10c26..b6b65314e 100644 --- a/packages/taler-wallet-webextension/src/popup/History.tsx +++ b/packages/taler-wallet-webextension/src/popup/History.tsx @@ -14,7 +14,7 @@ TALER; see the file COPYING. If not, see */ -import { AmountString, Timestamp, Transaction, TransactionsResponse, TransactionType } from "@gnu-taler/taler-util"; +import { AmountJson, Amounts, AmountString, Balance, Timestamp, Transaction, TransactionsResponse, TransactionType } from "@gnu-taler/taler-util"; import { JSX } from "preact"; import { useEffect, useState } from "preact/hooks"; import * as wxApi from "../wxApi"; @@ -25,6 +25,8 @@ export function HistoryPage(props: any): JSX.Element { const [transactions, setTransactions] = useState< TransactionsResponse | undefined >(undefined); + const balance = useBalances() + const balanceWithoutError = balance?.error ? [] : (balance?.response.balances || []) useEffect(() => { const fetchData = async (): Promise => { @@ -38,16 +40,36 @@ export function HistoryPage(props: any): JSX.Element { return
Loading ...
; } - return ; + return ; } -export function HistoryView({ list }: { list: Transaction[] }) { - return +function amountToString(c: AmountString) { + const idx = c.indexOf(':') + return `${c.substring(idx+1)} ${c.substring(0,idx)}` +} + + + +export function HistoryView({ list, balances }: { list: Transaction[], balances: Balance[] }) { + return + {balances.length > 0 &&
+ {balances.length === 1 &&
+ Balance: {amountToString(balances[0].available)} +
} + {balances.length > 1 &&
+ Balance:
    + {balances.map(b =>
  • {b.available}
  • )} +
+
} +
}
- {list.map((tx, i) => ( + {list.slice(0, 3).map((tx, i) => ( ))}
+
} @@ -57,6 +79,8 @@ import imageRefund from '../../static/img/ri-refund-2-line.svg'; import imageHandHeart from '../../static/img/ri-hand-heart-line.svg'; import imageRefresh from '../../static/img/ri-refresh-line.svg'; import { Column, ExtraLargeText, HistoryRow, PopupBox, Row, RowBorderGray, SmallTextLight } from "../components/styled"; +import { useBalances } from "../hooks/useBalances"; +import { formatDistance } from "date-fns"; function TransactionItem(props: { tx: Transaction }): JSX.Element { const tx = props.tx; @@ -144,23 +168,21 @@ function TransactionItem(props: { tx: Transaction }): JSX.Element { function TransactionLayout(props: TransactionLayoutProps): JSX.Element { const date = new Date(props.timestamp.t_ms); - const dateStr = date.toLocaleString([], { - dateStyle: "medium", - timeStyle: "short", - } as any); + const now = new Date(); + const dateStr = formatDistance(date, now, { addSuffix: true }) return ( - {dateStr} {props.title} {props.pending ? ( (Pending) ) : null} + {dateStr} -
{props.subtitle}
+ {/*
{props.subtitle}
*/}
+ {sign} {amount} -- cgit v1.2.3