mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-24 16:49:30 +00:00
[Address Book v2] 1603 Use addressbook over known addresses (#2352)
* Use ADDRESS_BOOK_DEFAULT_NAME instead of hard coded string * Use address book name in Send Collectible review step * Show name if known in contract interaction review * Use string comparison util
This commit is contained in:
parent
0d915a6bc1
commit
e58b6d6b7b
@ -7,6 +7,9 @@ import { push } from 'connected-react-router'
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useDispatch, useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
|
|
||||||
|
import { sameString } from 'src/utils/strings'
|
||||||
|
import { ADDRESS_BOOK_DEFAULT_NAME } from 'src/logic/addressBook/model/addressBook'
|
||||||
|
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
||||||
import { SAFELIST_ADDRESS } from 'src/routes/routes'
|
import { SAFELIST_ADDRESS } from 'src/routes/routes'
|
||||||
import { safeParamAddressFromStateSelector } from 'src/logic/safe/store/selectors'
|
import { safeParamAddressFromStateSelector } from 'src/logic/safe/store/selectors'
|
||||||
import { xs } from 'src/theme/variables'
|
import { xs } from 'src/theme/variables'
|
||||||
@ -35,13 +38,11 @@ const useStyles = makeStyles(
|
|||||||
|
|
||||||
type EllipsisTransactionDetailsProps = {
|
type EllipsisTransactionDetailsProps = {
|
||||||
address: string
|
address: string
|
||||||
knownAddress?: boolean
|
|
||||||
sendModalOpenHandler?: () => void
|
sendModalOpenHandler?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const EllipsisTransactionDetails = ({
|
export const EllipsisTransactionDetails = ({
|
||||||
address,
|
address,
|
||||||
knownAddress,
|
|
||||||
sendModalOpenHandler,
|
sendModalOpenHandler,
|
||||||
}: EllipsisTransactionDetailsProps): React.ReactElement => {
|
}: EllipsisTransactionDetailsProps): React.ReactElement => {
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
@ -51,6 +52,10 @@ export const EllipsisTransactionDetails = ({
|
|||||||
const currentSafeAddress = useSelector(safeParamAddressFromStateSelector)
|
const currentSafeAddress = useSelector(safeParamAddressFromStateSelector)
|
||||||
const isOwnerConnected = useSelector(grantedSelector)
|
const isOwnerConnected = useSelector(grantedSelector)
|
||||||
|
|
||||||
|
const recipientName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
||||||
|
// We have to check that the name returned is not UNKNOWN
|
||||||
|
const isStoredInAddressBook = !sameString(recipientName, ADDRESS_BOOK_DEFAULT_NAME)
|
||||||
|
|
||||||
const handleClick = (event) => setAnchorEl(event.currentTarget)
|
const handleClick = (event) => setAnchorEl(event.currentTarget)
|
||||||
|
|
||||||
const closeMenuHandler = () => setAnchorEl(null)
|
const closeMenuHandler = () => setAnchorEl(null)
|
||||||
@ -73,7 +78,7 @@ export const EllipsisTransactionDetails = ({
|
|||||||
<Divider key="divider" />,
|
<Divider key="divider" />,
|
||||||
]
|
]
|
||||||
: null}
|
: null}
|
||||||
{knownAddress ? (
|
{isStoredInAddressBook ? (
|
||||||
<MenuItem onClick={addOrEditEntryHandler}>Edit Address book Entry</MenuItem>
|
<MenuItem onClick={addOrEditEntryHandler}>Edit Address book Entry</MenuItem>
|
||||||
) : (
|
) : (
|
||||||
<MenuItem onClick={addOrEditEntryHandler}>Add to address book</MenuItem>
|
<MenuItem onClick={addOrEditEntryHandler}>Add to address book</MenuItem>
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
getValueFromTxInputs,
|
getValueFromTxInputs,
|
||||||
} from 'src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/utils'
|
} from 'src/routes/safe/components/Balances/SendModal/screens/ContractInteraction/utils'
|
||||||
import { useEstimateTransactionGas, EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
|
import { useEstimateTransactionGas, EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
|
||||||
|
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
||||||
import { useEstimationStatus } from 'src/logic/hooks/useEstimationStatus'
|
import { useEstimationStatus } from 'src/logic/hooks/useEstimationStatus'
|
||||||
import { ButtonStatus, Modal } from 'src/components/Modal'
|
import { ButtonStatus, Modal } from 'src/components/Modal'
|
||||||
import { TransactionFees } from 'src/components/TransactionsFees'
|
import { TransactionFees } from 'src/components/TransactionsFees'
|
||||||
@ -60,6 +61,9 @@ const ContractInteractionReview = ({ onClose, onPrev, tx }: Props): React.ReactE
|
|||||||
const [manualSafeTxGas, setManualSafeTxGas] = useState(0)
|
const [manualSafeTxGas, setManualSafeTxGas] = useState(0)
|
||||||
const [manualGasPrice, setManualGasPrice] = useState<string | undefined>()
|
const [manualGasPrice, setManualGasPrice] = useState<string | undefined>()
|
||||||
const [manualGasLimit, setManualGasLimit] = useState<string | undefined>()
|
const [manualGasLimit, setManualGasLimit] = useState<string | undefined>()
|
||||||
|
const addressName = useSelector((state) =>
|
||||||
|
getNameFromAddressBookSelector(state, { address: tx.contractAddress as string }),
|
||||||
|
)
|
||||||
|
|
||||||
const [txInfo, setTxInfo] = useState<{
|
const [txInfo, setTxInfo] = useState<{
|
||||||
txRecipient: string
|
txRecipient: string
|
||||||
@ -154,7 +158,13 @@ const ContractInteractionReview = ({ onClose, onPrev, tx }: Props): React.ReactE
|
|||||||
</Paragraph>
|
</Paragraph>
|
||||||
</Row>
|
</Row>
|
||||||
<Row align="center" margin="md">
|
<Row align="center" margin="md">
|
||||||
<EthHashInfo hash={tx.contractAddress as string} showAvatar showCopyBtn explorerUrl={explorerUrl} />
|
<EthHashInfo
|
||||||
|
hash={tx.contractAddress as string}
|
||||||
|
name={addressName}
|
||||||
|
showAvatar
|
||||||
|
showCopyBtn
|
||||||
|
explorerUrl={explorerUrl}
|
||||||
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
<Row margin="xs">
|
<Row margin="xs">
|
||||||
<Paragraph color="disabled" noMargin size="md" style={{ letterSpacing: '-0.5px' }}>
|
<Paragraph color="disabled" noMargin size="md" style={{ letterSpacing: '-0.5px' }}>
|
||||||
|
@ -35,6 +35,7 @@ const useStyles = makeStyles(styles)
|
|||||||
|
|
||||||
export type CollectibleTx = {
|
export type CollectibleTx = {
|
||||||
recipientAddress: string
|
recipientAddress: string
|
||||||
|
recipientName?: string
|
||||||
assetAddress: string
|
assetAddress: string
|
||||||
assetName: string
|
assetName: string
|
||||||
nftTokenId: string
|
nftTokenId: string
|
||||||
@ -177,6 +178,7 @@ const ReviewCollectible = ({ onClose, onPrev, tx }: Props): React.ReactElement =
|
|||||||
<Col xs={12}>
|
<Col xs={12}>
|
||||||
<EthHashInfo
|
<EthHashInfo
|
||||||
hash={tx.recipientAddress}
|
hash={tx.recipientAddress}
|
||||||
|
name={tx.recipientName}
|
||||||
showAvatar
|
showAvatar
|
||||||
showCopyBtn
|
showCopyBtn
|
||||||
explorerUrl={getExplorerInfo(tx.recipientAddress)}
|
explorerUrl={getExplorerInfo(tx.recipientAddress)}
|
||||||
|
@ -57,6 +57,7 @@ export type SendCollectibleTxInfo = {
|
|||||||
assetName: string
|
assetName: string
|
||||||
nftTokenId: string
|
nftTokenId: string
|
||||||
recipientAddress?: string
|
recipientAddress?: string
|
||||||
|
recipientName?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const SendCollectible = ({
|
const SendCollectible = ({
|
||||||
@ -106,7 +107,7 @@ const SendCollectible = ({
|
|||||||
if (!values.recipientAddress) {
|
if (!values.recipientAddress) {
|
||||||
values.recipientAddress = selectedEntry?.address
|
values.recipientAddress = selectedEntry?.address
|
||||||
}
|
}
|
||||||
|
values.recipientName = selectedEntry?.name
|
||||||
values.assetName = nftAssets[values.assetAddress].name
|
values.assetName = nftAssets[values.assetAddress].name
|
||||||
|
|
||||||
onNext(values)
|
onNext(values)
|
||||||
|
@ -4,6 +4,7 @@ import { useSelector } from 'react-redux'
|
|||||||
|
|
||||||
import { getExplorerInfo } from 'src/config'
|
import { getExplorerInfo } from 'src/config'
|
||||||
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
||||||
|
import { ADDRESS_BOOK_DEFAULT_NAME } from 'src/logic/addressBook/model/addressBook'
|
||||||
import { sameString } from 'src/utils/strings'
|
import { sameString } from 'src/utils/strings'
|
||||||
|
|
||||||
import DataDisplay from './DataDisplay'
|
import DataDisplay from './DataDisplay'
|
||||||
@ -21,7 +22,7 @@ const AddressInfo = ({ address, title }: AddressInfoProps): ReactElement => {
|
|||||||
<DataDisplay title={title}>
|
<DataDisplay title={title}>
|
||||||
<EthHashInfo
|
<EthHashInfo
|
||||||
hash={address}
|
hash={address}
|
||||||
name={sameString(name, 'UNKNOWN') ? undefined : name}
|
name={sameString(name, ADDRESS_BOOK_DEFAULT_NAME) ? undefined : name}
|
||||||
showCopyBtn
|
showCopyBtn
|
||||||
showAvatar
|
showAvatar
|
||||||
textSize="lg"
|
textSize="lg"
|
||||||
|
@ -4,6 +4,8 @@ import { useSelector } from 'react-redux'
|
|||||||
|
|
||||||
import { getExplorerInfo } from 'src/config'
|
import { getExplorerInfo } from 'src/config'
|
||||||
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
||||||
|
import { ADDRESS_BOOK_DEFAULT_NAME } from 'src/logic/addressBook/model/addressBook'
|
||||||
|
import { sameString } from 'src/utils/strings'
|
||||||
|
|
||||||
export const OwnerRow = ({ address }: { address: string }): ReactElement => {
|
export const OwnerRow = ({ address }: { address: string }): ReactElement => {
|
||||||
const ownerName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
const ownerName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
||||||
@ -11,7 +13,7 @@ export const OwnerRow = ({ address }: { address: string }): ReactElement => {
|
|||||||
return (
|
return (
|
||||||
<EthHashInfo
|
<EthHashInfo
|
||||||
hash={address}
|
hash={address}
|
||||||
name={ownerName === 'UNKNOWN' ? '' : ownerName}
|
name={sameString(ownerName, ADDRESS_BOOK_DEFAULT_NAME) ? undefined : ownerName}
|
||||||
showAvatar
|
showAvatar
|
||||||
showCopyBtn
|
showCopyBtn
|
||||||
explorerUrl={getExplorerInfo(address)}
|
explorerUrl={getExplorerInfo(address)}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import React, { ReactElement, useContext, useEffect, useState } from 'react'
|
import React, { ReactElement, useContext, useEffect, useState } from 'react'
|
||||||
import { useSelector } from 'react-redux'
|
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
import { fromTokenUnit } from 'src/logic/tokens/utils/humanReadableValue'
|
import { fromTokenUnit } from 'src/logic/tokens/utils/humanReadableValue'
|
||||||
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
|
||||||
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
|
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
|
||||||
import { Erc721Transfer, Transfer } from 'src/logic/safe/store/models/types/gateway.d'
|
import { Erc721Transfer, Transfer } from 'src/logic/safe/store/models/types/gateway.d'
|
||||||
import { EllipsisTransactionDetails } from 'src/routes/safe/components/AddressBook/EllipsisTransactionDetails'
|
import { EllipsisTransactionDetails } from 'src/routes/safe/components/AddressBook/EllipsisTransactionDetails'
|
||||||
@ -35,9 +33,6 @@ export const TxInfoDetails = ({
|
|||||||
name,
|
name,
|
||||||
avatarUrl,
|
avatarUrl,
|
||||||
}: TxInfoDetailsProps): ReactElement => {
|
}: TxInfoDetailsProps): ReactElement => {
|
||||||
const recipientName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
|
||||||
const knownAddress = recipientName !== 'UNKNOWN'
|
|
||||||
|
|
||||||
const { txLocation } = useContext<TxLocationProps>(TxLocationContext)
|
const { txLocation } = useContext<TxLocationProps>(TxLocationContext)
|
||||||
const canRepeatTransaction =
|
const canRepeatTransaction =
|
||||||
// is transfer type by context
|
// is transfer type by context
|
||||||
@ -89,7 +84,6 @@ export const TxInfoDetails = ({
|
|||||||
<AddressInfo address={address} name={name} avatarUrl={avatarUrl} />
|
<AddressInfo address={address} name={name} avatarUrl={avatarUrl} />
|
||||||
<EllipsisTransactionDetails
|
<EllipsisTransactionDetails
|
||||||
address={address}
|
address={address}
|
||||||
knownAddress={knownAddress}
|
|
||||||
sendModalOpenHandler={canRepeatTransaction ? sendModalOpenHandler : undefined}
|
sendModalOpenHandler={canRepeatTransaction ? sendModalOpenHandler : undefined}
|
||||||
/>
|
/>
|
||||||
</SingleRow>
|
</SingleRow>
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import { useSelector } from 'react-redux'
|
import { useSelector } from 'react-redux'
|
||||||
|
|
||||||
|
import { sameString } from 'src/utils/strings'
|
||||||
|
import { ADDRESS_BOOK_DEFAULT_NAME } from 'src/logic/addressBook/model/addressBook'
|
||||||
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
import { getNameFromAddressBookSelector } from 'src/logic/addressBook/store/selectors'
|
||||||
|
|
||||||
type AddressInfo = { name: string | undefined; image: string | undefined }
|
type AddressInfo = { name: string | undefined; image: string | undefined }
|
||||||
@ -8,8 +10,8 @@ type UseKnownAddressResponse = AddressInfo & { isAddressBook: boolean }
|
|||||||
|
|
||||||
export const useKnownAddress = (address: string, addressInfo: AddressInfo): UseKnownAddressResponse => {
|
export const useKnownAddress = (address: string, addressInfo: AddressInfo): UseKnownAddressResponse => {
|
||||||
const recipientName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
const recipientName = useSelector((state) => getNameFromAddressBookSelector(state, { address }))
|
||||||
|
// We have to check that the name returned is not UNKNOWN
|
||||||
const isInAddressBook = recipientName !== 'UNKNOWN'
|
const isInAddressBook = !sameString(recipientName, ADDRESS_BOOK_DEFAULT_NAME)
|
||||||
|
|
||||||
return isInAddressBook
|
return isInAddressBook
|
||||||
? {
|
? {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user