Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Components support eip3770 prefixes #2896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8d7d3ee
Create hook to return the prefixed address as per settings
Oct 26, 2021
9e256b3
Apply appearence settings on Sidebar header
Oct 26, 2021
a39cf15
Bump @gnosis.pm/safe-react-components to use latest EthHashInfo
Oct 28, 2021
aee9dd2
Add EthHashInfo wrapper component for shortName settings
Oct 28, 2021
9a9e79d
Use PrefixedEthHashInfo component in the Appearance settings page
Oct 28, 2021
a45999b
Replace EthHashInfo for the wrapper in the Safe owner management options
Oct 29, 2021
b1b0632
Replace EthHashInfo for the wrapper in the Balances modal's send screens
Oct 29, 2021
644b2ad
Replace EthHashInfo for its wrapper in the Advanced Settings and Spen…
Oct 29, 2021
b53afb3
Replace EthHashInfo for its wrapper PrefixedEthHashInfo
Oct 29, 2021
5e9dbd9
Remove unnecessarily introduced hook
Oct 29, 2021
2dd13f3
Implement InlineEthHashInfo from the EthHashInfo wrapper
Oct 29, 2021
c44d55d
Use lib component props and avoid duplication
Oct 29, 2021
98b2b7a
Add test for PrefixedEthHashInfo component
Nov 1, 2021
01e7fca
Fix "<p> cannot appear as a descendant of <p>" warning
Nov 1, 2021
c07aa71
Unset font-weight in PrefixedEthHashInfo when it is inline.
Nov 1, 2021
9e38627
Rename PrefixedEthHashInfo inline styled component in TxList
Nov 1, 2021
82624fb
Do not display chain shortName in AddressBook addresses
Nov 1, 2021
8261959
Use PrefixedEthHashInfo displaying addresses for the sake of consistency
Nov 8, 2021
7df7897
Merge branch 'dev' into components-support-eip3770-prefixes
DiogoSoaress Nov 8, 2021
0520004
Merge branch 'dev' into components-support-eip3770-prefixes
Nov 10, 2021
cb51b39
Pass chainName prop to the EthHashInfo in the SafeListSideBar
Nov 10, 2021
572817e
Remove temporarly condition to not toggle prefixed addresses in PROD
Nov 15, 2021
d01319c
Merge branch 'feature/eip-3770-prefixes' into components-support-eip3…
Nov 16, 2021
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"@gnosis.pm/safe-apps-sdk-v1": "npm:@gnosis.pm/safe-apps-sdk@0.4.2",
"@gnosis.pm/safe-core-sdk": "^0.3.1",
"@gnosis.pm/safe-deployments": "^1.2.0",
"@gnosis.pm/safe-react-components": "^0.8.0",
"@gnosis.pm/safe-react-components": "^0.8.5",
"@gnosis.pm/safe-react-gateway-sdk": "^2.4.0",
"@ledgerhq/hw-transport-node-hid-singleton": "6.3.0",
"@material-ui/core": "^4.12.3",
Expand Down
17 changes: 7 additions & 10 deletions src/components/App/ReceiveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ import QRCode from 'qrcode.react'
import { ChangeEvent, ReactElement, useState } from 'react'
import FormControlLabel from '@material-ui/core/FormControlLabel/FormControlLabel'
import Checkbox from '@material-ui/core/Checkbox/Checkbox'
import { EthHashInfo } from '@gnosis.pm/safe-react-components'
import { useSelector } from 'react-redux'

import Block from 'src/components/layout/Block'
import Col from 'src/components/layout/Col'
import Hairline from 'src/components/layout/Hairline'
import Paragraph from 'src/components/layout/Paragraph'
import Row from 'src/components/layout/Row'
import PrefixedEthHashInfo from '../PrefixedEthHashInfo'
import { border, fontColor, lg, md, screenSm, secondaryText } from 'src/theme/variables'
import { getExplorerInfo, getNetworkInfo } from 'src/config'
import { NetworkSettings } from 'src/config/networks/network'
import { copyShortNameSelector } from 'src/logic/appearance/selectors'
import { getPrefixedSafeAddressSlug } from 'src/routes/routes'
import { IS_PRODUCTION } from 'src/utils/constants'

const useStyles = (networkInfo: NetworkSettings) =>
makeStyles(
Expand Down Expand Up @@ -86,7 +85,7 @@ const ReceiveModal = ({ onClose, safeAddress, safeName }: Props): ReactElement =
const classes = useStyles(networkInfo)

const copyShortName = useSelector(copyShortNameSelector)
const [shouldCopyShortName, setShouldCopyShortName] = useState<boolean>(IS_PRODUCTION ? false : copyShortName)
const [shouldCopyShortName, setShouldCopyShortName] = useState<boolean>(copyShortName)

// Does not update store
const handleCopyChange = (_: ChangeEvent<HTMLInputElement>, checked: boolean) => setShouldCopyShortName(checked)
Expand Down Expand Up @@ -117,14 +116,12 @@ const ReceiveModal = ({ onClose, safeAddress, safeName }: Props): ReactElement =
<Block className={classes.qrContainer}>
<QRCode size={135} value={qrCodeString} />
</Block>
{!IS_PRODUCTION && (
<FormControlLabel
control={<Checkbox checked={shouldCopyShortName} onChange={handleCopyChange} name="shouldCopyShortName" />}
label="Copy addresses with chain prefix."
/>
)}
<FormControlLabel
control={<Checkbox checked={shouldCopyShortName} onChange={handleCopyChange} name="shouldCopyShortName" />}
label="Copy addresses with chain prefix."
/>
<Block className={classes.addressContainer} justify="center">
<EthHashInfo hash={safeAddress} showAvatar showCopyBtn explorerUrl={getExplorerInfo(safeAddress)} />
<PrefixedEthHashInfo hash={safeAddress} showAvatar showCopyBtn explorerUrl={getExplorerInfo(safeAddress)} />
</Block>
</Col>
<Hairline />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import styled from 'styled-components'
import { makeStyles } from '@material-ui/core/styles'
import { EthHashInfo, Identicon, Card } from '@gnosis.pm/safe-react-components'
import { Identicon, Card } from '@gnosis.pm/safe-react-components'
import { createStyles } from '@material-ui/core'

import Spacer from 'src/components/Spacer'
Expand All @@ -11,6 +11,7 @@ import Hairline from 'src/components/layout/Hairline'
import Img from 'src/components/layout/Img'
import Paragraph from 'src/components/layout/Paragraph'
import Row from 'src/components/layout/Row'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { background, connected as connectedBg, lg, md, sm, warning, xs } from 'src/theme/variables'
import { getExplorerInfo } from 'src/config'
import { KeyRing } from 'src/components/AppLayout/Header/components/KeyRing'
Expand Down Expand Up @@ -129,7 +130,7 @@ export const UserDetails = ({
</Row>
<Block className={classes.user} justify="center">
{userAddress ? (
<EthHashInfo hash={userAddress} showCopyBtn explorerUrl={explorerUrl} shortenHash={4} />
<PrefixedEthHashInfo hash={userAddress} showCopyBtn explorerUrl={explorerUrl} shortenHash={4} />
) : (
'Address not available'
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { makeStyles } from '@material-ui/core/styles'
import * as React from 'react'
import { useSelector } from 'react-redux'
import { EthHashInfo, Text } from '@gnosis.pm/safe-react-components'
import { Text } from '@gnosis.pm/safe-react-components'

import Col from 'src/components/layout/Col'
import Paragraph from 'src/components/layout/Paragraph'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import WalletIcon from '../WalletIcon'
import { connected as connectedBg, screenSm, sm } from 'src/theme/variables'
import { KeyRing } from 'src/components/AppLayout/Header/components/KeyRing'
Expand Down Expand Up @@ -91,7 +92,7 @@ const ProviderInfo = ({ connected, provider, userAddress }: ProviderInfoProps):
</Paragraph>
<div className={classes.providerContainer}>
{connected ? (
<EthHashInfo
<PrefixedEthHashInfo
hash={userAddress}
shortenHash={4}
showAvatar
Expand Down
20 changes: 13 additions & 7 deletions src/components/AppLayout/Sidebar/SafeHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from 'styled-components'
import { useSelector } from 'react-redux'
import {
Icon,
FixedIcon,
EthHashInfo,
Text,
Identicon,
Button,
Expand All @@ -12,9 +12,12 @@ import {

import ButtonHelper from 'src/components/ButtonHelper'
import FlexSpacer from 'src/components/FlexSpacer'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { getExplorerInfo, getNetworkInfo } from 'src/config'
import { NetworkSettings } from 'src/config/networks/network.d'
import { border, fontColor } from 'src/theme/variables'
import { copyShortNameSelector } from 'src/logic/appearance/selectors'
import { extractShortChainName } from 'src/routes/routes'

export const TOGGLE_SIDEBAR_BTN_TESTID = 'TOGGLE_SIDEBAR_BTN'

Expand Down Expand Up @@ -77,13 +80,13 @@ const StyledTextLabel = styled(Text)`
background-color: ${(props: StyledTextLabelProps) => props.networkInfo?.backgroundColor ?? border};
`

const StyldTextSafeName = styled(Text)`
const StyledTextSafeName = styled(Text)`
width: 90%;
overflow: hidden;
text-overflow: ellipsis;
`

const StyledEthHashInfo = styled(EthHashInfo)`
const StyledPrefixedEthHashInfo = styled(PrefixedEthHashInfo)`
p {
color: ${({ theme }) => theme.colors.placeHolder};
font-size: 14px;
Expand Down Expand Up @@ -123,6 +126,9 @@ const SafeHeader = ({
onReceiveClick,
onNewTransactionClick,
}: Props): React.ReactElement => {
const copyChainPrefix = useSelector(copyShortNameSelector)
const shortName = extractShortChainName()

if (!address) {
return (
<Container>
Expand Down Expand Up @@ -157,15 +163,15 @@ const SafeHeader = ({
</IdenticonContainer>

{/* SafeInfo */}
<StyldTextSafeName size="lg" center>
<StyledTextSafeName size="lg" center>
{safeName}
</StyldTextSafeName>
<StyledEthHashInfo hash={address} shortenHash={4} textSize="sm" />
</StyledTextSafeName>
<StyledPrefixedEthHashInfo hash={address} shortenHash={4} textSize="sm" />
<IconContainer>
<ButtonHelper onClick={onReceiveClick}>
<Icon size="sm" type="qrCode" tooltip="Show QR" />
</ButtonHelper>
<CopyToClipboardBtn textToCopy={address} />
<CopyToClipboardBtn textToCopy={copyChainPrefix ? `${shortName}:${address}` : `${address}`} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CopyToClipboardBtn is used in two other places, should we also create a wrapper for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was implementing a wrapper for it called CopyAddressToClipboardBtn but the CopyToClipboardBtn is only copying an address in the SafeHeader component.
Screen Shot 2021-11-01 at 11 16 34
Is it worthy to implement the wrapper afterall?

<ExplorerButton explorerUrl={explorerUrl} />
</IconContainer>

Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomIconText/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EthHashInfo } from '@gnosis.pm/safe-react-components'
import { ReactElement } from 'react'
import PrefixedEthHashInfo from '../PrefixedEthHashInfo'

type Props = {
address: string
Expand All @@ -9,7 +9,7 @@ type Props = {
}

export const CustomIconText = ({ address, iconUrl, text, iconUrlFallback }: Props): ReactElement => (
<EthHashInfo
<PrefixedEthHashInfo
hash={address}
showHash={false}
avatarSize="sm"
Expand Down
7 changes: 4 additions & 3 deletions src/components/DecodeTxs/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ReactElement } from 'react'
import styled from 'styled-components'
import { Transaction } from '@gnosis.pm/safe-apps-sdk-v1'
import { Text, EthHashInfo, CopyToClipboardBtn, IconText, FixedIcon } from '@gnosis.pm/safe-react-components'
import { Text, CopyToClipboardBtn, IconText, FixedIcon } from '@gnosis.pm/safe-react-components'
import get from 'lodash.get'
import { hexToBytes } from 'web3-utils'

import { getExplorerInfo, getNetworkInfo } from 'src/config'
import { DecodedData, DecodedDataBasicParameter, DecodedDataParameterValue } from 'src/types/transactions/decode.d'
import { DecodedTxDetail } from 'src/routes/safe/components/Apps/components/ConfirmTxModal'
import PrefixedEthHashInfo from '../PrefixedEthHashInfo'

const FlexWrapper = styled.div<{ margin: number }>`
display: flex;
Expand Down Expand Up @@ -84,7 +85,7 @@ export const BasicTxInfo = ({
<Text size="lg" strong>
{`Send ${txValue} ${nativeCoin.symbol} to:`}
</Text>
<EthHashInfo
<PrefixedEthHashInfo
hash={txRecipient}
showAvatar
textSize="lg"
Expand Down Expand Up @@ -112,7 +113,7 @@ export const getParameterElement = (parameter: DecodedDataBasicParameter, index:

if (parameter.type === 'address') {
valueElement = (
<EthHashInfo
<PrefixedEthHashInfo
hash={parameter.value}
showAvatar
textSize="lg"
Expand Down
39 changes: 39 additions & 0 deletions src/components/PrefixedEthHashInfo/index.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import PrefixedEthHashInfo from '.'
import { render, screen } from 'src/utils/test-utils'

const hash = '0x69904ff6d6100799344E5C9A2806936318F6ba4f'
jest.mock('src/routes/routes', () => {
const original = jest.requireActual('src/routes/routes')
return {
...original,
extractShortChainName: () => 'arb',
}
})

describe('<PrefixedEthHashInfo>', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not also add a test to check that copying also works?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The copy functionality is abstracted by the SRC components so I am not sure how to test it... I am trying to assert the clipboard content but I don't think we should be testing that in safe-react. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Answering the comment) I think I have covered all the address visualizations in the UI. The ones I haven't prefixed I comment in #2896 (comment) . Said this, I will ask QA to help me spotting any edge case that I might have missed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could still render the component, click copy and see what is in the clipboard, no? Did you test it in SRC?

it('Renders PrefixedEthHashInfo without shortName', () => {
const customState = {
appearance: {
showShortName: false,
},
}

render(<PrefixedEthHashInfo hash={hash} />, customState)

expect(screen.queryByText('arb:')).not.toBeInTheDocument()
expect(screen.getByText(hash)).toBeInTheDocument()
})

it('Renders PrefixedEthHashInfo with shortName', () => {
const customState = {
appearance: {
showShortName: true,
},
}

render(<PrefixedEthHashInfo hash={hash} />, customState)

expect(screen.queryByText('arb:')).toBeInTheDocument()
expect(screen.getByText(hash)).toBeInTheDocument()
})
})
24 changes: 24 additions & 0 deletions src/components/PrefixedEthHashInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { EthHashInfo } from '@gnosis.pm/safe-react-components'
import { ReactElement } from 'react'
import { useSelector } from 'react-redux'
import { copyShortNameSelector, showShortNameSelector } from 'src/logic/appearance/selectors'
import { extractShortChainName } from 'src/routes/routes'

type Props = Omit<Parameters<typeof EthHashInfo>[0], 'shouldShowShortName' | 'shouldCopyShortName'>

const PrefixedEthHashInfo = ({ hash, ...rest }: Props): ReactElement => {
const showChainPrefix = useSelector(showShortNameSelector)
const copyChainPrefix = useSelector(copyShortNameSelector)

return (
<EthHashInfo
hash={hash}
shortName={extractShortChainName()}
shouldShowShortName={showChainPrefix}
shouldCopyShortName={copyChainPrefix}
{...rest}
/>
)
}

export default PrefixedEthHashInfo
8 changes: 5 additions & 3 deletions src/components/SafeListSidebar/SafeList/SafeListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EthHashInfo, Text, Icon } from '@gnosis.pm/safe-react-components'
import { Text, Icon } from '@gnosis.pm/safe-react-components'
import { useEffect, useRef, ReactElement } from 'react'
import { useHistory } from 'react-router'
import ListItem from '@material-ui/core/ListItem/ListItem'
Expand All @@ -7,6 +7,7 @@ import styled from 'styled-components'

import { sameAddress } from 'src/logic/wallets/ethAddresses'
import Link from 'src/components/layout/Link'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { formatAmount } from 'src/logic/tokens/utils/formatAmount'
import { useSelector } from 'react-redux'
import { addressBookName } from 'src/logic/addressBook/store/selectors'
Expand All @@ -26,7 +27,7 @@ const StyledIcon = styled(Icon)<{ checked: boolean }>`
${({ checked }) => (checked ? { marginRight: '4px' } : { visibility: 'hidden', width: '28px' })}
`

const StyledEthHashInfo = styled(EthHashInfo)`
const StyledPrefixedEthHashInfo = styled(PrefixedEthHashInfo)`
& > div > p:first-of-type {
width: 210px;
white-space: nowrap;
Expand Down Expand Up @@ -61,6 +62,7 @@ const SafeListItem = ({
const safeRef = useRef<HTMLDivElement>(null)
const nativeCoinSymbol = getNetworkConfigById(networkId)?.network?.nativeCoin?.symbol ?? 'ETH'
const showAddSafeLink = !isSafeAdded(loadedSafes, address)
const shortName = getShortChainNameById(networkId)

useEffect(() => {
if (isCurrentSafe && shouldScrollToSafe) {
Expand All @@ -86,7 +88,7 @@ const SafeListItem = ({
return (
<ListItem button onClick={handleOpenSafe} ref={safeRef}>
<StyledIcon type="check" size="md" color="primary" checked={isCurrentSafe} />
<StyledEthHashInfo hash={address} name={safeName} showAvatar shortenHash={4} />
<StyledPrefixedEthHashInfo hash={address} name={safeName} shortName={shortName} showAvatar shortenHash={4} />
<ListItemSecondaryAction>
{ethBalance ? (
`${formatAmount(ethBalance)} ${nativeCoinSymbol}`
Expand Down
6 changes: 3 additions & 3 deletions src/routes/CreateSafePage/steps/ReviewNewSafeStep.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { ReactElement, useEffect } from 'react'
import { useForm } from 'react-final-form'
import { useSelector } from 'react-redux'
import { EthHashInfo } from '@gnosis.pm/safe-react-components'
import styled from 'styled-components'
import TableContainer from '@material-ui/core/TableContainer'

Expand All @@ -22,6 +21,7 @@ import {
import { getExplorerInfo, getNetworkInfo } from 'src/config'
import { useEstimateSafeCreationGas } from 'src/logic/hooks/useEstimateSafeCreationGas'
import NetworkLabel from 'src/components/NetworkLabel/NetworkLabel'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { useStepper } from 'src/components/Stepper/stepperContext'
import { providerNameSelector } from 'src/logic/wallets/store/selectors'

Expand Down Expand Up @@ -114,7 +114,7 @@ function ReviewNewSafeStep(): ReactElement | null {
<React.Fragment key={`owner-${addressFieldName}`}>
<OwnersAddressesContainer>
<Col align="center" xs={12} data-testid={`create-safe-owner-details-${ownerAddress}`}>
<EthHashInfo
<PrefixedEthHashInfo
hash={ownerAddress}
name={ownerName}
showAvatar
Expand Down Expand Up @@ -163,7 +163,7 @@ const OwnersAddressesContainer = styled(Row)`
padding-left: ${lg};
`
const DescriptionContainer = styled(Row)`
background-colo: ${background};
background-color: ${background};
padding: ${lg};
text-align: center;
`
4 changes: 2 additions & 2 deletions src/routes/LoadSafePage/steps/LoadSafeOwnersStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ReactElement } from 'react'
import { useForm } from 'react-final-form'
import styled from 'styled-components'
import TableContainer from '@material-ui/core/TableContainer'
import { EthHashInfo } from '@gnosis.pm/safe-react-components'

import Block from 'src/components/layout/Block'
import Col from 'src/components/layout/Col'
Expand All @@ -11,6 +10,7 @@ import Paragraph from 'src/components/layout/Paragraph'
import Row from 'src/components/layout/Row'
import Field from 'src/components/forms/Field'
import TextField from 'src/components/forms/TextField'
import PrefixedEthHashInfo from 'src/components/PrefixedEthHashInfo'
import { disabled, extraSmallFontSize, lg, md, sm } from 'src/theme/variables'
import { minMaxLength } from 'src/components/forms/validator'
import { getExplorerInfo } from 'src/config'
Expand Down Expand Up @@ -56,7 +56,7 @@ function LoadSafeOwnersStep(): ReactElement {
</Col>
<Col xs={8}>
<OwnerAddressContainer>
<EthHashInfo hash={address} showAvatar showCopyBtn explorerUrl={getExplorerInfo(address)} />
<PrefixedEthHashInfo hash={address} showAvatar showCopyBtn explorerUrl={getExplorerInfo(address)} />
</OwnerAddressContainer>
</Col>
</OwnerContainer>
Expand Down
Loading