From 6e928c661e09ef3f206de0fda627fe9b546cd3dc Mon Sep 17 00:00:00 2001 From: David Walsh Date: Wed, 27 Oct 2021 18:54:18 -0500 Subject: [PATCH] Create function for hardware keyring checking (#12457) --- .../account-details-modal/account-details-modal.component.js | 3 ++- ui/components/app/wallet-overview/eth-overview.js | 3 ++- ui/components/app/wallet-overview/token-overview.js | 3 ++- ui/helpers/utils/hardware.js | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 ui/helpers/utils/hardware.js diff --git a/ui/components/app/modals/account-details-modal/account-details-modal.component.js b/ui/components/app/modals/account-details-modal/account-details-modal.component.js index 72767f310..858fc5999 100644 --- a/ui/components/app/modals/account-details-modal/account-details-modal.component.js +++ b/ui/components/app/modals/account-details-modal/account-details-modal.component.js @@ -7,6 +7,7 @@ import QrView from '../../../ui/qr-code'; import EditableLabel from '../../../ui/editable-label'; import Button from '../../../ui/button'; import { getURLHostName } from '../../../../helpers/utils/util'; +import { isHardwareKeyring } from '../../../../helpers/utils/hardware'; export default class AccountDetailsModal extends Component { static propTypes = { @@ -40,7 +41,7 @@ export default class AccountDetailsModal extends Component { let exportPrivateKeyFeatureEnabled = true; // This feature is disabled for hardware wallets - if (keyring?.type?.search('Hardware') !== -1) { + if (isHardwareKeyring(keyring?.type)) { exportPrivateKeyFeatureEnabled = false; } diff --git a/ui/components/app/wallet-overview/eth-overview.js b/ui/components/app/wallet-overview/eth-overview.js index ef822ca05..1579c5830 100644 --- a/ui/components/app/wallet-overview/eth-overview.js +++ b/ui/components/app/wallet-overview/eth-overview.js @@ -34,6 +34,7 @@ import BuyIcon from '../../ui/icon/overview-buy-icon.component'; import SendIcon from '../../ui/icon/overview-send-icon.component'; import { setSwapsFromToken } from '../../../ducks/swaps/swaps'; import IconButton from '../../ui/icon-button'; +import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import WalletOverview from './wallet-overview'; const EthOverview = ({ className }) => { @@ -55,7 +56,7 @@ const EthOverview = ({ className }) => { }); const history = useHistory(); const keyring = useSelector(getCurrentKeyring); - const usingHardwareWallet = keyring.type.search('Hardware') !== -1; + const usingHardwareWallet = isHardwareKeyring(keyring.type); const balanceIsCached = useSelector(isBalanceCached); const showFiat = useSelector(getShouldShowFiat); const selectedAccount = useSelector(getSelectedAccount); diff --git a/ui/components/app/wallet-overview/token-overview.js b/ui/components/app/wallet-overview/token-overview.js index 0b5476261..1db872854 100644 --- a/ui/components/app/wallet-overview/token-overview.js +++ b/ui/components/app/wallet-overview/token-overview.js @@ -7,6 +7,7 @@ import Identicon from '../../ui/identicon'; import Tooltip from '../../ui/tooltip'; import CurrencyDisplay from '../../ui/currency-display'; import { I18nContext } from '../../../contexts/i18n'; +import { isHardwareKeyring } from '../../../helpers/utils/hardware'; import { SEND_ROUTE, BUILD_QUOTE_ROUTE, @@ -42,7 +43,7 @@ const TokenOverview = ({ className, token }) => { }); const history = useHistory(); const keyring = useSelector(getCurrentKeyring); - const usingHardwareWallet = keyring.type.search('Hardware') !== -1; + const usingHardwareWallet = isHardwareKeyring(keyring.type); const { tokensWithBalances } = useTokenTracker([token]); const balanceToRender = tokensWithBalances[0]?.string; const balance = tokensWithBalances[0]?.balance; diff --git a/ui/helpers/utils/hardware.js b/ui/helpers/utils/hardware.js new file mode 100644 index 000000000..b011f7879 --- /dev/null +++ b/ui/helpers/utils/hardware.js @@ -0,0 +1,3 @@ +export function isHardwareKeyring(keyringType = '') { + return keyringType.includes('Hardware'); +}