Skip to content

Commit

Permalink
fix: bug preventing nom pools bondextra extrinsics (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidg authored Dec 24, 2024
1 parent 6124cc9 commit 99b4922
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
2 changes: 1 addition & 1 deletion apps/extension/src/ui/domains/Staking/Bond/BondForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export const BondForm = () => {
</div>
</div>
</div>
<div></div>

<Button primary fullWidth disabled={!payload} onClick={() => setStep("review")}>
{t("Review")}
</Button>
Expand Down
62 changes: 40 additions & 22 deletions apps/extension/src/ui/domains/Staking/shared/useGetStakeInfo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChainId } from "extension-core"
import { UseQueryResult } from "@tanstack/react-query"
import { ChainId, SignerPayloadJSON } from "extension-core"
import { useMemo } from "react"

import { ScaleApi } from "@ui/util/scaleApi"
Expand All @@ -24,6 +25,15 @@ type GetStakeInfo = {

type BondType = "bittensor" | "nomPools"

type StakeInfo = {
payloadInfo: UseQueryResult<{
payload: SignerPayloadJSON
txMetadata?: Uint8Array
} | null>
bondType: BondType
currentPoolId: string | number | undefined | null
}

export const useGetStakeInfo = ({ sapi, address, poolId, plancks, chainId }: GetStakeInfo) => {
const { data: minJoinBond } = useGetMinJoinBond(chainId)

Expand All @@ -47,12 +57,9 @@ export const useGetStakeInfo = ({ sapi, address, poolId, plancks, chainId }: Get

const { data: claimPermission } = useNomPoolsClaimPermission(chainId, address)

let payloadInfo
let bondType: BondType
let currentPoolId: string | number | undefined | null = 0

// we must craft a different extrinsic if the user is already staking in a pool
const hasJoinedNomPool = useMemo(() => !!currentPoolId, [currentPoolId])
const { data: currentNomPool } = useNomPoolByMember(chainId, address)
const hasJoinedNomPool = Boolean(currentNomPool?.pool_id)

const withSetClaimPermission = useMemo(() => {
switch (claimPermission) {
Expand All @@ -75,27 +82,38 @@ export const useGetStakeInfo = ({ sapi, address, poolId, plancks, chainId }: Get
minJoinBond,
})

const { data: currentNomPool } = useNomPoolByMember(chainId, address)
const { data: isSoloStaking } = useIsSoloStaking(chainId, address)
const { data: poolState } = useNomPoolState(chainId, poolId)

switch (chainId) {
case "bittensor":
payloadInfo = bittensorStakingPayload
bondType = "bittensor"
currentPoolId = hotkeys?.[0] ?? poolId
break
default:
payloadInfo = nomPoolStakingPayload
bondType = "nomPools"
currentPoolId = currentNomPool?.pool_id
break
}
const stakeInfo: StakeInfo = useMemo(() => {
switch (chainId) {
case "bittensor":
return {
payloadInfo: bittensorStakingPayload,
bondType: "bittensor" as const,
currentPoolId: hotkeys?.[0] ?? poolId,
}
default:
return {
payloadInfo: nomPoolStakingPayload,
bondType: "nomPools" as const,
currentPoolId: currentNomPool?.pool_id,
}
}
}, [
chainId,
bittensorStakingPayload,
nomPoolStakingPayload,
hotkeys,
poolId,
currentNomPool?.pool_id,
])

const {
data: payloadAndMetadata,
isLoading: isLoadingPayload,
error: errorPayload,
} = payloadInfo || {}
} = stakeInfo?.payloadInfo || {}

const { payload, txMetadata } = payloadAndMetadata || {}

Expand All @@ -113,8 +131,8 @@ export const useGetStakeInfo = ({ sapi, address, poolId, plancks, chainId }: Get
feeEstimate,
isLoadingFeeEstimate,
errorFeeEstimate,
bondType,
currentPoolId,
bondType: stakeInfo?.bondType,
currentPoolId: stakeInfo?.currentPoolId,
hasJoinedNomPool,
minJoinBond,
isSoloStaking,
Expand Down

0 comments on commit 99b4922

Please sign in to comment.