From 2edb8ce56d586698f3eef99d52ee7b97d80846a4 Mon Sep 17 00:00:00 2001 From: POA <33550681+poaman@users.noreply.github.com> Date: Thu, 19 Nov 2020 14:52:51 +0300 Subject: [PATCH] Small refactoring --- apps/block_scout_web/assets/js/pages/stakes.js | 11 ++++++----- .../assets/js/pages/stakes/become_candidate.js | 3 ++- .../assets/js/pages/stakes/constants.js | 4 ++++ .../assets/js/pages/stakes/make_stake.js | 3 ++- apps/block_scout_web/assets/js/pages/stakes/utils.js | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 apps/block_scout_web/assets/js/pages/stakes/constants.js diff --git a/apps/block_scout_web/assets/js/pages/stakes.js b/apps/block_scout_web/assets/js/pages/stakes.js index 6dda027d71..c0b8c15960 100644 --- a/apps/block_scout_web/assets/js/pages/stakes.js +++ b/apps/block_scout_web/assets/js/pages/stakes.js @@ -18,6 +18,7 @@ import { openClaimRewardModal, claimRewardConnectionLost } from './stakes/claim_ import { openClaimWithdrawalModal } from './stakes/claim_withdrawal' import { checkForTokenDefinition, isSupportedNetwork } from './stakes/utils' import { currentModal, openWarningModal, openErrorModal } from '../lib/modals' +import constants from './stakes/constants' const stakesPageSelector = '[data-page="stakes"]' @@ -306,8 +307,8 @@ async function getAccounts () { try { accounts = await window.ethereum.request({ method: 'eth_accounts' }) } catch (e) { - console.error('eth_accounts request failed. Make sure you are using the latest version of MetaMask') - openErrorModal('Get account', 'Cannot get your account address. Make sure you are using the latest version of MetaMask') + console.error(`eth_accounts request failed. ${constants.METAMASK_VERSION_WARNING}`) + openErrorModal('Get account', `Cannot get your account address. ${constants.METAMASK_VERSION_WARNING}`) } return accounts } @@ -315,7 +316,7 @@ async function getAccounts () { async function getNetId (web3) { let netId = null if (!window.ethereum.chainId) { - console.error('Cannot get chainId. Make sure you are using the latest MetaMask version') + console.error(`Cannot get chainId. ${constants.METAMASK_VERSION_WARNING}`) } else { const { chainId } = window.ethereum netId = web3.utils.isHex(chainId) ? web3.utils.hexToNumber(chainId) : chainId @@ -385,8 +386,8 @@ async function loginByMetamask () { } catch (e) { console.log(e) if (e.code !== 4001) { - console.error('eth_requestAccounts failed. Make sure you are using the latest MetaMask version') - openErrorModal('Request account access', 'Cannot request access to your account in MetaMask. Make sure you are using the latest version of MetaMask') + console.error(`eth_requestAccounts failed. ${constants.METAMASK_VERSION_WARNING}`) + openErrorModal(`Request account access', 'Cannot request access to your account in MetaMask. ${constants.METAMASK_VERSION_WARNING}`) } } } diff --git a/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js b/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js index 126e5ba307..898b250746 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js +++ b/apps/block_scout_web/assets/js/pages/stakes/become_candidate.js @@ -3,6 +3,7 @@ import { BigNumber } from 'bignumber.js' import { openModal, openErrorModal, openWarningModal, lockModal } from '../../lib/modals' import { setupValidation, displayInputError } from '../../lib/validation' import { makeContractCall, isSupportedNetwork, isStakingAllowed } from './utils' +import constants from './constants' let status = 'modalClosed' @@ -10,7 +11,7 @@ export async function openBecomeCandidateModal (event, store) { const state = store.getState() if (!state.account) { - openWarningModal('Unauthorized', 'You haven\'t approved the reading of account list from your MetaMask or the latest MetaMask is not installed.') + openWarningModal('Unauthorized', constants.METAMASK_ACCOUNTS_EMPTY) return } diff --git a/apps/block_scout_web/assets/js/pages/stakes/constants.js b/apps/block_scout_web/assets/js/pages/stakes/constants.js new file mode 100644 index 0000000000..eaa076a419 --- /dev/null +++ b/apps/block_scout_web/assets/js/pages/stakes/constants.js @@ -0,0 +1,4 @@ +module.exports = { + METAMASK_ACCOUNTS_EMPTY: 'You haven\'t approved the reading of account list from your MetaMask or the latest MetaMask version is not installed.', + METAMASK_VERSION_WARNING: 'Make sure you are using the latest version of MetaMask.' +} diff --git a/apps/block_scout_web/assets/js/pages/stakes/make_stake.js b/apps/block_scout_web/assets/js/pages/stakes/make_stake.js index 50548ac4ae..6b64404baa 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/make_stake.js +++ b/apps/block_scout_web/assets/js/pages/stakes/make_stake.js @@ -3,12 +3,13 @@ import { BigNumber } from 'bignumber.js' import { openErrorModal, openModal, openWarningModal, lockModal } from '../../lib/modals' import { setupValidation } from '../../lib/validation' import { makeContractCall, setupChart, isSupportedNetwork, isStakingAllowed } from './utils' +import constants from './constants' export function openMakeStakeModal (event, store) { const state = store.getState() if (!state.account) { - openWarningModal('Unauthorized', 'You haven\'t approved the reading of account list from your MetaMask or the latest MetaMask is not installed.') + openWarningModal('Unauthorized', constants.METAMASK_ACCOUNTS_EMPTY) return } diff --git a/apps/block_scout_web/assets/js/pages/stakes/utils.js b/apps/block_scout_web/assets/js/pages/stakes/utils.js index c61651b169..71c6c1080b 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/utils.js +++ b/apps/block_scout_web/assets/js/pages/stakes/utils.js @@ -19,7 +19,7 @@ export async function makeContractCall (call, store, gasLimit, callbackFunc) { } if (!from) { - return callbackFunc('Your MetaMask account is undefined. Please, ensure you are using the latest MetaMask and connected it to the page') + return callbackFunc('Your MetaMask account is undefined. Please, ensure you are using the latest version of MetaMask and connected it to the page') } else if (!web3) { return callbackFunc('Web3 is undefined. Please, contact support.') }