Merge pull request #3476 from ethcore/ng-signer-reject
Handle Signer Rejection
This commit is contained in:
commit
a9f017648a
@ -122,6 +122,7 @@
|
|||||||
"brace": "^0.9.0",
|
"brace": "^0.9.0",
|
||||||
"bytes": "^2.4.0",
|
"bytes": "^2.4.0",
|
||||||
"chart.js": "^2.3.0",
|
"chart.js": "^2.3.0",
|
||||||
|
"es6-error": "^4.0.0",
|
||||||
"es6-promise": "^3.2.1",
|
"es6-promise": "^3.2.1",
|
||||||
"ethereumjs-tx": "^1.1.2",
|
"ethereumjs-tx": "^1.1.2",
|
||||||
"file-saver": "^1.3.3",
|
"file-saver": "^1.3.3",
|
||||||
|
53
js/src/api/transport/error.js
Normal file
53
js/src/api/transport/error.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||||
|
// This file is part of Parity.
|
||||||
|
|
||||||
|
// Parity is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Parity is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import ExtendableError from 'es6-error';
|
||||||
|
|
||||||
|
export const ERROR_CODES = {
|
||||||
|
UNSUPPORTED_REQUEST: -32000,
|
||||||
|
NO_WORK: -32001,
|
||||||
|
NO_AUTHOR: -32002,
|
||||||
|
NO_NEW_WORK: -32003,
|
||||||
|
NOT_ENOUGH_DATA: -32006,
|
||||||
|
UNKNOWN_ERROR: -32009,
|
||||||
|
TRANSACTION_ERROR: -32010,
|
||||||
|
EXECUTION_ERROR: -32015,
|
||||||
|
ACCOUNT_LOCKED: -32020,
|
||||||
|
PASSWORD_INVALID: -32021,
|
||||||
|
ACCOUNT_ERROR: -32023,
|
||||||
|
SIGNER_DISABLED: -32030,
|
||||||
|
DAPPS_DISABLED: -32031,
|
||||||
|
NETWORK_DISABLED: -32035,
|
||||||
|
REQUEST_REJECTED: -32040,
|
||||||
|
REQUEST_REJECTED_LIMIT: -32041,
|
||||||
|
REQUEST_NOT_FOUND: -32042,
|
||||||
|
COMPILATION_ERROR: -32050,
|
||||||
|
ENCRYPTION_ERROR: -32055,
|
||||||
|
FETCH_ERROR: -32060
|
||||||
|
};
|
||||||
|
|
||||||
|
export default class TransportError extends ExtendableError {
|
||||||
|
constructor (method, code, message) {
|
||||||
|
const m = `${method}: ${code}: ${message}`;
|
||||||
|
super(m);
|
||||||
|
|
||||||
|
this.code = code;
|
||||||
|
this.type = Object.keys(ERROR_CODES).find((k) => ERROR_CODES[k] === code) || '';
|
||||||
|
|
||||||
|
this.method = method;
|
||||||
|
this.text = message;
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import { Logging } from '../../subscriptions';
|
import { Logging } from '../../subscriptions';
|
||||||
import JsonRpcBase from '../jsonRpcBase';
|
import JsonRpcBase from '../jsonRpcBase';
|
||||||
|
import TransportError from '../error';
|
||||||
|
|
||||||
/* global fetch */
|
/* global fetch */
|
||||||
export default class Http extends JsonRpcBase {
|
export default class Http extends JsonRpcBase {
|
||||||
@ -73,7 +74,8 @@ export default class Http extends JsonRpcBase {
|
|||||||
this.error(JSON.stringify(response));
|
this.error(JSON.stringify(response));
|
||||||
console.error(`${method}(${JSON.stringify(params)}): ${response.error.code}: ${response.error.message}`);
|
console.error(`${method}(${JSON.stringify(params)}): ${response.error.code}: ${response.error.message}`);
|
||||||
|
|
||||||
throw new Error(`${method}: ${response.error.code}: ${response.error.message}`);
|
const error = new TransportError(method, response.error.code, response.error.message);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log(JSON.stringify(response));
|
this.log(JSON.stringify(response));
|
||||||
|
@ -16,3 +16,4 @@
|
|||||||
|
|
||||||
export Http from './http';
|
export Http from './http';
|
||||||
export Ws from './ws';
|
export Ws from './ws';
|
||||||
|
export TransportError from './error.js';
|
||||||
|
@ -18,6 +18,7 @@ import { keccak_256 } from 'js-sha3'; // eslint-disable-line camelcase
|
|||||||
|
|
||||||
import { Logging } from '../../subscriptions';
|
import { Logging } from '../../subscriptions';
|
||||||
import JsonRpcBase from '../jsonRpcBase';
|
import JsonRpcBase from '../jsonRpcBase';
|
||||||
|
import TransportError from '../error';
|
||||||
|
|
||||||
/* global WebSocket */
|
/* global WebSocket */
|
||||||
export default class Ws extends JsonRpcBase {
|
export default class Ws extends JsonRpcBase {
|
||||||
@ -109,7 +110,9 @@ export default class Ws extends JsonRpcBase {
|
|||||||
|
|
||||||
console.error(`${method}(${JSON.stringify(params)}): ${result.error.code}: ${result.error.message}`);
|
console.error(`${method}(${JSON.stringify(params)}): ${result.error.code}: ${result.error.message}`);
|
||||||
|
|
||||||
reject(new Error(`${method}: ${result.error.code}: ${result.error.message}`));
|
const error = new TransportError(method, result.error.code, result.error.message);
|
||||||
|
reject(error);
|
||||||
|
|
||||||
delete this._messages[result.id];
|
delete this._messages[result.id];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ import ErrorStep from './ErrorStep';
|
|||||||
|
|
||||||
import styles from './deployContract.css';
|
import styles from './deployContract.css';
|
||||||
|
|
||||||
|
import { ERROR_CODES } from '../../api/transport/error';
|
||||||
|
|
||||||
const steps = ['contract details', 'deployment', 'completed'];
|
const steps = ['contract details', 'deployment', 'completed'];
|
||||||
|
|
||||||
export default class DeployContract extends Component {
|
export default class DeployContract extends Component {
|
||||||
@ -63,7 +65,8 @@ export default class DeployContract extends Component {
|
|||||||
params: [],
|
params: [],
|
||||||
paramsError: [],
|
paramsError: [],
|
||||||
step: 0,
|
step: 0,
|
||||||
deployError: null
|
deployError: null,
|
||||||
|
rejected: false
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount () {
|
componentWillMount () {
|
||||||
@ -92,15 +95,20 @@ export default class DeployContract extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { step, deployError } = this.state;
|
const { step, deployError, rejected } = this.state;
|
||||||
|
|
||||||
|
const realSteps = deployError || rejected ? null : steps;
|
||||||
|
const title = realSteps
|
||||||
|
? null
|
||||||
|
: (deployError ? 'deployment failed' : 'rejected');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
actions={ this.renderDialogActions() }
|
actions={ this.renderDialogActions() }
|
||||||
current={ step }
|
current={ step }
|
||||||
steps={ deployError ? null : steps }
|
steps={ realSteps }
|
||||||
title={ deployError ? 'deployment failed' : null }
|
title={ title }
|
||||||
waiting={ [1] }
|
waiting={ realSteps ? [1] : null }
|
||||||
visible
|
visible
|
||||||
scroll>
|
scroll>
|
||||||
{ this.renderStep() }
|
{ this.renderStep() }
|
||||||
@ -158,7 +166,7 @@ export default class DeployContract extends Component {
|
|||||||
|
|
||||||
renderStep () {
|
renderStep () {
|
||||||
const { accounts, readOnly } = this.props;
|
const { accounts, readOnly } = this.props;
|
||||||
const { address, deployError, step, deployState, txhash } = this.state;
|
const { address, deployError, step, deployState, txhash, rejected } = this.state;
|
||||||
|
|
||||||
if (deployError) {
|
if (deployError) {
|
||||||
return (
|
return (
|
||||||
@ -166,6 +174,15 @@ export default class DeployContract extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rejected) {
|
||||||
|
return (
|
||||||
|
<BusyStep
|
||||||
|
title='The deployment has been rejected'
|
||||||
|
state='You can safely close this window, the contract deployment will not occur.'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
switch (step) {
|
switch (step) {
|
||||||
case 0:
|
case 0:
|
||||||
return (
|
return (
|
||||||
@ -273,6 +290,11 @@ export default class DeployContract extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
if (error.code === ERROR_CODES.REQUEST_REJECTED) {
|
||||||
|
this.setState({ rejected: true });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
console.error('error deploying contract', error);
|
console.error('error deploying contract', error);
|
||||||
this.setState({ deployError: error });
|
this.setState({ deployError: error });
|
||||||
store.dispatch({ type: 'newError', error });
|
store.dispatch({ type: 'newError', error });
|
||||||
|
@ -23,6 +23,8 @@ import { validateAddress, validateUint } from '../../util/validation';
|
|||||||
|
|
||||||
import DetailsStep from './DetailsStep';
|
import DetailsStep from './DetailsStep';
|
||||||
|
|
||||||
|
import { ERROR_CODES } from '../../api/transport/error';
|
||||||
|
|
||||||
export default class ExecuteContract extends Component {
|
export default class ExecuteContract extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
api: PropTypes.object.isRequired,
|
api: PropTypes.object.isRequired,
|
||||||
@ -49,7 +51,8 @@ export default class ExecuteContract extends Component {
|
|||||||
step: 0,
|
step: 0,
|
||||||
sending: false,
|
sending: false,
|
||||||
busyState: null,
|
busyState: null,
|
||||||
txhash: null
|
txhash: null,
|
||||||
|
rejected: false
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
@ -80,6 +83,7 @@ export default class ExecuteContract extends Component {
|
|||||||
const { onClose, fromAddress } = this.props;
|
const { onClose, fromAddress } = this.props;
|
||||||
const { sending, step, fromAddressError, valuesError } = this.state;
|
const { sending, step, fromAddressError, valuesError } = this.state;
|
||||||
const hasError = fromAddressError || valuesError.find((error) => error);
|
const hasError = fromAddressError || valuesError.find((error) => error);
|
||||||
|
|
||||||
const cancelBtn = (
|
const cancelBtn = (
|
||||||
<Button
|
<Button
|
||||||
key='cancel'
|
key='cancel'
|
||||||
@ -115,7 +119,16 @@ export default class ExecuteContract extends Component {
|
|||||||
|
|
||||||
renderStep () {
|
renderStep () {
|
||||||
const { onFromAddressChange } = this.props;
|
const { onFromAddressChange } = this.props;
|
||||||
const { step, busyState, txhash } = this.state;
|
const { step, busyState, txhash, rejected } = this.state;
|
||||||
|
|
||||||
|
if (rejected) {
|
||||||
|
return (
|
||||||
|
<BusyStep
|
||||||
|
title='The execution has been rejected'
|
||||||
|
state='You can safely close this window, the function execution will not occur.'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (step === 0) {
|
if (step === 0) {
|
||||||
return (
|
return (
|
||||||
@ -221,7 +234,17 @@ export default class ExecuteContract extends Component {
|
|||||||
})
|
})
|
||||||
.then((requestId) => {
|
.then((requestId) => {
|
||||||
this.setState({ busyState: 'Waiting for authorization in the Parity Signer' });
|
this.setState({ busyState: 'Waiting for authorization in the Parity Signer' });
|
||||||
return api.pollMethod('parity_checkRequest', requestId);
|
|
||||||
|
return api
|
||||||
|
.pollMethod('parity_checkRequest', requestId)
|
||||||
|
.catch((e) => {
|
||||||
|
if (e.code === ERROR_CODES.REQUEST_REJECTED) {
|
||||||
|
this.setState({ rejected: true });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((txhash) => {
|
.then((txhash) => {
|
||||||
this.setState({ sending: false, step: 2, txhash, busyState: 'Your transaction has been posted to the network' });
|
this.setState({ sending: false, step: 2, txhash, busyState: 'Your transaction has been posted to the network' });
|
||||||
|
@ -28,13 +28,16 @@ import Extras from './Extras';
|
|||||||
import ERRORS from './errors';
|
import ERRORS from './errors';
|
||||||
import styles from './transfer.css';
|
import styles from './transfer.css';
|
||||||
|
|
||||||
|
import { ERROR_CODES } from '../../api/transport/error';
|
||||||
|
|
||||||
const DEFAULT_GAS = '21000';
|
const DEFAULT_GAS = '21000';
|
||||||
const DEFAULT_GASPRICE = '20000000000';
|
const DEFAULT_GASPRICE = '20000000000';
|
||||||
const TITLES = {
|
const TITLES = {
|
||||||
transfer: 'transfer details',
|
transfer: 'transfer details',
|
||||||
sending: 'sending',
|
sending: 'sending',
|
||||||
complete: 'complete',
|
complete: 'complete',
|
||||||
extras: 'extra information'
|
extras: 'extra information',
|
||||||
|
rejected: 'rejected'
|
||||||
};
|
};
|
||||||
const STAGES_BASIC = [TITLES.transfer, TITLES.sending, TITLES.complete];
|
const STAGES_BASIC = [TITLES.transfer, TITLES.sending, TITLES.complete];
|
||||||
const STAGES_EXTRA = [TITLES.transfer, TITLES.extras, TITLES.sending, TITLES.complete];
|
const STAGES_EXTRA = [TITLES.transfer, TITLES.extras, TITLES.sending, TITLES.complete];
|
||||||
@ -74,7 +77,8 @@ export default class Transfer extends Component {
|
|||||||
valueAll: false,
|
valueAll: false,
|
||||||
valueError: null,
|
valueError: null,
|
||||||
isEth: true,
|
isEth: true,
|
||||||
busyState: null
|
busyState: null,
|
||||||
|
rejected: false
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
@ -82,13 +86,19 @@ export default class Transfer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { stage, extras } = this.state;
|
const { stage, extras, rejected } = this.state;
|
||||||
|
|
||||||
|
const steps = [].concat(extras ? STAGES_EXTRA : STAGES_BASIC);
|
||||||
|
|
||||||
|
if (rejected) {
|
||||||
|
steps[steps.length - 1] = TITLES.rejected;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
actions={ this.renderDialogActions() }
|
actions={ this.renderDialogActions() }
|
||||||
current={ stage }
|
current={ stage }
|
||||||
steps={ extras ? STAGES_EXTRA : STAGES_BASIC }
|
steps={ steps }
|
||||||
waiting={ extras ? [2] : [1] }
|
waiting={ extras ? [2] : [1] }
|
||||||
visible
|
visible
|
||||||
scroll
|
scroll
|
||||||
@ -133,7 +143,16 @@ export default class Transfer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderCompletePage () {
|
renderCompletePage () {
|
||||||
const { sending, txhash, busyState } = this.state;
|
const { sending, txhash, busyState, rejected } = this.state;
|
||||||
|
|
||||||
|
if (rejected) {
|
||||||
|
return (
|
||||||
|
<BusyStep
|
||||||
|
title='The transaction has been rejected'
|
||||||
|
state='You can safely close this window, the transfer will not occur.'
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (sending) {
|
if (sending) {
|
||||||
return (
|
return (
|
||||||
@ -455,7 +474,17 @@ export default class Transfer extends Component {
|
|||||||
: this._sendToken()
|
: this._sendToken()
|
||||||
).then((requestId) => {
|
).then((requestId) => {
|
||||||
this.setState({ busyState: 'Waiting for authorization in the Parity Signer' });
|
this.setState({ busyState: 'Waiting for authorization in the Parity Signer' });
|
||||||
return api.pollMethod('parity_checkRequest', requestId);
|
|
||||||
|
return api
|
||||||
|
.pollMethod('parity_checkRequest', requestId)
|
||||||
|
.catch((e) => {
|
||||||
|
if (e.code === ERROR_CODES.REQUEST_REJECTED) {
|
||||||
|
this.setState({ rejected: true });
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.then((txhash) => {
|
.then((txhash) => {
|
||||||
this.onNext();
|
this.onNext();
|
||||||
|
Loading…
Reference in New Issue
Block a user