From de6119ea089485965f4f760a4b8f2bf8b09e3357 Mon Sep 17 00:00:00 2001 From: Kheops <26880866+0xKheops@users.noreply.github.com> Date: Wed, 18 Dec 2024 13:01:40 +0900 Subject: [PATCH] fix: staking buttons adjustments (#1751) * fix: dont show nom pool staking button if solo staking * fix: staking buttons inside balance buttons * fix: dont show unbond button on crowdloan rows --- .../AssetDetails/DashboardAssetDetails.tsx | 7 +- .../AssetDetails/PopupAssetDetails.tsx | 8 +- .../AssetsTable/DashboardAssetRow.tsx | 36 +++---- .../AssetsTable/PopupAssetsTable.tsx | 93 ++++++++++--------- .../ui/domains/Staking/Bond/useBondButton.ts | 32 +++++-- 5 files changed, 102 insertions(+), 74 deletions(-) diff --git a/apps/extension/src/ui/domains/Portfolio/AssetDetails/DashboardAssetDetails.tsx b/apps/extension/src/ui/domains/Portfolio/AssetDetails/DashboardAssetDetails.tsx index 9de4ab609..c3bfd996c 100644 --- a/apps/extension/src/ui/domains/Portfolio/AssetDetails/DashboardAssetDetails.tsx +++ b/apps/extension/src/ui/domains/Portfolio/AssetDetails/DashboardAssetDetails.tsx @@ -321,6 +321,11 @@ const LockedExtra: FC<{ [accountStatus?.canWithdrawIn, rowMeta.unbonding], ) + const canUnbond = useMemo( + () => (accountStatus?.canUnstake && rowMeta.poolId) || tokenId === "bittensor-substrate-native", + [accountStatus?.canUnstake, rowMeta.poolId, tokenId], + ) + if (!rowAddress) return null return ( @@ -343,7 +348,7 @@ const LockedExtra: FC<{ )} ) - ) : accountStatus?.canUnstake || tokenId === "bittensor-substrate-native" ? ( + ) : canUnbond ? ( (accountStatus?.canUnstake && rowMeta.poolId) || tokenId === "bittensor-substrate-native", + [accountStatus?.canUnstake, rowMeta.poolId, tokenId], + ) + if (!rowAddress) return null return ( @@ -304,8 +309,7 @@ const LockedExtra: FC<{ )} ) - ) : //eslint-disable-next-line @typescript-eslint/no-explicit-any - accountStatus?.canUnstake || tokenId === "bittensor-substrate-native" ? ( + ) : canUnbond ? ( = ({ if (!token || !summary) return null return ( -
+
+ {canBondNomPool && ( + <> +
+ +
+
+
+ +
+
+ + )}
) } diff --git a/apps/extension/src/ui/domains/Portfolio/AssetsTable/PopupAssetsTable.tsx b/apps/extension/src/ui/domains/Portfolio/AssetsTable/PopupAssetsTable.tsx index 2a5d06cab..3a297904a 100644 --- a/apps/extension/src/ui/domains/Portfolio/AssetsTable/PopupAssetsTable.tsx +++ b/apps/extension/src/ui/domains/Portfolio/AssetsTable/PopupAssetsTable.tsx @@ -96,46 +96,47 @@ const AssetRow: FC<{ if (!token || !summary) return null return ( - + + {showStakingButton && ( +
+ +
+ )} +
) } diff --git a/apps/extension/src/ui/domains/Staking/Bond/useBondButton.ts b/apps/extension/src/ui/domains/Staking/Bond/useBondButton.ts index 621898ab9..e44deb2e2 100644 --- a/apps/extension/src/ui/domains/Staking/Bond/useBondButton.ts +++ b/apps/extension/src/ui/domains/Staking/Bond/useBondButton.ts @@ -24,16 +24,28 @@ export const useBondButton = ({ const ownedAddresses = useMemo(() => ownedAccounts.map(({ address }) => address), [ownedAccounts]) + // accounts that are solo-staking cannot stake in nomination pools + const soloStakingAddresses = useMemo(() => { + type SoloStakingMeta = { id?: string } | undefined + return ( + balances?.each + .filter((b) => b.locks.some((l) => (l.meta as SoloStakingMeta)?.id === "staking ")) // yes, there is a space at the end :jean: + .map((b) => b.address) ?? [] + ) + }, [balances]) + const sorted = useMemo(() => { if (!balances || !tokenId) return [] return balances .find({ tokenId }) - .each.filter((b) => ownedAddresses.includes(b.address)) + .each.filter( + (b) => ownedAddresses.includes(b.address) && !soloStakingAddresses.includes(b.address), + ) .sort((a, b) => { if (a.transferable.planck === b.transferable.planck) return 0 return a.transferable.planck > b.transferable.planck ? -1 : 1 }) - }, [balances, ownedAddresses, tokenId]) + }, [balances, ownedAddresses, soloStakingAddresses, tokenId]) const address = sorted[0]?.address @@ -47,24 +59,26 @@ export const useBondButton = ({ if (!poolId) return [null, false] - // if a watch-only account is selected, there will be no entries here + // if a watch-only or solo-staking account is selected, array will be empty if (!sorted.length) return [null, false] // lookup existing poolId for that account for (const balance of sorted.filter((b) => b.address === address)) { switch (token.chain.id) { case "bittensor": { - type SubtensorMeta = { hotkeys?: string[] } - const entry = balance.subtensor.find((b) => !!(b.meta as SubtensorMeta).hotkeys?.length) - const meta = entry?.meta as SubtensorMeta | undefined + type SubtensorMeta = { hotkeys?: string[] } | undefined + const entry = balance.subtensor.find( + (b) => !!(b.meta as SubtensorMeta)?.hotkeys?.length, + ) + const meta = entry?.meta as SubtensorMeta if (meta?.hotkeys?.[0]) return [{ tokenId, address, poolId: meta?.hotkeys[0] }, false] break } default: { // assume nomination pool staking, but there will be more in the future - type NomPoolMeta = { poolId?: number } - const entry = balance.nompools.find((b) => !!(b.meta as NomPoolMeta).poolId) - const meta = entry?.meta as NomPoolMeta | undefined + type NomPoolMeta = { poolId?: number } | undefined + const entry = balance.nompools.find((b) => !!(b.meta as NomPoolMeta)?.poolId) + const meta = entry?.meta as NomPoolMeta if (meta?.poolId) return [{ tokenId, address, poolId: meta.poolId }, true] break }