Skip to content

Commit

Permalink
📥 Enable voting stake reuse (#2910)
Browse files Browse the repository at this point in the history
* Exclude Voting from conflicting locks

* Refactor isConflictingWith function

* Fix test
  • Loading branch information
RafalPloszka authored Apr 27, 2022
1 parent 46e53b8 commit 63fed09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions packages/ui/src/accounts/model/lockTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ const isRivalrous = (lockType: LockType) => RIVALROUS.includes(lockType)
const asLockTypes = (locks: BalanceLock[]): LockType[] => locks.flatMap((lock) => lock.type ?? [])
const isConflictingWith = (lockTypeA: LockType): ((lockTypeB: LockType) => boolean) => {
if (!lockTypeA) {
return () => false // Don't block transactions based on unknown locks
} else if (isRivalrous(lockTypeA)) {
// Don't block transactions based on unknown locks
return () => false
}

if (isRivalrous(lockTypeA)) {
return isRivalrous
} else {
return (lockTypeB) => lockTypeA === lockTypeB
}

return (lockTypeB) => {
if (lockTypeA === 'Voting' && lockTypeB === 'Voting') {
// Vote stake should be reusable in next elections
return false
}

return lockTypeA === lockTypeB
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ui/test/accounts/hooks/useHasRequiredStake.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ describe('useHasRequiredStake', () => {
locks: [
{
amount: new BN(100),
type: 'Voting',
type: 'Storage Worker',
},
],
},
}
const { result } = renderUseTotalBalances(1000, 'Voting')
const { result } = renderUseTotalBalances(1000, 'Storage Worker')
expect(result.current).toStrictEqual({
hasRequiredStake: false,
accountsWithTransferableBalance: null,
Expand Down

1 comment on commit 63fed09

@vercel
Copy link

@vercel vercel bot commented on 63fed09 Apr 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2-git-dev-joystream.vercel.app

Please sign in to comment.