Small refactoring

pull/3460/head
POA 4 years ago
parent 8ea4bbda83
commit 2edb8ce56d
  1. 11
      apps/block_scout_web/assets/js/pages/stakes.js
  2. 3
      apps/block_scout_web/assets/js/pages/stakes/become_candidate.js
  3. 4
      apps/block_scout_web/assets/js/pages/stakes/constants.js
  4. 3
      apps/block_scout_web/assets/js/pages/stakes/make_stake.js
  5. 2
      apps/block_scout_web/assets/js/pages/stakes/utils.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}`)
}
}
}

@ -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
}

@ -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.'
}

@ -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
}

@ -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.')
}

Loading…
Cancel
Save