extract getTxData to utils

This commit is contained in:
mmv 2019-07-11 14:39:14 +04:00
parent 7cda208066
commit db1f2ab77f
2 changed files with 46 additions and 22 deletions

View File

@ -6,35 +6,16 @@ import { type Transaction } from '~/routes/safe/store/models/transaction'
import Bold from '~/components/layout/Bold' import Bold from '~/components/layout/Bold'
import Paragraph from '~/components/layout/Paragraph' import Paragraph from '~/components/layout/Paragraph'
import Block from '~/components/layout/Block' import Block from '~/components/layout/Block'
import { getEtherScanLink, getWeb3 } from '~/logic/wallets/getWeb3' import { getEtherScanLink } from '~/logic/wallets/getWeb3'
import { shortVersionOf } from '~/logic/wallets/ethAddresses' import { shortVersionOf } from '~/logic/wallets/ethAddresses'
import { md, lg, secondary } from '~/theme/variables' import { md, lg, secondary } from '~/theme/variables'
import { getTxData } from './utils'
const web3 = getWeb3()
const { toBN, fromWei } = web3.utils
const openIconStyle = { const openIconStyle = {
height: '13px', height: '13px',
color: secondary, color: secondary,
} }
const getTxData = (tx: Transaction) => {
const txData = {}
if (tx.isTokenTransfer && tx.decodedParams) {
txData.recipient = tx.decodedParams.recipient
txData.value = fromWei(toBN(tx.decodedParams.value), 'ether')
} else if (Number(tx.value) > 0) {
txData.recipient = tx.recipient
txData.value = fromWei(toBN(tx.value), 'ether')
} else if (tx.modifySettingsTx) {
txData.recipient = tx.recipient
txData.modifySettingsTx = true
}
return txData
}
export const styles = () => ({ export const styles = () => ({
txDataContainer: { txDataContainer: {
padding: `${lg} ${md}`, padding: `${lg} ${md}`,
@ -47,7 +28,9 @@ type Props = {
} }
const TxDescription = ({ tx, classes }: Props) => { const TxDescription = ({ tx, classes }: Props) => {
const { recipient, value, modifySettingsTx } = getTxData(tx) const {
recipient, value, modifySettingsTx, replacedOwner, removedOwner, addedOwner, newThreshold,
} = getTxData(tx)
return ( return (
<Block className={classes.txDataContainer}> <Block className={classes.txDataContainer}>

View File

@ -0,0 +1,41 @@
// @flow
import { type Transaction } from '~/routes/safe/store/models/transaction'
import { getWeb3 } from '~/logic/wallets/getWeb3'
const web3 = getWeb3()
const { toBN, fromWei } = web3.utils
export const getTxData = (tx: Transaction) => {
const txData = {}
if (tx.isTokenTransfer && tx.decodedParams) {
txData.recipient = tx.decodedParams.recipient
txData.value = fromWei(toBN(tx.decodedParams.value), 'ether')
} else if (Number(tx.value) > 0) {
txData.recipient = tx.recipient
txData.value = fromWei(toBN(tx.value), 'ether')
} else if (tx.modifySettingsTx) {
txData.recipient = tx.recipient
txData.modifySettingsTx = true
if (tx.decodedParams) {
/* eslint-disable */
if (tx.decodedParams.methodName === 'removeOwner') {
txData.removedOwner = tx.decodedParams.args[1]
txData.newThreshold = tx.decodedParams.args[2]
} else if (tx.decodedParams.methodName === 'changeThreshold') {
txData.newThreshold = tx.decodedParams.args[0]
} else if (tx.decodedParams.methodName === 'addOWnerWithThreshold') {
txData.addedOwner = tx.decodedParams.args[1]
txData.newThreshold = tx.decodedParams.args[1]
} else if (tx.decodedParams.methodName === 'swapOwner') {
txData.replacedOwner = tx.decodedParams.args[0]
txData.removedOwner = tx.decodedParams.args[1]
txData.newThreshold = tx.decodedParams.args[2]
}
/* eslint-enable */
}
}
return txData
}