1 |
|
2 |
|
3 |
|
4 | import { Json } from '@polkadot/types-codec';
|
5 | import { isFunction, isNull, isUndefined } from '@polkadot/util';
|
6 | function createValue(registry, type, value, asArray = true) {
|
7 |
|
8 | if (value && isFunction(value.unwrapOrDefault)) {
|
9 | return value;
|
10 | }
|
11 | return registry.createTypeUnsafe(type, [asArray ? isNull(value) || isUndefined(value) ? null : Array.isArray(value) ? value : [value] : value]);
|
12 | }
|
13 | function decodeValue(registry, key, value) {
|
14 | return key === 'ss58Format' ? createValue(registry, 'Option<u32>', value, false) : key === 'tokenDecimals' ? createValue(registry, 'Option<Vec<u32>>', value) : key === 'tokenSymbol' ? createValue(registry, 'Option<Vec<Text>>', value) : value;
|
15 | }
|
16 | function decode(registry, value) {
|
17 | return (
|
18 |
|
19 | value && isFunction(value.entries) ? [...value.entries()] : Object.entries(value || {})).reduce((all, [key, value]) => {
|
20 | all[key] = decodeValue(registry, key, value);
|
21 | return all;
|
22 | }, {
|
23 | ss58Format: registry.createTypeUnsafe('Option<u32>', []),
|
24 | tokenDecimals: registry.createTypeUnsafe('Option<Vec<u32>>', []),
|
25 | tokenSymbol: registry.createTypeUnsafe('Option<Vec<Text>>', [])
|
26 | });
|
27 | }
|
28 | export class GenericChainProperties extends Json {
|
29 | constructor(registry, value) {
|
30 | super(registry, decode(registry, value));
|
31 | }
|
32 |
|
33 | |
34 |
|
35 |
|
36 | get ss58Format() {
|
37 | return this.getT('ss58Format');
|
38 | }
|
39 |
|
40 | |
41 |
|
42 |
|
43 | get tokenDecimals() {
|
44 | return this.getT('tokenDecimals');
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 | get tokenSymbol() {
|
51 | return this.getT('tokenSymbol');
|
52 | }
|
53 | } |
\ | No newline at end of file |