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",
|
||||
"bytes": "^2.4.0",
|
||||
"chart.js": "^2.3.0",
|
||||
"es6-error": "^4.0.0",
|
||||
"es6-promise": "^3.2.1",
|
||||
"ethereumjs-tx": "^1.1.2",
|
||||
"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 JsonRpcBase from '../jsonRpcBase';
|
||||
import TransportError from '../error';
|
||||
|
||||
/* global fetch */
|
||||
export default class Http extends JsonRpcBase {
|
||||
@ -73,7 +74,8 @@ export default class Http extends JsonRpcBase {
|
||||
this.error(JSON.stringify(response));
|
||||
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));
|
||||
|
@ -16,3 +16,4 @@
|
||||
|
||||
export Http from './http';
|
||||
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 JsonRpcBase from '../jsonRpcBase';
|
||||
import TransportError from '../error';
|
||||
|
||||
/* global WebSocket */
|
||||
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}`);
|
||||
|
||||
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];
|
||||
return;
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ import ErrorStep from './ErrorStep';
|
||||
|
||||
import styles from './deployContract.css';
|
||||
|
||||
import { ERROR_CODES } from '../../api/transport/error';
|
||||
|
||||
const steps = ['contract details', 'deployment', 'completed'];
|
||||
|
||||
export default class DeployContract extends Component {
|
||||
@ -63,7 +65,8 @@ export default class DeployContract extends Component {
|
||||
params: [],
|
||||
paramsError: [],
|
||||
step: 0,
|
||||
deployError: null
|
||||
deployError: null,
|
||||
rejected: false
|
||||
}
|
||||
|
||||
componentWillMount () {
|
||||
@ -92,15 +95,20 @@ export default class DeployContract extends Component {
|
||||
}
|
||||
|
||||
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 (
|
||||
<Modal
|
||||
actions={ this.renderDialogActions() }
|
||||
current={ step }
|
||||
steps={ deployError ? null : steps }
|
||||
title={ deployError ? 'deployment failed' : null }
|
||||
waiting={ [1] }
|
||||
steps={ realSteps }
|
||||
title={ title }
|
||||
waiting={ realSteps ? [1] : null }
|
||||
visible
|
||||
scroll>
|
||||
{ this.renderStep() }
|
||||
@ -158,7 +166,7 @@ export default class DeployContract extends Component {
|
||||
|
||||
renderStep () {
|
||||
const { accounts, readOnly } = this.props;
|
||||
const { address, deployError, step, deployState, txhash } = this.state;
|
||||
const { address, deployError, step, deployState, txhash, rejected } = this.state;
|
||||
|
||||
if (deployError) {
|
||||
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) {
|
||||
case 0:
|
||||
return (
|
||||
@ -273,6 +290,11 @@ export default class DeployContract extends Component {
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.code === ERROR_CODES.REQUEST_REJECTED) {
|
||||
this.setState({ rejected: true });
|
||||
return false;
|
||||
}
|
||||
|
||||
console.error('error deploying contract', error);
|
||||
this.setState({ deployError: error });
|
||||
store.dispatch({ type: 'newError', error });
|
||||
|
@ -23,6 +23,8 @@ import { validateAddress, validateUint } from '../../util/validation';
|
||||
|
||||
import DetailsStep from './DetailsStep';
|
||||
|
||||
import { ERROR_CODES } from '../../api/transport/error';
|
||||
|
||||
export default class ExecuteContract extends Component {
|
||||
static contextTypes = {
|
||||
api: PropTypes.object.isRequired,
|
||||
@ -49,7 +51,8 @@ export default class ExecuteContract extends Component {
|
||||
step: 0,
|
||||
sending: false,
|
||||
busyState: null,
|
||||
txhash: null
|
||||
txhash: null,
|
||||
rejected: false
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@ -80,6 +83,7 @@ export default class ExecuteContract extends Component {
|
||||
const { onClose, fromAddress } = this.props;
|
||||
const { sending, step, fromAddressError, valuesError } = this.state;
|
||||
const hasError = fromAddressError || valuesError.find((error) => error);
|
||||
|
||||
const cancelBtn = (
|
||||
<Button
|
||||
key='cancel'
|
||||
@ -115,7 +119,16 @@ export default class ExecuteContract extends Component {
|
||||
|
||||
renderStep () {
|
||||
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) {
|
||||
return (
|
||||
@ -221,7 +234,17 @@ export default class ExecuteContract extends Component {
|
||||
})
|
||||
.then((requestId) => {
|
||||
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) => {
|
||||
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 styles from './transfer.css';
|
||||
|
||||
import { ERROR_CODES } from '../../api/transport/error';
|
||||
|
||||
const DEFAULT_GAS = '21000';
|
||||
const DEFAULT_GASPRICE = '20000000000';
|
||||
const TITLES = {
|
||||
transfer: 'transfer details',
|
||||
sending: 'sending',
|
||||
complete: 'complete',
|
||||
extras: 'extra information'
|
||||
extras: 'extra information',
|
||||
rejected: 'rejected'
|
||||
};
|
||||
const STAGES_BASIC = [TITLES.transfer, 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,
|
||||
valueError: null,
|
||||
isEth: true,
|
||||
busyState: null
|
||||
busyState: null,
|
||||
rejected: false
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
@ -82,13 +86,19 @@ export default class Transfer extends Component {
|
||||
}
|
||||
|
||||
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 (
|
||||
<Modal
|
||||
actions={ this.renderDialogActions() }
|
||||
current={ stage }
|
||||
steps={ extras ? STAGES_EXTRA : STAGES_BASIC }
|
||||
steps={ steps }
|
||||
waiting={ extras ? [2] : [1] }
|
||||
visible
|
||||
scroll
|
||||
@ -133,7 +143,16 @@ export default class Transfer extends Component {
|
||||
}
|
||||
|
||||
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) {
|
||||
return (
|
||||
@ -455,7 +474,17 @@ export default class Transfer extends Component {
|
||||
: this._sendToken()
|
||||
).then((requestId) => {
|
||||
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) => {
|
||||
this.onNext();
|
||||
|
Loading…
Reference in New Issue
Block a user