mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-12-03 10:07:11 +00:00
Rebrand: polkadot → pezkuwi, substrate → bizinikiwi, kusama → dicle
This commit is contained in:
commit
d5f038faea
1383 files changed
+1088018
No files matched your search
@@ -0,0 +1,35 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@pezkuwi/types/interfaces';
|
||||
import type { DeriveApi, DeriveCouncilVote } from '../types.js';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name votesOf
|
||||
* @description Retrieves the council votes associated with a given account.
|
||||
* @returns The stake and the list of candidates the account has voted for.
|
||||
* @param {string | Uint8Array | AccountId} accountId The accountId to retrieve votes for.
|
||||
* @example
|
||||
* ```javascript
|
||||
* const accountId = "5Gw3s7qQ9Z..."; // Replace with a valid account ID
|
||||
* const votes = await api.derive.council.votesOf(accountId);
|
||||
* console.log("Account votes:", votes);
|
||||
* ```
|
||||
*/
|
||||
export function votesOf (instanceId: string, api: DeriveApi): (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]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user