Commit 6e07a683 authored by Amaury Martiny's avatar Amaury Martiny

Make signer page work

parent 5e7402e3
......@@ -22,10 +22,10 @@ class Signer extends Component {
const { history, sendStore, token } = this.props;
return sendStore
.send(values.password)
.send(token, values.password)
.then(() => history.push(`/send/${token.address}/sent`))
.catch(error => ({
password: error
password: error.text
}));
};
......@@ -74,7 +74,7 @@ class Signer extends Component {
<Form
key='signerForm'
onSubmit={this.handleAccept}
render={({ handleSubmit, submitting, valid }) => (
render={({ errors, handleSubmit, pristine, submitting }) => (
<form onSubmit={handleSubmit}>
<div className='text'>
<p>Enter your password to confirm this transaction.</p>
......@@ -99,7 +99,7 @@ class Signer extends Component {
<button
className='button -submit'
disabled={!valid || submitting}
disabled={pristine || submitting}
>
Confirm transaction
</button>
......
......@@ -27,6 +27,7 @@ export class ParityStore {
// Retrieve token from localStorage
const token = store.get(LS_KEY);
if (token) {
debug('Got token from localStorage.');
this.setToken(token);
}
......@@ -99,6 +100,7 @@ export class ParityStore {
}
// If `parity signer new-token` has successfully given us a token back,
// then we submit it
debug('Successfully received new token.');
this.setToken(token);
});
};
......@@ -137,7 +139,6 @@ export class ParityStore {
return;
}
debug(`Setting token in localStorage.`);
this.token = token;
// If we receive a new token, then we try to connect to the Api with this
......
......@@ -7,12 +7,9 @@ import abi from '@parity/shared/lib/contracts/abi/eip20';
import { action, computed, observable } from 'mobx';
import { BigNumber } from 'bignumber.js';
import { blockNumber$, makeContract$, post$ } from '@parity/light.js';
import memoize from 'lodash/memoize';
import noop from 'lodash/noop';
import Debug from '../utils/debug';
import parityStore from './parityStore';
import tokensStore from './tokensStore';
import { txForErc20, txForEth } from '../utils/estimateGas';
const debug = Debug('sendStore');
......@@ -22,7 +19,6 @@ const DEFAULT_GAS = new BigNumber(21000 * GAS_MULT_FACTOR); // Default gas amoun
export class SendStore {
@observable blockNumber; // Current block number, used to calculate tx confirmations.
@observable estimated = DEFAULT_GAS; // Estimated gas amount for this transaction.
@observable tokenAddress; // 'ETH', or the token contract address
tx = {}; // The actual tx we are sending. No need to be observable.
@observable txStatus; // Status of the tx, see wiki for details.
......@@ -66,64 +62,21 @@ export class SendStore {
return makeContract$(this.tokenAddress, abi);
}
/**
* Estimate the amount of gas for our transaction.
*/
estimateGas = () => {
if (!this.tx || !Object.keys(this.tx).length) {
return Promise.reject(new Error('Tx not set in sendStore.'));
}
if (this.tokenAddress === 'ETH') {
return this.estimateGasForEth(txForEth(this.tx));
} else {
return this.estimateGasForErc20(
txForErc20(this.tx, tokensStore.tokens[this.tokenAddress])
);
}
};
/**
* Estimate gas to transfer in ERC20 contract. Expensive function, so we
* memoize it.
*/
estimateGasForErc20 = memoize(
txForErc20 =>
this.contract.contractObject.instance.transfer
.estimateGas(txForErc20.options, txForErc20.args)
.then(this.setEstimated)
.catch(noop),
JSON.stringify
);
/**
* Estimate gas to transfer to an ETH address. Expensive function, so we
* memoize it.
*/
estimateGasForEth = memoize(
txForEth =>
parityStore.api.eth
.estimateGas(txForEth)
.then(this.setEstimated)
.catch(noop),
JSON.stringify
);
/**
* Create a transaction.
*/
send = password => {
send = (token, password) => {
const send$ =
this.tokenAddress === 'ETH'
token.address === 'ETH'
? post$(txForEth(this.tx))
: this.contract.transfer$(
...txForErc20(this.tx).args,
txForErc20(this.tx).options
...txForErc20(this.tx, token).args,
txForErc20(this.tx, token).options
);
debug(
'Sending tx.',
this.tokenAddress === 'ETH' ? this.txForEth : this.txForErc20
token.address === 'ETH' ? this.txForEth : this.txForErc20
);
return new Promise((resolve, reject) => {
......@@ -151,11 +104,6 @@ export class SendStore {
debug('Estimated gas,', +estimated, ', with buffer,', +this.estimated);
};
@action
setTokenAddress = tokenAddress => {
this.tokenAddress = tokenAddress;
};
@action
setTx = tx => {
this.tx = tx;
......
......@@ -18,10 +18,10 @@ export const Field = ({
<div className='form_field'>
<label>{label}</label>
<Popup
content={meta && meta.error}
content={meta && (meta.error || meta.submitError)}
inverted
on='click'
open={meta && !meta.pristine && !meta.valid}
open={meta && !meta.pristine && !meta.valid && !meta.dirtySinceLastSubmit}
position='top center'
size='mini'
trigger={<T {...input} {...otherProps} />}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment