Skip to content

Commit

Permalink
Fixes #9260 (#10002)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 authored Nov 3, 2023
1 parent fa8b3ac commit 02e9cf4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions packages/page-referenda/src/useAccountLocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Lock, PalletReferenda, PalletVote } from './types.js';

import { useMemo } from 'react';

import { CONVICTIONS } from '@polkadot/react-components/ConvictionDropdown';
import { createNamedHook, useApi, useCall } from '@polkadot/react-hooks';
import { BN_MAX_INTEGER } from '@polkadot/util';

Expand Down Expand Up @@ -84,16 +85,17 @@ function getLocks (api: ApiPromise, palletVote: PalletVote, votes: [classId: BN,
const [, tally] = refInfo;
let total: BN | undefined;
let endBlock: BN| undefined;
let conviction = 0;
let convictionIndex = 0;
let locked = 'None';
const durationIndex = 1;

if (accountVote.isStandard) {
const { balance, vote } = accountVote.asStandard;

total = balance;

if ((tally.isApproved && vote.isAye) || (tally.isRejected && vote.isNay)) {
conviction = vote.conviction.index;
convictionIndex = vote.conviction.index;
locked = vote.conviction.type;
}
} else if (accountVote.isSplit) {
Expand All @@ -118,7 +120,7 @@ function getLocks (api: ApiPromise, palletVote: PalletVote, votes: [classId: BN,
: tally.asTimedOut[0];
} else if (tally.isApproved || tally.isRejected) {
endBlock = lockPeriod
.muln(conviction)
.muln(convictionIndex ? CONVICTIONS[convictionIndex - 1][durationIndex] : 0)
.add(
tally.isApproved
? tally.asApproved[0]
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/src/ConvictionDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Props {
voteLockingPeriod: BN;
}

const CONVICTIONS = [1, 2, 4, 8, 16, 32].map((lock, index): [value: number, duration: number, durationBn: BN] => [index + 1, lock, new BN(lock)]);
export const CONVICTIONS = [1, 2, 4, 8, 16, 32].map((lock, index): [value: number, duration: number, durationBn: BN] => [index + 1, lock, new BN(lock)]);

function createOptions (blockTime: BN, voteLockingPeriod: BN, t: (key: string, options?: { replace: Record<string, unknown> }) => string): { text: string; value: number }[] {
return [
Expand Down

0 comments on commit 02e9cf4

Please sign in to comment.