Disable referenda app where no tracks are defined (#8821)

This commit is contained in:
Jaco 2023-01-16 09:20:54 +02:00 committed by GitHub
parent fbfb697410
commit ec90bd2898
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -13,7 +13,8 @@ export default function create (t: TFunction): Route {
needsAccounts: true,
needsApi: [
'tx.fellowshipCollective.vote',
'tx.fellowshipReferenda.submit'
'tx.fellowshipReferenda.submit',
'consts.fellowshipReferenda.tracks'
]
},
group: 'governance',

View File

@ -12,7 +12,8 @@ export default function create (t: TFunction): Route {
display: {
needsApi: [
'tx.referenda.submit',
'tx.convictionVoting.vote'
'tx.convictionVoting.vote',
'consts.referenda.tracks'
]
},
group: 'governance',

View File

@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
import { ApiPromise } from '@polkadot/api';
import { isFunction } from '@polkadot/util';
import { isFunction, isObject } from '@polkadot/util';
type ApiMapper = Record<string, Record<string, Record<string, unknown>>>;
@ -11,7 +11,9 @@ function hasEndpoint (api: ApiPromise, endpoint: string, needsApiInstances: bool
const [section] = (needsApiInstances && api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), _section)) || [_section];
try {
return isFunction((api as unknown as ApiMapper)[area][section][method]);
return area === 'consts'
? isObject((api as unknown as ApiMapper)[area][section][method])
: isFunction((api as unknown as ApiMapper)[area][section][method]);
} catch (error) {
return false;
}