Retry transaction logic added to tx-list-item, confirm-send-ether, customize-gas-modal, and dependents.

feature/default_network_editable
Dan 7 years ago
parent 6cee76b3e7
commit 5433d2fe3a
  1. 4
      ui/app/actions.js
  2. 18
      ui/app/components/customize-gas-modal/index.js
  3. 20
      ui/app/components/pending-tx/confirm-send-ether.js
  4. 47
      ui/app/components/tx-list-item.js
  5. 13
      ui/app/components/tx-list.js
  6. 13
      ui/app/conversion-util.js
  7. 4
      ui/app/reducers/metamask.js
  8. 5
      ui/app/selectors.js
  9. 5
      ui/app/send-v2.js

@ -1228,8 +1228,10 @@ function retryTransaction (txId) {
if (err) { if (err) {
return dispatch(actions.displayWarning(err.message)) return dispatch(actions.displayWarning(err.message))
} }
const { selectedAddressTxList } = newState
const { id: newTxId } = selectedAddressTxList[selectedAddressTxList.length - 1]
dispatch(actions.updateMetamaskState(newState)) dispatch(actions.updateMetamaskState(newState))
dispatch(actions.viewPendingTx(txId)) dispatch(actions.viewPendingTx(newTxId))
}) })
} }
} }

@ -21,12 +21,14 @@ const {
conversionUtil, conversionUtil,
multiplyCurrencies, multiplyCurrencies,
conversionGreaterThan, conversionGreaterThan,
conversionMax,
subtractCurrencies, subtractCurrencies,
} = require('../../conversion-util') } = require('../../conversion-util')
const { const {
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getForceGasMin,
conversionRateSelector, conversionRateSelector,
getSendAmount, getSendAmount,
getSelectedToken, getSelectedToken,
@ -44,6 +46,7 @@ function mapStateToProps (state) {
return { return {
gasPrice: getGasPrice(state), gasPrice: getGasPrice(state),
gasLimit: getGasLimit(state), gasLimit: getGasLimit(state),
forceGasMin: getForceGasMin(state),
conversionRate, conversionRate,
amount: getSendAmount(state), amount: getSendAmount(state),
maxModeOn: getSendMaxModeState(state), maxModeOn: getSendMaxModeState(state),
@ -217,7 +220,7 @@ CustomizeGasModal.prototype.convertAndSetGasPrice = function (newGasPrice) {
} }
CustomizeGasModal.prototype.render = function () { CustomizeGasModal.prototype.render = function () {
const { hideModal } = this.props const { hideModal, forceGasMin } = this.props
const { gasPrice, gasLimit, gasTotal, error, priceSigZeros, priceSigDec } = this.state const { gasPrice, gasLimit, gasTotal, error, priceSigZeros, priceSigDec } = this.state
let convertedGasPrice = conversionUtil(gasPrice, { let convertedGasPrice = conversionUtil(gasPrice, {
@ -229,6 +232,17 @@ CustomizeGasModal.prototype.render = function () {
convertedGasPrice += convertedGasPrice.match(/[.]/) ? priceSigZeros : `${priceSigDec}${priceSigZeros}` convertedGasPrice += convertedGasPrice.match(/[.]/) ? priceSigZeros : `${priceSigDec}${priceSigZeros}`
if (forceGasMin) {
const convertedMinPrice = conversionUtil(forceGasMin, {
fromNumericBase: 'hex',
toNumericBase: 'dec',
})
convertedGasPrice = conversionMax(
{ value: convertedMinPrice, fromNumericBase: 'dec' },
{ value: convertedGasPrice, fromNumericBase: 'dec' }
)
}
const convertedGasLimit = conversionUtil(gasLimit, { const convertedGasLimit = conversionUtil(gasLimit, {
fromNumericBase: 'hex', fromNumericBase: 'hex',
toNumericBase: 'dec', toNumericBase: 'dec',
@ -251,7 +265,7 @@ CustomizeGasModal.prototype.render = function () {
h(GasModalCard, { h(GasModalCard, {
value: convertedGasPrice, value: convertedGasPrice,
min: MIN_GAS_PRICE_GWEI, min: forceGasMin || MIN_GAS_PRICE_GWEI,
// max: 1000, // max: 1000,
step: multiplyCurrencies(MIN_GAS_PRICE_GWEI, 10), step: multiplyCurrencies(MIN_GAS_PRICE_GWEI, 10),
onChange: value => this.convertAndSetGasPrice(value), onChange: value => this.convertAndSetGasPrice(value),

@ -36,13 +36,29 @@ function mapDispatchToProps (dispatch) {
return { return {
clearSend: () => dispatch(actions.clearSend()), clearSend: () => dispatch(actions.clearSend()),
editTransaction: txMeta => { editTransaction: txMeta => {
const { id, txParams } = txMeta const { id, txParams, lastGasPrice } = txMeta
const { const {
gas: gasLimit, gas: gasLimit,
gasPrice, gasPrice,
to, to,
value: amount, value: amount,
} = txParams } = txParams
let forceGasMin
let nonce
if (lastGasPrice) {
const stripped = ethUtil.stripHexPrefix(lastGasPrice)
forceGasMin = ethUtil.addHexPrefix(addCurrencies(stripped, MIN_GAS_PRICE_HEX, {
aBase: 16,
bBase: 16,
toNumericBase: 'hex',
fromDenomination: 'WEI',
toDenomination: 'GWEI',
}))
nonce = txParams.nonce
}
dispatch(actions.updateSend({ dispatch(actions.updateSend({
gasLimit, gasLimit,
gasPrice, gasPrice,
@ -51,6 +67,8 @@ function mapDispatchToProps (dispatch) {
amount, amount,
errors: { to: null, amount: null }, errors: { to: null, amount: null },
editingTransactionId: id, editingTransactionId: id,
forceGasMin,
nonce,
})) }))
dispatch(actions.showSendPage()) dispatch(actions.showSendPage())
}, },

@ -9,18 +9,26 @@ abiDecoder.addABI(abi)
const Identicon = require('./identicon') const Identicon = require('./identicon')
const contractMap = require('eth-contract-metadata') const contractMap = require('eth-contract-metadata')
const actions = require('../actions')
const { conversionUtil, multiplyCurrencies } = require('../conversion-util') const { conversionUtil, multiplyCurrencies } = require('../conversion-util')
const { calcTokenAmount } = require('../token-util') const { calcTokenAmount } = require('../token-util')
const { getCurrentCurrency } = require('../selectors') const { getCurrentCurrency } = require('../selectors')
module.exports = connect(mapStateToProps)(TxListItem) module.exports = connect(mapStateToProps, mapDispatchToProps)(TxListItem)
function mapStateToProps (state) { function mapStateToProps (state) {
return { return {
tokens: state.metamask.tokens, tokens: state.metamask.tokens,
currentCurrency: getCurrentCurrency(state), currentCurrency: getCurrentCurrency(state),
tokenExchangeRates: state.metamask.tokenExchangeRates, tokenExchangeRates: state.metamask.tokenExchangeRates,
selectedAddressTxList: state.metamask.selectedAddressTxList,
}
}
function mapDispatchToProps (dispatch) {
return {
retryTransaction: transactionId => dispatch(actions.retryTransaction(transactionId)),
} }
} }
@ -167,12 +175,32 @@ TxListItem.prototype.getSendTokenTotal = async function () {
} }
} }
TxListItem.prototype.showRetryButton = function () {
const {
transactionStatus,
transactionTime,
selectedAddressTxList,
transactionId,
txParams,
} = this.props
const currentNonce = txParams.nonce
const currentNonceTxs = selectedAddressTxList.filter(tx => tx.txParams.nonce === currentNonce)
const isLastWithNonce = currentNonceTxs[currentNonceTxs.length - 1].id === transactionId
return transactionStatus === 'submitted' && isLastWithNonce && Date.now() - transactionTime > 5000
}
TxListItem.prototype.resubmit = function () {
const { transactionId } = this.props
this.props.retryTransaction(transactionId)
}
TxListItem.prototype.render = function () { TxListItem.prototype.render = function () {
const { const {
transactionStatus, transactionStatus,
transactionAmount, transactionAmount,
onClick, onClick,
transActionId, transactionId,
dateString, dateString,
address, address,
className, className,
@ -181,8 +209,8 @@ TxListItem.prototype.render = function () {
const showFiatTotal = transactionAmount !== '0x0' && fiatTotal const showFiatTotal = transactionAmount !== '0x0' && fiatTotal
return h(`div${className || ''}`, { return h(`div${className || ''}`, {
key: transActionId, key: transactionId,
onClick: () => onClick && onClick(transActionId), onClick: () => onClick && onClick(transactionId),
}, [ }, [
h(`div.flex-column.tx-list-item-wrapper`, {}, [ h(`div.flex-column.tx-list-item-wrapper`, {}, [
@ -241,12 +269,17 @@ TxListItem.prototype.render = function () {
]), ]),
]), ]),
h('div.tx-list-item-retry-container', [ this.showRetryButton() && h('div.tx-list-item-retry-container', [
h('span.tx-list-item-retry-copy', 'Taking too long?'), h('span.tx-list-item-retry-copy', 'Taking too long?'),
h('span.tx-list-item-retry-link', 'Increase the gas on your transaction'), h('span.tx-list-item-retry-link', {
onClick: (event) => {
event.stopPropagation()
this.resubmit()
},
}, 'Increase the gas on your transaction'),
]), ]),
]), // holding on icon from design ]), // holding on icon from design

@ -74,9 +74,10 @@ TxList.prototype.renderTransactionListItem = function (transaction, conversionRa
address: transaction.txParams.to, address: transaction.txParams.to,
transactionStatus: transaction.status, transactionStatus: transaction.status,
transactionAmount: transaction.txParams.value, transactionAmount: transaction.txParams.value,
transActionId: transaction.id, transactionId: transaction.id,
transactionHash: transaction.hash, transactionHash: transaction.hash,
transactionNetworkId: transaction.metamaskNetworkId, transactionNetworkId: transaction.metamaskNetworkId,
transactionTime: transaction.time,
} }
const { const {
@ -84,29 +85,31 @@ TxList.prototype.renderTransactionListItem = function (transaction, conversionRa
transactionStatus, transactionStatus,
transactionAmount, transactionAmount,
dateString, dateString,
transActionId, transactionId,
transactionHash, transactionHash,
transactionNetworkId, transactionNetworkId,
transactionTime,
} = props } = props
const { showConfTxPage } = this.props const { showConfTxPage } = this.props
const opts = { const opts = {
key: transActionId || transactionHash, key: transactionId || transactionHash,
txParams: transaction.txParams, txParams: transaction.txParams,
transactionStatus, transactionStatus,
transActionId, transactionId,
dateString, dateString,
address, address,
transactionAmount, transactionAmount,
transactionHash, transactionHash,
conversionRate, conversionRate,
tokenInfoGetter: this.tokenInfoGetter, tokenInfoGetter: this.tokenInfoGetter,
transactionTime,
} }
const isUnapproved = transactionStatus === 'unapproved' const isUnapproved = transactionStatus === 'unapproved'
if (isUnapproved) { if (isUnapproved) {
opts.onClick = () => showConfTxPage({id: transActionId}) opts.onClick = () => showConfTxPage({id: transactionId})
opts.transactionStatus = 'Not Started' opts.transactionStatus = 'Not Started'
} else if (transactionHash) { } else if (transactionHash) {
opts.onClick = () => this.view(transactionHash, transactionNetworkId) opts.onClick = () => this.view(transactionHash, transactionNetworkId)

@ -187,6 +187,18 @@ const conversionGreaterThan = (
return firstValue.gt(secondValue) return firstValue.gt(secondValue)
} }
const conversionMax = (
{ ...firstProps },
{ ...secondProps },
) => {
const firstIsGreater = conversionGreaterThan(
{ ...firstProps },
{ ...secondProps }
)
return firstIsGreater ? firstProps.value : secondProps.value
}
const conversionGTE = ( const conversionGTE = (
{ ...firstProps }, { ...firstProps },
{ ...secondProps }, { ...secondProps },
@ -216,6 +228,7 @@ module.exports = {
conversionGreaterThan, conversionGreaterThan,
conversionGTE, conversionGTE,
conversionLTE, conversionLTE,
conversionMax,
toNegative, toNegative,
subtractCurrencies, subtractCurrencies,
} }

@ -38,6 +38,8 @@ function reduceMetamask (state, action) {
errors: {}, errors: {},
maxModeOn: false, maxModeOn: false,
editingTransactionId: null, editingTransactionId: null,
forceGasMin: null,
nonce: null,
}, },
coinOptions: {}, coinOptions: {},
useBlockie: false, useBlockie: false,
@ -298,6 +300,8 @@ function reduceMetamask (state, action) {
memo: '', memo: '',
errors: {}, errors: {},
editingTransactionId: null, editingTransactionId: null,
forceGasMin: null,
nonce: null,
}, },
}) })

@ -18,6 +18,7 @@ const selectors = {
getCurrentAccountWithSendEtherInfo, getCurrentAccountWithSendEtherInfo,
getGasPrice, getGasPrice,
getGasLimit, getGasLimit,
getForceGasMin,
getAddressBook, getAddressBook,
getSendFrom, getSendFrom,
getCurrentCurrency, getCurrentCurrency,
@ -130,6 +131,10 @@ function getGasLimit (state) {
return state.metamask.send.gasLimit return state.metamask.send.gasLimit
} }
function getForceGasMin (state) {
return state.metamask.send.forceGasMin
}
function getSendFrom (state) { function getSendFrom (state) {
return state.metamask.send.from return state.metamask.send.from
} }

@ -543,6 +543,7 @@ SendTransactionScreen.prototype.getEditedTx = function () {
selectedToken, selectedToken,
editingTransactionId, editingTransactionId,
unapprovedTxs, unapprovedTxs,
nonce,
} = this.props } = this.props
const editingTx = { const editingTx = {
@ -554,6 +555,10 @@ SendTransactionScreen.prototype.getEditedTx = function () {
}, },
} }
if (nonce) {
editingTx.txParams.nonce = ethUtil.addHexPrefix(nonce)
}
if (selectedToken) { if (selectedToken) {
const data = TOKEN_TRANSFER_FUNCTION_SIGNATURE + Array.prototype.map.call( const data = TOKEN_TRANSFER_FUNCTION_SIGNATURE + Array.prototype.map.call(
ethAbi.rawEncode(['address', 'uint256'], [to, ethUtil.addHexPrefix(amount)]), ethAbi.rawEncode(['address', 'uint256'], [to, ethUtil.addHexPrefix(amount)]),

Loading…
Cancel
Save