Skip to content

Commit

Permalink
fix: tao staking fee estimation (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
UrbanWill authored Oct 1, 2024
1 parent c5891b6 commit 315fc70
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions apps/portal/src/domains/staking/subtensor/hooks/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ export const useAddStakeForm = (account: Account, stake: Stake, delegate: string
const [input, setInput] = useState('')
const amount = useTokenAmount(input)

const feeEstimateTx: SubmittableExtrinsic<any> = useMemo(
() => (api.tx as any)?.subtensorModule?.addStake?.(delegate, accountInfo.data.free.toBigInt() ?? 0n),
[accountInfo.data.free, api.tx, delegate]
const tx: SubmittableExtrinsic<any> = useMemo(
() =>
api.tx.utility.batchAll([
(api.tx as any)?.subtensorModule?.addStake?.(delegate, amount.decimalAmount?.planck ?? 0n),
api.tx.system.remarkWithEvent(`talisman-bittensor`),
]),
[api.tx, delegate, amount.decimalAmount?.planck]
)
const [feeEstimate, isFeeEstimateReady] = useStakeFormFeeEstimate(account.address, feeEstimateTx)

const [feeEstimate, isFeeEstimateReady] = useStakeFormFeeEstimate(account.address, tx)

const existentialDeposit = useMemo(
() => api.consts.balances.existentialDeposit.toBigInt(),
Expand Down Expand Up @@ -88,14 +93,6 @@ export const useAddStakeForm = (account: Account, stake: Stake, delegate: string
transferable.decimalAmount.planck,
])

const tx: SubmittableExtrinsic<any> = useMemo(
() =>
api.tx.utility.batchAll([
(api.tx as any)?.subtensorModule?.addStake?.(delegate, amount.decimalAmount?.planck ?? 0n),
api.tx.system.remarkWithEvent(`talisman-bittensor`),
]),
[api.tx, delegate, amount.decimalAmount?.planck]
)
const extrinsic = useExtrinsic(tx)

const ready = isFeeEstimateReady && (amount.decimalAmount?.planck ?? 0n) > 0n && error === undefined
Expand Down

0 comments on commit 315fc70

Please sign in to comment.