Skip to content

Commit

Permalink
Merge pull request #54 from AudiusProject/jowlee-decrease-delegation-bug
Browse files Browse the repository at this point in the history
Disable decrease delegation if already pending
  • Loading branch information
jowlee authored Feb 8, 2021
2 parents 103dccd + a5c5028 commit 6d0e387
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/components/Delegate/Delegate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import Button, { ButtonType } from 'components/Button'
import { IconArrowWhite } from '@audius/stems'
import { useModalControls } from 'utils/hooks'
import UpdateDelegationModal from 'components/UpdateDelegationModal'
import { Address } from 'types'
import { Address, Status } from 'types'
import { formatWei, formatShortAud } from 'utils/format'
import { useHasPendingDecreaseDelegationTx } from 'store/account/hooks'

const messages = {
title: 'Manage Delegation',
Expand Down Expand Up @@ -106,6 +107,10 @@ const DelegateSection: React.FC<DelegateSectionProps> = ({
wallet,
delegates
}: DelegateSectionProps) => {
const useHasPendingDecrease = useHasPendingDecreaseDelegationTx()
const isDecreaseDelegationDisabled =
useHasPendingDecrease.status !== Status.Success ||
useHasPendingDecrease.hasPendingDecreaseTx
return (
<Paper className={clsx(styles.container, { [className!]: !!className })}>
<div className={styles.title}>{messages.title} </div>
Expand All @@ -131,7 +136,7 @@ const DelegateSection: React.FC<DelegateSectionProps> = ({
<DecreaseDelegation
wallet={wallet}
delegates={delegates}
isDisabled={false}
isDisabled={isDecreaseDelegationDisabled}
className={styles.decreaseBtn}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ManageService/ManageService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TransactionStatus from 'components/TransactionStatus'
import {
useAccount,
useAccountUser,
useHasPendingDecreaseTx
useHasPendingDecreaseStakeTx
} from 'store/account/hooks'
import { usePendingClaim } from 'store/cache/claims/hooks'
import { Address, Status, Operator } from 'types'
Expand Down Expand Up @@ -220,7 +220,7 @@ const ManageService: React.FC<ManageServiceProps> = (
const isDelegator =
userStatus === Status.Success && 'delegates' in accountUser

const hasPendingDecreaseTx = useHasPendingDecreaseTx()
const hasPendingDecreaseTx = useHasPendingDecreaseStakeTx()
let increaseStakeDisabled = !isServiceProvider
const decreaseStakeDisabled =
!isServiceProvider ||
Expand Down
14 changes: 13 additions & 1 deletion src/store/account/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const usePendingTransactions = () => {
return pendingTransactions
}

export const useHasPendingDecreaseTx = () => {
export const useHasPendingDecreaseStakeTx = () => {
const pendingTransactions = usePendingTransactions()
if (pendingTransactions.status === Status.Success) {
const hasPendingDecreaseTx =
Expand All @@ -182,3 +182,15 @@ export const useHasPendingDecreaseTx = () => {
}
return { status: Status.Loading, hasPendingDecreaseTx: true }
}

export const useHasPendingDecreaseDelegationTx = () => {
const pendingTransactions = usePendingTransactions()
if (pendingTransactions.status === Status.Success) {
const hasPendingDecreaseTx =
pendingTransactions.transactions?.some(tx => {
return tx.name === PendingTransactionName.Undelegate
}) ?? false
return { status: Status.Success, hasPendingDecreaseTx }
}
return { status: Status.Loading, hasPendingDecreaseTx: true }
}

0 comments on commit 6d0e387

Please sign in to comment.