refactor: remove duplicated and unused functions
This commit is contained in:
parent
363e9f3888
commit
be4caa1baf
|
@ -27,8 +27,8 @@ import Table from '~/components/Table'
|
||||||
import { type Column, cellWidth } from '~/components/Table/TableHead'
|
import { type Column, cellWidth } from '~/components/Table/TableHead'
|
||||||
import Block from '~/components/layout/Block'
|
import Block from '~/components/layout/Block'
|
||||||
import Row from '~/components/layout/Row'
|
import Row from '~/components/layout/Row'
|
||||||
import { extendedTransactionsSelector } from '~/routes/safe/container/selector'
|
|
||||||
import { safeCancellationTransactionsSelector } from '~/routes/safe/store/selectors'
|
import { safeCancellationTransactionsSelector } from '~/routes/safe/store/selectors'
|
||||||
|
import { extendedTransactionsSelector } from '~/routes/safe/store/selectors/transactions'
|
||||||
|
|
||||||
export const TRANSACTION_ROW_TEST_ID = 'transaction-row'
|
export const TRANSACTION_ROW_TEST_ID = 'transaction-row'
|
||||||
|
|
||||||
|
|
|
@ -7,45 +7,15 @@ import { tokensSelector } from '~/logic/tokens/store/selectors'
|
||||||
import { getEthAsToken } from '~/logic/tokens/utils/tokenHelpers'
|
import { getEthAsToken } from '~/logic/tokens/utils/tokenHelpers'
|
||||||
import { isUserOwner } from '~/logic/wallets/ethAddresses'
|
import { isUserOwner } from '~/logic/wallets/ethAddresses'
|
||||||
import { userAccountSelector } from '~/logic/wallets/store/selectors'
|
import { userAccountSelector } from '~/logic/wallets/store/selectors'
|
||||||
import type { IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction'
|
|
||||||
import { type Safe } from '~/routes/safe/store/models/safe'
|
import { type Safe } from '~/routes/safe/store/models/safe'
|
||||||
import { type Transaction, type TransactionStatus } from '~/routes/safe/store/models/transaction'
|
|
||||||
import {
|
import {
|
||||||
type RouterProps,
|
type RouterProps,
|
||||||
safeActiveTokensSelector,
|
safeActiveTokensSelector,
|
||||||
safeBalancesSelector,
|
safeBalancesSelector,
|
||||||
safeCancellationTransactionsSelector,
|
|
||||||
safeIncomingTransactionsSelector,
|
|
||||||
safeSelector,
|
safeSelector,
|
||||||
safeTransactionsSelector,
|
|
||||||
} from '~/routes/safe/store/selectors'
|
} from '~/routes/safe/store/selectors'
|
||||||
import { type GlobalState } from '~/store'
|
import { type GlobalState } from '~/store'
|
||||||
|
|
||||||
const getTxStatus = (tx: Transaction, userAddress: string, safe: Safe): TransactionStatus => {
|
|
||||||
let txStatus
|
|
||||||
if (tx.executionTxHash) {
|
|
||||||
txStatus = 'success'
|
|
||||||
} else if (tx.cancelled) {
|
|
||||||
txStatus = 'cancelled'
|
|
||||||
} else if (tx.confirmations.size === safe.threshold) {
|
|
||||||
txStatus = 'awaiting_execution'
|
|
||||||
} else if (tx.creationTx) {
|
|
||||||
txStatus = 'success'
|
|
||||||
} else if (!tx.confirmations.size) {
|
|
||||||
txStatus = 'pending'
|
|
||||||
} else {
|
|
||||||
const userConfirmed = tx.confirmations.filter((conf) => conf.owner === userAddress).size === 1
|
|
||||||
const userIsSafeOwner = safe.owners.filter((owner) => owner.address === userAddress).size === 1
|
|
||||||
txStatus = !userConfirmed && userIsSafeOwner ? 'awaiting_your_confirmation' : 'awaiting_confirmations'
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tx.isSuccessful === false) {
|
|
||||||
txStatus = 'failed'
|
|
||||||
}
|
|
||||||
|
|
||||||
return txStatus
|
|
||||||
}
|
|
||||||
|
|
||||||
export const grantedSelector: Selector<GlobalState, RouterProps, boolean> = createSelector(
|
export const grantedSelector: Selector<GlobalState, RouterProps, boolean> = createSelector(
|
||||||
userAccountSelector,
|
userAccountSelector,
|
||||||
safeSelector,
|
safeSelector,
|
||||||
|
@ -87,35 +57,3 @@ export const extendedSafeTokensSelector: Selector<GlobalState, RouterProps, List
|
||||||
return extendedTokens.toList()
|
return extendedTokens.toList()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
export const extendedTransactionsSelector: Selector<
|
|
||||||
GlobalState,
|
|
||||||
RouterProps,
|
|
||||||
List<Transaction | IncomingTransaction>,
|
|
||||||
> = createSelector(
|
|
||||||
safeSelector,
|
|
||||||
userAccountSelector,
|
|
||||||
safeTransactionsSelector,
|
|
||||||
safeCancellationTransactionsSelector,
|
|
||||||
safeIncomingTransactionsSelector,
|
|
||||||
(safe, userAddress, transactions, cancellationTransactions, incomingTransactions) => {
|
|
||||||
const cancellationTransactionsByNonce = cancellationTransactions.reduce((acc, tx) => acc.set(tx.nonce, tx), Map())
|
|
||||||
const extendedTransactions = transactions.map((tx: Transaction) => {
|
|
||||||
let extendedTx = tx
|
|
||||||
|
|
||||||
if (!tx.isExecuted) {
|
|
||||||
if (
|
|
||||||
(cancellationTransactionsByNonce.get(tx.nonce) &&
|
|
||||||
cancellationTransactionsByNonce.get(tx.nonce).get('isExecuted')) ||
|
|
||||||
transactions.find((safeTx) => tx.nonce === safeTx.nonce && safeTx.isExecuted)
|
|
||||||
) {
|
|
||||||
extendedTx = tx.set('cancelled', true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return extendedTx.set('status', getTxStatus(extendedTx, userAddress, safe))
|
|
||||||
})
|
|
||||||
|
|
||||||
return List([...extendedTransactions, ...incomingTransactions])
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import { type SafeTransactionsType, loadOutgoingTransactions } from './loadOutgo
|
||||||
import { addCancellationTransactions } from '~/routes/safe/store/actions/transactions/addCancellationTransactions'
|
import { addCancellationTransactions } from '~/routes/safe/store/actions/transactions/addCancellationTransactions'
|
||||||
import { type IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction'
|
import { type IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction'
|
||||||
import { type GlobalState } from '~/store'
|
import { type GlobalState } from '~/store'
|
||||||
|
|
||||||
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState) => {
|
export default (safeAddress: string) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState) => {
|
||||||
const transactions: SafeTransactionsType | typeof undefined = await loadOutgoingTransactions(safeAddress, getState)
|
const transactions: SafeTransactionsType | typeof undefined = await loadOutgoingTransactions(safeAddress, getState)
|
||||||
if (transactions) {
|
if (transactions) {
|
||||||
|
|
Loading…
Reference in New Issue