1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00
metamask-extension/ui/selectors/institutional/selectors.js
Mark Stacey f765b8c9b9
Refactor provider config selector (#18905)
The provider configuration selector has been renamed from `getProvider`
to `getProviderConfig`, and it has been moved from the selectors module
into the MetaMask slice. A JSDoc description has been added as well.

This refactor was done to make a future PR simpler, and to make this
selector better aligned with best practices.

This relates to #18902
2023-05-01 21:04:43 -02:30

81 lines
2.3 KiB
JavaScript

import { toChecksumAddress } from 'ethereumjs-util';
import { getSelectedIdentity, getAccountType } from '../selectors';
import { getProviderConfig } from '../../ducks/metamask/metamask';
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;
const checksummedAddress = toChecksumAddress(address);
if (state.metamask.custodyAccountDetails?.[checksummedAddress]) {
const { custodianName } =
state.metamask.custodyAccountDetails[checksummedAddress];
custodianIcon = state.metamask.mmiConfiguration?.custodians?.find(
(custodian) => custodian.name === custodianName,
)?.iconUrl;
}
return custodianIcon;
}
export function getIsCustodianSupportedChain(state) {
const selectedIdentity = getSelectedIdentity(state);
const accountType = getAccountType(state);
const providerConfig = getProviderConfig(state);
const supportedChains =
accountType === 'custody'
? getCustodyAccountSupportedChains(state, selectedIdentity.address)
: null;
return supportedChains?.supportedChains
? supportedChains.supportedChains.includes(
Number(providerConfig.chainId).toString(),
)
: true;
}
export function getMMIAddressFromModalOrAddress(state) {
return (
state.appState.modal.modalState.props.address ||
state.metamask.selectedAddress
);
}
export function getMMIConfiguration(state) {
return state.metamask.mmiConfiguration || [];
}
export function getInteractiveReplacementToken(state) {
return state.metamask.interactiveReplacementToken || {};
}