Skip to content

Commit 851bbe4

Browse files
authored
Use assertReturn as applicable (#4393)
1 parent 0fec750 commit 851bbe4

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

packages/api/src/base/Decorate.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { getAvailableDerives } from '@polkadot/api-derive';
1919
import { memo, RpcCore } from '@polkadot/rpc-core';
2020
import { WsProvider } from '@polkadot/rpc-provider';
2121
import { expandMetadata, Metadata, TypeRegistry, unwrapStorageType } from '@polkadot/types';
22-
import { arrayChunk, arrayFlatten, assert, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, objectSpread, u8aToHex } from '@polkadot/util';
22+
import { arrayChunk, arrayFlatten, assert, assertReturn, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, objectSpread, u8aToHex } from '@polkadot/util';
2323

2424
import { createSubmittable } from '../submittable';
2525
import { augmentObject } from '../util/augmentObject';
@@ -50,9 +50,7 @@ const l = logger('api/init');
5050
let instanceCounter = 0;
5151

5252
function getAtQueryFn<ApiType extends ApiTypes> (api: ApiDecoration<ApiType>, { method, section }: StorageEntry): AugmentedQuery<'rxjs', GenericStorageEntryFunction, AnyTuple> {
53-
assert(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
54-
55-
return api.rx.query[section][method];
53+
return assertReturn(api.rx.query[section] && api.rx.query[section][method], () => `query.${section}.${method} is not available in this version of the metadata`);
5654
}
5755

5856
export abstract class Decorate<ApiType extends ApiTypes> extends Events {

packages/api/src/base/Init.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { firstValueFrom, map, of, switchMap } from 'rxjs';
1515

1616
import { Metadata, TypeRegistry } from '@polkadot/types';
1717
import { getSpecAlias, getSpecExtensions, getSpecHasher, getSpecRpc, getSpecTypes, getUpgradeVersion } from '@polkadot/types-known';
18-
import { assert, BN_ZERO, isUndefined, logger, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
18+
import { assert, assertReturn, BN_ZERO, isUndefined, logger, objectSpread, u8aEq, u8aToHex, u8aToU8a } from '@polkadot/util';
1919
import { cryptoWaitReady } from '@polkadot/util-crypto';
2020

2121
import { Decorate } from './Decorate';
@@ -102,12 +102,7 @@ export abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
102102
* @description Returns the default versioned registry
103103
*/
104104
private _getDefaultRegistry (): VersionedRegistry<ApiType> {
105-
// get the default registry version
106-
const thisRegistry = this.#registries.find(({ isDefault }) => isDefault);
107-
108-
assert(thisRegistry, 'Initialization error, cannot find the default registry');
109-
110-
return thisRegistry;
105+
return assertReturn(this.#registries.find(({ isDefault }) => isDefault), 'Initialization error, cannot find the default registry');
111106
}
112107

113108
/**

0 commit comments

Comments
 (0)