Resolve module location for endpoints if it exists (#10483)

* Council fix in endpoint for modules

* lint
This commit is contained in:
Tarik Gul 2024-04-18 09:36:57 -07:00 committed by GitHub
parent c4044ec5f0
commit 5f6cb557b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,11 +10,14 @@ type ApiMapper = Record<string, Record<string, Record<string, unknown>>>;
function hasEndpoint (api: ApiPromise, endpoint: string, needsApiInstances: boolean): boolean {
const [area, _section, method] = endpoint.split('.');
const [section] = (needsApiInstances && api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), _section)) || [_section];
const resolvedSection = (api as unknown as ApiMapper)[area][section]
? section
: _section;
try {
return area === 'consts'
? isObject((api as unknown as ApiMapper)[area][section][method])
: isFunction((api as unknown as ApiMapper)[area][section][method]);
? isObject((api as unknown as ApiMapper)[area][resolvedSection][method])
: isFunction((api as unknown as ApiMapper)[area][resolvedSection][method]);
} catch {
return false;
}