aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2019-01-15 06:34:37 +0800
committerWhymarrh Whitby <whymarrh.whitby@gmail.com>2019-01-25 07:01:30 +0800
commit941a9a0fd95cb0d68d940e42a431f520d717921c (patch)
tree1d619adbd0c663c4b045ac14d6199c76dd087336 /ui
parent2d7c9b3dacc08c3d308100894b14d8c9f971e775 (diff)
downloadtangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar.gz
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar.bz2
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar.lz
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar.xz
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.tar.zst
tangerine-wallet-browser-941a9a0fd95cb0d68d940e42a431f520d717921c.zip
Order shapeshift transactions by time within the transactions list
Diffstat (limited to 'ui')
-rw-r--r--ui/app/selectors/transactions.js44
1 files changed, 32 insertions, 12 deletions
diff --git a/ui/app/selectors/transactions.js b/ui/app/selectors/transactions.js
index 301e8d11f..fc1271c59 100644
--- a/ui/app/selectors/transactions.js
+++ b/ui/app/selectors/transactions.js
@@ -83,7 +83,7 @@ const insertOrderedNonce = (nonces, nonceToInsert) => {
for (let i = 0; i < nonces.length; i++) {
const nonce = nonces[i]
- if (Number(hexToDecimal(nonce)) < Number(hexToDecimal(nonceToInsert))) {
+ if (Number(hexToDecimal(nonce)) > Number(hexToDecimal(nonceToInsert))) {
insertIndex = i
break
}
@@ -138,17 +138,17 @@ const insertTransactionByTime = (transactions, transaction) => {
* @param {transactionGroup[]} transactionGroups - Array of transactionGroup objects.
* @param {transactionGroup} transactionGroup - transactionGroup object to be inserted into the
* array of transactionGroups.
- * @returns {transactionGroup[]}
*/
const insertTransactionGroupByTime = (transactionGroups, transactionGroup) => {
- const { primaryTransaction: { time } = {} } = transactionGroup
+ const { primaryTransaction: { time: groupToInsertTime } = {} } = transactionGroup
let insertIndex = transactionGroups.length
for (let i = 0; i < transactionGroups.length; i++) {
const txGroup = transactionGroups[i]
+ const { primaryTransaction: { time } = {} } = txGroup
- if (txGroup.time > time) {
+ if (time > groupToInsertTime) {
insertIndex = i
break
}
@@ -158,6 +158,22 @@ const insertTransactionGroupByTime = (transactionGroups, transactionGroup) => {
}
/**
+ * @name mergeShapeshiftTransactionGroups
+ * @private
+ * @description Inserts (mutates) shapeshift transactionGroups into an array of nonce-ordered
+ * transactionGroups by time. Shapeshift transactionGroups need to be sorted by time within the list
+ * of transactions as they do not have nonces.
+ * @param {transactionGroup[]} orderedTransactionGroups - Array of transactionGroups ordered by
+ * nonce.
+ * @param {transactionGroup[]} shapeshiftTransactionGroups - Array of shapeshift transactionGroups
+ */
+const mergeShapeshiftTransactionGroups = (orderedTransactionGroups, shapeshiftTransactionGroups) => {
+ shapeshiftTransactionGroups.forEach(shapeshiftGroup => {
+ insertTransactionGroupByTime(orderedTransactionGroups, shapeshiftGroup)
+ })
+}
+
+/**
* @name nonceSortedTransactionsSelector
* @description Returns an array of transactionGroups sorted by nonce in ascending order.
* @returns {transactionGroup[]}
@@ -166,11 +182,12 @@ export const nonceSortedTransactionsSelector = createSelector(
transactionsSelector,
(transactions = []) => {
const unapprovedTransactionGroups = []
+ const shapeshiftTransactionGroups = []
const orderedNonces = []
const nonceToTransactionsMap = {}
transactions.forEach(transaction => {
- const { txParams: { nonce } = {}, status, type, time: txTime } = transaction
+ const { txParams: { nonce } = {}, status, type, time: txTime, key } = transaction
if (typeof nonce === 'undefined') {
const transactionGroup = {
@@ -181,7 +198,11 @@ export const nonceSortedTransactionsSelector = createSelector(
hasCancelled: false,
}
- insertTransactionGroupByTime(unapprovedTransactionGroups, transactionGroup)
+ if (key === 'shapeshift') {
+ shapeshiftTransactionGroups.push(transactionGroup)
+ } else {
+ insertTransactionGroupByTime(unapprovedTransactionGroups, transactionGroup)
+ }
} else if (nonce in nonceToTransactionsMap) {
const nonceProps = nonceToTransactionsMap[nonce]
insertTransactionByTime(nonceProps.transactions, transaction)
@@ -224,6 +245,7 @@ export const nonceSortedTransactionsSelector = createSelector(
})
const orderedTransactionGroups = orderedNonces.map(nonce => nonceToTransactionsMap[nonce])
+ mergeShapeshiftTransactionGroups(orderedTransactionGroups, shapeshiftTransactionGroups)
return unapprovedTransactionGroups.concat(orderedTransactionGroups)
}
)
@@ -237,9 +259,7 @@ export const nonceSortedTransactionsSelector = createSelector(
export const nonceSortedPendingTransactionsSelector = createSelector(
nonceSortedTransactionsSelector,
(transactions = []) => (
- transactions
- .filter(({ primaryTransaction }) => primaryTransaction.status in pendingStatusHash)
- .reverse()
+ transactions.filter(({ primaryTransaction }) => primaryTransaction.status in pendingStatusHash)
)
)
@@ -252,9 +272,9 @@ export const nonceSortedPendingTransactionsSelector = createSelector(
export const nonceSortedCompletedTransactionsSelector = createSelector(
nonceSortedTransactionsSelector,
(transactions = []) => (
- transactions.filter(({ primaryTransaction }) => {
- return !(primaryTransaction.status in pendingStatusHash)
- })
+ transactions
+ .filter(({ primaryTransaction }) => !(primaryTransaction.status in pendingStatusHash))
+ .reverse()
)
)