Cleanup api-observable Vector FIXMEs (#410)
* Cleanup api-observable Vector FIXMEs * Simplify rawStorage * Fix linting * Bump deps
This commit is contained in:
@@ -13,11 +13,10 @@ import extrinsicsFromMeta from '@polkadot/extrinsics/fromMetadata';
|
||||
import extrinsicsStatic from '@polkadot/extrinsics/static';
|
||||
import storageFromMeta from '@polkadot/storage/fromMetadata';
|
||||
import storageStatic from '@polkadot/storage/static';
|
||||
import { Vector } from '@polkadot/types/codec';
|
||||
import { Hash, Method } from '@polkadot/types/index';
|
||||
import Event from '@polkadot/types/Event';
|
||||
import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
import { assert, isUndefined, isU8a } from '@polkadot/util';
|
||||
import { assert, isU8a } from '@polkadot/util';
|
||||
|
||||
type MapFn<R, T> = (combined: R) => T;
|
||||
|
||||
@@ -115,9 +114,7 @@ export default class ApiBase {
|
||||
)
|
||||
.pipe(
|
||||
map((result: Array<T>): T | undefined =>
|
||||
result
|
||||
? result[0]
|
||||
: undefined
|
||||
result[0]
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -134,11 +131,8 @@ export default class ApiBase {
|
||||
|
||||
return observable.pipe(
|
||||
defaultIfEmpty(),
|
||||
map((result?: Vector<any>): T =>
|
||||
isUndefined(result)
|
||||
? [] as T
|
||||
// FIXME When Vector extends Array, this mapping can be removed
|
||||
: result.map((item: any) => item) as T
|
||||
map((result?: Array<any>): T =>
|
||||
(result || []) as T
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,8 +14,6 @@ import { Tuple } from '@polkadot/types/codec';
|
||||
import ApiBase from './Base';
|
||||
import { RxProposal, RxProposalDeposits, RxReferendum } from './classes';
|
||||
|
||||
// FIXME Revert Vector -> Array mappings in here once https://github.com/polkadot-js/api/pull/172 is in
|
||||
|
||||
// Perform storage queries to the API endpoints.
|
||||
export default class ApiQueries extends ApiBase {
|
||||
accountNonce = (address: AccountId | string): Observable<Index | undefined> => {
|
||||
@@ -52,10 +50,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((accounts: Array<AccountId> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(accounts || ([] as Array<AccountId>)).map((accountId) =>
|
||||
accountId
|
||||
)
|
||||
accounts || ([] as Array<AccountId>)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -83,7 +78,6 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((proposals: Array<Tuple> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(proposals || ([] as Array<Tuple>))
|
||||
.map((result: Tuple): RxProposal | undefined =>
|
||||
result
|
||||
@@ -124,10 +118,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((voters: Array<AccountId> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(voters || ([] as Array<AccountId>)).map((accountId) =>
|
||||
accountId
|
||||
)
|
||||
voters || ([] as Array<AccountId>)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -195,10 +186,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((validators: Array<AccountId> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(validators || ([] as Array<AccountId>)).map((authorityId) =>
|
||||
authorityId
|
||||
)
|
||||
validators || ([] as Array<AccountId>)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -209,10 +197,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((intentions: Array<AccountId> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(intentions || ([] as Array<AccountId>)).map((accountId) =>
|
||||
accountId
|
||||
)
|
||||
intentions || ([] as Array<AccountId>)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -223,10 +208,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((nominators: Array<AccountId> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(nominators || ([] as Array<AccountId>)).map((accountId) =>
|
||||
accountId
|
||||
)
|
||||
nominators || ([] as Array<AccountId>)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -241,10 +223,7 @@ export default class ApiQueries extends ApiBase {
|
||||
.pipe(
|
||||
// @ts-ignore After upgrade to 6.3.2
|
||||
map((events: Array<EventRecord> | null | undefined) =>
|
||||
// FIXME not really a Array here, it is a Vector (easier to match, to be fixed in extending Array)
|
||||
(events || ([] as Array<EventRecord>)).map((event) =>
|
||||
event
|
||||
)
|
||||
events || ([] as Array<EventRecord>)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,6 @@
|
||||
"@polkadot/jsonrpc": "^0.32.2",
|
||||
"@polkadot/rpc-provider": "^0.32.2",
|
||||
"@polkadot/types": "^0.32.2",
|
||||
"@polkadot/util": "^0.32.23"
|
||||
"@polkadot/util": "^0.33.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.1.5",
|
||||
"@polkadot/keyring": "^0.32.23",
|
||||
"@polkadot/keyring": "^0.33.1",
|
||||
"@polkadot/storage": "^0.32.2",
|
||||
"@polkadot/util": "^0.32.23",
|
||||
"@polkadot/util-crypto": "^0.32.23",
|
||||
"@polkadot/util": "^0.33.1",
|
||||
"@polkadot/util-crypto": "^0.33.1",
|
||||
"@types/nock": "^9.3.0",
|
||||
"eventemitter3": "^3.1.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
|
||||
@@ -12,6 +12,6 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.1.5",
|
||||
"@polkadot/types": "^0.32.2",
|
||||
"@polkadot/util": "^0.32.23"
|
||||
"@polkadot/util": "^0.33.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.1.5",
|
||||
"@polkadot/keyring": "^0.32.23",
|
||||
"@polkadot/keyring": "^0.33.1",
|
||||
"@polkadot/types": "^0.32.2",
|
||||
"@polkadot/util": "^0.32.23",
|
||||
"@polkadot/util-crypto": "^0.32.23"
|
||||
"@polkadot/util": "^0.33.1",
|
||||
"@polkadot/util-crypto": "^0.33.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.1.5",
|
||||
"@polkadot/keyring": "^0.32.23",
|
||||
"@polkadot/util": "^0.32.23"
|
||||
"@polkadot/keyring": "^0.33.1",
|
||||
"@polkadot/util": "^0.33.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user