Provide fallback for tx defaults (Extrinsic, Proposal) (#576)
This commit is contained in:
parent
274c9f32cc
commit
312f57f302
@ -14,12 +14,19 @@ type Props = ApiProps & BaseProps;
|
||||
|
||||
class Call extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { apiPromise, className, isDisabled, isError, label, onChange, style, withLabel } = this.props;
|
||||
const { apiDefaultTx, apiPromise, className, isDisabled, isError, label, onChange, style, withLabel } = this.props;
|
||||
const defaultValue = (() => {
|
||||
try {
|
||||
return apiPromise.tx.balances.transfer;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<Extrinsic
|
||||
className={className}
|
||||
defaultValue={apiPromise.tx.balances.transfer}
|
||||
defaultValue={defaultValue}
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
isPrivate={false}
|
||||
|
||||
@ -39,7 +39,7 @@ class ExtrinsicDisplay extends React.PureComponent<Props> {
|
||||
label
|
||||
}
|
||||
})}
|
||||
labelSection={t('proposal.method', {
|
||||
labelSection={t('proposal.section', {
|
||||
defaultValue: '{{label}} (section)',
|
||||
replace: {
|
||||
label
|
||||
|
||||
@ -15,12 +15,19 @@ type Props = ApiProps & BaseProps;
|
||||
|
||||
class ProposalDisplay extends React.PureComponent<Props> {
|
||||
render () {
|
||||
const { apiPromise, className, isDisabled, isError, label, style, withLabel } = this.props;
|
||||
const { apiDefaultTx, apiPromise, className, isDisabled, isError, label, style, withLabel } = this.props;
|
||||
const defaultValue = (() => {
|
||||
try {
|
||||
return apiPromise.tx.consensus.setCode;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<ExtrinsicDisplay
|
||||
className={className}
|
||||
defaultValue={apiPromise.tx.consensus.setCode}
|
||||
defaultValue={defaultValue}
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
isPrivate
|
||||
|
||||
@ -36,8 +36,15 @@ class Selection extends React.PureComponent<Props, State> {
|
||||
} as State;
|
||||
|
||||
render () {
|
||||
const { apiPromise, t } = this.props;
|
||||
const { apiDefaultTx, apiPromise, t } = this.props;
|
||||
const { isValid, accountId } = this.state;
|
||||
const defaultExtrinsic = (() => {
|
||||
try {
|
||||
return apiPromise.tx.balances.transfer;
|
||||
} catch (error) {
|
||||
return apiDefaultTx;
|
||||
}
|
||||
})();
|
||||
|
||||
return (
|
||||
<div className='extrinsics--Selection'>
|
||||
@ -50,7 +57,7 @@ class Selection extends React.PureComponent<Props, State> {
|
||||
type='account'
|
||||
/>
|
||||
<ExtrinsicDisplay
|
||||
defaultValue={apiPromise.tx.balances.transfer}
|
||||
defaultValue={defaultExtrinsic}
|
||||
labelMethod={t('display.method', {
|
||||
defaultValue: 'submit the following extrinsic'
|
||||
})}
|
||||
|
||||
@ -50,7 +50,7 @@ export default class ApiWrapper extends React.PureComponent<Props, State> {
|
||||
isApiReady: false,
|
||||
apiPromise: new ApiPromise(provider),
|
||||
setApiUrl
|
||||
};
|
||||
} as State;
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@ -116,16 +116,23 @@ export default class ApiWrapper extends React.PureComponent<Props, State> {
|
||||
|
||||
private subscribeIsReady = (api: ApiPromise) => {
|
||||
api.on('ready', () => {
|
||||
this.setState({ isApiReady: true });
|
||||
const section = Object.keys(api.tx)[0];
|
||||
const method = Object.keys(api.tx[section])[0];
|
||||
|
||||
this.setState({
|
||||
isApiReady: true,
|
||||
apiDefaultTx: api.tx[section][method]
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
const { apiPromise, chain, isApiConnected, isApiReady, setApiUrl } = this.state;
|
||||
const { apiDefaultTx, apiPromise, chain, isApiConnected, isApiReady, setApiUrl } = this.state;
|
||||
|
||||
return (
|
||||
<ApiContext.Provider
|
||||
value={{
|
||||
apiDefaultTx,
|
||||
apiPromise,
|
||||
isApiConnected,
|
||||
isApiReady: isApiReady && !!chain,
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types';
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
|
||||
export type BareProps = {
|
||||
@ -12,6 +13,7 @@ export type BareProps = {
|
||||
export type ApiProps = {
|
||||
isApiConnected: boolean,
|
||||
isApiReady: boolean,
|
||||
apiDefaultTx: SubmittableExtrinsicFunction,
|
||||
apiPromise: ApiPromise,
|
||||
setApiUrl: (url?: string) => void
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user