Handle Signer Rejection // Real Custom Errors #3153

This commit is contained in:
Nicolas Gotchac
2016-11-16 18:55:53 +01:00
parent 18f570327e
commit 7144da5d7e
8 changed files with 151 additions and 17 deletions

View File

@@ -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();