From 0e9b6d2cc1a7a2aee65ca80dd2e650d9f02e6977 Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Thu, 23 Apr 2020 18:14:49 +0400 Subject: [PATCH] fix getNameFromAddressBook selector & selector calls --- src/logic/addressBook/store/selectors/index.js | 11 +++++++---- .../ExpandedTx/IncomingTxDescription/index.jsx | 2 +- .../ExpandedTx/OwnersColumn/OwnerComponent.jsx | 7 +++---- .../TxsTable/ExpandedTx/TxDescription/index.jsx | 8 ++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/logic/addressBook/store/selectors/index.js b/src/logic/addressBook/store/selectors/index.js index 19a5c213..41857384 100644 --- a/src/logic/addressBook/store/selectors/index.js +++ b/src/logic/addressBook/store/selectors/index.js @@ -35,15 +35,18 @@ export const getAddressBookListSelector: Selector - createSelector(getAddressBook, (addressBook: AddressBook, address: string) => { +export const getNameFromAddressBook = createSelector( + getAddressBookListSelector, + (_, address) => address, + (addressBook: Map, 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' - }) + }, +) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx index a15bf48f..25b58f74 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/IncomingTxDescription/index.jsx @@ -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 ( diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/OwnerComponent.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/OwnerComponent.jsx index d97bf860..49623be6 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/OwnerComponent.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/OwnersColumn/OwnerComponent.jsx @@ -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 = ({ - {ownerName} + {nameInAdbk} @@ -140,7 +139,7 @@ const OwnerComponent = ({ )} )} - {owner.address === executor && Executor} + {owner === executor && Executor} ) } diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx index 184091e8..b5e0be78 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/TxDescription/index.jsx @@ -69,7 +69,7 @@ type CustomDescProps = { } const TransferDescription = ({ amount = '', recipient }: TransferDescProps) => { - const recipientName = useSelector(getNameFromAddressBook(recipient)) + const recipientName = useSelector((state) => getNameFromAddressBook(state, recipient)) return ( Send {amount} to: @@ -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 ( @@ -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 ( @@ -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 ( <>