From e94a448de6e7ae551eecec92ec7b084dc8087b97 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Fri, 24 Apr 2020 19:32:52 -0300 Subject: [PATCH 01/14] feature: display formatted amount for incoming/outgoing txs `getAmountWithSymbol` was created to be used for the outgoing and incoming txs, and `getIncomingTxAmount` and `getTxAmount` were both refactored to use it. This way we can have a consistent display of values for all the txs. --- .../Transactions/TxsTable/columns.js | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index 925d6bc073..afc4dbfa3b 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -9,7 +9,6 @@ import TxType from './TxType' import { type Column } from '~/components/Table/TableHead' import { type SortRow, buildOrderFieldFrom } from '~/components/Table/sorting' import { formatAmount } from '~/logic/tokens/utils/formatAmount' -import { getWeb3 } from '~/logic/wallets/getWeb3' import { INCOMING_TX_TYPES, type IncomingTransaction } from '~/routes/safe/store/models/incomingTransaction' import { type Transaction } from '~/routes/safe/store/models/transaction' @@ -34,29 +33,35 @@ type TxData = { export const formatDate = (date: string): string => format(parseISO(date), 'MMM d, yyyy - HH:mm:ss') -export const getIncomingTxAmount = (tx: IncomingTransaction) => { - const txAmount = tx.value ? `${new BigNumber(tx.value).div(`1e${tx.decimals}`).toFixed()}` : 'n/a' - return `${txAmount} ${tx.symbol || 'n/a'}` +type TxValues = { + value?: string | number, + decimals?: string | number, + symbol?: string, } -export const getTxAmount = (tx: Transaction) => { - const web3 = getWeb3() - const { fromWei, toBN } = web3.utils - - let txAmount = 'n/a' - - if (tx.isTokenTransfer && tx.decodedParams) { - const tokenDecimals = tx.decimals.toNumber ? tx.decimals.toNumber() : tx.decimals - txAmount = `${formatAmount( - BigNumber(tx.decodedParams.value) - .div(10 ** tokenDecimals) - .toString(), - )} ${tx.symbol}` - } else if (Number(tx.value) > 0) { - txAmount = `${fromWei(toBN(tx.value), 'ether')} ${tx.symbol}` +const NOT_AVAILABLE = 'n/a' + +const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, useFormatAmount = false) => { + const nonFormattedValue = BigNumber(value).times(`1e-${decimals}`).toFixed() + const finalValue = useFormatAmount ? formatAmount(nonFormattedValue).toString() : nonFormattedValue + const txAmount = finalValue === 'NaN' ? NOT_AVAILABLE : finalValue + + return `${txAmount} ${symbol}` +} + +export const getIncomingTxAmount = (tx: IncomingTransaction, useFormatAmount: boolean = true) => { + return getAmountWithSymbol(tx, useFormatAmount) +} + +export const getTxAmount = (tx: Transaction, useFormatAmount: boolean = true) => { + const { decodedParams, isTokenTransfer, symbol } = tx + const { decimals = 18, value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx + + if (!isTokenTransfer && !(Number(value) > 0)) { + return NOT_AVAILABLE } - return txAmount + return getAmountWithSymbol({ decimals, symbol, value }, useFormatAmount) } export type TransactionRow = SortRow From 9a18d1d9f8a823291cf972c0acf3447e98878537 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Fri, 24 Apr 2020 19:33:34 -0300 Subject: [PATCH 02/14] feature: display tx amount without formatting --- .../TxsTable/ExpandedTx/IncomingTxDescription/index.jsx | 2 +- .../Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx index a7107233b9..b169866c16 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx @@ -49,7 +49,7 @@ const IncomingTxDescription = ({ tx }: Props) => { const txFromName = getNameFromAddressBook(tx.from) return ( - + ) } diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx index dd09fcec82..54ac5a2a66 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx @@ -222,7 +222,7 @@ const TxDescription = ({ classes, tx }: Props) => { removedOwner, upgradeTx, } = getTxData(tx) - const amount = getTxAmount(tx) + const amount = getTxAmount(tx, false) return ( {modifySettingsTx && action && ( From d45199bef0494bc07197f0d72fd11e0f264a2955 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Fri, 24 Apr 2020 19:40:47 -0300 Subject: [PATCH 03/14] fix: remove nonce from IncomingTx details --- .../Transactions/TxsTable/ExpandedTx/index.jsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx index fdaaeee3b9..21ebc53ed9 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx @@ -66,10 +66,12 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { Hash: {tx.executionTxHash ? : 'n/a'} - - Nonce: - {tx.nonce} - + {INCOMING_TX_TYPES.includes(tx.type) ? null : ( + + Nonce: + {tx.nonce} + + )} Fee: {tx.fee ? tx.fee : 'n/a'} From 8d294c5ee960078abf6e0dec9ac08a942a34df43 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Fri, 24 Apr 2020 19:54:59 -0300 Subject: [PATCH 04/14] refactor: INCOMING_TX_TYPES Migrate it from array to an object --- .../Transactions/TxsTable/ExpandedTx/index.jsx | 16 +++++++--------- .../components/Transactions/TxsTable/columns.js | 2 +- .../safe/store/models/incomingTransaction.js | 7 ++++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx index 21ebc53ed9..58d89b74b9 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx @@ -41,8 +41,8 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { const [openModal, setOpenModal] = useState(null) const openApproveModal = () => setOpenModal('approveTx') const closeModal = () => setOpenModal(null) - const thresholdReached = !INCOMING_TX_TYPES.includes(tx.type) && threshold <= tx.confirmations.size - const canExecute = !INCOMING_TX_TYPES.includes(tx.type) && nonce === tx.nonce + const thresholdReached = !INCOMING_TX_TYPES[tx.type] && threshold <= tx.confirmations.size + const canExecute = !INCOMING_TX_TYPES[tx.type] && nonce === tx.nonce const cancelThresholdReached = !!cancelTx && threshold <= cancelTx.confirmations.size const canExecuteCancel = nonce === tx.nonce @@ -59,14 +59,12 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { - + Hash: {tx.executionTxHash ? : 'n/a'} - {INCOMING_TX_TYPES.includes(tx.type) ? null : ( + {INCOMING_TX_TYPES[tx.type] ? null : ( Nonce: {tx.nonce} @@ -76,7 +74,7 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { Fee: {tx.fee ? tx.fee : 'n/a'} - {INCOMING_TX_TYPES.includes(tx.type) ? ( + {INCOMING_TX_TYPES[tx.type] ? ( <> Created: @@ -115,9 +113,9 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { )} - {INCOMING_TX_TYPES.includes(tx.type) ? : } + {INCOMING_TX_TYPES[tx.type] ? : } - {!INCOMING_TX_TYPES.includes(tx.type) && ( + {!INCOMING_TX_TYPES[tx.type] && ( acc.set(tx.nonce, tx), Map()) return transactions.map((tx) => { - if (INCOMING_TX_TYPES.includes(tx.type)) { + if (INCOMING_TX_TYPES[tx.type]) { return getIncomingTxTableData(tx) } diff --git a/src/routes/safe/store/models/incomingTransaction.js b/src/routes/safe/store/models/incomingTransaction.js index ebe5d7f54f..d88405b0bf 100644 --- a/src/routes/safe/store/models/incomingTransaction.js +++ b/src/routes/safe/store/models/incomingTransaction.js @@ -2,7 +2,12 @@ import { Record } from 'immutable' import type { RecordFactory, RecordOf } from 'immutable' -export const INCOMING_TX_TYPES = ['INCOMING', 'ERC721_TRANSFER', 'ERC20_TRANSFER', 'ETHER_TRANSFER'] +export const INCOMING_TX_TYPES = { + INCOMING: 'INCOMING', + ERC721_TRANSFER: 'ERC721_TRANSFER', + ERC20_TRANSFER: 'ERC20_TRANSFER', + ETHER_TRANSFER: 'ETHER_TRANSFER', +} export type IncomingTransactionProps = { blockNumber: number, From de35e6b9169bedef0614e10f227e00a52c0befd5 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Fri, 24 Apr 2020 20:05:40 -0300 Subject: [PATCH 05/14] fix: Incoming Txs NFT amount Now the amount for the incoming NFTs transfer were displayed as '> 1000T '. For instance, for CK: `> 1000T CK`. To avoid confusions, if it's recognized as a `ERC721_TRANSFER` the amount is hardcoded to `1` accompanied with its respective symbol --- src/routes/safe/components/Transactions/TxsTable/columns.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index 44f784af2b..f14d115d75 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -50,6 +50,11 @@ const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: Tx } export const getIncomingTxAmount = (tx: IncomingTransaction, useFormatAmount: boolean = true) => { + // simple workaround to avoid displaying unexpected values for incoming NFT transfer + if (INCOMING_TX_TYPES[tx.type] === INCOMING_TX_TYPES.ERC721_TRANSFER) { + return `1 ${tx.symbol}` + } + return getAmountWithSymbol(tx, useFormatAmount) } From d9e8f80c891180f0cf0bc6f7eb4c4359d7e76137 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 25 Apr 2020 10:19:06 -0300 Subject: [PATCH 06/14] fix: Remove decimals for the exact 0 (zero) amount --- src/logic/tokens/utils/formatAmount.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/tokens/utils/formatAmount.js b/src/logic/tokens/utils/formatAmount.js index 6c4221afe0..a6b5e62804 100644 --- a/src/logic/tokens/utils/formatAmount.js +++ b/src/logic/tokens/utils/formatAmount.js @@ -18,7 +18,7 @@ export const formatAmount = (number: string | number) => { let numberFloat = parseFloat(number) if (numberFloat === 0) { - numberFloat = '0.000' + numberFloat = '0' } else if (numberFloat < 0.001) { numberFloat = '< 0.001' } else if (numberFloat < 1000) { From a9bde84fa0237ed6bc62253b766c3d19bb00a0d6 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 25 Apr 2020 11:15:10 -0300 Subject: [PATCH 07/14] fix: Extract decimals from tx object (always) --- src/routes/safe/components/Transactions/TxsTable/columns.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index f14d115d75..c2da3cb64f 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -59,8 +59,8 @@ export const getIncomingTxAmount = (tx: IncomingTransaction, useFormatAmount: bo } export const getTxAmount = (tx: Transaction, useFormatAmount: boolean = true) => { - const { decodedParams, isTokenTransfer, symbol } = tx - const { decimals = 18, value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx + const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx + const { value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx if (!isTokenTransfer && !(Number(value) > 0)) { return NOT_AVAILABLE From 05c8ea1ba4bd695faa2879b5b8eea5f245f7dce0 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 25 Apr 2020 12:48:46 -0300 Subject: [PATCH 08/14] fix: Use already known ERC-20 Tokens info For instance, `cDai` tokens symbol were represented as `DAI` --- src/logic/tokens/store/reducer/tokens.js | 2 +- .../safe/store/actions/fetchTransactions.js | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/logic/tokens/store/reducer/tokens.js b/src/logic/tokens/store/reducer/tokens.js index 3d9d191685..fa4f47a21d 100644 --- a/src/logic/tokens/store/reducer/tokens.js +++ b/src/logic/tokens/store/reducer/tokens.js @@ -9,7 +9,7 @@ import { type Token, makeToken } from '~/logic/tokens/store/model/token' export const TOKEN_REDUCER_ID = 'tokens' -export type State = Map> +export type State = Map export default handleActions( { diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index c9ef0d1140..d804d6ad28 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -76,12 +76,12 @@ type IncomingTxServiceModel = { export const buildTransactionFrom = async ( safeAddress: string, - tx: TxServiceModel, knownTokens, + tx: TxServiceModel, + txTokenCode, txTokenDecimals, - txTokenSymbol, txTokenName, - code, + txTokenSymbol, ): Promise => { const localSafe = await getLocalSafe(safeAddress) @@ -108,7 +108,7 @@ export const buildTransactionFrom = async ( 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)) || + (txTokenCode && txTokenCode.includes(SAFE_TRANSFER_FROM_WITHOUT_DATA_HASH)) || (isTokenTransfer(tx.data, Number(tx.value)) && !knownTokens.get(tx.to) && txTokenDecimals !== null) let isSendTokenTx = !isERC721Token && isTokenTransfer(tx.data, Number(tx.value)) const isMultiSendTx = isMultisendTransaction(tx.data, Number(tx.value)) @@ -231,7 +231,7 @@ const batchRequestTxsData = (txs: any[]) => { const web3Batch = new web3.BatchRequest() const whenTxsValues = txs.map((tx) => { - const methods = ['decimals', { method: 'getCode', type: 'eth', args: [tx.to] }, 'symbol', 'name'] + const methods = [{ method: 'getCode', type: 'eth', args: [tx.to] }, 'decimals', 'name', 'symbol'] return generateBatchRequests({ abi: ERC20Detailed.abi, address: tx.to, @@ -341,9 +341,15 @@ export const loadSafeTransactions = async (safeAddress: string, getState: GetSta const txsWithData = await batchRequestTxsData(transactions) // In case that the etags don't match, we parse the new transactions and save them to the cache const txsRecord: Array> = await Promise.all( - txsWithData.map(([tx: TxServiceModel, decimals, code, symbol, name]) => - buildTransactionFrom(safeAddress, tx, knownTokens, decimals, symbol, name, code), - ), + txsWithData.map(([tx: TxServiceModel, code, decimals, name, symbol]) => { + const knownToken = knownTokens.get(tx.to) + + if (knownToken) { + ;({ decimals, name, symbol } = knownToken) + } + + return buildTransactionFrom(safeAddress, knownTokens, tx, code, decimals, name, symbol) + }), ) const groupedTxs = List(txsRecord).groupBy((tx) => (tx.get('cancellationTx') ? 'cancel' : 'outgoing')) From a5b9f8e56f3f3b59432bb0561771c51db4632d27 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Sat, 25 Apr 2020 12:49:40 -0300 Subject: [PATCH 09/14] fix: Wrong variable used for `decimals` --- src/routes/safe/store/actions/fetchTransactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index d804d6ad28..9bcc5c41c1 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -118,7 +118,7 @@ export const buildTransactionFrom = async ( let refundParams = null if (tx.gasPrice > 0) { const refundSymbol = txTokenSymbol || 'ETH' - const decimals = txTokenName || 18 + const decimals = txTokenDecimals || 18 const feeString = (tx.gasPrice * (tx.baseGas + tx.safeTxGas)).toString().padStart(decimals, 0) const whole = feeString.slice(0, feeString.length - decimals) || '0' const fraction = feeString.slice(feeString.length - decimals) From 10e8a977489fd8ccb6fb68cfe9b9193d67d767cd Mon Sep 17 00:00:00 2001 From: fernandomg Date: Mon, 27 Apr 2020 09:14:17 -0300 Subject: [PATCH 10/14] refactor: rename `useFormatAmount` in favor of `precise` --- .../safe/components/Transactions/TxsTable/columns.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index c2da3cb64f..e85b2e3cac 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -41,24 +41,24 @@ type TxValues = { const NOT_AVAILABLE = 'n/a' -const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, useFormatAmount = false) => { +const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, precise = false) => { const nonFormattedValue = BigNumber(value).times(`1e-${decimals}`).toFixed() - const finalValue = useFormatAmount ? formatAmount(nonFormattedValue).toString() : nonFormattedValue + const finalValue = precise ? formatAmount(nonFormattedValue).toString() : nonFormattedValue const txAmount = finalValue === 'NaN' ? NOT_AVAILABLE : finalValue return `${txAmount} ${symbol}` } -export const getIncomingTxAmount = (tx: IncomingTransaction, useFormatAmount: boolean = true) => { +export const getIncomingTxAmount = (tx: IncomingTransaction, precise: boolean = true) => { // simple workaround to avoid displaying unexpected values for incoming NFT transfer if (INCOMING_TX_TYPES[tx.type] === INCOMING_TX_TYPES.ERC721_TRANSFER) { return `1 ${tx.symbol}` } - return getAmountWithSymbol(tx, useFormatAmount) + return getAmountWithSymbol(tx, precise) } -export const getTxAmount = (tx: Transaction, useFormatAmount: boolean = true) => { +export const getTxAmount = (tx: Transaction, precise: boolean = true) => { const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx const { value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx @@ -66,7 +66,7 @@ export const getTxAmount = (tx: Transaction, useFormatAmount: boolean = true) => return NOT_AVAILABLE } - return getAmountWithSymbol({ decimals, symbol, value }, useFormatAmount) + return getAmountWithSymbol({ decimals, symbol, value }, precise) } export type TransactionRow = SortRow From 4653243ac8aa76c63920d91d4baf9e5167d33833 Mon Sep 17 00:00:00 2001 From: fernandomg Date: Mon, 27 Apr 2020 09:21:33 -0300 Subject: [PATCH 11/14] refactor: extract `INCOMING_TX_TYPE` evaluation, to a single variable --- .../Transactions/TxsTable/ExpandedTx/index.jsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx index 58d89b74b9..f3e0926087 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/index.jsx @@ -41,8 +41,9 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { const [openModal, setOpenModal] = useState(null) const openApproveModal = () => setOpenModal('approveTx') const closeModal = () => setOpenModal(null) - const thresholdReached = !INCOMING_TX_TYPES[tx.type] && threshold <= tx.confirmations.size - const canExecute = !INCOMING_TX_TYPES[tx.type] && nonce === tx.nonce + const isIncomingTx = !!INCOMING_TX_TYPES[tx.type] + const thresholdReached = !isIncomingTx && threshold <= tx.confirmations.size + const canExecute = !isIncomingTx && nonce === tx.nonce const cancelThresholdReached = !!cancelTx && threshold <= cancelTx.confirmations.size const canExecuteCancel = nonce === tx.nonce @@ -59,12 +60,12 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { - + Hash: {tx.executionTxHash ? : 'n/a'} - {INCOMING_TX_TYPES[tx.type] ? null : ( + {!isIncomingTx && ( Nonce: {tx.nonce} @@ -74,7 +75,7 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { Fee: {tx.fee ? tx.fee : 'n/a'} - {INCOMING_TX_TYPES[tx.type] ? ( + {isIncomingTx ? ( <> Created: @@ -113,9 +114,9 @@ const ExpandedTx = ({ cancelTx, tx }: Props) => { )} - {INCOMING_TX_TYPES[tx.type] ? : } + {isIncomingTx ? : } - {!INCOMING_TX_TYPES[tx.type] && ( + {!isIncomingTx && ( Date: Mon, 27 Apr 2020 09:25:43 -0300 Subject: [PATCH 12/14] refactor: rename `whenTxsValues` in favor of `txsTokenInfo` --- src/routes/safe/store/actions/fetchTransactions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/routes/safe/store/actions/fetchTransactions.js b/src/routes/safe/store/actions/fetchTransactions.js index 9bcc5c41c1..267b5c3cd1 100644 --- a/src/routes/safe/store/actions/fetchTransactions.js +++ b/src/routes/safe/store/actions/fetchTransactions.js @@ -230,7 +230,7 @@ const addMockSafeCreationTx = (safeAddress): Array => [ const batchRequestTxsData = (txs: any[]) => { const web3Batch = new web3.BatchRequest() - const whenTxsValues = txs.map((tx) => { + const txsTokenInfo = txs.map((tx) => { const methods = [{ method: 'getCode', type: 'eth', args: [tx.to] }, 'decimals', 'name', 'symbol'] return generateBatchRequests({ abi: ERC20Detailed.abi, @@ -243,7 +243,7 @@ const batchRequestTxsData = (txs: any[]) => { web3Batch.execute() - return Promise.all(whenTxsValues) + return Promise.all(txsTokenInfo) } const batchRequestIncomingTxsData = (txs: IncomingTxServiceModel[]) => { From 61c54cedc6ee10f95a4ce0437ad9b27d54d00f9b Mon Sep 17 00:00:00 2001 From: fernandomg Date: Mon, 27 Apr 2020 10:13:05 -0300 Subject: [PATCH 13/14] refactor: rename `precise` in favor of `usePrecise` --- .../safe/components/Transactions/TxsTable/columns.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index e85b2e3cac..d0fb512251 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -41,24 +41,24 @@ type TxValues = { const NOT_AVAILABLE = 'n/a' -const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, precise = false) => { +const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, usePrecise = false) => { const nonFormattedValue = BigNumber(value).times(`1e-${decimals}`).toFixed() - const finalValue = precise ? formatAmount(nonFormattedValue).toString() : nonFormattedValue + const finalValue = usePrecise ? formatAmount(nonFormattedValue).toString() : nonFormattedValue const txAmount = finalValue === 'NaN' ? NOT_AVAILABLE : finalValue return `${txAmount} ${symbol}` } -export const getIncomingTxAmount = (tx: IncomingTransaction, precise: boolean = true) => { +export const getIncomingTxAmount = (tx: IncomingTransaction, usePrecise: boolean = true) => { // simple workaround to avoid displaying unexpected values for incoming NFT transfer if (INCOMING_TX_TYPES[tx.type] === INCOMING_TX_TYPES.ERC721_TRANSFER) { return `1 ${tx.symbol}` } - return getAmountWithSymbol(tx, precise) + return getAmountWithSymbol(tx, usePrecise) } -export const getTxAmount = (tx: Transaction, precise: boolean = true) => { +export const getTxAmount = (tx: Transaction, usePrecise: boolean = true) => { const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx const { value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx @@ -66,7 +66,7 @@ export const getTxAmount = (tx: Transaction, precise: boolean = true) => { return NOT_AVAILABLE } - return getAmountWithSymbol({ decimals, symbol, value }, precise) + return getAmountWithSymbol({ decimals, symbol, value }, usePrecise) } export type TransactionRow = SortRow From 00a8c02433986604c3155ece86a8f9656ef6b4de Mon Sep 17 00:00:00 2001 From: fernandomg Date: Mon, 27 Apr 2020 10:34:33 -0300 Subject: [PATCH 14/14] refactor: rename `usePrecise` in favor of `formatted` --- .../safe/components/Transactions/TxsTable/columns.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/columns.js b/src/routes/safe/components/Transactions/TxsTable/columns.js index d0fb512251..b6d47de14e 100644 --- a/src/routes/safe/components/Transactions/TxsTable/columns.js +++ b/src/routes/safe/components/Transactions/TxsTable/columns.js @@ -41,24 +41,24 @@ type TxValues = { const NOT_AVAILABLE = 'n/a' -const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, usePrecise = false) => { +const getAmountWithSymbol = ({ decimals = 0, symbol = NOT_AVAILABLE, value }: TxValues, formatted = false) => { const nonFormattedValue = BigNumber(value).times(`1e-${decimals}`).toFixed() - const finalValue = usePrecise ? formatAmount(nonFormattedValue).toString() : nonFormattedValue + const finalValue = formatted ? formatAmount(nonFormattedValue).toString() : nonFormattedValue const txAmount = finalValue === 'NaN' ? NOT_AVAILABLE : finalValue return `${txAmount} ${symbol}` } -export const getIncomingTxAmount = (tx: IncomingTransaction, usePrecise: boolean = true) => { +export const getIncomingTxAmount = (tx: IncomingTransaction, formatted: boolean = true) => { // simple workaround to avoid displaying unexpected values for incoming NFT transfer if (INCOMING_TX_TYPES[tx.type] === INCOMING_TX_TYPES.ERC721_TRANSFER) { return `1 ${tx.symbol}` } - return getAmountWithSymbol(tx, usePrecise) + return getAmountWithSymbol(tx, formatted) } -export const getTxAmount = (tx: Transaction, usePrecise: boolean = true) => { +export const getTxAmount = (tx: Transaction, formatted: boolean = true) => { const { decimals = 18, decodedParams, isTokenTransfer, symbol } = tx const { value } = isTokenTransfer && decodedParams && decodedParams.value ? decodedParams : tx @@ -66,7 +66,7 @@ export const getTxAmount = (tx: Transaction, usePrecise: boolean = true) => { return NOT_AVAILABLE } - return getAmountWithSymbol({ decimals, symbol, value }, usePrecise) + return getAmountWithSymbol({ decimals, symbol, value }, formatted) } export type TransactionRow = SortRow