From ec9e7f9fb8f1a09fbd266646408a090c1a03642a Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Thu, 30 Apr 2020 14:29:10 +0400 Subject: [PATCH] Revert "transaction decoder wip" This reverts commit 5c00c48d75eabeb9abacdd2e3d5c1e976cba3a4b. --- src/logic/safe/transactions/txHistory.js | 1 + src/routes/safe/components/Balances/index.jsx | 4 +- src/routes/safe/container/index.jsx | 4 +- .../loadOutgoingTransactions.js | 22 +++--- src/routes/safe/store/models/confirmation.js | 4 + src/routes/safe/store/selectors/index.js | 6 +- .../safe/store/selectors/transactions.js | 77 ------------------- .../selectors/utils/transactionDecoder.js | 5 -- 8 files changed, 25 insertions(+), 98 deletions(-) delete mode 100644 src/routes/safe/store/selectors/transactions.js delete mode 100644 src/routes/safe/store/selectors/utils/transactionDecoder.js diff --git a/src/logic/safe/transactions/txHistory.js b/src/logic/safe/transactions/txHistory.js index 0ec7605a..cc8f4588 100644 --- a/src/logic/safe/transactions/txHistory.js +++ b/src/logic/safe/transactions/txHistory.js @@ -4,6 +4,7 @@ import axios from 'axios' import { getTxServiceHost, getTxServiceUriFrom } from '~/config' import { getWeb3 } from '~/logic/wallets/getWeb3' +export type TxServiceType = 'confirmation' | 'execution' | 'initialised' export type Operation = 0 | 1 | 2 const calculateBodyFrom = async ( diff --git a/src/routes/safe/components/Balances/index.jsx b/src/routes/safe/components/Balances/index.jsx index c496f039..e6fb1532 100644 --- a/src/routes/safe/components/Balances/index.jsx +++ b/src/routes/safe/components/Balances/index.jsx @@ -17,7 +17,7 @@ import { SAFELIST_ADDRESS } from '~/routes/routes' import SendModal from '~/routes/safe/components/Balances/SendModal' import DropdownCurrency from '~/routes/safe/components/DropdownCurrency' import { useFetchTokens } from '~/routes/safe/container/Hooks/useFetchTokens' -import { safeEnabledFeaturesSelector, safeParamAddressFromStateSelector } from '~/routes/safe/store/selectors' +import { safeFeaturesEnabledSelector, safeParamAddressFromStateSelector } from '~/routes/safe/store/selectors' import { history } from '~/store' import { wrapInSuspense } from '~/utils/wrapInSuspense' const Collectibles = React.lazy(() => import('~/routes/safe/components/Balances/Collectibles')) @@ -64,7 +64,7 @@ const Balances = (props: Props) => { const [state, setState] = useState(INITIAL_STATE) const address = useSelector(safeParamAddressFromStateSelector) - const featuresEnabled = useSelector(safeEnabledFeaturesSelector) + const featuresEnabled = useSelector(safeFeaturesEnabledSelector) useFetchTokens() diff --git a/src/routes/safe/container/index.jsx b/src/routes/safe/container/index.jsx index 0486dfb3..f4787a13 100644 --- a/src/routes/safe/container/index.jsx +++ b/src/routes/safe/container/index.jsx @@ -6,8 +6,8 @@ import { useSelector } from 'react-redux' import Page from '~/components/layout/Page' import { type Token } from '~/logic/tokens/store/model/token' import Layout from '~/routes/safe/components/Layout' -import { useCheckForUpdates } from '~/routes/safe/container/hooks/useCheckForUpdates' -import { useLoadSafe } from '~/routes/safe/container/hooks/useLoadSafe' +import { useCheckForUpdates } from '~/routes/safe/container/Hooks/useCheckForUpdates' +import { useLoadSafe } from '~/routes/safe/container/Hooks/useLoadSafe' import { safeParamAddressFromStateSelector } from '~/routes/safe/store/selectors' type Action = 'Send' | 'Receive' diff --git a/src/routes/safe/store/actions/transactions/fetchTransactions/loadOutgoingTransactions.js b/src/routes/safe/store/actions/transactions/fetchTransactions/loadOutgoingTransactions.js index bdd0bdc3..85c302cd 100644 --- a/src/routes/safe/store/actions/transactions/fetchTransactions/loadOutgoingTransactions.js +++ b/src/routes/safe/store/actions/transactions/fetchTransactions/loadOutgoingTransactions.js @@ -5,7 +5,7 @@ import { List, Map, type RecordInstance } from 'immutable' import generateBatchRequests from '~/logic/contracts/generateBatchRequests' import { decodeParamsFromSafeMethod } from '~/logic/contracts/methodIds' -import { buildTxServiceUrl } from '~/logic/safe/transactions/txHistory' +import { type TxServiceType, buildTxServiceUrl } from '~/logic/safe/transactions/txHistory' import { TOKEN_REDUCER_ID } from '~/logic/tokens/store/reducer/tokens' import { SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH, @@ -22,7 +22,7 @@ import { type Transaction, makeTransaction } from '~/routes/safe/store/models/tr type ConfirmationServiceModel = { owner: string, submissionDate: Date, - signature: string, + confirmationType: string, transactionHash: string, } @@ -67,12 +67,14 @@ export const buildTransactionFrom = async ( tx.confirmations.map((conf: ConfirmationServiceModel) => makeConfirmation({ owner: conf.owner, + type: ((conf.confirmationType.toLowerCase(): any): TxServiceType), hash: conf.transactionHash, signature: conf.signature, }), ), ) - + const modifySettingsTx = sameAddress(tx.to, safeAddress) && Number(tx.value) === 0 && !!tx.data + const cancellationTx = sameAddress(tx.to, safeAddress) && Number(tx.value) === 0 && !tx.data const isERC721Token = (code && code.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH)) || (isTokenTransfer(tx.data, Number(tx.value)) && !knownTokens.get(tx.to) && txTokenDecimals !== null) @@ -159,7 +161,9 @@ export const buildTransactionFrom = async ( multiSendTx: isMultiSendTx, upgradeTx: isUpgradeTx, decodedParams, + modifySettingsTx, customTx, + cancellationTx, creationTx: tx.creationTx, origin: tx.origin, }) @@ -184,18 +188,18 @@ const batchTxTokenRequest = (txs: any[]) => { return Promise.all(whenTxsValues) } -let prevOutgoingTxsEtag = null +let prevSaveTransactionsEtag = null export const loadOutgoingTransactions = async ( safeAddress: string, getState: GetState, ): Promise => { - let transactions: TxServiceModel[] = [] + let transactions: TxServiceModel[] = addMockSafeCreationTx(safeAddress) try { - const config = prevOutgoingTxsEtag + const config = prevSaveTransactionsEtag ? { headers: { - 'If-None-Match': prevOutgoingTxsEtag, + 'If-None-Match': prevSaveTransactionsEtag, }, } : undefined @@ -203,12 +207,12 @@ export const loadOutgoingTransactions = async ( const url = buildTxServiceUrl(safeAddress) const response = await axios.get(url, config) if (response.data.count > 0) { - if (prevOutgoingTxsEtag === response.headers.etag) { + if (prevSaveTransactionsEtag === response.headers.etag) { // The txs are the same as we currently have, we don't have to proceed return } transactions = transactions.concat(response.data.results) - prevOutgoingTxsEtag = response.headers.etag + prevSaveTransactionsEtag = response.headers.etag } } catch (err) { if (err && err.response && err.response.status === 304) { diff --git a/src/routes/safe/store/models/confirmation.js b/src/routes/safe/store/models/confirmation.js index 5b26abd2..90d47a89 100644 --- a/src/routes/safe/store/models/confirmation.js +++ b/src/routes/safe/store/models/confirmation.js @@ -2,14 +2,18 @@ import { Record } from 'immutable' import type { RecordFactory, RecordOf } from 'immutable' +import { type TxServiceType } from '~/logic/safe/transactions/txHistory' + export type ConfirmationProps = { owner: string, + type: TxServiceType, hash: string, signature?: string, } export const makeConfirmation: RecordFactory = Record({ owner: '', + type: 'initialised', hash: '', signature: null, }) diff --git a/src/routes/safe/store/selectors/index.js b/src/routes/safe/store/selectors/index.js index dcfea640..e346eae2 100644 --- a/src/routes/safe/store/selectors/index.js +++ b/src/routes/safe/store/selectors/index.js @@ -150,8 +150,8 @@ export const safeSelector: OutputSelector, diff --git a/src/routes/safe/store/selectors/transactions.js b/src/routes/safe/store/selectors/transactions.js deleted file mode 100644 index 1e4ec933..00000000 --- a/src/routes/safe/store/selectors/transactions.js +++ /dev/null @@ -1,77 +0,0 @@ -// @flow -import { List, Map } from 'immutable' -import { type Selector, createSelector } from 'reselect' - -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 Transaction, type TransactionStatus } from '~/routes/safe/store/models/transaction' -import { - type RouterProps, - safeCancellationTransactionsSelector, - safeIncomingTransactionsSelector, - safeSelector, - safeTransactionsSelector, -} from '~/routes/safe/store/selectors' -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 extendedTransactionsSelector: Selector< - GlobalState, - RouterProps, - List, -> = 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) => - tx.withMutations((transaction) => { - transaction.set('modifySettingsTx', sameAddress(transaction.to, safe) && Number(tx.value) === 0 && !!tx.data) - transaction.set('cancellationTx', sameAddress(transaction.to, safe) && Number(tx.value) === 0 && !tx.data) - - if (!transaction.isExecuted) { - if ( - (cancellationTransactionsByNonce.get(tx.nonce) && - cancellationTransactionsByNonce.get(tx.nonce).get('isExecuted')) || - transactions.find((safeTx) => tx.nonce === safeTx.nonce && safeTx.isExecuted) - ) { - transaction.set('cancelled', true) - } - } - transaction.set('status', getTxStatus(transaction, userAddress, safe)) - - return transaction - }), - ) - - return List([...extendedTransactions, ...incomingTransactions]) - }, -) diff --git a/src/routes/safe/store/selectors/utils/transactionDecoder.js b/src/routes/safe/store/selectors/utils/transactionDecoder.js deleted file mode 100644 index eb4ea6ad..00000000 --- a/src/routes/safe/store/selectors/utils/transactionDecoder.js +++ /dev/null @@ -1,5 +0,0 @@ -// @flow -import { sameAddress } from '~/logic/wallets/ethAddresses' -import { type Transaction } from '~/routes/safe/store/models/transaction' - -const isModifySettingsTx = (tx: Transaction) => sameAddress(transaction.to, safe) && Number(tx.value) === 0 && !!tx.data