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. 10
      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 { 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'))

@ -83,12 +83,18 @@ export function setupChart ($canvas, self, total) {
})
}
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.<br /> <a href="https://docs.xdaichain.com" target="_blank">Instructions</a>')
return false
}

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

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

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

@ -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">
<%= BlockScoutWeb.AddressView.trimmed_hash(@address) %>
</span>

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

@ -17,7 +17,7 @@
<div class="stakes-progress-infos">
<div class="stakes-progress-info">
<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) %>
</p>
</div>

Loading…
Cancel
Save