fix getNameFromAddressBook selector & selector calls
This commit is contained in:
parent
171528d418
commit
0e9b6d2cc1
|
@ -35,15 +35,18 @@ export const getAddressBookListSelector: Selector<GlobalState, {}, List<AddressB
|
|||
},
|
||||
)
|
||||
|
||||
export const getNameFromAddressBook = (userAddress: string): string | null =>
|
||||
createSelector(getAddressBook, (addressBook: AddressBook, address: string) => {
|
||||
export const getNameFromAddressBook = createSelector(
|
||||
getAddressBookListSelector,
|
||||
(_, address) => address,
|
||||
(addressBook: Map<string, AddressBook>, address: string) => {
|
||||
if (!address) {
|
||||
return 'UNKNOWN'
|
||||
}
|
||||
|
||||
const adbkEntry = addressBook.find((addressBookItem) => addressBookItem.address === userAddress)
|
||||
const adbkEntry = addressBook.find((addressBookItem) => addressBookItem.address === address)
|
||||
if (adbkEntry) {
|
||||
return adbkEntry.name
|
||||
}
|
||||
return 'UNKNOWN'
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
|
@ -47,7 +47,7 @@ const TransferDescription = ({ from, txFromName, value = '' }: TransferDescProps
|
|||
|
||||
const IncomingTxDescription = ({ tx }: Props) => {
|
||||
const classes = useStyles()
|
||||
const txFromName = useSelector(getNameFromAddressBook(tx.from))
|
||||
const txFromName = useSelector((state) => getNameFromAddressBook(state, tx.from))
|
||||
return (
|
||||
<Block className={classes.txDataContainer}>
|
||||
<TransferDescription from={tx.from} txFromName={txFromName} value={getIncomingTxAmount(tx)} />
|
||||
|
|
|
@ -57,8 +57,7 @@ const OwnerComponent = ({
|
|||
thresholdReached,
|
||||
userAddress,
|
||||
}: OwnerProps) => {
|
||||
const nameInAdbk = useSelector(getNameFromAddressBook(owner))
|
||||
const ownerName = nameInAdbk || 'UNKNOWN'
|
||||
const nameInAdbk = useSelector((state) => getNameFromAddressBook(state, owner))
|
||||
const [imgCircle, setImgCircle] = React.useState(ConfirmSmallGreyCircle)
|
||||
|
||||
React.useMemo(() => {
|
||||
|
@ -80,7 +79,7 @@ const OwnerComponent = ({
|
|||
<Identicon address={owner} className={classes.icon} diameter={32} />
|
||||
<Block>
|
||||
<Paragraph className={classes.name} noMargin>
|
||||
{ownerName}
|
||||
{nameInAdbk}
|
||||
</Paragraph>
|
||||
<EtherscanLink className={classes.address} cut={4} type="address" value={owner} />
|
||||
</Block>
|
||||
|
@ -140,7 +139,7 @@ const OwnerComponent = ({
|
|||
)}
|
||||
</Block>
|
||||
)}
|
||||
{owner.address === executor && <Block className={classes.executor}>Executor</Block>}
|
||||
{owner === executor && <Block className={classes.executor}>Executor</Block>}
|
||||
</Block>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ type CustomDescProps = {
|
|||
}
|
||||
|
||||
const TransferDescription = ({ amount = '', recipient }: TransferDescProps) => {
|
||||
const recipientName = useSelector(getNameFromAddressBook(recipient))
|
||||
const recipientName = useSelector((state) => getNameFromAddressBook(state, recipient))
|
||||
return (
|
||||
<Block data-testid={TRANSACTIONS_DESC_SEND_TEST_ID}>
|
||||
<Bold>Send {amount} to:</Bold>
|
||||
|
@ -83,7 +83,7 @@ const TransferDescription = ({ amount = '', recipient }: TransferDescProps) => {
|
|||
}
|
||||
|
||||
const RemovedOwner = ({ removedOwner }: { removedOwner: string }) => {
|
||||
const ownerChangedName = useSelector(getNameFromAddressBook(removedOwner))
|
||||
const ownerChangedName = useSelector((state) => getNameFromAddressBook(state, removedOwner))
|
||||
|
||||
return (
|
||||
<Block data-testid={TRANSACTIONS_DESC_REMOVE_OWNER_TEST_ID}>
|
||||
|
@ -98,7 +98,7 @@ const RemovedOwner = ({ removedOwner }: { removedOwner: string }) => {
|
|||
}
|
||||
|
||||
const AddedOwner = ({ addedOwner }: { addedOwner: string }) => {
|
||||
const ownerChangedName = useSelector(getNameFromAddressBook(addedOwner))
|
||||
const ownerChangedName = useSelector((state) => getNameFromAddressBook(state, addedOwner))
|
||||
|
||||
return (
|
||||
<Block data-testid={TRANSACTIONS_DESC_ADD_OWNER_TEST_ID}>
|
||||
|
@ -162,7 +162,7 @@ const SettingsDescription = ({ action, addedOwner, newThreshold, removedOwner }:
|
|||
|
||||
const CustomDescription = ({ amount = 0, classes, data, recipient }: CustomDescProps) => {
|
||||
const [showTxData, setShowTxData] = useState(false)
|
||||
const recipientName = useSelector(getNameFromAddressBook(recipient))
|
||||
const recipientName = useSelector((state) => getNameFromAddressBook(state, recipient))
|
||||
return (
|
||||
<>
|
||||
<Block data-testid={TRANSACTIONS_DESC_CUSTOM_VALUE_TEST_ID}>
|
||||
|
|
Loading…
Reference in New Issue