Commit 75ea2d3d authored by Chi Kei Chan's avatar Chi Kei Chan

Add Pending Tx to Send

parent 0a5509e9
...@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; ...@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import classnames from 'classnames'; import classnames from 'classnames';
import {BigNumber as BN} from "bignumber.js"; import {BigNumber as BN} from "bignumber.js";
import { CSSTransitionGroup } from "react-transition-group"; import { CSSTransitionGroup } from "react-transition-group";
import { selectors } from '../../ducks/web3connect'; import { selectors, addPendingTx } from '../../ducks/web3connect';
import Header from '../../components/Header'; import Header from '../../components/Header';
import NavigationTabs from '../../components/NavigationTabs'; import NavigationTabs from '../../components/NavigationTabs';
import AddressInputPanel from '../../components/AddressInputPanel'; import AddressInputPanel from '../../components/AddressInputPanel';
...@@ -359,6 +359,7 @@ class Send extends Component { ...@@ -359,6 +359,7 @@ class Send extends Component {
account, account,
web3, web3,
selectors, selectors,
addPendingTx,
} = this.props; } = this.props;
const { const {
inputValue, inputValue,
...@@ -397,7 +398,12 @@ class Send extends Component { ...@@ -397,7 +398,12 @@ class Send extends Component {
.send({ .send({
from: account, from: account,
value: BN(inputValue).multipliedBy(10 ** 18).toFixed(0), value: BN(inputValue).multipliedBy(10 ** 18).toFixed(0),
}, err => !err && this.reset()); }, (err, data) => {
if (!err) {
addPendingTx(data);
this.reset();
}
});
break; break;
case 'TOKEN_TO_ETH': case 'TOKEN_TO_ETH':
new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency]) new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency])
...@@ -408,9 +414,12 @@ class Send extends Component { ...@@ -408,9 +414,12 @@ class Send extends Component {
deadline, deadline,
recipient, recipient,
) )
.send({ .send({ from: account }, (err, data) => {
from: account, if (!err) {
}, err => !err && this.reset()); addPendingTx(data);
this.reset();
}
});
break; break;
case 'TOKEN_TO_TOKEN': case 'TOKEN_TO_TOKEN':
new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency]) new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency])
...@@ -423,9 +432,12 @@ class Send extends Component { ...@@ -423,9 +432,12 @@ class Send extends Component {
recipient, recipient,
outputCurrency, outputCurrency,
) )
.send({ .send({ from: account }, (err, data) => {
from: account, if (!err) {
}, err => !err && this.reset()); addPendingTx(data);
this.reset();
}
});
break; break;
default: default:
break; break;
...@@ -450,7 +462,12 @@ class Send extends Component { ...@@ -450,7 +462,12 @@ class Send extends Component {
.send({ .send({
from: account, from: account,
value: BN(inputValue).multipliedBy(10 ** inputDecimals).multipliedBy(1 + ALLOWED_SLIPPAGE).toFixed(0), value: BN(inputValue).multipliedBy(10 ** inputDecimals).multipliedBy(1 + ALLOWED_SLIPPAGE).toFixed(0),
}, err => !err && this.reset()); }, (err, data) => {
if (!err) {
addPendingTx(data);
this.reset();
}
});
break; break;
case 'TOKEN_TO_ETH': case 'TOKEN_TO_ETH':
new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency]) new web3.eth.Contract(EXCHANGE_ABI, fromToken[inputCurrency])
...@@ -461,9 +478,12 @@ class Send extends Component { ...@@ -461,9 +478,12 @@ class Send extends Component {
deadline, deadline,
recipient, recipient,
) )
.send({ .send({ from: account }, (err, data) => {
from: account, if (!err) {
}, err => !err && this.reset()); addPendingTx(data);
this.reset();
}
});
break; break;
case 'TOKEN_TO_TOKEN': case 'TOKEN_TO_TOKEN':
if (!inputAmountB) { if (!inputAmountB) {
...@@ -479,9 +499,13 @@ class Send extends Component { ...@@ -479,9 +499,13 @@ class Send extends Component {
deadline, deadline,
recipient, recipient,
outputCurrency, outputCurrency,
).send({ )
from: account, .send({ from: account }, (err, data) => {
}, err => !err && this.reset()); if (!err) {
addPendingTx(data);
this.reset();
}
});
break; break;
default: default:
break; break;
...@@ -798,6 +822,7 @@ export default connect( ...@@ -798,6 +822,7 @@ export default connect(
}), }),
dispatch => ({ dispatch => ({
selectors: () => dispatch(selectors()), selectors: () => dispatch(selectors()),
addPendingTx: id => dispatch(addPendingTx(id)),
}), }),
)(Send); )(Send);
......
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