From e21795d1788e0138fae9034b8dc018ab3b5c52b5 Mon Sep 17 00:00:00 2001 From: yurixander <101931215+yurixander@users.noreply.github.com> Date: Fri, 27 Sep 2024 22:45:35 -0400 Subject: [PATCH] feat(tangle-dapp): Filter my pools --- .../NetworkSelectionButton.tsx | 8 +++-- .../tangle-dapp/containers/LsMyPoolsTable.tsx | 32 +++++++++++++++---- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/apps/tangle-dapp/components/NetworkSelector/NetworkSelectionButton.tsx b/apps/tangle-dapp/components/NetworkSelector/NetworkSelectionButton.tsx index ddd5675db..d52de5717 100644 --- a/apps/tangle-dapp/components/NetworkSelector/NetworkSelectionButton.tsx +++ b/apps/tangle-dapp/components/NetworkSelector/NetworkSelectionButton.tsx @@ -60,7 +60,9 @@ const NetworkSelectionButton: FC = () => { // Disable network switching when in Liquid Staking page, // since it would have no effect there. - const isInLiquidStakingPath = pathname.startsWith(PagePath.LIQUID_STAKING); + const isInLiquidStakingPage = + pathname.startsWith(PagePath.LIQUID_STAKING) && + !pathname.startsWith(PagePath.LIQUID_STAKING_OVERVIEW); const isInBridgePath = useMemo( () => pathname.startsWith(PagePath.BRIDGE), @@ -96,8 +98,8 @@ const NetworkSelectionButton: FC = () => { return null; } // Network can't be switched from the Tangle Restaking Parachain while - // on liquid staking page. - else if (isInLiquidStakingPath) { + // on the liquid staking page. + else if (isInLiquidStakingPage) { // Special case when the liquifier is selected. const lsNetworkName = isLiquifierProtocolId(selectedProtocolId) ? IS_PRODUCTION_ENV diff --git a/apps/tangle-dapp/containers/LsMyPoolsTable.tsx b/apps/tangle-dapp/containers/LsMyPoolsTable.tsx index 7cb3e24f5..d7da43c77 100644 --- a/apps/tangle-dapp/containers/LsMyPoolsTable.tsx +++ b/apps/tangle-dapp/containers/LsMyPoolsTable.tsx @@ -26,6 +26,7 @@ import { ArrowRight } from '@webb-tools/icons'; import useLsPools from '../data/liquidStaking/useLsPools'; import useSubstrateAddress from '../hooks/useSubstrateAddress'; import { BN } from '@polkadot/util'; +import assert from 'assert'; type MyLsPoolRow = LsPool & { myStake: BN; @@ -165,13 +166,30 @@ const LsMyPoolsTable: FC = () => { const lsPools = lsPoolsMap instanceof Map ? Array.from(lsPoolsMap.values()) : lsPoolsMap; - const myPools = - substrateAddress === null || !Array.isArray(lsPools) - ? null - : lsPools.filter((lsPool) => lsPool.members.has(substrateAddress)); + const rows: MyLsPoolRow[] = useMemo(() => { + if (substrateAddress === null || !Array.isArray(lsPools)) { + return []; + } + + return lsPools + .filter((lsPool) => lsPool.members.has(substrateAddress)) + .map((lsPool) => { + const account = lsPool.members.get(substrateAddress); + + assert(account !== undefined); + + return { + ...lsPool, + myStake: account.balance.toBn(), + isRoot: lsPool.ownerAddress === substrateAddress, + isNominator: lsPool.nominatorAddress === substrateAddress, + isBouncer: lsPool.bouncerAddress === substrateAddress, + }; + }); + }, []); const table = useReactTable({ - data: myPools ?? [], + data: rows, columns: POOL_COLUMNS, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), @@ -199,7 +217,7 @@ const LsMyPoolsTable: FC = () => { { canNextPage={table.getCanNextPage()} nextPage={table.nextPage} setPageIndex={table.setPageIndex} - title={pluralize('pool', myPools.length === 0 || myPools.length > 1)} + title={pluralize('pool', rows.length === 0 || rows.length > 1)} className="border-t-0 py-5" />