This commit is contained in:
G. Kami Ekbatanifard 2023-11-03 12:06:18 +02:00 committed by GitHub
parent fa8b3ac348
commit 02e9cf489f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -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';
@ -84,8 +85,9 @@ 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;
@ -93,7 +95,7 @@ function getLocks (api: ApiPromise, palletVote: PalletVote, votes: [classId: BN,
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) {
@ -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]

View File

@ -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 [