2023-04-17 10:22:53 +02:00
|
|
|
import { toChecksumAddress } from 'ethereumjs-util';
|
2023-05-02 01:34:43 +02:00
|
|
|
import { getSelectedIdentity, getAccountType } from '../selectors';
|
|
|
|
import { getProviderConfig } from '../../ducks/metamask/metamask';
|
2023-06-09 22:48:48 +02:00
|
|
|
import { hexToDecimal } from '../../../shared/modules/conversion.utils';
|
2023-04-17 10:22:53 +02:00
|
|
|
|
|
|
|
export function getWaitForConfirmDeepLinkDialog(state) {
|
|
|
|
return state.metamask.waitForConfirmDeepLinkDialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getTransactionStatusMap(state) {
|
|
|
|
return state.metamask.custodyStatusMaps;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCustodyAccountDetails(state) {
|
|
|
|
return state.metamask.custodyAccountDetails;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCustodyAccountSupportedChains(state, address) {
|
|
|
|
return state.metamask.custodianSupportedChains
|
|
|
|
? state.metamask.custodianSupportedChains[toChecksumAddress(address)]
|
|
|
|
: [];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMmiPortfolioEnabled(state) {
|
|
|
|
return state.metamask.mmiConfiguration?.portfolio?.enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getMmiPortfolioUrl(state) {
|
|
|
|
return state.metamask.mmiConfiguration?.portfolio?.url;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getConfiguredCustodians(state) {
|
|
|
|
return state.metamask.mmiConfiguration?.custodians || [];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCustodianIconForAddress(state, address) {
|
|
|
|
let custodianIcon;
|
|
|
|
|
2023-06-15 18:57:35 +02:00
|
|
|
const checksummedAddress = address && toChecksumAddress(address);
|
|
|
|
if (
|
|
|
|
checksummedAddress &&
|
|
|
|
state.metamask.custodyAccountDetails?.[checksummedAddress]
|
|
|
|
) {
|
2023-04-17 10:22:53 +02:00
|
|
|
const { custodianName } =
|
|
|
|
state.metamask.custodyAccountDetails[checksummedAddress];
|
|
|
|
custodianIcon = state.metamask.mmiConfiguration?.custodians?.find(
|
|
|
|
(custodian) => custodian.name === custodianName,
|
|
|
|
)?.iconUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return custodianIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getIsCustodianSupportedChain(state) {
|
2023-08-31 17:45:07 +02:00
|
|
|
try {
|
|
|
|
const selectedIdentity = getSelectedIdentity(state);
|
|
|
|
const accountType = getAccountType(state);
|
|
|
|
const providerConfig = getProviderConfig(state);
|
|
|
|
|
|
|
|
if (!selectedIdentity || !accountType || !providerConfig) {
|
|
|
|
throw new Error('Invalid state');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accountType !== 'custody') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const supportedChains = getCustodyAccountSupportedChains(
|
|
|
|
state,
|
|
|
|
selectedIdentity.address,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!supportedChains || !supportedChains.supportedChains) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return supportedChains.supportedChains.includes(
|
|
|
|
hexToDecimal(providerConfig.chainId),
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
throw error;
|
|
|
|
}
|
2023-04-17 10:22:53 +02:00
|
|
|
}
|
2023-04-21 10:58:03 +02:00
|
|
|
|
2023-04-25 15:39:16 +02:00
|
|
|
export function getMMIAddressFromModalOrAddress(state) {
|
2023-08-31 17:45:07 +02:00
|
|
|
const modalAddress = state?.appState?.modal?.modalState?.props?.address;
|
|
|
|
const selectedAddress = state?.metamask?.selectedAddress;
|
|
|
|
|
|
|
|
return modalAddress || selectedAddress;
|
2023-04-25 15:39:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getMMIConfiguration(state) {
|
2023-04-27 12:27:31 +02:00
|
|
|
return state.metamask.mmiConfiguration || [];
|
2023-04-25 15:39:16 +02:00
|
|
|
}
|
|
|
|
|
2023-04-21 10:58:03 +02:00
|
|
|
export function getInteractiveReplacementToken(state) {
|
|
|
|
return state.metamask.interactiveReplacementToken || {};
|
|
|
|
}
|
2023-06-07 08:43:28 +02:00
|
|
|
|
|
|
|
export function getIsNoteToTraderSupported(state, fromChecksumHexAddress) {
|
|
|
|
let isNoteToTraderSupported = false;
|
|
|
|
if (state.metamask.custodyAccountDetails?.[fromChecksumHexAddress]) {
|
|
|
|
const { custodianName } =
|
|
|
|
state.metamask.custodyAccountDetails[fromChecksumHexAddress];
|
|
|
|
|
|
|
|
isNoteToTraderSupported = state.metamask.mmiConfiguration?.custodians?.find(
|
|
|
|
(custodian) => custodian.name === custodianName,
|
|
|
|
)?.isNoteToTraderSupported;
|
|
|
|
}
|
|
|
|
return isNoteToTraderSupported;
|
|
|
|
}
|