From aa233644867710f0392a61fba38df99cb2b968a4 Mon Sep 17 00:00:00 2001 From: Vadim Date: Fri, 6 Dec 2019 17:12:40 +0300 Subject: [PATCH] Add check for staking token definition --- .../block_scout_web/assets/js/pages/stakes.js | 50 +++++++++++++++---- .../assets/js/pages/stakes/utils.js | 16 ++++-- .../assets/js/pages/stakes/validator_info.js | 2 +- .../channels/stakes_channel.ex | 2 + .../lib/block_scout_web/notifier.ex | 1 + .../templates/stakes/_stakes_address.html.eex | 2 +- .../stakes/_stakes_modal_pool_info.html.eex | 16 +++--- .../stakes/_stakes_progress.html.eex | 2 +- 8 files changed, 66 insertions(+), 25 deletions(-) diff --git a/apps/block_scout_web/assets/js/pages/stakes.js b/apps/block_scout_web/assets/js/pages/stakes.js index 5e277bce8f..54ae816f99 100644 --- a/apps/block_scout_web/assets/js/pages/stakes.js +++ b/apps/block_scout_web/assets/js/pages/stakes.js @@ -6,7 +6,7 @@ import { subscribeChannel } from '../socket' import { connectElements } from '../lib/redux_helpers.js' import { createAsyncLoadStore, refreshPage } from '../lib/async_listing_load' import Web3 from 'web3' -import { openValidatorInfoModal } from './stakes/validator_info' +import { openPoolInfoModal } from './stakes/validator_info' import { openDelegatorsListModal } from './stakes/delegators_list' import { openBecomeCandidateModal } from './stakes/become_candidate' import { openRemovePoolModal } from './stakes/remove_pool' @@ -14,6 +14,7 @@ import { openMakeStakeModal } from './stakes/make_stake' import { openMoveStakeModal } from './stakes/move_stake' import { openWithdrawStakeModal } from './stakes/withdraw_stake' import { openClaimWithdrawalModal } from './stakes/claim_withdrawal' +import { checkForTokenDefinition } from './stakes/utils' import { openWarningModal } from '../lib/modals' const stakesPageSelector = '[data-page="stakes"]' @@ -27,6 +28,7 @@ export const initialState = { network: null, refreshInterval: null, stakingAllowed: false, + stakingTokenDefined: false, stakingContract: null, tokenDecimals: 0, tokenSymbol: '', @@ -78,6 +80,7 @@ export function reducer (state = initialState, action) { lastBlockNumber: action.lastBlockNumber, lastEpochNumber: action.lastEpochNumber, stakingAllowed: action.stakingAllowed, + stakingTokenDefined: action.stakingTokenDefined, validatorSetApplyBlock: action.validatorSetApplyBlock }) } @@ -104,6 +107,7 @@ function reloadPoolList(msg, store) { lastBlockNumber: msg.block_number, lastEpochNumber: msg.epoch_number, stakingAllowed: msg.staking_allowed, + stakingTokenDefined: msg.staking_token_defined, validatorSetApplyBlock: msg.validator_set_apply_block }) refreshPage(store) @@ -195,14 +199,42 @@ if ($stakesPage.length) { }) $(document.body) - .on('click', '.js-validator-info', event => openValidatorInfoModal(event, store)) - .on('click', '.js-delegators-list', event => openDelegatorsListModal(event, store)) - .on('click', '.js-become-candidate', () => openBecomeCandidateModal(store)) - .on('click', '.js-remove-pool', () => openRemovePoolModal(store)) - .on('click', '.js-make-stake', event => openMakeStakeModal(event, store)) - .on('click', '.js-move-stake', event => openMoveStakeModal(event, store)) - .on('click', '.js-withdraw-stake', event => openWithdrawStakeModal(event, store)) - .on('click', '.js-claim-withdrawal', event => openClaimWithdrawalModal(event, store)) + .on('click', '.js-pool-info', event => { + if (checkForTokenDefinition(store)) { + openPoolInfoModal(event, store) + } + }) + .on('click', '.js-delegators-list', event => { + openDelegatorsListModal(event, store) + }) + .on('click', '.js-become-candidate', () => { + if (checkForTokenDefinition(store)) { + openBecomeCandidateModal(store) + } + }) + .on('click', '.js-remove-pool', () => { + openRemovePoolModal(store) + }) + .on('click', '.js-make-stake', event => { + if (checkForTokenDefinition(store)) { + openMakeStakeModal(event, store) + } + }) + .on('click', '.js-move-stake', event => { + if (checkForTokenDefinition(store)) { + openMoveStakeModal(event, store) + } + }) + .on('click', '.js-withdraw-stake', event => { + if (checkForTokenDefinition(store)) { + openWithdrawStakeModal(event, store) + } + }) + .on('click', '.js-claim-withdrawal', event => { + if (checkForTokenDefinition(store)) { + openClaimWithdrawalModal(event, store) + } + }) $stakesPage .on('change', '[pool-filter-banned]', () => updateFilters(store, 'banned')) 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 fe8e543493..2d1a97dbbe 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/utils.js +++ b/apps/block_scout_web/assets/js/pages/stakes/utils.js @@ -3,7 +3,7 @@ import Chart from 'chart.js' import { refreshPage } from '../../lib/async_listing_load' import { openErrorModal, openSuccessModal, openWarningModal } from '../../lib/modals' -export async function makeContractCall (call, store) { +export async function makeContractCall(call, store) { let gas, timeout let resultShown = false const account = store.getState().account @@ -52,7 +52,7 @@ export async function makeContractCall (call, store) { } } -export function setupChart ($canvas, self, total) { +export function setupChart($canvas, self, total) { const primaryColor = $('.stakes-progress-graph-thing-for-getting-color').css('color') const backgroundColors = [ primaryColor, @@ -83,12 +83,18 @@ export function setupChart ($canvas, self, total) { }) } -export function isSupportedNetwork (store) { - if (store.getState().network.authorized) { +export function checkForTokenDefinition(store) { + if (store.getState().stakingTokenDefined) { return true } + openWarningModal('Token unavailable', 'Token contract is not defined yet. Please try later.') + return false +} +export function isSupportedNetwork(store) { + if (store.getState().network.authorized) { + return true + } openWarningModal('Unauthorized', 'Connect to the xDai Chain for staking.
Instructions') - return false } diff --git a/apps/block_scout_web/assets/js/pages/stakes/validator_info.js b/apps/block_scout_web/assets/js/pages/stakes/validator_info.js index 6a8942cb80..9fb035b9aa 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/validator_info.js +++ b/apps/block_scout_web/assets/js/pages/stakes/validator_info.js @@ -1,7 +1,7 @@ import $ from 'jquery' import { openModal } from '../../lib/modals' -export function openValidatorInfoModal (event, store) { +export function openPoolInfoModal (event, store) { const address = $(event.target).closest('[data-address]').data('address') store.getState().channel diff --git a/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex b/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex index 9f66194ba0..f1d6989d26 100644 --- a/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex +++ b/apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex @@ -29,6 +29,7 @@ defmodule BlockScoutWeb.StakesChannel do block_number: BlockNumber.get_max(), epoch_number: ContractState.get(:epoch_number, 0), staking_allowed: ContractState.get(:staking_allowed, false), + staking_token_defined: ContractState.get(:token, nil) != nil, validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0) }, socket @@ -255,6 +256,7 @@ defmodule BlockScoutWeb.StakesChannel do block_number: data.block_number, epoch_number: data.epoch_number, staking_allowed: data.staking_allowed, + staking_token_defined: data.staking_token_defined, validator_set_apply_block: data.validator_set_apply_block, top_html: StakesController.render_top(socket) }) diff --git a/apps/block_scout_web/lib/block_scout_web/notifier.ex b/apps/block_scout_web/lib/block_scout_web/notifier.ex index e6f5c8b911..bd4f1aa486 100644 --- a/apps/block_scout_web/lib/block_scout_web/notifier.ex +++ b/apps/block_scout_web/lib/block_scout_web/notifier.ex @@ -112,6 +112,7 @@ defmodule BlockScoutWeb.Notifier do block_number: BlockNumber.get_max(), epoch_number: ContractState.get(:epoch_number, 0), staking_allowed: ContractState.get(:staking_allowed, false), + staking_token_defined: ContractState.get(:token, nil) != nil, validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0) }) end diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_address.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_address.html.eex index e46c445d84..bec16ba6fc 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_address.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_address.html.eex @@ -1,4 +1,4 @@ -
+
<%= BlockScoutWeb.AddressView.trimmed_hash(@address) %> diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex index 828154550a..44c67adb05 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex @@ -27,49 +27,49 @@