aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/helpers')
-rw-r--r--ui/app/helpers/transactions.util.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/ui/app/helpers/transactions.util.js b/ui/app/helpers/transactions.util.js
index 04cef150f..68e935702 100644
--- a/ui/app/helpers/transactions.util.js
+++ b/ui/app/helpers/transactions.util.js
@@ -2,6 +2,8 @@ import ethUtil from 'ethereumjs-util'
import MethodRegistry from 'eth-method-registry'
const registry = new MethodRegistry({ provider: global.ethereumProvider })
+import { hexToDecimal } from './conversions.util'
+
import {
TOKEN_METHOD_TRANSFER,
TOKEN_METHOD_APPROVE,
@@ -55,3 +57,22 @@ export async function getMethodData (data = {}) {
params: parsedResult.args,
}
}
+
+export function getLatestSubmittedTxWithEarliestNonce (transactions = []) {
+ if (!transactions.length) {
+ return {}
+ }
+
+ return transactions.reduce((acc, current) => {
+ const accNonce = hexToDecimal(acc.nonce)
+ const currentNonce = hexToDecimal(current.nonce)
+
+ if (currentNonce < accNonce) {
+ return current
+ } else if (currentNonce === accNonce) {
+ return current.submittedTime > acc.submittedTime ? current : acc
+ } else {
+ return acc
+ }
+ })
+}