Use assertReturn as applicable (#4393)
This commit is contained in:
@@ -19,7 +19,7 @@ import { getAvailableDerives } from '@polkadot/api-derive';
|
||||
import { memo, RpcCore } from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { expandMetadata, Metadata, TypeRegistry, unwrapStorageType } from '@polkadot/types';
|
||||
import { arrayChunk, arrayFlatten, assert, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, objectSpread, u8aToHex } from '@polkadot/util';
|
||||
import { arrayChunk, arrayFlatten, assert, assertReturn, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, objectSpread, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { augmentObject } from '../util/augmentObject';
|
||||
@@ -50,9 +50,7 @@ const l = logger('api/init');
|
||||
let instanceCounter = 0;
|
||||
|
||||
function getAtQueryFn<ApiType extends ApiTypes> (api: ApiDecoration<ApiType>, { method, section }: StorageEntry): AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> {
|
||||
assert(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
|
||||
|
||||
return api.rx.query[section][method];
|
||||
return assertReturn(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
|
||||
}
|
||||
|
||||
export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { firstValueFrom, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { Metadata, TypeRegistry } from '@polkadot/types';
|
||||
import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
|
||||
import { assert, BN_ZERO, isUndefined, logger, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, assertReturn, BN_ZERO, isUndefined, logger, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
import { Decorate } from './Decorate';
|
||||
@@ -102,12 +102,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
||||
* @description Returns the default versioned registry
|
||||
*/
|
||||
private _getDefaultRegistry (): VersionedRegistry<ApiType> {
|
||||
// get the default registry version
|
||||
const thisRegistry = this.#registries.find(({ isDefault }) => isDefault);
|
||||
|
||||
assert(thisRegistry, 'Initialization error, cannot find the default registry');
|
||||
|
||||
return thisRegistry;
|
||||
return assertReturn(this.#registries.find(({ isDefault }) => isDefault), 'Initialization error, cannot find the default registry');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user