2021-02-04 19:15:23 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { compose } from 'redux';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { clearConfirmTransaction } from '../../ducks/confirm-transaction/confirm-transaction.duck';
|
|
|
|
import { updateSend, showSendTokenPage } from '../../store/actions';
|
|
|
|
import { conversionUtil } from '../../helpers/utils/conversion-util';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
getTokenValueParam,
|
|
|
|
getTokenAddressParam,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../../helpers/utils/token-util';
|
|
|
|
import { sendTokenTokenAmountAndToAddressSelector } from '../../selectors';
|
|
|
|
import ConfirmSendToken from './confirm-send-token.component';
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapStateToProps = (state) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { tokenAmount } = sendTokenTokenAmountAndToAddressSelector(state);
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
return {
|
2018-07-14 22:47:07 +02:00
|
|
|
tokenAmount,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
2018-06-23 08:52:45 +02:00
|
|
|
return {
|
|
|
|
editTransaction: ({ txData, tokenData, tokenProps }) => {
|
2020-03-06 22:34:56 +01:00
|
|
|
const {
|
|
|
|
id,
|
2020-11-03 00:41:28 +01:00
|
|
|
txParams: { from, to: tokenAddress, gas: gasLimit, gasPrice } = {},
|
2021-02-04 19:15:23 +01:00
|
|
|
} = txData;
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const to = getTokenValueParam(tokenData);
|
|
|
|
const tokenAmountInDec = getTokenAddressParam(tokenData);
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2018-06-23 08:52:45 +02:00
|
|
|
const tokenAmountInHex = conversionUtil(tokenAmountInDec, {
|
|
|
|
fromNumericBase: 'dec',
|
|
|
|
toNumericBase: 'hex',
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2020-03-06 22:34:56 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
dispatch(
|
|
|
|
updateSend({
|
|
|
|
from,
|
|
|
|
gasLimit,
|
|
|
|
gasPrice,
|
|
|
|
gasTotal: null,
|
|
|
|
to,
|
|
|
|
amount: tokenAmountInHex,
|
|
|
|
errors: { to: null, amount: null },
|
2020-11-05 16:35:58 +01:00
|
|
|
editingTransactionId: id?.toString(),
|
2020-11-03 00:41:28 +01:00
|
|
|
token: {
|
|
|
|
...tokenProps,
|
|
|
|
address: tokenAddress,
|
|
|
|
},
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
dispatch(clearConfirmTransaction());
|
|
|
|
dispatch(showSendTokenPage());
|
2018-06-23 08:52:45 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
|
|
|
};
|
2018-06-23 08:52:45 +02:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withRouter,
|
2020-07-14 17:20:41 +02:00
|
|
|
connect(mapStateToProps, mapDispatchToProps),
|
2021-02-04 19:15:23 +01:00
|
|
|
)(ConfirmSendToken);
|