2021-10-21 21:17:03 +02:00
|
|
|
import { addHexPrefix, isHexString, stripHexPrefix } from 'ethereumjs-util';
|
2021-02-04 19:15:23 +01:00
|
|
|
import * as actionConstants from '../../store/actionConstants';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { ALERT_TYPES } from '../../../shared/constants/alerts';
|
|
|
|
import { NETWORK_TYPE_RPC } from '../../../shared/constants/network';
|
2021-06-08 18:03:59 +02:00
|
|
|
import {
|
|
|
|
accountsWithSendEtherInfoSelector,
|
2021-08-06 01:59:58 +02:00
|
|
|
checkNetworkAndAccountSupports1559,
|
2021-06-08 18:03:59 +02:00
|
|
|
getAddressBook,
|
|
|
|
} from '../../selectors';
|
2021-07-08 22:23:00 +02:00
|
|
|
import { updateTransaction } from '../../store/actions';
|
|
|
|
import { setCustomGasLimit, setCustomGasPrice } from '../gas/gas.duck';
|
|
|
|
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
|
2021-10-21 21:17:03 +02:00
|
|
|
import { isEqualCaseInsensitive } from '../../helpers/utils/util';
|
2021-08-06 01:59:58 +02:00
|
|
|
import { GAS_ESTIMATE_TYPES } from '../../../shared/constants/gas';
|
2021-10-21 21:17:03 +02:00
|
|
|
import { KEYRING_TYPES } from '../../../shared/constants/hardware-wallets';
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export default function reduceMetamask(state = {}, action) {
|
2020-08-19 18:27:05 +02:00
|
|
|
const metamaskState = {
|
2016-04-14 00:28:44 +02:00
|
|
|
isInitialized: false,
|
|
|
|
isUnlocked: false,
|
2017-10-16 07:28:25 +02:00
|
|
|
isAccountMenuOpen: false,
|
2016-04-14 00:28:44 +02:00
|
|
|
identities: {},
|
2017-01-28 01:11:59 +01:00
|
|
|
unapprovedTxs: {},
|
2017-03-08 01:01:51 +01:00
|
|
|
frequentRpcList: [],
|
2017-03-09 22:58:42 +01:00
|
|
|
addressBook: [],
|
2018-04-16 05:37:42 +02:00
|
|
|
contractExchangeRates: {},
|
2018-05-20 08:04:19 +02:00
|
|
|
pendingTokens: {},
|
2019-09-27 06:30:36 +02:00
|
|
|
customNonceValue: '',
|
2017-11-24 02:33:44 +01:00
|
|
|
useBlockie: false,
|
2017-11-14 17:04:55 +01:00
|
|
|
featureFlags: {},
|
2018-03-08 18:31:21 +01:00
|
|
|
welcomeScreenSeen: false,
|
2018-03-23 17:59:59 +01:00
|
|
|
currentLocale: '',
|
2021-06-08 18:03:59 +02:00
|
|
|
currentBlockGasLimit: '',
|
2018-10-17 01:03:29 +02:00
|
|
|
preferences: {
|
2020-05-13 16:53:00 +02:00
|
|
|
autoLockTimeLimit: undefined,
|
2019-02-26 19:30:41 +01:00
|
|
|
showFiatInTestnets: false,
|
2020-05-13 16:53:00 +02:00
|
|
|
useNativeCurrencyAsPrimaryCurrency: true,
|
2018-10-17 01:03:29 +02:00
|
|
|
},
|
2019-03-05 16:45:01 +01:00
|
|
|
firstTimeFlowType: null,
|
2019-01-23 16:25:34 +01:00
|
|
|
completedOnboarding: false,
|
2019-01-22 19:22:56 +01:00
|
|
|
knownMethodData: {},
|
2019-03-05 16:45:01 +01:00
|
|
|
participateInMetaMetrics: null,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce: null,
|
2021-06-08 18:03:59 +02:00
|
|
|
conversionRate: null,
|
|
|
|
nativeCurrency: 'ETH',
|
2020-08-19 18:27:05 +02:00
|
|
|
...state,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
|
|
|
|
switch (action.type) {
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.UPDATE_METAMASK_STATE:
|
2021-02-04 19:15:23 +01:00
|
|
|
return { ...metamaskState, ...action.value };
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.LOCK_METAMASK:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2016-06-21 22:18:32 +02:00
|
|
|
isUnlocked: false,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_RPC_TARGET:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2016-06-21 22:18:32 +02:00
|
|
|
provider: {
|
2021-01-20 17:49:05 +01:00
|
|
|
type: NETWORK_TYPE_RPC,
|
2020-10-06 19:57:02 +02:00
|
|
|
rpcUrl: action.value,
|
2016-06-21 22:18:32 +02:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_PROVIDER_TYPE:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2016-06-21 22:18:32 +02:00
|
|
|
provider: {
|
|
|
|
type: action.value,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SHOW_ACCOUNT_DETAIL:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2016-06-21 22:18:32 +02:00
|
|
|
isUnlocked: true,
|
|
|
|
isInitialized: true,
|
2017-01-31 00:08:31 +01:00
|
|
|
selectedAddress: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-08-12 18:41:27 +02:00
|
|
|
case actionConstants.SET_ACCOUNT_LABEL: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { account } = action.value;
|
|
|
|
const name = action.value.label;
|
|
|
|
const id = {};
|
|
|
|
id[account] = { ...metamaskState.identities[account], name };
|
|
|
|
const identities = { ...metamaskState.identities, ...id };
|
|
|
|
return Object.assign(metamaskState, { identities });
|
2020-08-12 18:41:27 +02:00
|
|
|
}
|
2016-06-21 22:18:32 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.UPDATE_CUSTOM_NONCE:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-09-27 06:30:36 +02:00
|
|
|
customNonceValue: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-10-12 18:42:14 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.TOGGLE_ACCOUNT_MENU:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2017-10-16 07:28:25 +02:00
|
|
|
isAccountMenuOpen: !metamaskState.isAccountMenuOpen,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-10-16 07:28:25 +02:00
|
|
|
|
2020-08-12 18:41:27 +02:00
|
|
|
case actionConstants.UPDATE_TRANSACTION_PARAMS: {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { id: txId, value } = action;
|
|
|
|
let { currentNetworkTxList } = metamaskState;
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList = currentNetworkTxList.map((tx) => {
|
2017-11-08 20:18:27 +01:00
|
|
|
if (tx.id === txId) {
|
2021-02-04 19:15:23 +01:00
|
|
|
const newTx = { ...tx };
|
|
|
|
newTx.txParams = value;
|
|
|
|
return newTx;
|
2017-11-08 17:44:48 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return tx;
|
|
|
|
});
|
2017-11-08 17:44:48 +01:00
|
|
|
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2020-03-06 22:34:56 +01:00
|
|
|
currentNetworkTxList,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-12 18:41:27 +02:00
|
|
|
}
|
2017-11-08 17:44:48 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_PARTICIPATE_IN_METAMETRICS:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-03-05 16:45:01 +01:00
|
|
|
participateInMetaMetrics: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_USE_BLOCKIE:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2018-10-10 10:12:25 +02:00
|
|
|
useBlockie: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-24 02:33:44 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.UPDATE_FEATURE_FLAGS:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2017-11-14 17:04:55 +01:00
|
|
|
featureFlags: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-14 17:04:55 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.CLOSE_WELCOME_SCREEN:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2018-03-08 18:31:21 +01:00
|
|
|
welcomeScreenSeen: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-08 18:31:21 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_CURRENT_LOCALE:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-09-06 15:47:07 +02:00
|
|
|
currentLocale: action.value.locale,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-16 01:29:45 +01:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_PENDING_TOKENS:
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2018-05-20 08:04:19 +02:00
|
|
|
pendingTokens: { ...action.payload },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.CLEAR_PENDING_TOKENS: {
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2018-05-20 08:04:19 +02:00
|
|
|
pendingTokens: {},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-05-20 08:04:19 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.UPDATE_PREFERENCES: {
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-02-26 19:30:41 +01:00
|
|
|
preferences: {
|
|
|
|
...metamaskState.preferences,
|
|
|
|
...action.payload,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.COMPLETE_ONBOARDING: {
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-01-23 16:25:34 +01:00
|
|
|
completedOnboarding: true,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_FIRST_TIME_FLOW_TYPE: {
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-03-05 16:45:01 +01:00
|
|
|
firstTimeFlowType: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2020-04-09 02:35:37 +02:00
|
|
|
case actionConstants.SET_NEXT_NONCE: {
|
2020-01-13 17:29:21 +01:00
|
|
|
return {
|
|
|
|
...metamaskState,
|
2019-09-27 06:30:36 +02:00
|
|
|
nextNonce: action.value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2016-06-21 22:18:32 +02:00
|
|
|
default:
|
2021-02-04 19:15:23 +01:00
|
|
|
return metamaskState;
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-23 18:07:05 +01:00
|
|
|
|
2021-07-08 22:23:00 +02:00
|
|
|
const toHexWei = (value, expectHexWei) => {
|
|
|
|
return addHexPrefix(expectHexWei ? value : decGWEIToHexWEI(value));
|
|
|
|
};
|
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
export function updateTransactionGasFees({
|
|
|
|
gasPrice,
|
|
|
|
gasLimit,
|
|
|
|
maxPriorityFeePerGas,
|
|
|
|
maxFeePerGas,
|
|
|
|
transaction,
|
|
|
|
expectHexWei = false,
|
|
|
|
}) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
const txParamsCopy = { ...transaction.txParams, gas: gasLimit };
|
|
|
|
if (gasPrice) {
|
|
|
|
dispatch(
|
|
|
|
setCustomGasPrice(toHexWei(txParamsCopy.gasPrice, expectHexWei)),
|
|
|
|
);
|
|
|
|
txParamsCopy.gasPrice = toHexWei(gasPrice, expectHexWei);
|
|
|
|
} else if (maxFeePerGas && maxPriorityFeePerGas) {
|
|
|
|
txParamsCopy.maxFeePerGas = toHexWei(maxFeePerGas, expectHexWei);
|
|
|
|
txParamsCopy.maxPriorityFeePerGas = addHexPrefix(
|
|
|
|
decGWEIToHexWEI(maxPriorityFeePerGas),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
const updatedTx = {
|
|
|
|
...transaction,
|
|
|
|
txParams: txParamsCopy,
|
|
|
|
};
|
|
|
|
|
|
|
|
const customGasLimit = isHexString(addHexPrefix(gasLimit))
|
|
|
|
? addHexPrefix(gasLimit)
|
|
|
|
: addHexPrefix(gasLimit.toString(16));
|
|
|
|
dispatch(setCustomGasLimit(customGasLimit));
|
|
|
|
await dispatch(updateTransaction(updatedTx));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selectors
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const getCurrentLocale = (state) => state.metamask.currentLocale;
|
2020-05-08 21:45:52 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const getAlertEnabledness = (state) => state.metamask.alertEnabledness;
|
2020-05-08 21:45:52 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export const getUnconnectedAccountAlertEnabledness = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
getAlertEnabledness(state)[ALERT_TYPES.unconnectedAccount];
|
2020-05-12 15:01:52 +02:00
|
|
|
|
2020-12-11 00:40:29 +01:00
|
|
|
export const getWeb3ShimUsageAlertEnabledness = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
getAlertEnabledness(state)[ALERT_TYPES.web3ShimUsage];
|
2020-12-11 00:40:29 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export const getUnconnectedAccountAlertShown = (state) =>
|
2021-02-04 19:15:23 +01:00
|
|
|
state.metamask.unconnectedAccountAlertShownOrigins;
|
2020-05-29 02:43:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
export const getTokens = (state) => state.metamask.tokens;
|
2021-06-08 18:03:59 +02:00
|
|
|
|
|
|
|
export function getBlockGasLimit(state) {
|
|
|
|
return state.metamask.currentBlockGasLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getConversionRate(state) {
|
|
|
|
return state.metamask.conversionRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getNativeCurrency(state) {
|
|
|
|
return state.metamask.nativeCurrency;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSendHexDataFeatureFlagState(state) {
|
|
|
|
return state.metamask.featureFlags.sendHexData;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSendToAccounts(state) {
|
|
|
|
const fromAccounts = accountsWithSendEtherInfoSelector(state);
|
|
|
|
const addressBookAccounts = getAddressBook(state);
|
|
|
|
return [...fromAccounts, ...addressBookAccounts];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getUnapprovedTxs(state) {
|
|
|
|
return state.metamask.unapprovedTxs;
|
|
|
|
}
|
2021-06-25 18:24:00 +02:00
|
|
|
|
2021-09-30 13:57:59 +02:00
|
|
|
/**
|
|
|
|
* Function returns true if network details are fetched and it is found to not support EIP-1559
|
|
|
|
*/
|
|
|
|
export function isNotEIP1559Network(state) {
|
|
|
|
return state.metamask.networkDetails?.EIPS[1559] === false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function returns true if network details are fetched and it is found to support EIP-1559
|
|
|
|
*/
|
2021-06-25 18:24:00 +02:00
|
|
|
export function isEIP1559Network(state) {
|
2021-07-30 13:35:30 +02:00
|
|
|
return state.metamask.networkDetails?.EIPS[1559] === true;
|
2021-06-25 18:24:00 +02:00
|
|
|
}
|
2021-07-08 22:23:00 +02:00
|
|
|
|
|
|
|
export function getGasEstimateType(state) {
|
|
|
|
return state.metamask.gasEstimateType;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getGasFeeEstimates(state) {
|
|
|
|
return state.metamask.gasFeeEstimates;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getEstimatedGasFeeTimeBounds(state) {
|
|
|
|
return state.metamask.estimatedGasFeeTimeBounds;
|
|
|
|
}
|
2021-08-06 01:59:58 +02:00
|
|
|
|
|
|
|
export function getIsGasEstimatesLoading(state) {
|
|
|
|
const networkAndAccountSupports1559 = checkNetworkAndAccountSupports1559(
|
|
|
|
state,
|
|
|
|
);
|
|
|
|
const gasEstimateType = getGasEstimateType(state);
|
|
|
|
|
|
|
|
// We consider the gas estimate to be loading if the gasEstimateType is
|
|
|
|
// 'NONE' or if the current gasEstimateType cannot be supported by the current
|
|
|
|
// network
|
|
|
|
const isEIP1559TolerableEstimateType =
|
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET ||
|
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE;
|
|
|
|
const isGasEstimatesLoading =
|
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.NONE ||
|
|
|
|
(networkAndAccountSupports1559 && !isEIP1559TolerableEstimateType) ||
|
|
|
|
(!networkAndAccountSupports1559 &&
|
|
|
|
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET);
|
|
|
|
|
|
|
|
return isGasEstimatesLoading;
|
|
|
|
}
|
2021-09-30 23:34:11 +02:00
|
|
|
|
|
|
|
export function getCompletedOnboarding(state) {
|
|
|
|
return state.metamask.completedOnboarding;
|
|
|
|
}
|
|
|
|
export function getIsInitialized(state) {
|
|
|
|
return state.metamask.isInitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getIsUnlocked(state) {
|
|
|
|
return state.metamask.isUnlocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getSeedPhraseBackedUp(state) {
|
|
|
|
return state.metamask.seedPhraseBackedUp;
|
|
|
|
}
|
2021-10-21 21:17:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the redux state object and an address, finds a keyring that contains that address, if one exists
|
|
|
|
*
|
|
|
|
* @param {Object} state - the redux state object
|
|
|
|
* @param {string} address - the address to search for among the keyring addresses
|
|
|
|
* @returns {Object|undefined} The keyring which contains the passed address, or undefined
|
|
|
|
*/
|
|
|
|
export function findKeyringForAddress(state, address) {
|
|
|
|
const keyring = state.metamask.keyrings.find((kr) => {
|
|
|
|
return kr.accounts.some((account) => {
|
|
|
|
return (
|
|
|
|
isEqualCaseInsensitive(account, addHexPrefix(address)) ||
|
|
|
|
isEqualCaseInsensitive(account, stripHexPrefix(address))
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return keyring;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the redux state object, returns the users preferred ledger transport type
|
|
|
|
*
|
|
|
|
* @param {Object} state - the redux state object
|
|
|
|
* @returns {string} The users preferred ledger transport type. One of'ledgerLive', 'webhid' or 'u2f'
|
|
|
|
*/
|
|
|
|
export function getLedgerTransportType(state) {
|
|
|
|
return state.metamask.ledgerTransportType;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the redux state object and an address, returns a boolean indicating whether the passed address is part of a Ledger keyring
|
|
|
|
*
|
|
|
|
* @param {Object} state - the redux state object
|
|
|
|
* @param {string} address - the address to search for among all keyring addresses
|
|
|
|
* @returns {boolean} true if the passed address is part of a ledger keyring, and false otherwise
|
|
|
|
*/
|
|
|
|
export function isAddressLedger(state, address) {
|
|
|
|
const keyring = findKeyringForAddress(state, address);
|
|
|
|
|
|
|
|
return keyring?.type === KEYRING_TYPES.LEDGER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given the redux state object, returns a boolean indicating whether the user has any Ledger accounts added to MetaMask (i.e. Ledger keyrings
|
|
|
|
* in state)
|
|
|
|
*
|
|
|
|
* @param {Object} state - the redux state object
|
|
|
|
* @returns {boolean} true if the user has a Ledger account and false otherwise
|
|
|
|
*/
|
|
|
|
export function doesUserHaveALedgerAccount(state) {
|
|
|
|
return state.metamask.keyrings.some((kr) => {
|
|
|
|
return kr.type === KEYRING_TYPES.LEDGER;
|
|
|
|
});
|
|
|
|
}
|