Adjust API check order, ensure deposit is defaultValue (#7465)

This commit is contained in:
Jaco 2022-04-27 07:45:58 +02:00 committed by GitHub
parent 601f8787a5
commit fb3e35118e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 10 deletions

View File

@ -21,13 +21,22 @@ function needsApiCheck (api: ApiPromise): boolean {
);
assert(total.eq(BN_ONE) && own.eq(BN_ONE) && who.eq(TEST_ADDR) && value.eq(BN_ONE), 'Needs a known Exposure type');
return true;
} catch (error) {
console.warn('Unable to create PalletStakingIndividualExposure type, disabling staking route');
} catch {
console.warn('Unable to create known-shape Exposure type, disabling staking route');
return false;
}
try {
// we need to be able to bond
api.tx.staking.bond(TEST_ADDR, BN_ONE, { Account: TEST_ADDR });
} catch {
console.warn('Unable to create staking bond transaction, disabling staking route');
return false;
}
return true;
}
export default function create (t: TFunction): Route {
@ -35,7 +44,8 @@ export default function create (t: TFunction): Route {
Component,
display: {
needsApi: [
['tx.staking.bond']
'query.staking.erasStakers',
'tx.staking.bond'
],
needsApiCheck
},

View File

@ -18,17 +18,21 @@ function hasEndpoint (api: ApiPromise, endpoint: string, needsApiInstances: bool
}
export function findMissingApis (api: ApiPromise, needsApi?: (string | string[])[], needsApiInstances = false, needsApiCheck?: (api: ApiPromise) => boolean): (string | string[])[] {
if (needsApiCheck && !needsApiCheck(api)) {
return ['needsApiCheck'];
} else if (!needsApi) {
if (!needsApi) {
return [];
}
return needsApi.filter((endpoint: string | string[]): boolean => {
const missing = needsApi.filter((endpoint: string | string[]): boolean => {
const hasApi = Array.isArray(endpoint)
? endpoint.reduce((hasApi, endpoint) => hasApi || hasEndpoint(api, endpoint, needsApiInstances), false)
: hasEndpoint(api, endpoint, needsApiInstances);
return !hasApi;
});
if (!missing.length && needsApiCheck && !needsApiCheck(api)) {
return ['needsApiCheck'];
}
return missing;
}

View File

@ -57,9 +57,9 @@ function Seconding ({ deposit, depositors, image, proposalId }: Props): React.Re
</Modal.Columns>
<Modal.Columns hint={t<string>('The deposit will be locked for the lifetime of the proposal.')}>
<InputBalance
defaultValue={deposit || api.consts.democracy.minimumDeposit}
isDisabled
label={t<string>('deposit required')}
value={deposit || api.consts.democracy.minimumDeposit}
/>
</Modal.Columns>
</Modal.Content>