From 8445d75ac1b2c18279236527b91a4de4fc1f7ec9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9rard=20Dethier?= Date: Thu, 9 Nov 2023 11:56:04 +0100 Subject: [PATCH] feat: expose reserved balance. logion-network/logion-internal#1055 --- src/common/AccountAddress.css | 4 +- src/common/AccountAddress.test.tsx | 3 +- src/common/AccountAddress.tsx | 20 +++- src/common/BalanceDetails.css | 21 +++++ src/common/BalanceDetails.tsx | 33 +++++++ src/common/TestData.ts | 3 +- src/common/Transactions.tsx | 8 +- src/common/Wallet.tsx | 11 +-- src/common/WalletGauge.css | 1 - src/common/WalletGauge.test.tsx | 13 ++- src/common/WalletGauge.tsx | 21 +++-- .../AccountAddress.test.tsx.snap | 39 +++++--- src/common/__snapshots__/Wallet.test.tsx.snap | 93 ++++++++++++++----- src/components/inlineamount/InlineAmount.css | 3 + src/components/inlineamount/InlineAmount.tsx | 17 ++++ src/legal-officer/Home.tsx | 6 +- src/wallet-user/Home.tsx | 6 +- .../WalletRecoveryProcessTab.test.tsx | 3 +- yarn.lock | 6 +- 19 files changed, 233 insertions(+), 78 deletions(-) create mode 100644 src/common/BalanceDetails.css create mode 100644 src/common/BalanceDetails.tsx create mode 100644 src/components/inlineamount/InlineAmount.css create mode 100644 src/components/inlineamount/InlineAmount.tsx diff --git a/src/common/AccountAddress.css b/src/common/AccountAddress.css index 93a37d40..52c86ae7 100644 --- a/src/common/AccountAddress.css +++ b/src/common/AccountAddress.css @@ -40,8 +40,8 @@ text-overflow: ellipsis; } -.AccountAddress .text .balance .symbol { - font-size: 0.7rem; +.AccountAddress .text .balance .reserved { + opacity: 0.5; } .AccountAddress .text .name { diff --git a/src/common/AccountAddress.test.tsx b/src/common/AccountAddress.test.tsx index 7eb14554..1497be8b 100644 --- a/src/common/AccountAddress.test.tsx +++ b/src/common/AccountAddress.test.tsx @@ -9,7 +9,8 @@ test("renders", () => { - { props.balance === null ? : props.balance.balance.coefficient.toFixedPrecision(2) }{" "} - { (props.balance?.balance.prefix.symbol || "") + (props.balance?.coin.symbol || "LGNT") } + { + props.balance === null && + + } + { + props.balance !== null && + <> + {" "} + { + !props.balance.reserved.coefficient.isZero() && + + +{" "} + + + } + + } } diff --git a/src/common/BalanceDetails.css b/src/common/BalanceDetails.css new file mode 100644 index 00000000..c6743e94 --- /dev/null +++ b/src/common/BalanceDetails.css @@ -0,0 +1,21 @@ +.BalanceDetails { + font-size: 1rem; + margin-left: auto; + margin-right: auto; +} + +.BalanceDetails .detail { + display: flex; + justify-content: space-between; +} + +.BalanceDetails .label { + display: inline-block; + width: 130px; +} + +.BalanceDetails.arc { + width: 300px; + padding-top: 40px; + padding-bottom: 30px; +} diff --git a/src/common/BalanceDetails.tsx b/src/common/BalanceDetails.tsx new file mode 100644 index 00000000..7fe4dd1e --- /dev/null +++ b/src/common/BalanceDetails.tsx @@ -0,0 +1,33 @@ +import { CoinBalance } from "@logion/node-api"; +import InlineAmount from "src/components/inlineamount/InlineAmount"; +import "./BalanceDetails.css"; + +export interface Props { + balance: CoinBalance; + type: 'arc' | 'linear'; +} + +export default function BalanceDetails(props: Props) { + return ( +
+
+
Available:
+
+ +
+
+
+
Reserved:
+
+ +
+
+
+
Total:
+
+ +
+
+
+ ); +} diff --git a/src/common/TestData.ts b/src/common/TestData.ts index 3ff80730..1a0a19c6 100644 --- a/src/common/TestData.ts +++ b/src/common/TestData.ts @@ -127,8 +127,9 @@ export const DEFAULT_COIN: Coin = { export const DEFAULT_COIN_BALANCE: CoinBalance = { coin: DEFAULT_COIN, - balance: new Numbers.PrefixedNumber("42", Numbers.ATTO), + total: new Numbers.PrefixedNumber("42", Numbers.ATTO), available: new Numbers.PrefixedNumber("42", Numbers.ATTO), + reserved: new Numbers.PrefixedNumber("0", Numbers.ATTO), level: 0.1, }; diff --git a/src/common/Transactions.tsx b/src/common/Transactions.tsx index 7eb2ea02..5ecf5eff 100644 --- a/src/common/Transactions.tsx +++ b/src/common/Transactions.tsx @@ -156,10 +156,8 @@ function Content(props: ContentProps) { title={ } > @@ -188,10 +186,8 @@ function Content(props: ContentProps) { className="gauge-container" > diff --git a/src/common/Wallet.tsx b/src/common/Wallet.tsx index 8e0ab074..a81033f6 100644 --- a/src/common/Wallet.tsx +++ b/src/common/Wallet.tsx @@ -63,7 +63,6 @@ export function Content(props: Props & { type: WalletType }) { const latestTransaction = transactions[0]; - const gaugeCoin = balances[0].coin; return ( <> { @@ -98,7 +97,7 @@ export function Content(props: Props & { type: WalletType }) { }, { header: "Balance", - render: balance => , + render: balance => , width: width({ onSmallScreen: "120px", otherwise: "140px" @@ -115,7 +114,7 @@ export function Content(props: Props & { type: WalletType }) { }, { header: "Last transaction amount", - render: balance => , + render: balance => , align: 'right', }, { @@ -145,9 +144,7 @@ export function Content(props: Props & { type: WalletType }) { className="gauge-container" > @@ -167,7 +164,7 @@ export function AssetNameCell(props: AssetNameCellProps) { return (
- ({ props.balance.balance.prefix.symbol }{ props.balance.coin.symbol }) + ({ props.balance.available.prefix.symbol }{ props.balance.coin.symbol })
); } diff --git a/src/common/WalletGauge.css b/src/common/WalletGauge.css index 24d960b5..9f599ef5 100644 --- a/src/common/WalletGauge.css +++ b/src/common/WalletGauge.css @@ -4,7 +4,6 @@ } .WalletGauge.arc .actions { - margin-top: 60px; margin-bottom: 30px; margin-left: auto; margin-right: auto; diff --git a/src/common/WalletGauge.test.tsx b/src/common/WalletGauge.test.tsx index 6dd120fc..1cfc976f 100644 --- a/src/common/WalletGauge.test.tsx +++ b/src/common/WalletGauge.test.tsx @@ -1,7 +1,7 @@ jest.mock("../logion-chain"); import { shallowRender } from '../tests'; -import { Queries, Numbers } from '@logion/node-api'; +import { CoinBalance, Queries, Numbers } from '@logion/node-api'; import WalletGauge from './WalletGauge'; @@ -10,10 +10,15 @@ test("renders arc", () => { }); function testWalletGauge(type: 'arc' | 'linear') { + const balance: CoinBalance = { + coin: Queries.getCoin('lgnt'), + available: new Numbers.PrefixedNumber("20.00", Numbers.MILLI), + reserved: new Numbers.PrefixedNumber("0", Numbers.NONE), + total: new Numbers.PrefixedNumber("20.00", Numbers.MILLI), + level: 0.5, + }; const result = shallowRender(); expect(result).toMatchSnapshot(); diff --git a/src/common/WalletGauge.tsx b/src/common/WalletGauge.tsx index b7ebba4f..eb8e0742 100644 --- a/src/common/WalletGauge.tsx +++ b/src/common/WalletGauge.tsx @@ -1,7 +1,7 @@ import { useState, useCallback } from 'react'; import { Form, Spinner, InputGroup, DropdownButton, Dropdown } from 'react-bootstrap'; -import { BalanceState } from '@logion/client/dist/Balance.js'; -import { Numbers, Coin, Currency } from '@logion/node-api'; +import { BalanceState } from '@logion/client'; +import { Numbers, CoinBalance, Currency } from '@logion/node-api'; import { useLogionChain } from '../logion-chain'; import ClientExtrinsicSubmitter, { Call, CallCallback } from '../ClientExtrinsicSubmitter'; @@ -16,11 +16,10 @@ import Alert from './Alert'; import TransactionConfirmation, { Status } from "./TransactionConfirmation"; import './WalletGauge.css'; +import BalanceDetails from './BalanceDetails'; export interface Props { - coin: Coin, - balance: Numbers.PrefixedNumber, - level: number, + balance: CoinBalance, type: 'arc' | 'linear', vaultAddress?: string, sendButton?: boolean @@ -72,10 +71,14 @@ export default function WalletGauge(props: Props) { children={ (status, startTransferringCallback, cancelCallback, successCallback) => { return
+ { (sendButton === undefined || sendButton) && diff --git a/src/common/__snapshots__/AccountAddress.test.tsx.snap b/src/common/__snapshots__/AccountAddress.test.tsx.snap index ec589fe5..c3614e6d 100644 --- a/src/common/__snapshots__/AccountAddress.test.tsx.snap +++ b/src/common/__snapshots__/AccountAddress.test.tsx.snap @@ -79,17 +79,34 @@ exports[`renders 1`] = ` } } > - - 2.00 - - - - LGNT - + + + +
diff --git a/src/common/__snapshots__/Wallet.test.tsx.snap b/src/common/__snapshots__/Wallet.test.tsx.snap index bdc4f567..8fc27872 100644 --- a/src/common/__snapshots__/Wallet.test.tsx.snap +++ b/src/common/__snapshots__/Wallet.test.tsx.snap @@ -97,7 +97,27 @@ exports[`renders with all data 1`] = ` "_tenExponent": -18, }, }, - "balance": PrefixedNumber { + "coin": Object { + "id": "lgnt", + "symbol": "LGNT", + }, + "level": 0.1, + "reserved": PrefixedNumber { + "_prefix": Object { + "symbol": "a", + "tenExponent": -18, + }, + "_scientificNumber": ScientificNumber { + "_normalized": NormalizedNumber { + "_decimalPart": "", + "_integerPart": "", + "_negative": false, + "_normalized": ".", + }, + "_tenExponent": -18, + }, + }, + "total": PrefixedNumber { "_prefix": Object { "symbol": "a", "tenExponent": -18, @@ -112,11 +132,6 @@ exports[`renders with all data 1`] = ` "_tenExponent": -18, }, }, - "coin": Object { - "id": "lgnt", - "symbol": "LGNT", - }, - "level": 0.1, }, ] } @@ -148,29 +163,59 @@ exports[`renders with all data 1`] = ` > diff --git a/src/components/inlineamount/InlineAmount.css b/src/components/inlineamount/InlineAmount.css new file mode 100644 index 00000000..3afdb310 --- /dev/null +++ b/src/components/inlineamount/InlineAmount.css @@ -0,0 +1,3 @@ +.InlineAmount .symbol { + font-size: 0.7em; +} diff --git a/src/components/inlineamount/InlineAmount.tsx b/src/components/inlineamount/InlineAmount.tsx new file mode 100644 index 00000000..5bc75ea2 --- /dev/null +++ b/src/components/inlineamount/InlineAmount.tsx @@ -0,0 +1,17 @@ +import { Coin, Numbers } from "@logion/node-api"; + +import "./InlineAmount.css"; + +export interface Props { + coin: Coin; + amount: Numbers.PrefixedNumber; +} + +export default function InlineAmount(props: Props) { + return ( + + { props.amount.coefficient.toFixedPrecision(2) }{" "} + { props.amount.prefix.symbol + props.coin.symbol } + + ); +} diff --git a/src/legal-officer/Home.tsx b/src/legal-officer/Home.tsx index e3ae461f..acaca3b8 100644 --- a/src/legal-officer/Home.tsx +++ b/src/legal-officer/Home.tsx @@ -102,9 +102,9 @@ export default function Account() {