From 6e07a6830ab8f14b0e6a1358721967333a075384 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Thu, 5 Jul 2018 10:59:28 +0200 Subject: [PATCH] Make signer page work --- .../fether-react/src/Send/Signer/Signer.js | 8 +-- .../fether-react/src/stores/parityStore.js | 3 +- packages/fether-react/src/stores/sendStore.js | 62 ++----------------- packages/fether-ui/src/Form/Field/Field.js | 4 +- 4 files changed, 13 insertions(+), 64 deletions(-) diff --git a/packages/fether-react/src/Send/Signer/Signer.js b/packages/fether-react/src/Send/Signer/Signer.js index bb21f860..5b938ee6 100644 --- a/packages/fether-react/src/Send/Signer/Signer.js +++ b/packages/fether-react/src/Send/Signer/Signer.js @@ -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 {
( + render={({ errors, handleSubmit, pristine, submitting }) => (

Enter your password to confirm this transaction.

@@ -99,7 +99,7 @@ class Signer extends Component { diff --git a/packages/fether-react/src/stores/parityStore.js b/packages/fether-react/src/stores/parityStore.js index 365267ab..0c026a06 100644 --- a/packages/fether-react/src/stores/parityStore.js +++ b/packages/fether-react/src/stores/parityStore.js @@ -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 diff --git a/packages/fether-react/src/stores/sendStore.js b/packages/fether-react/src/stores/sendStore.js index 8103f675..f20c83ef 100644 --- a/packages/fether-react/src/stores/sendStore.js +++ b/packages/fether-react/src/stores/sendStore.js @@ -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; diff --git a/packages/fether-ui/src/Form/Field/Field.js b/packages/fether-ui/src/Form/Field/Field.js index 90780166..b1681714 100644 --- a/packages/fether-ui/src/Form/Field/Field.js +++ b/packages/fether-ui/src/Form/Field/Field.js @@ -18,10 +18,10 @@ export const Field = ({
} -- GitLab