* Prototype static init Enum/Set/Struct * Adjust (similar, logic extracted - further local testing) * Adjust with latest util (no prototype atm) * Introduce prototype assignment * Old Enum tests * Fix toCallsOnly spread * Adjust * Use objectSpread in derives (decorated objects only) * Adjust * Remove extra map from bag get * Additional spreads * Signer spread * Formatting * typo * Adjust spreads for session * Additional spread * Adjust spread * Formatting * CHANGELOG * Adjust * slice * CHANGELOG
32 lines
992 B
TypeScript
32 lines
992 B
TypeScript
// Copyright 2017-2022 @polkadot/api-derive authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import type { Observable } from 'rxjs';
|
|
import type { BN } from '@polkadot/util';
|
|
import type { DeriveApi } from '../types';
|
|
import type { Bag, BagExpanded } from './types';
|
|
|
|
import { map, switchMap } from 'rxjs';
|
|
|
|
import { objectSpread } from '@polkadot/util';
|
|
|
|
import { memo } from '../util';
|
|
|
|
export function expand (instanceId: string, api: DeriveApi): (bag: Bag) => Observable<BagExpanded> {
|
|
return memo(instanceId, (bag: Bag): Observable<BagExpanded> =>
|
|
api.derive.bagsList.listNodes(bag.bag).pipe(
|
|
map((nodes) => objectSpread({ nodes }, bag))
|
|
)
|
|
);
|
|
}
|
|
|
|
export function getExpanded (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<BagExpanded> {
|
|
return memo(instanceId, (id: BN | number): Observable<BagExpanded> =>
|
|
api.derive.bagsList.get(id).pipe(
|
|
switchMap((bag) =>
|
|
api.derive.bagsList.expand(bag)
|
|
)
|
|
)
|
|
);
|
|
}
|