Add check for staking token definition

staking
Vadim 5 years ago committed by Victor Baranov
parent 5f237d1769
commit aa23364486
  1. 50
      apps/block_scout_web/assets/js/pages/stakes.js
  2. 16
      apps/block_scout_web/assets/js/pages/stakes/utils.js
  3. 2
      apps/block_scout_web/assets/js/pages/stakes/validator_info.js
  4. 2
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  5. 1
      apps/block_scout_web/lib/block_scout_web/notifier.ex
  6. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_address.html.eex
  7. 16
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex
  8. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_progress.html.eex

@ -6,7 +6,7 @@ import { subscribeChannel } from '../socket'
import { connectElements } from '../lib/redux_helpers.js' import { connectElements } from '../lib/redux_helpers.js'
import { createAsyncLoadStore, refreshPage } from '../lib/async_listing_load' import { createAsyncLoadStore, refreshPage } from '../lib/async_listing_load'
import Web3 from 'web3' import Web3 from 'web3'
import { openValidatorInfoModal } from './stakes/validator_info' import { openPoolInfoModal } from './stakes/validator_info'
import { openDelegatorsListModal } from './stakes/delegators_list' import { openDelegatorsListModal } from './stakes/delegators_list'
import { openBecomeCandidateModal } from './stakes/become_candidate' import { openBecomeCandidateModal } from './stakes/become_candidate'
import { openRemovePoolModal } from './stakes/remove_pool' import { openRemovePoolModal } from './stakes/remove_pool'
@ -14,6 +14,7 @@ import { openMakeStakeModal } from './stakes/make_stake'
import { openMoveStakeModal } from './stakes/move_stake' import { openMoveStakeModal } from './stakes/move_stake'
import { openWithdrawStakeModal } from './stakes/withdraw_stake' import { openWithdrawStakeModal } from './stakes/withdraw_stake'
import { openClaimWithdrawalModal } from './stakes/claim_withdrawal' import { openClaimWithdrawalModal } from './stakes/claim_withdrawal'
import { checkForTokenDefinition } from './stakes/utils'
import { openWarningModal } from '../lib/modals' import { openWarningModal } from '../lib/modals'
const stakesPageSelector = '[data-page="stakes"]' const stakesPageSelector = '[data-page="stakes"]'
@ -27,6 +28,7 @@ export const initialState = {
network: null, network: null,
refreshInterval: null, refreshInterval: null,
stakingAllowed: false, stakingAllowed: false,
stakingTokenDefined: false,
stakingContract: null, stakingContract: null,
tokenDecimals: 0, tokenDecimals: 0,
tokenSymbol: '', tokenSymbol: '',
@ -78,6 +80,7 @@ export function reducer (state = initialState, action) {
lastBlockNumber: action.lastBlockNumber, lastBlockNumber: action.lastBlockNumber,
lastEpochNumber: action.lastEpochNumber, lastEpochNumber: action.lastEpochNumber,
stakingAllowed: action.stakingAllowed, stakingAllowed: action.stakingAllowed,
stakingTokenDefined: action.stakingTokenDefined,
validatorSetApplyBlock: action.validatorSetApplyBlock validatorSetApplyBlock: action.validatorSetApplyBlock
}) })
} }
@ -104,6 +107,7 @@ function reloadPoolList(msg, store) {
lastBlockNumber: msg.block_number, lastBlockNumber: msg.block_number,
lastEpochNumber: msg.epoch_number, lastEpochNumber: msg.epoch_number,
stakingAllowed: msg.staking_allowed, stakingAllowed: msg.staking_allowed,
stakingTokenDefined: msg.staking_token_defined,
validatorSetApplyBlock: msg.validator_set_apply_block validatorSetApplyBlock: msg.validator_set_apply_block
}) })
refreshPage(store) refreshPage(store)
@ -195,14 +199,42 @@ if ($stakesPage.length) {
}) })
$(document.body) $(document.body)
.on('click', '.js-validator-info', event => openValidatorInfoModal(event, store)) .on('click', '.js-pool-info', event => {
.on('click', '.js-delegators-list', event => openDelegatorsListModal(event, store)) if (checkForTokenDefinition(store)) {
.on('click', '.js-become-candidate', () => openBecomeCandidateModal(store)) openPoolInfoModal(event, 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-delegators-list', event => {
.on('click', '.js-withdraw-stake', event => openWithdrawStakeModal(event, store)) openDelegatorsListModal(event, store)
.on('click', '.js-claim-withdrawal', event => openClaimWithdrawalModal(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 $stakesPage
.on('change', '[pool-filter-banned]', () => updateFilters(store, 'banned')) .on('change', '[pool-filter-banned]', () => updateFilters(store, 'banned'))

@ -3,7 +3,7 @@ import Chart from 'chart.js'
import { refreshPage } from '../../lib/async_listing_load' import { refreshPage } from '../../lib/async_listing_load'
import { openErrorModal, openSuccessModal, openWarningModal } from '../../lib/modals' import { openErrorModal, openSuccessModal, openWarningModal } from '../../lib/modals'
export async function makeContractCall (call, store) { export async function makeContractCall(call, store) {
let gas, timeout let gas, timeout
let resultShown = false let resultShown = false
const account = store.getState().account 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 primaryColor = $('.stakes-progress-graph-thing-for-getting-color').css('color')
const backgroundColors = [ const backgroundColors = [
primaryColor, primaryColor,
@ -83,12 +83,18 @@ export function setupChart ($canvas, self, total) {
}) })
} }
export function isSupportedNetwork (store) { export function checkForTokenDefinition(store) {
if (store.getState().network.authorized) { if (store.getState().stakingTokenDefined) {
return true 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.<br /> <a href="https://docs.xdaichain.com" target="_blank">Instructions</a>') openWarningModal('Unauthorized', 'Connect to the xDai Chain for staking.<br /> <a href="https://docs.xdaichain.com" target="_blank">Instructions</a>')
return false return false
} }

@ -1,7 +1,7 @@
import $ from 'jquery' import $ from 'jquery'
import { openModal } from '../../lib/modals' import { openModal } from '../../lib/modals'
export function openValidatorInfoModal (event, store) { export function openPoolInfoModal (event, store) {
const address = $(event.target).closest('[data-address]').data('address') const address = $(event.target).closest('[data-address]').data('address')
store.getState().channel store.getState().channel

@ -29,6 +29,7 @@ defmodule BlockScoutWeb.StakesChannel do
block_number: BlockNumber.get_max(), block_number: BlockNumber.get_max(),
epoch_number: ContractState.get(:epoch_number, 0), epoch_number: ContractState.get(:epoch_number, 0),
staking_allowed: ContractState.get(:staking_allowed, false), 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) validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0)
}, },
socket socket
@ -255,6 +256,7 @@ defmodule BlockScoutWeb.StakesChannel do
block_number: data.block_number, block_number: data.block_number,
epoch_number: data.epoch_number, epoch_number: data.epoch_number,
staking_allowed: data.staking_allowed, staking_allowed: data.staking_allowed,
staking_token_defined: data.staking_token_defined,
validator_set_apply_block: data.validator_set_apply_block, validator_set_apply_block: data.validator_set_apply_block,
top_html: StakesController.render_top(socket) top_html: StakesController.render_top(socket)
}) })

@ -112,6 +112,7 @@ defmodule BlockScoutWeb.Notifier do
block_number: BlockNumber.get_max(), block_number: BlockNumber.get_max(),
epoch_number: ContractState.get(:epoch_number, 0), epoch_number: ContractState.get(:epoch_number, 0),
staking_allowed: ContractState.get(:staking_allowed, false), 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) validator_set_apply_block: ContractState.get(:validator_set_apply_block, 0)
}) })
end end

@ -1,4 +1,4 @@
<div class="stakes-address-container js-validator-info" data-address="<%= to_string(@address) %>"> <div class="stakes-address-container js-pool-info" data-address="<%= to_string(@address) %>">
<span class="stakes-address stakes-address-active"> <span class="stakes-address stakes-address-active">
<%= BlockScoutWeb.AddressView.trimmed_hash(@address) %> <%= BlockScoutWeb.AddressView.trimmed_hash(@address) %>
</span> </span>

@ -27,49 +27,49 @@
<div class="modal-validator-info-content"> <div class="modal-validator-info-content">
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("Candidate’s Staked Amount"), title: gettext("Candidate’s Staked Amount"),
value: format_token_amount(@validator.self_staked_amount, @token) value: format_token_amount(@validator.self_staked_amount, @token)
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("Delegators’ Staked Amount"), title: gettext("Delegators’ Staked Amount"),
value: format_token_amount(Decimal.sub(@validator.total_staked_amount, @validator.self_staked_amount), @token) value: format_token_amount(Decimal.sub(@validator.total_staked_amount, @validator.self_staked_amount), @token)
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("Stakes Ratio"), title: gettext("Stakes Ratio"),
value: if(@validator.is_active, do: "#{@validator.stakes_ratio}%") value: if(@validator.is_active, do: "#{@validator.stakes_ratio}%")
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("Share of Pool’s Reward"), title: gettext("Share of Pool’s Reward"),
value: "#{@validator.validator_reward_percent}%" value: "#{@validator.validator_reward_percent}%"
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("How Many Times this Address has been a Validator"), title: gettext("How Many Times this Address has been a Validator"),
value: @validator.was_validator_count value: @validator.was_validator_count
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("How Many Times this Address has been Banned"), title: gettext("How Many Times this Address has been Banned"),
value: @validator.was_banned_count value: @validator.was_banned_count
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("Likelihood of Becoming a Validator on the Next Epoch"), title: gettext("Likelihood of Becoming a Validator on the Next Epoch"),
value: "#{@validator.likelihood}%" value: "#{@validator.likelihood}%"
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_pool_info_item.html",
title: gettext("The Number of Delegators in the Pool"), title: gettext("The Number of Delegators in the Pool"),
value: @validator.delegators_count value: @validator.delegators_count
%> %>

@ -17,7 +17,7 @@
<div class="stakes-progress-infos"> <div class="stakes-progress-infos">
<div class="stakes-progress-info"> <div class="stakes-progress-info">
<h2 class="stakes-progress-info-title"><%= gettext("Pool") %></h2> <h2 class="stakes-progress-info-title"><%= gettext("Pool") %></h2>
<p class="stakes-progress-info-value stakes-progress-info-link js-validator-info" data-address="<%= to_string(@pool.staking_address_hash) %>"> <p class="stakes-progress-info-value stakes-progress-info-link js-pool-info" data-address="<%= to_string(@pool.staking_address_hash) %>">
<%= BlockScoutWeb.AddressView.trimmed_hash(@pool.staking_address_hash) %> <%= BlockScoutWeb.AddressView.trimmed_hash(@pool.staking_address_hash) %>
</p> </p>
</div> </div>

Loading…
Cancel
Save