From e4c10d2a48c5470d15bbf0f2eef036975ac02087 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Thu, 4 Jul 2019 15:09:34 +0400 Subject: [PATCH] add transaction status in selector --- .../TransactionsNew/TxsTable/columns.js | 16 ++------- src/routes/safe/container/selector.js | 34 +++++++++++++------ src/routes/safe/store/models/transaction.js | 4 +++ 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/routes/safe/components/TransactionsNew/TxsTable/columns.js b/src/routes/safe/components/TransactionsNew/TxsTable/columns.js index 7abcc774..9d56166d 100644 --- a/src/routes/safe/components/TransactionsNew/TxsTable/columns.js +++ b/src/routes/safe/components/TransactionsNew/TxsTable/columns.js @@ -22,26 +22,14 @@ type TxData = { type: string, date: string, amount: number | string, - status: string, tx: Transaction, + status?: string, } export const formatDate = (date: Date): string => format(date, 'MMM D, YYYY - h:m:s') export type TransactionRow = SortRow -const getTxStatus = (tx: Transaction): string => { - let txStatus = 'awaiting' - - if (tx.isExecuted) { - txStatus = 'success' - } else if (tx.cancelled) { - txStatus = 'cancelled' - } - - return txStatus -} - export const getTxTableData = (transactions: List): List => { const rows = transactions.map((tx: Transaction) => { const txDate = tx.isExecuted ? tx.executionDate : tx.submissionDate @@ -52,7 +40,7 @@ export const getTxTableData = (transactions: List): List 0 ? `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}` : 'n/a', - [TX_TABLE_STATUS_ID]: getTxStatus(tx), + [TX_TABLE_STATUS_ID]: tx.status, [TX_TABLE_RAW_TX_ID]: tx, } }) diff --git a/src/routes/safe/container/selector.js b/src/routes/safe/container/selector.js index f9f085cc..233cbc8e 100644 --- a/src/routes/safe/container/selector.js +++ b/src/routes/safe/container/selector.js @@ -17,7 +17,7 @@ import { sameAddress } from '~/logic/wallets/ethAddresses' import { safeTransactionsSelector } from '~/routes/safe/store/selectors/index' import { orderedTokenListSelector, tokensSelector } from '~/logic/tokens/store/selectors' import { type Token } from '~/logic/tokens/store/model/token' -import { type Transaction } from '~/routes/safe/store/models/transaction' +import { type Transaction, type TransactionStatus } from '~/routes/safe/store/models/transaction' import { type TokenBalance } from '~/routes/safe/store/models/tokenBalance' import { safeParamAddressSelector } from '../store/selectors' import { getEthAsToken } from '~/logic/tokens/utils/tokenHelpers' @@ -33,6 +33,18 @@ export type SelectorProps = { transactions: List, } +const getTxStatus = (tx: Transaction): TransactionStatus => { + let txStatus = 'awaiting' + + if (tx.isExecuted) { + txStatus = 'success' + } else if (tx.cancelled) { + txStatus = 'cancelled' + } + + return txStatus +} + export const grantedSelector: Selector = createSelector( userAccountSelector, safeSelector, @@ -94,21 +106,21 @@ const extendedTransactionsSelector: Selector { const extendedTransactions = transactions.map((tx: Transaction) => { - if (tx.isExecuted) { - return tx - } + let extendedTx = tx // If transactions is not executed, but there's a transaction with the same nonce submitted later // it means that the transaction was cancelled (Replaced) and shouldn't get executed - const replacementTransaction = transactions.findLast( - transaction => transaction.nonce === tx.nonce && isAfter(transaction.submissionDate, tx.submissionDate), - ) - - if (!replacementTransaction) { - return tx + let replacementTransaction + if (!tx.isExecuted) { + replacementTransaction = transactions.findLast( + transaction => transaction.nonce === tx.nonce && isAfter(transaction.submissionDate, tx.submissionDate), + ) + if (replacementTransaction) { + extendedTx = tx.set('cancelled', true) + } } - return tx.set('cancelled', true) + return extendedTx.set('status', getTxStatus(extendedTx)) }) return extendedTransactions diff --git a/src/routes/safe/store/models/transaction.js b/src/routes/safe/store/models/transaction.js index bc162b50..fa5a7017 100644 --- a/src/routes/safe/store/models/transaction.js +++ b/src/routes/safe/store/models/transaction.js @@ -3,6 +3,8 @@ import { List, Record } from 'immutable' import type { RecordFactory, RecordOf } from 'immutable' import { type Confirmation } from '~/routes/safe/store/models/confirmation' +export type TransactionStatus = 'awaiting' | 'success' | 'cancelled' + export type TransactionProps = { name: string, nonce: number, @@ -17,6 +19,7 @@ export type TransactionProps = { creationTxHash: string, executionTxHash?: string, cancelled?: boolean, + status?: TransactionStatus, } export const makeTransaction: RecordFactory = Record({ @@ -33,6 +36,7 @@ export const makeTransaction: RecordFactory = Record({ executionTxHash: undefined, creationTxHash: '', cancelled: false, + status: 'awaiting', }) export type Transaction = RecordOf