Add bagList expand(bag: Bag) (#4731)

This commit is contained in:
Jaco
2022-04-09 12:17:58 +03:00
committed by GitHub
parent d5aff171e4
commit 7af9330026
@@ -4,19 +4,25 @@
import type { Observable } from 'rxjs';
import type { BN } from '@polkadot/util';
import type { DeriveApi } from '../types';
import type { Bag } from './types';
import type { Bag, BagExpanded } from './types';
import { map, switchMap } from 'rxjs';
import { memo } from '../util';
export function getExpanded (instanceId: string, api: DeriveApi): (id: BN | number) => Observable<Bag> {
return memo(instanceId, (id: BN | number): Observable<Bag> =>
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) => ({ ...bag, nodes }))
)
);
}
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((base) =>
api.derive.bagsList.listNodes(base.bag).pipe(
map((nodes) => ({ ...base, nodes }))
)
switchMap((bag) =>
api.derive.bagsList.expand(bag)
)
)
);