packages/api-derive/src/balances/votingBalances.ts
// Copyright 2017-2024 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import type { DeriveApi, DeriveBalancesAccount } from '../types.js';
import { combineLatest, of } from 'rxjs';
import { memo } from '../util/index.js';
export function votingBalances (instanceId: string, api: DeriveApi): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
return memo(instanceId, (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DeriveBalancesAccount[]> =>
!addresses?.length
? of([] as DeriveBalancesAccount[])
: combineLatest(
addresses.map((accountId): Observable<DeriveBalancesAccount> =>
api.derive.balances.account(accountId)
)
)
);
}