aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-08-12 12:12:30 +0800
committerAlexander Tseung <alextsg@gmail.com>2018-08-24 07:45:27 +0800
commitb48a293af059d2ad23fea0af601740888acd3f8b (patch)
treefd72fb11cb22667b4c0fb1f66eb8f7e059234307 /ui
parent5dcd8ceb7bbaef33fef5588feceac17577679e74 (diff)
downloadtangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar.gz
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar.bz2
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar.lz
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar.xz
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.tar.zst
tangerine-wallet-browser-b48a293af059d2ad23fea0af601740888acd3f8b.zip
Update retry transaction logic to use network nonce
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/transaction-list/transaction-list.component.js14
-rw-r--r--ui/app/components/transaction-list/transaction-list.container.js28
-rw-r--r--ui/app/helpers/transactions.util.js16
3 files changed, 46 insertions, 12 deletions
diff --git a/ui/app/components/transaction-list/transaction-list.component.js b/ui/app/components/transaction-list/transaction-list.component.js
index c1e1885f3..e30476d8c 100644
--- a/ui/app/components/transaction-list/transaction-list.component.js
+++ b/ui/app/components/transaction-list/transaction-list.component.js
@@ -20,6 +20,20 @@ export default class TransactionList extends PureComponent {
completedTransactions: PropTypes.array,
transactionToRetry: PropTypes.object,
selectedToken: PropTypes.object,
+ updateNetworkNonce: PropTypes.func,
+ }
+
+ componentDidMount () {
+ this.props.updateNetworkNonce()
+ }
+
+ componentDidUpdate (prevProps) {
+ const { pendingTransactions: prevPendingTransactions = [] } = prevProps
+ const { pendingTransactions = [], updateNetworkNonce } = this.props
+
+ if (pendingTransactions.length > prevPendingTransactions.length) {
+ updateNetworkNonce()
+ }
}
shouldShowRetry = transaction => {
diff --git a/ui/app/components/transaction-list/transaction-list.container.js b/ui/app/components/transaction-list/transaction-list.container.js
index e1d19e787..1ec1f9ccf 100644
--- a/ui/app/components/transaction-list/transaction-list.container.js
+++ b/ui/app/components/transaction-list/transaction-list.container.js
@@ -7,22 +7,44 @@ import {
submittedPendingTransactionsSelector,
completedTransactionsSelector,
} from '../../selectors/transactions'
+import { getSelectedAddress } from '../../selectors'
import { selectedTokenSelector } from '../../selectors/tokens'
-import { getLatestSubmittedTxWithEarliestNonce } from '../../helpers/transactions.util'
+import { getLatestSubmittedTxWithNonce } from '../../helpers/transactions.util'
+import { updateNetworkNonce } from '../../actions'
const mapStateToProps = state => {
const pendingTransactions = pendingTransactionsSelector(state)
const submittedPendingTransactions = submittedPendingTransactionsSelector(state)
+ const networkNonce = state.appState.networkNonce
return {
completedTransactions: completedTransactionsSelector(state),
pendingTransactions,
- transactionToRetry: getLatestSubmittedTxWithEarliestNonce(submittedPendingTransactions),
+ transactionToRetry: getLatestSubmittedTxWithNonce(submittedPendingTransactions, networkNonce),
selectedToken: selectedTokenSelector(state),
+ selectedAddress: getSelectedAddress(state),
+ }
+}
+
+const mapDispatchToProps = dispatch => {
+ return {
+ updateNetworkNonce: address => dispatch(updateNetworkNonce(address)),
+ }
+}
+
+const mergeProps = (stateProps, dispatchProps, ownProps) => {
+ const { selectedAddress, ...restStateProps } = stateProps
+ const { updateNetworkNonce, ...restDispatchProps } = dispatchProps
+
+ return {
+ ...restStateProps,
+ ...restDispatchProps,
+ ...ownProps,
+ updateNetworkNonce: () => updateNetworkNonce(selectedAddress),
}
}
export default compose(
withRouter,
- connect(mapStateToProps)
+ connect(mapStateToProps, mapDispatchToProps, mergeProps)
)(TransactionList)
diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js
index e890a0852..e92a22e16 100644
--- a/ui/app/helpers/transactions.util.js
+++ b/ui/app/helpers/transactions.util.js
@@ -2,7 +2,6 @@ import ethUtil from 'ethereumjs-util'
import MethodRegistry from 'eth-method-registry'
import abi from 'human-standard-token-abi'
import abiDecoder from 'abi-decoder'
-import { hexToDecimal } from './conversions.util'
import {
TOKEN_METHOD_TRANSFER,
@@ -76,21 +75,20 @@ export function getTransactionActionKey (transaction, methodData) {
}
}
-export function getLatestSubmittedTxWithEarliestNonce (transactions = []) {
+export function getLatestSubmittedTxWithNonce (transactions = [], nonce = '0x0') {
if (!transactions.length) {
return {}
}
return transactions.reduce((acc, current) => {
- const accNonce = hexToDecimal(acc.nonce)
- const currentNonce = hexToDecimal(current.nonce)
+ const { submittedTime, txParams: { nonce: currentNonce } = {} } = current
- if (currentNonce < accNonce) {
- return current
- } else if (currentNonce === accNonce) {
- return current.submittedTime > acc.submittedTime ? current : acc
+ if (currentNonce === nonce) {
+ return acc.submittedTime
+ ? submittedTime > acc.submittedTime ? current : acc
+ : current
} else {
return acc
}
- })
+ }, {})
}