From 29485b3601b6f6d801672543f4e6c5d2d2139e7e Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 25 Oct 2021 08:10:43 +0200 Subject: [PATCH] Display vouching tip, allow unvouch (#6400) --- packages/page-society/src/Candidates/Bid.tsx | 60 ++++++++++++++----- packages/page-society/src/Candidates/Bids.tsx | 1 + 2 files changed, 46 insertions(+), 15 deletions(-) diff --git a/packages/page-society/src/Candidates/Bid.tsx b/packages/page-society/src/Candidates/Bid.tsx index a35823ee75..8651d74ab2 100644 --- a/packages/page-society/src/Candidates/Bid.tsx +++ b/packages/page-society/src/Candidates/Bid.tsx @@ -22,13 +22,26 @@ function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElem const { api } = useApi(); const { allAccounts } = useAccounts(); - const isBidder = useMemo( - (): boolean => { - const address = who.toString(); + const [voucher, tip] = useMemo( + () => kind.isVouch + ? kind.asVouch + : [null, null], + [kind] + ); - return allAccounts.some((accountId) => accountId === address); + const [isBidder, isVoucher] = useMemo( + (): [boolean, boolean] => { + const whoSS58 = who.toString(); + const vouchSS58 = voucher && voucher.toString(); + + return [ + allAccounts.some((accountId) => accountId === whoSS58), + vouchSS58 + ? allAccounts.some((accountId) => accountId === vouchSS58) + : false + ]; }, - [allAccounts, who] + [allAccounts, voucher, who] ); return ( @@ -40,18 +53,35 @@ function BidRow ({ index, value: { kind, value, who } }: Props): React.ReactElem - - {!kind.isVouch && ( - ('Unbid')} - params={[index]} - tx={api.tx.society.unbid} - /> + + {tip && ( + )} + + {kind.isVouch + ? ( + ('Unvouch')} + params={[index]} + tx={api.tx.society.unvouch} + /> + ) + : ( + ('Unbid')} + params={[index]} + tx={api.tx.society.unbid} + /> + ) + } + ); } diff --git a/packages/page-society/src/Candidates/Bids.tsx b/packages/page-society/src/Candidates/Bids.tsx index edd71cfaed..b573855ece 100644 --- a/packages/page-society/src/Candidates/Bids.tsx +++ b/packages/page-society/src/Candidates/Bids.tsx @@ -24,6 +24,7 @@ function Bids ({ className }: Props): React.ReactElement { [t('bids'), 'start'], [t('bid kind'), 'start', 2], [t('value')], + [t('tip')], [] ]);