unwrapOr(undefined) for subs

This commit is contained in:
Jaco Greeff
2020-03-08 13:20:05 +01:00
parent e55f69a009
commit abebe9ef43
+5 -4
View File
@@ -17,7 +17,7 @@ import DecoratedMeta from '@polkadot/metadata/Decorated';
import getHasher from '@polkadot/metadata/Decorated/storage/fromMetadata/getHasher';
import RpcCore from '@polkadot/rpc-core';
import { WsProvider } from '@polkadot/rpc-provider';
import { Metadata, Null, Option, Text, TypeRegistry, u64 } from '@polkadot/types';
import { Metadata, Null, Option, Raw, Text, TypeRegistry, u64 } from '@polkadot/types';
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
import StorageKey, { StorageEntry, unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
@@ -452,16 +452,17 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
))
)
.pipe(
switchMap((keys): Observable<[StorageKey[], Option<Codec>[]]> =>
switchMap((keys): Observable<[StorageKey[], Option<Raw>[]]> =>
combineLatest([
of(keys.map((key) => key.decodeArgsFromMeta(meta))),
this._rpcCore.state.subscribeStorage<Option<Codec>[]>(keys)
// since we have a default constructed key, we have Option<Raw> as the result
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keys)
])
),
map(([keys, values]): [StorageKey, Codec][] =>
keys.map((key, index): [StorageKey, Codec] => [
key,
this.createType(outputType, values[index].unwrapOrDefault())
this.createType(outputType, values[index].unwrapOr(undefined))
])
)
);