Add chainProperties call to api-observable (#472)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { defaultIfEmpty, map } from 'rxjs/operators';
|
||||
import { BlockNumber, Extrinsic, ExtrinsicStatus, Hash, Header, SignedBlock } from '@polkadot/types/index';
|
||||
import { BlockNumber, ChainProperties, Extrinsic, ExtrinsicStatus, Hash, Header, SignedBlock } from '@polkadot/types/index';
|
||||
|
||||
import ApiQueries from './Queries';
|
||||
|
||||
@@ -26,6 +26,18 @@ export default class ApiCalls extends ApiQueries {
|
||||
return this._api.system.chain();
|
||||
}
|
||||
|
||||
chainProperties = (): Observable<ChainProperties> => {
|
||||
return this._api.system
|
||||
.properties()
|
||||
.pipe(
|
||||
map((properties?: ChainProperties | null): ChainProperties =>
|
||||
properties
|
||||
? properties
|
||||
: new ChainProperties()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
getBlock = (hash: Uint8Array): Observable<SignedBlock | undefined> => {
|
||||
return this._api.chain.getBlock(hash);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2018 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import ChainProperties from './ChainProperties';
|
||||
|
||||
describe('ChainProperties', () => {
|
||||
it('decodes from a null value', () => {
|
||||
expect(
|
||||
[...new ChainProperties(null).entries()]
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('decodes from an actual object', () => {
|
||||
expect(
|
||||
[...new ChainProperties({
|
||||
decimals: 15,
|
||||
tokenSymbol: 'BBQ'
|
||||
}).entries()]
|
||||
).toEqual([['decimals', 15], ['tokenSymbol', 'BBQ']]);
|
||||
});
|
||||
});
|
||||
@@ -15,14 +15,12 @@ import { Codec } from './types';
|
||||
* @noInheritDoc
|
||||
*/
|
||||
export default class ChainProperties extends Map<string, any> implements Codec {
|
||||
constructor (value: { [index: string]: any } = {}) {
|
||||
constructor (value?: { [index: string]: any } | null) {
|
||||
super(ChainProperties.decodeChainProperties(value));
|
||||
}
|
||||
|
||||
private static decodeChainProperties (value: { [index: string]: any }): Array<[string, any]> {
|
||||
return Object.keys(value).map((key) => ([
|
||||
key, value[key]
|
||||
] as [string, any]));
|
||||
private static decodeChainProperties (value?: { [index: string]: any } | null): Array<[string, any]> {
|
||||
return Object.entries(value || {});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user