25 lines
934 B
TypeScript
25 lines
934 B
TypeScript
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
|
import type { AccountId } from '@polkadot/types/interfaces';
|
|
import type { Observable } from '@polkadot/x-rxjs';
|
|
import type { DeriveCouncilVote } from '../types';
|
|
|
|
import { map } from '@polkadot/x-rxjs/operators';
|
|
|
|
import { memo } from '../util';
|
|
|
|
export function votesOf (instanceId: string, api: ApiInterfaceRx): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
|
return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
|
api.derive.council.votes().pipe(
|
|
map((votes): DeriveCouncilVote =>
|
|
(
|
|
votes.find(([from]) => from.eq(accountId)) ||
|
|
[null, { stake: api.registry.createType('Balance'), votes: [] as AccountId[] }]
|
|
)[1]
|
|
)
|
|
)
|
|
);
|
|
}
|