Skip to content

Commit

Permalink
Fix issue where lock increase don't work
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed May 30, 2024
1 parent 1c9763b commit 18e1ef3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 35 deletions.
16 changes: 4 additions & 12 deletions src/components/content-staking/mutations/lockOrIncreaseTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import {
} from '@/services/subsocial/utils/mutation'
import { getBalancesQuery } from '@/services/substrateBalances/query'
import { useSendEvent } from '@/stores/analytics'
import { useMyAccount } from '@/stores/my-account'
import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation'
import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types'
import { balanceWithDecimal } from '@subsocial/utils'
import { useQueryClient } from '@tanstack/react-query'
import { useMemo } from 'react'
import getAmountRange from '../utils/getAmountRangeForAnalytics'

type MutationProps = {
Expand Down Expand Up @@ -97,20 +95,14 @@ type LockOrIncreaseTxWrapperProps = {
}) => JSX.Element
}

const Wrapper = createMutationWrapper(
useLockOrIncreaseTx,
'Failed to stake or increase the stake tokens. Please try again.'
)
export const LockOrIncreaseTxWrapper = ({
closeModal,
children,
}: LockOrIncreaseTxWrapperProps) => {
const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress)

const Wrapper = useMemo(() => {
return createMutationWrapper(
useLockOrIncreaseTx,
'Failed to stake or increase the stake tokens. Please try again.',
!!parentProxyAddress
)
}, [parentProxyAddress])

return (
<Wrapper
loadingUntilTxSuccess
Expand Down
15 changes: 4 additions & 11 deletions src/components/content-staking/mutations/unlockTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation'
import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types'
import { balanceWithDecimal, isDef } from '@subsocial/utils'
import { useQueryClient } from '@tanstack/react-query'
import { useMemo } from 'react'
import { useGetMyCreatorsIds } from '../hooks/useGetMyCreatorsIds'
import { ACTIVE_STAKING_SPACE_ID } from '../utils'

Expand Down Expand Up @@ -202,20 +201,14 @@ type UnlockTxWrapperProps = {
}) => JSX.Element
}

const Wrapper = createMutationWrapper(
useUnlockTx,
'Failed to unlock the tokens'
)
export const UnlockTxWrapper = ({
closeModal,
children,
}: UnlockTxWrapperProps) => {
const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress)

const Wrapper = useMemo(() => {
return createMutationWrapper(
useUnlockTx,
'Failed to unlock the tokens',
!!parentProxyAddress
)
}, [parentProxyAddress])

return (
<Wrapper
loadingUntilTxSuccess
Expand Down
16 changes: 4 additions & 12 deletions src/components/content-staking/mutations/withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
} from '@/services/subsocial/utils/mutation'
import { getBalancesQuery } from '@/services/substrateBalances/query'
import { useSendEvent } from '@/stores/analytics'
import { useMyAccount } from '@/stores/my-account'
import { useSubsocialMutation } from '@/subsocial-query/subsocial/mutation'
import { SubsocialMutationConfig } from '@/subsocial-query/subsocial/types'
import { useQueryClient } from '@tanstack/react-query'
import { useMemo } from 'react'

export function useWithdrawTx(config?: SubsocialMutationConfig<{}>) {
const client = useQueryClient()
Expand Down Expand Up @@ -54,17 +52,11 @@ type WithdrawTxWrapperProps = {
}) => JSX.Element
}

const Wrapper = createMutationWrapper(
useWithdrawTx,
'Failed to withdraw unlocked tokens. Please try again.'
)
export const WithdrawTxWrapper = ({ children }: WithdrawTxWrapperProps) => {
const parentProxyAddress = useMyAccount((state) => state.parentProxyAddress)

const Wrapper = useMemo(() => {
return createMutationWrapper(
useWithdrawTx,
'Failed to withdraw unlocked tokens. Please try again.',
!!parentProxyAddress
)
}, [parentProxyAddress])

return (
<Wrapper loadingUntilTxSuccess>
{(props) => {
Expand Down
1 change: 1 addition & 0 deletions src/services/api/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import mutationWrapper from '@/subsocial-query/base'
import { apiInstance } from './utils'

export async function requestToken({ address }: ApiRequestTokenBody) {
if (!address) return
// make request token as pending transaction so websocket won't disconnect for 10 secs after request token
// this is to make energy subscription work
const requestTokenId = `request-token-${Date.now()}`
Expand Down

0 comments on commit 18e1ef3

Please sign in to comment.