Skip to content

Commit 72d5330

Browse files
authored
Use lookup types in derives (#4012)
* Use lookup types in derives * additional * society
1 parent 1c3bdda commit 72d5330

File tree

22 files changed

+191
-155
lines changed

22 files changed

+191
-155
lines changed

packages/api-derive/src/accounts/identity.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
66
import type { Data, Option } from '@polkadot/types';
7-
import type { AccountId, IdentityInfoAdditional, Registration } from '@polkadot/types/interfaces';
7+
import type { AccountId } from '@polkadot/types/interfaces';
8+
import type { PalletIdentityIdentityInfo, PalletIdentityRegistration } from '@polkadot/types/lookup';
89
import type { ITuple } from '@polkadot/types/types';
910
import type { DeriveAccountRegistration, DeriveHasIdentity } from '../types';
1011

@@ -14,6 +15,8 @@ import { isHex, u8aToString } from '@polkadot/util';
1415

1516
import { memo } from '../util';
1617

18+
type IdentityInfoAdditional = PalletIdentityIdentityInfo['additional'][0];
19+
1720
const UNDEF_HEX = { toHex: () => undefined };
1821

1922
function dataAsString (data: Data): string | undefined {
@@ -37,7 +40,7 @@ function extractOther (additional: IdentityInfoAdditional[]): Record<string, str
3740
}, {});
3841
}
3942

40-
function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
43+
function extractIdentity (identityOfOpt?: Option<PalletIdentityRegistration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
4144
if (!identityOfOpt?.isSome) {
4245
return { judgements: [] };
4346
}
@@ -61,7 +64,7 @@ function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [Accou
6164
};
6265
}
6366

64-
function getParent (api: ApiInterfaceRx, identityOfOpt: Option<Registration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<Registration> | undefined, [AccountId, Data] | undefined]> {
67+
function getParent (api: ApiInterfaceRx, identityOfOpt: Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
6568
if (identityOfOpt?.isSome) {
6669
// this identity has something set
6770
return of([identityOfOpt, undefined]);
@@ -70,7 +73,7 @@ function getParent (api: ApiInterfaceRx, identityOfOpt: Option<Registration> | u
7073

7174
// we have a super
7275
return combineLatest([
73-
api.query.identity.identityOf<Option<Registration>>(superOf[0]),
76+
api.query.identity.identityOf(superOf[0]),
7477
of(superOf)
7578
]);
7679
}
@@ -79,9 +82,9 @@ function getParent (api: ApiInterfaceRx, identityOfOpt: Option<Registration> | u
7982
return of([undefined, undefined]);
8083
}
8184

82-
function getBase (api: ApiInterfaceRx, accountId?: AccountId | Uint8Array | string): Observable<[Option<Registration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
85+
function getBase (api: ApiInterfaceRx, accountId?: AccountId | Uint8Array | string): Observable<[Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
8386
return accountId && api.query.identity?.identityOf
84-
? api.queryMulti<[Option<Registration>, Option<ITuple<[AccountId, Data]>>]>([
87+
? api.queryMulti<[Option<PalletIdentityRegistration>, Option<ITuple<[AccountId, Data]>>]>([
8588
[api.query.identity.identityOf, accountId],
8689
[api.query.identity.superOf, accountId]
8790
])

packages/api-derive/src/balances/all.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '@polkadot/api/types';
66
import type { Option, Vec } from '@polkadot/types';
7-
import type { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo212, BlockNumber, VestingInfo, VestingSchedule } from '@polkadot/types/interfaces';
7+
import type { AccountId, AccountIndex, Address, Balance, BalanceLockTo212, BlockNumber, VestingSchedule } from '@polkadot/types/interfaces';
8+
import type { PalletBalancesBalanceLock, PalletVestingVestingInfo } from '@polkadot/types/lookup';
89
import type { DeriveBalancesAccount, DeriveBalancesAccountData, DeriveBalancesAll, DeriveBalancesAllAccountData } from '../types';
910

1011
import { combineLatest, map, of, switchMap } from 'rxjs';
@@ -13,15 +14,15 @@ import { BN, bnMax, isFunction } from '@polkadot/util';
1314

1415
import { memo } from '../util';
1516

16-
type BalanceLocksEntry = Vec<BalanceLock | BalanceLockTo212>;
17+
type BalanceLocksEntry = Vec<PalletBalancesBalanceLock | BalanceLockTo212>;
1718
type BalanceLocks = BalanceLocksEntry[];
18-
type ResultBalance = [VestingInfo | null, ((BalanceLock | BalanceLockTo212)[])[]];
19+
type ResultBalance = [PalletVestingVestingInfo | null, ((PalletBalancesBalanceLock | BalanceLockTo212)[])[]];
1920
type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance];
2021

2122
interface AllLocked {
2223
allLocked: boolean,
2324
lockedBalance: Balance,
24-
lockedBreakdown: (BalanceLock | BalanceLockTo212)[],
25+
lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[],
2526
vestingLocked: Balance
2627
}
2728

@@ -33,9 +34,9 @@ type DeriveCustomLocks = ApiInterfaceRx['derive'] & {
3334

3435
const VESTING_ID = '0x76657374696e6720';
3536

36-
function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (BalanceLock | BalanceLockTo212)[]): AllLocked {
37+
function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): AllLocked {
3738
let lockedBalance = api.registry.createType('Balance');
38-
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
39+
let lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[] = [];
3940
let vestingLocked = api.registry.createType('Balance');
4041
let allLocked = false;
4142

@@ -56,7 +57,7 @@ function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (Balan
5657
return { allLocked, lockedBalance, lockedBreakdown, vestingLocked };
5758
}
5859

59-
function calcShared (api: ApiInterfaceRx, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (BalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
60+
function calcShared (api: ApiInterfaceRx, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
6061
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
6162

6263
return {
@@ -73,7 +74,7 @@ function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLock
7374
// Calculate the vesting balances,
7475
// - offset = balance locked at startingBlock
7576
// - perBlock is the unlock amount
76-
const emptyVest = api.registry.createType('VestingInfo');
77+
const emptyVest = api.registry.createType<PalletVestingVestingInfo>('VestingInfo');
7778
const { locked: vestingTotal, perBlock, startingBlock } = vesting || emptyVest;
7879
const isStarted = bestNumber.gt(startingBlock);
7980
const vestedNow = isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : new BN(0);
@@ -96,7 +97,7 @@ function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLock
9697

9798
// old
9899
function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<ResultBalance> {
99-
return api.queryMulti<[Vec<BalanceLock>, Option<VestingSchedule>]>([
100+
return api.queryMulti<[Vec<PalletBalancesBalanceLock>, Option<VestingSchedule>]>([
100101
[api.query.balances.locks, accountId],
101102
[api.query.balances.vesting, accountId]
102103
]).pipe(
@@ -106,7 +107,7 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
106107
if (optVesting.isSome) {
107108
const { offset: locked, perBlock, startingBlock } = optVesting.unwrap();
108109

109-
vestingNew = api.registry.createType('VestingInfo', { locked, perBlock, startingBlock });
110+
vestingNew = api.registry.createType<PalletVestingVestingInfo>('VestingInfo', { locked, perBlock, startingBlock });
110111
}
111112

112113
return [vestingNew, [locks]];
@@ -126,20 +127,20 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstanc
126127

127128
return (
128129
api.query.vesting?.vesting
129-
? api.queryMulti<[Option<VestingInfo>, ...BalanceLocks]>([[api.query.vesting.vesting, accountId], ...queries])
130+
? api.queryMulti<[Option<PalletVestingVestingInfo>, ...BalanceLocks]>([[api.query.vesting.vesting, accountId], ...queries])
130131
// TODO We need to check module instances here as well, not only the balances module
131132
: queries.length
132-
? api.queryMulti<[...(Vec<BalanceLock>)[]]>(queries).pipe(
133-
map((r): [Option<VestingInfo>, ...BalanceLocks] => [api.registry.createType('Option<VestingInfo>'), ...r])
133+
? api.queryMulti<[...(Vec<PalletBalancesBalanceLock>)[]]>(queries).pipe(
134+
map((r): [Option<PalletVestingVestingInfo>, ...BalanceLocks] => [api.registry.createType('Option<VestingInfo>'), ...r])
134135
)
135-
: of([api.registry.createType('Option<VestingInfo>')] as [Option<VestingInfo>])
136+
: of([api.registry.createType('Option<VestingInfo>')] as [Option<PalletVestingVestingInfo>])
136137
).pipe(
137138
map(([opt, ...locks]): ResultBalance => {
138139
let offset = -1;
139140

140141
return [
141142
opt.unwrapOr(null),
142-
lockEmpty.map((e) => e ? api.registry.createType('Vec<BalanceLock>') : locks[++offset])
143+
lockEmpty.map((e) => e ? api.registry.createType<Vec<PalletBalancesBalanceLock>>('Vec<BalanceLock>') : locks[++offset])
143144
];
144145
})
145146
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import type { AccountId, Balance, BalanceLockTo212, BlockNumber, Index } from '@polkadot/types/interfaces';
5+
import type { PalletBalancesBalanceLock } from '@polkadot/types/lookup';
6+
7+
export interface DeriveBalancesAccountData {
8+
freeBalance: Balance;
9+
frozenFee: Balance;
10+
frozenMisc: Balance;
11+
reservedBalance: Balance;
12+
votingBalance: Balance;
13+
}
14+
15+
export interface DeriveBalancesAccount extends DeriveBalancesAccountData {
16+
accountId: AccountId;
17+
accountNonce: Index;
18+
additional: DeriveBalancesAccountData[];
19+
}
20+
21+
export interface DeriveBalancesAllAccountData extends DeriveBalancesAccountData {
22+
availableBalance: Balance;
23+
lockedBalance: Balance;
24+
lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[];
25+
vestingLocked: Balance;
26+
}
27+
28+
export interface DeriveBalancesAll extends DeriveBalancesAccount, DeriveBalancesAllAccountData {
29+
additional: DeriveBalancesAllAccountData[];
30+
isVesting: boolean;
31+
vestedBalance: Balance;
32+
vestedClaimable: Balance;
33+
vestingEndBlock: BlockNumber;
34+
vestingPerBlock: Balance;
35+
vestingTotal: Balance;
36+
}
37+
38+
export type DeriveBalancesMap = Record<string, DeriveBalancesAll>;

packages/api-derive/src/council/votes.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx, QueryableModuleStorage } from '@polkadot/api/types';
66
import type { Vec } from '@polkadot/types';
7-
import type { AccountId, Balance, Voter } from '@polkadot/types/interfaces';
7+
import type { AccountId, Balance } from '@polkadot/types/interfaces';
8+
import type { PalletElectionsPhragmenVoter } from '@polkadot/types/lookup';
89
import type { ITuple } from '@polkadot/types/types';
910
import type { DeriveCouncilVote, DeriveCouncilVotes } from '../types';
1011

@@ -13,9 +14,9 @@ import { combineLatest, map, of } from 'rxjs';
1314
import { memo } from '../util';
1415

1516
// Voter is current tuple is 2.x-era
16-
type VoteEntry = Voter | ITuple<[Balance, Vec<AccountId>]>;
17+
type VoteEntry = PalletElectionsPhragmenVoter | ITuple<[Balance, Vec<AccountId>]>;
1718

18-
function isVoter (value: VoteEntry): value is Voter {
19+
function isVoter (value: VoteEntry): value is PalletElectionsPhragmenVoter {
1920
return !Array.isArray(value);
2021
}
2122

packages/api-derive/src/democracy/locks.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { AccountId, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
7-
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
6+
import type { AccountId, ReferendumInfoTo239, Vote } from '@polkadot/types/interfaces';
7+
import type { PalletDemocracyReferendumInfo, PalletDemocracyVoteVoting } from '@polkadot/types/lookup';
88
import type { BN } from '@polkadot/util';
99
import type { DeriveDemocracyLock } from '../types';
1010

@@ -14,6 +14,11 @@ import { BN_ZERO, isUndefined } from '@polkadot/util';
1414

1515
import { memo } from '../util';
1616

17+
type ReferendumInfoFinished = PalletDemocracyReferendumInfo['asFinished'];
18+
type VotingDelegating = PalletDemocracyVoteVoting['asDelegating'];
19+
type VotingDirect = PalletDemocracyVoteVoting['asDirect'];
20+
type VotingDirectVote = VotingDirect['votes'][0];
21+
1722
const LOCKUPS = [0, 1, 2, 4, 8, 16, 32];
1823

1924
function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: ReferendumInfoFinished): [BN, BN] {

packages/api-derive/src/democracy/nextExternal.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
66
import type { Option } from '@polkadot/types';
7-
import type { Hash, VoteThreshold } from '@polkadot/types/interfaces';
7+
import type { H256 } from '@polkadot/types/interfaces';
8+
import type { PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
89
import type { ITuple } from '@polkadot/types/types';
910
import type { DeriveProposalExternal } from '../types';
1011

1112
import { map, of, switchMap } from 'rxjs';
1213

1314
import { memo } from '../util';
1415

15-
function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[Hash, VoteThreshold]>>): Observable<DeriveProposalExternal | null> {
16+
function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[H256, PalletDemocracyVoteThreshold]>>): Observable<DeriveProposalExternal | null> {
1617
if (nextOpt.isNone) {
1718
return of(null);
1819
}
@@ -31,7 +32,7 @@ function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[Hash, VoteThres
3132
export function nextExternal (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposalExternal | null> {
3233
return memo(instanceId, (): Observable<DeriveProposalExternal | null> =>
3334
api.query.democracy?.nextExternal
34-
? api.query.democracy.nextExternal<Option<ITuple<[Hash, VoteThreshold]>>>().pipe(
35+
? api.query.democracy.nextExternal().pipe(
3536
switchMap((nextOpt) => withImage(api, nextOpt))
3637
)
3738
: of(null)

packages/api-derive/src/democracy/preimage.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,17 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Bytes, Option } from '@polkadot/types';
7-
import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
8-
import type { ITuple } from '@polkadot/types/types';
6+
import type { Hash } from '@polkadot/types/interfaces';
97
import type { DeriveProposalImage } from '../types';
108

119
import { map } from 'rxjs';
1210

1311
import { memo } from '../util';
1412
import { parseImage } from './util';
1513

16-
type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
17-
1814
export function preimage (instanceId: string, api: ApiInterfaceRx): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
1915
return memo(instanceId, (hash: Hash): Observable<DeriveProposalImage | undefined> =>
20-
api.query.democracy.preimages<PreImage>(hash).pipe(
16+
api.query.democracy.preimages(hash).pipe(
2117
map((imageOpt) => parseImage(api, imageOpt))
2218
)
2319
);

packages/api-derive/src/democracy/referendumsInfo.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
66
import type { Option, Vec } from '@polkadot/types';
7-
import type { AccountId, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces';
8-
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
7+
import type { AccountId, ReferendumInfoTo239, Vote } from '@polkadot/types/interfaces';
8+
import type { PalletDemocracyReferendumInfo, PalletDemocracyVoteVoting } from '@polkadot/types/lookup';
99
import type { BN } from '@polkadot/util';
1010
import type { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
1111

@@ -16,6 +16,10 @@ import { isFunction } from '@polkadot/util';
1616
import { memo } from '../util';
1717
import { calcVotes, getStatus, parseImage } from './util';
1818

19+
type VotingDelegating = PalletDemocracyVoteVoting['asDelegating'];
20+
type VotingDirect = PalletDemocracyVoteVoting['asDirect'];
21+
type VotingDirectVote = VotingDirect['votes'][0];
22+
1923
function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
2024
return api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
2125
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DeriveBalancesAccount[]]> =>
@@ -42,7 +46,7 @@ function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveRef
4246
);
4347
}
4448

45-
function extractVotes (mapped: [AccountId, Voting][], referendumId: BN): DeriveReferendumVote[] {
49+
function extractVotes (mapped: [AccountId, PalletDemocracyVoteVoting][], referendumId: BN): DeriveReferendumVote[] {
4650
return mapped
4751
.filter(([, voting]) => voting.isDirect)
4852
.map(([accountId, voting]): [AccountId, VotingDirectVote[]] => [
@@ -67,9 +71,9 @@ function extractVotes (mapped: [AccountId, Voting][], referendumId: BN): DeriveR
6771
}
6872

6973
function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
70-
return api.query.democracy.votingOf.entries<Voting, [AccountId]>().pipe(
74+
return api.query.democracy.votingOf.entries().pipe(
7175
map((allVoting): DeriveReferendumVote[] => {
72-
const mapped = allVoting.map(([{ args: [accountId] }, voting]): [AccountId, Voting] => [accountId, voting]);
76+
const mapped = allVoting.map(([{ args: [accountId] }, voting]): [AccountId, PalletDemocracyVoteVoting] => [accountId, voting]);
7377
const votes = extractVotes(mapped, referendumId);
7478
const delegations = mapped
7579
.filter(([, voting]) => voting.isDelegating)

packages/api-derive/src/democracy/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import type { Vec } from '@polkadot/types';
5-
import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, Vote, VoteThreshold } from '@polkadot/types/interfaces';
6-
import type { PalletDemocracyReferendumStatus } from '@polkadot/types/lookup';
5+
import type { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal, ReferendumIndex, ReferendumInfoTo239, Vote } from '@polkadot/types/interfaces';
6+
import type { PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
77
import type { BN } from '@polkadot/util';
88

99
export interface DeriveDemocracyLock {
@@ -42,7 +42,7 @@ export interface DeriveProposal {
4242
export interface DeriveProposalExternal {
4343
image?: DeriveProposalImage;
4444
imageHash: Hash;
45-
threshold: VoteThreshold;
45+
threshold: PalletDemocracyVoteThreshold;
4646
}
4747

4848
export interface DeriveReferendum {

packages/api-derive/src/society/candidates.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,31 @@
33

44
import type { Observable } from 'rxjs';
55
import type { ApiInterfaceRx } from '@polkadot/api/types';
6-
import type { Option, Vec } from '@polkadot/types';
7-
import type { AccountId, BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces';
6+
import type { Option } from '@polkadot/types';
7+
import type { BalanceOf } from '@polkadot/types/interfaces';
8+
import type { PalletSocietyBid, PalletSocietyBidKind } from '@polkadot/types/lookup';
89
import type { ITuple } from '@polkadot/types/types';
910
import type { DeriveSocietyCandidate } from '../types';
1011

1112
import { combineLatest, map, of, switchMap } from 'rxjs';
1213

1314
import { memo } from '../util';
1415

15-
type ResultSuspend = Option<ITuple<[BalanceOf, BidKind]>>;
16-
type Result = [Bid[], ResultSuspend[]]
16+
type ResultSuspend = Option<ITuple<[BalanceOf, PalletSocietyBidKind]>>;
17+
type Result = [PalletSocietyBid[], ResultSuspend[]]
1718

1819
/**
1920
* @description Get the candidate info for a society
2021
*/
2122
export function candidates (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSocietyCandidate[]> {
2223
return memo(instanceId, (): Observable<DeriveSocietyCandidate[]> =>
23-
api.query.society.candidates<Vec<Bid>>().pipe(
24-
switchMap((candidates: Vec<Bid>): Observable<Result> =>
24+
api.query.society.candidates().pipe(
25+
switchMap((candidates): Observable<Result> =>
2526
combineLatest([
2627
of(candidates),
2728
api.query.society.suspendedCandidates.multi(
28-
candidates.map(({ who }): AccountId => who))
29+
candidates.map(({ who }) => who)
30+
)
2931
])
3032
),
3133
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>

0 commit comments

Comments
 (0)