Skip to content

Commit

Permalink
fix: inline staking adjustments (#1645)
Browse files Browse the repository at this point in the history
* fix: consider withdrawable as soon as unbounding era is reached

* fix: nom pool name cleanup
  • Loading branch information
0xKheops authored Oct 10, 2024
1 parent c66fd3a commit e376d3a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from "react-i18next"

import { Address, Balances } from "@extension/core"
import { sortBigBy } from "@talisman/util/bigHelper"
import { cleanupNomPoolName } from "@ui/domains/Staking/helpers"
import { useBalancesStatus } from "@ui/hooks/useBalancesStatus"
import useChain from "@ui/hooks/useChain"
import { useSelectedCurrency } from "@ui/hooks/useCurrency"
Expand Down Expand Up @@ -96,12 +97,8 @@ export const useChainTokenBalances = ({ chainId, balances }: ChainTokenBalancesP
b.nompools.map((nomPool, index) => ({
key: `${b.id}-nomPool-${index}`,
title: getLockTitle(nomPool, { balance: b }),

description:
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(nomPool.meta as any)?.description
?.replace(": app.talisman.xyz/staking", "")
.replace(" | Auto-Compound > $2USD", "") ?? undefined,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
description: cleanupNomPoolName((nomPool.meta as any).description) ?? undefined,
tokens: BigNumber(nomPool.amount.tokens),
fiat: nomPool.amount.fiat(currency),
locked: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const useNomPoolWithdrawWizard = () => {
const pointsToWithdraw = useMemo(() => {
if (!currentEra || !pool) return null
return pool.unbonding_eras
.filter(([era]) => era < currentEra)
.filter(([era]) => era <= currentEra)
.reduce((acc, [, points]) => acc + points, 0n)
}, [currentEra, pool])

Expand Down
5 changes: 5 additions & 0 deletions apps/extension/src/ui/domains/Staking/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ export const getNomPoolStakingPayload = async (
{ address }
)
}
export const cleanupNomPoolName = (name: string | null | undefined) =>
name
?.replace(": app.talisman.xyz/staking", "")
.replace(" | Auto-Compound > $2USD", "")
.replace(" | Auto-Compound > 1 DOT", "") ?? null
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ChainId } from "extension-core"

import { useScaleApi } from "@ui/hooks/sapi/useScaleApi"

import { cleanupNomPoolName } from "../helpers"

export const useNomPoolName = (
chainId: ChainId | null | undefined,
poolId: number | null | undefined
Expand All @@ -17,12 +19,7 @@ export const useNomPoolName = (

const metadata = await sapi.getStorage<Binary>("NominationPools", "Metadata", [poolId])

return (
metadata
?.asText()
.replace(": app.talisman.xyz/staking", "")
.replace(" | Auto-Compound > $2USD", "") ?? null
)
return cleanupNomPoolName(metadata?.asText())
},
enabled: !!sapi,
refetchInterval: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useNomPoolStakingStatus = (tokenId: TokenId) => {
const unbondingEras =
nomPoolStakingByAddress[address]?.unbonding_eras.map(([era]) => era) ?? []
const maxUnbondingEra = Math.max(...unbondingEras)
const erasToUnbonding = currentEra < maxUnbondingEra ? maxUnbondingEra - currentEra : 0
const erasToUnbonding = currentEra <= maxUnbondingEra ? maxUnbondingEra - currentEra : 0

return {
address,
Expand All @@ -88,7 +88,7 @@ export const useNomPoolStakingStatus = (tokenId: TokenId) => {
isNomPoolsStaking: !!nomPoolStakingByAddress[address],
canBondNomPool: !soloStakingByAddress[address] && !!transferableByAddress[address],
canUnstake: nomPoolStakingByAddress[address]?.points,
canWithdraw: maxUnbondingEra < currentEra,
canWithdraw: maxUnbondingEra <= currentEra,
canWithdrawIn: await getWithdrawWaitDuration(sapi, erasToUnbonding),
}
})
Expand Down

0 comments on commit e376d3a

Please sign in to comment.