diff options
Diffstat (limited to 'ui/app/helpers/transactions.util.js')
-rw-r--r-- | ui/app/helpers/transactions.util.js | 21 |
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 + } + }) +} |