Skip to content

Commit

Permalink
fix a bug in deposit mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfirefist committed Dec 5, 2023
1 parent 203586a commit 19ccf55
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 10 additions & 3 deletions frontend/components/panels/StakePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BasePanel } from './BasePanel'
import { useDepositMutation } from 'hooks/useDepositMutation'
import { VestingAccountState } from '@pythnetwork/staking'
import { StakeAccount, VestingAccountState } from '@pythnetwork/staking'
import { usePythBalance } from 'hooks/usePythBalance'
import { useStakeConnection } from 'hooks/useStakeConnection'
import { useVestingAccountState } from 'hooks/useVestingAccountState'
Expand Down Expand Up @@ -35,7 +35,11 @@ export function StakePanel({ mainStakeAccount }: StakePanelProps) {
onAction={(amount) =>
depositMutation.mutate({
amount,
mainStakeAccount: mainStakeAccount,
// If mainStakeAccount is undefined this action is disabled
// undefined means that the mainStakeAccount is loading.
// If we execute this action, this will work. But it will create a
// new stake account for the user.
mainStakeAccount: mainStakeAccount as StakeAccount | 'NA',
// action is disabled below if these is undefined
stakeConnection: stakeConnection!,
})
Expand All @@ -45,7 +49,10 @@ export function StakePanel({ mainStakeAccount }: StakePanelProps) {
isBalanceLoading={isStakeConnectionLoading || isPythBalanceLoading}
balance={pythBalance}
isActionDisabled={
stakeConnection === undefined || accountWithLockedTokens
// if mainStakeAccount is undefined, the action should be disabled
mainStakeAccount === undefined ||
stakeConnection === undefined ||
accountWithLockedTokens
}
tooltipContentOnDisabled={
accountWithLockedTokens
Expand Down
9 changes: 6 additions & 3 deletions frontend/hooks/useDepositMutation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { PythBalance, StakeConnection } from '@pythnetwork/staking'
import {
PythBalance,
StakeAccount,
StakeConnection,
} from '@pythnetwork/staking'
import toast from 'react-hot-toast'
import { StakeConnectionQueryKey } from './useStakeConnection'
import { useMutation, useQueryClient } from 'react-query'
import { MainStakeAccount } from 'pages'

export function useDepositMutation() {
const queryClient = useQueryClient()
Expand All @@ -16,7 +19,7 @@ export function useDepositMutation() {
}: {
amount: string
stakeConnection: StakeConnection
mainStakeAccount: MainStakeAccount
mainStakeAccount: StakeAccount | 'NA'
}) => {
if (!amount) {
throw new Error('Please enter a valid amount!')
Expand Down

0 comments on commit 19ccf55

Please sign in to comment.