mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 19:10:22 +01:00
6e5c2f03bf
* addding the legacy tokenlist, tuning token detection OFF by default, adding new message while importing tokens updating the controller version and calling detectNewToken on network change fixing rebase error Run yarn lavamoat:auto for updating policies updating lavamoat Deleted node modules and run again lavamoat auto fixing rebase issues updating lavamoat policies updating lavamoat after rebasing policies updating custom token warning and blocking detectedtoken link when tpken detection is off for supported networks to update the token in fetchTosync updating the contract map object Revert build-system lavamoat policy changes Move token list selection logic from components to getTokenList selector updating the tokenList Update lavamoat Fix error updating lavamoat lint fix fix unit test fail fix unit test fail lint fix fixing rebase locale error rebase fix Revert build-system policy changes temp addressing review comments * rebase fix
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { useSelector } from 'react-redux';
|
|
|
|
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';
|
|
import {
|
|
getAddressBook,
|
|
getMetaMaskIdentities,
|
|
getTokenList,
|
|
} from '../selectors';
|
|
import { shortenAddress } from '../helpers/utils/util';
|
|
|
|
const useAddressDetails = (toAddress) => {
|
|
const addressBook = useSelector(getAddressBook);
|
|
const identities = useSelector(getMetaMaskIdentities);
|
|
const tokenList = useSelector(getTokenList);
|
|
const checksummedAddress = toChecksumHexAddress(toAddress);
|
|
|
|
if (!toAddress) {
|
|
return {};
|
|
}
|
|
const addressBookEntryObject = addressBook.find(
|
|
(entry) => entry.address === checksummedAddress,
|
|
);
|
|
if (addressBookEntryObject?.name) {
|
|
return { toName: addressBookEntryObject.name, isTrusted: true };
|
|
}
|
|
if (identities[toAddress]?.name) {
|
|
return { toName: identities[toAddress].name, isTrusted: true };
|
|
}
|
|
if (tokenList[toAddress?.toLowerCase()]?.name) {
|
|
return {
|
|
toName: tokenList[toAddress?.toLowerCase()].name,
|
|
isTrusted: true,
|
|
};
|
|
}
|
|
return {
|
|
toName: shortenAddress(checksummedAddress),
|
|
isTrusted: false,
|
|
};
|
|
};
|
|
|
|
export default useAddressDetails;
|