Default proposal/sudo for new 2.x substrate (#1296)
This commit is contained in:
parent
fe9d5c3233
commit
957e210043
@ -35,18 +35,10 @@ class Propose extends TxComponent<Props, State> {
|
||||
};
|
||||
|
||||
render () {
|
||||
const { api, apiDefaultTx, t } = this.props;
|
||||
const { apiDefaultTxSudo, t } = this.props;
|
||||
const { isValid, accountId, method, value } = this.state;
|
||||
const hasValue = !!value && value.gtn(0);
|
||||
|
||||
const defaultExtrinsic = (() => {
|
||||
try {
|
||||
return api.tx.consensus.setCode;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<section>
|
||||
<InputAddress
|
||||
@ -57,7 +49,7 @@ class Propose extends TxComponent<Props, State> {
|
||||
onChange={this.onChangeAccount}
|
||||
/>
|
||||
<Extrinsic
|
||||
defaultValue={defaultExtrinsic}
|
||||
defaultValue={apiDefaultTxSudo}
|
||||
label={t('propose')}
|
||||
onChange={this.onChangeExtrinsic}
|
||||
onEnter={this.sendTx}
|
||||
|
||||
@ -36,16 +36,9 @@ class Selection extends TxComponent<Props, State> {
|
||||
} as State;
|
||||
|
||||
render () {
|
||||
const { apiDefaultTx, api, t } = this.props;
|
||||
const { apiDefaultTxSudo, t } = this.props;
|
||||
const { isValid, isValidUnsigned, accountId } = this.state;
|
||||
const defaultExtrinsic = (() => {
|
||||
try {
|
||||
return api.tx.balances.transfer;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
const extrinsic = this.getExtrinsic() || defaultExtrinsic;
|
||||
const extrinsic = this.getExtrinsic() || apiDefaultTxSudo;
|
||||
|
||||
return (
|
||||
<div className='extrinsics--Selection'>
|
||||
@ -73,7 +66,7 @@ class Selection extends TxComponent<Props, State> {
|
||||
</div>
|
||||
<br></br>
|
||||
<Extrinsic
|
||||
defaultValue={defaultExtrinsic}
|
||||
defaultValue={apiDefaultTxSudo}
|
||||
label={t('submit the following extrinsic')}
|
||||
onChange={this.onChangeExtrinsic}
|
||||
onEnter={this.sendTx}
|
||||
|
||||
@ -29,21 +29,13 @@ class Propose extends TxComponent<Props, State> {
|
||||
};
|
||||
|
||||
render () {
|
||||
const { api, apiDefaultTx, isMine, sudoKey, t } = this.props;
|
||||
const { apiDefaultTxSudo, isMine, sudoKey, t } = this.props;
|
||||
const { method, isValid } = this.state;
|
||||
|
||||
const defaultExtrinsic = (() => {
|
||||
try {
|
||||
return api.tx.consensus.setCode;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
|
||||
return isMine ? (
|
||||
<section>
|
||||
<Extrinsic
|
||||
defaultValue={defaultExtrinsic}
|
||||
defaultValue={apiDefaultTxSudo}
|
||||
label={t('submit the following change')}
|
||||
onChange={this.onChangeExtrinsic}
|
||||
onEnter={this.sendTx}
|
||||
|
||||
@ -100,8 +100,6 @@ export default class Api extends React.PureComponent<Props, State> {
|
||||
api.rpc.system.properties<ChainProperties>(),
|
||||
api.rpc.system.chain<Text>()
|
||||
]);
|
||||
const section = Object.keys(api.tx)[0];
|
||||
const method = Object.keys(api.tx[section])[0];
|
||||
const chain = value
|
||||
? value.toString()
|
||||
: null;
|
||||
@ -133,22 +131,32 @@ export default class Api extends React.PureComponent<Props, State> {
|
||||
type: 'ed25519'
|
||||
}, injectedAccounts);
|
||||
|
||||
const section = Object.keys(api.tx)[0];
|
||||
const method = Object.keys(api.tx[section])[0];
|
||||
const apiDefaultTx = api.tx[section][method];
|
||||
const apiDefaultTxSudo =
|
||||
(api.tx.system && api.tx.system.setCode) || // 2.x
|
||||
(api.tx.consensus && api.tx.consensus.setCode) || // 1.x
|
||||
apiDefaultTx; // other
|
||||
|
||||
this.setState({
|
||||
isApiReady: true,
|
||||
apiDefaultTx: api.tx[section][method],
|
||||
apiDefaultTx,
|
||||
apiDefaultTxSudo,
|
||||
chain,
|
||||
isDevelopment
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
const { api, apiDefaultTx, chain, isApiConnected, isApiReady, isDevelopment, isWaitingInjected, setApiUrl } = this.state;
|
||||
const { api, apiDefaultTx, apiDefaultTxSudo, chain, isApiConnected, isApiReady, isDevelopment, isWaitingInjected, setApiUrl } = this.state;
|
||||
|
||||
return (
|
||||
<ApiContext.Provider
|
||||
value={{
|
||||
api,
|
||||
apiDefaultTx,
|
||||
apiDefaultTxSudo,
|
||||
currentChain: chain || '<unknown>',
|
||||
isApiConnected,
|
||||
isApiReady: isApiReady && !!chain,
|
||||
|
||||
@ -18,6 +18,7 @@ export type BareProps = {
|
||||
export type ApiProps = {
|
||||
api: ApiPromise,
|
||||
apiDefaultTx: SubmittableExtrinsicFunction,
|
||||
apiDefaultTxSudo: SubmittableExtrinsicFunction,
|
||||
currentChain: string,
|
||||
isApiConnected: boolean,
|
||||
isApiReady: boolean,
|
||||
|
||||
@ -15,19 +15,12 @@ type Props = ApiProps & BaseProps;
|
||||
|
||||
class ProposalDisplay extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { apiDefaultTx, api, className, isDisabled, isError, label, onEnter, style, withLabel } = this.props;
|
||||
const defaultValue = (() => {
|
||||
try {
|
||||
return api.tx.consensus.setCode;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
const { apiDefaultTxSudo, className, isDisabled, isError, label, onEnter, style, withLabel } = this.props;
|
||||
|
||||
return (
|
||||
<ExtrinsicDisplay
|
||||
className={className}
|
||||
defaultValue={defaultValue}
|
||||
defaultValue={apiDefaultTxSudo}
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
isPrivate
|
||||
|
||||
Loading…
Reference in New Issue
Block a user