Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IconText, Text } from '@gnosis.pm/safe-react-components'
import { IconText, Text, EthHashInfo } from '@gnosis.pm/safe-react-components'
import { makeStyles } from '@material-ui/core/styles'
import React from 'react'
import styled from 'styled-components'
Expand All @@ -12,8 +12,6 @@ import {
MultiSendDetails,
} from 'src/routes/safe/store/actions/transactions/utils/multiSendDecodedDetails'
import Bold from 'src/components/layout/Bold'
import OwnerAddressTableCell from 'src/routes/safe/components/Settings/ManageOwners/OwnerAddressTableCell'
import EtherscanLink from 'src/components/EtherscanLink'
import { humanReadableValue } from 'src/logic/tokens/utils/humanReadableValue'
import Collapse from 'src/components/Collapse'
import { useSelector } from 'react-redux'
Expand All @@ -24,6 +22,8 @@ import { shortVersionOf } from 'src/logic/wallets/ethAddresses'
import { Transaction } from 'src/logic/safe/store/models/types/transaction'
import { DataDecoded } from 'src/routes/safe/store/models/types/transactions.d'
import DividerLine from 'src/components/DividerLine'
import { isArrayParameter } from 'src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/utils'
import { getNetwork } from 'src/config'

export const TRANSACTIONS_DESC_CUSTOM_VALUE_TEST_ID = 'tx-description-custom-value'
export const TRANSACTIONS_DESC_CUSTOM_DATA_TEST_ID = 'tx-description-custom-data'
Expand All @@ -34,9 +34,14 @@ const useStyles = makeStyles(styles)
const TxDetailsMethodName = styled(Text)`
text-indent: 4px;
`
const TxDetailsMethodParam = styled.div`
text-indent: 8px;
display: flex;
const TxDetailsMethodParam = styled.div<{ isArrayParameter: boolean }>`
padding-left: 8px;
display: ${({ isArrayParameter }) => (isArrayParameter ? 'block' : 'flex')};
align-items: center;

p:first-of-type {
margin-right: ${({ isArrayParameter }) => (isArrayParameter ? '0' : '4px')};
}
`
const TxDetailsContent = styled.div`
padding: 8px 8px 8px 16px;
Expand All @@ -46,17 +51,21 @@ const TxInfo = styled.div`
padding: 8px 8px 8px 16px;
`

const StyledMethodName = styled(Text)`
white-space: nowrap;
`

const TxInfoDetails = ({ data }: { data: DataDecoded }): React.ReactElement => (
<TxInfo>
<TxDetailsMethodName size="lg" strong>
{data.method}
</TxDetailsMethodName>

{data.parameters.map((param, index) => (
<TxDetailsMethodParam key={`${data.method}_param-${index}`}>
<Text size="lg" strong>
<TxDetailsMethodParam key={`${data.method}_param-${index}`} isArrayParameter={isArrayParameter(param.type)}>
<StyledMethodName size="lg" strong>
{param.name}({param.type}):
</Text>
</StyledMethodName>
<Value method={data.method} type={param.type} value={param.value} />
</TxDetailsMethodParam>
))}
Expand All @@ -76,7 +85,7 @@ const MultiSendCustomDataAction = ({ tx, order }: { tx: MultiSendDetails; order:
<TxDetailsContent>
<TxInfo>
<Bold>Send {humanReadableValue(tx.value)} ETH to:</Bold>
<OwnerAddressTableCell address={tx.to} showLinks />
<EthHashInfo hash={tx.to} showIdenticon showCopyBtn showEtherscanBtn network={getNetwork()} />
</TxInfo>

{!!tx.data && <TxInfoDetails data={tx.data} />}
Expand Down Expand Up @@ -173,11 +182,15 @@ const GenericCustomData = ({ amount = '0', data, recipient, storedTx }: GenericC
<Block>
<Block data-testid={TRANSACTIONS_DESC_CUSTOM_VALUE_TEST_ID}>
<Bold>Send {amount} to:</Bold>
{recipientName ? (
<OwnerAddressTableCell address={recipient} knownAddress showLinks userName={recipientName} />
) : (
<EtherscanLink knownAddress={false} type="address" value={recipient} />
)}

<EthHashInfo
hash={recipient}
name={recipientName === 'UNKNOWN' ? undefined : recipientName}
showIdenticon
showCopyBtn
showEtherscanBtn
network={getNetwork()}
/>
</Block>

{!!storedTx?.dataDecoded && <TxActionData dataDecoded={storedTx.dataDecoded} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { Text } from '@gnosis.pm/safe-react-components'
import { makeStyles } from '@material-ui/core/styles'
import { Text, EthHashInfo } from '@gnosis.pm/safe-react-components'
import React from 'react'
import styled from 'styled-components'

import { styles } from './styles'

import { getNetwork } from 'src/config'
import {
isAddress,
isArrayParameter,
} from 'src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/utils'
import { useWindowDimensions } from 'src/logic/hooks/useWindowDimensions'
import SafeEtherscanLink from 'src/components/EtherscanLink'

const useStyles = makeStyles(styles)

const NestedWrapper = styled.div`
text-indent: 24px;
padding-left: 4px;
`

const StyledText = styled(Text)`
Expand All @@ -28,53 +22,38 @@ interface RenderValueProps {
value: string | string[]
}

const EtherscanLink = ({ method, type, value }: RenderValueProps): React.ReactElement => {
const classes = useStyles()
const [cut, setCut] = React.useState(0)
const { width } = useWindowDimensions()

React.useEffect(() => {
if (width <= 900) {
setCut(4)
} else if (width <= 1024) {
setCut(8)
} else {
setCut(12)
}
}, [width])
const GenericValue = ({ method, type, value }: RenderValueProps): React.ReactElement => {
const getTextValue = (value: string) => <StyledText size="lg">{value}</StyledText>

if (isArrayParameter(type)) {
return (
const getArrayValue = (parentId: string, value: string[] | string) => (
<div>
[
<NestedWrapper>
{(value as string[]).map((value, index) => (
<SafeEtherscanLink type="address" key={`${method}-value-${index}`} cut={cut} value={value} />
))}
{(value as string[]).map((currentValue, index) => {
const key = `${parentId}-value-${index}`
return (
<div key={key}>
{Array.isArray(currentValue) ? getArrayValue(key, currentValue) : getTextValue(currentValue)}
</div>
)
})}
</NestedWrapper>
)
}

return <SafeEtherscanLink type="address" className={classes.address} cut={cut} value={value as string} />
}
]
</div>
)

const GenericValue = ({ method, type, value }: RenderValueProps): React.ReactElement => {
if (isArrayParameter(type)) {
return (
<NestedWrapper>
{(value as string[]).map((value, index) => (
<StyledText key={`${method}-value-${index}`} size="lg">
{value}
</StyledText>
))}
</NestedWrapper>
)
if (isArrayParameter(type) || Array.isArray(value)) {
return getArrayValue(method, value)
}

return <StyledText size="lg">{value as string}</StyledText>
return getTextValue(value as string)
}

const Value = ({ type, ...props }: RenderValueProps): React.ReactElement => {
if (isAddress(type)) {
return <EtherscanLink type={type} {...props} />
return (
<EthHashInfo hash={props.value as string} showCopyBtn showEtherscanBtn shortenHash={4} network={getNetwork()} />
)
}

return <GenericValue type={type} {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ExpandedTx = ({ cancelTx, tx }: ExpandedTxProps): React.ReactElement => {
<>
<Block className={classes.expandedTxBlock}>
<Row>
<Col layout="column" xs={6}>
<Col layout="column" xs={6} className={classes.col}>
<Block className={cn(classes.txDataContainer, (isIncomingTx || isCreationTx) && classes.incomingTxBlock)}>
<div style={{ display: 'flex' }}>
<Bold className={classes.txHash}>Hash:</Bold>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { border, lg, md } from 'src/theme/variables'

const cssStyles = {
col: {
wordBreak: 'break-word',
whiteSpace: 'normal',
},
expandedTxBlock: {
borderBottom: `2px solid ${border}`,
},
Expand Down