Simplify render_claim_reward handling; remove UI freeze

staking
Vadim 5 years ago committed by Victor Baranov
parent 07f7fbbb4c
commit 71104468fe
  1. 10
      apps/block_scout_web/assets/js/pages/stakes/claim_reward.js
  2. 21
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward.html.eex

@ -33,14 +33,18 @@ export function openClaimRewardModal(store) {
closeButton.hide()
lockModal($modal)
$modal.on('shown.bs.modal', () => {
const timeout = 15000; // ms
channel.push('render_claim_reward', { timeout: timeout }, timeout * 2).receive('ok', msg_pools => {
channel.on('claim_reward_pools', msg_pools => {
channel.off('claim_reward_pools')
closeButton.show()
unlockModal($modal)
clearInterval(dotCounterInterval)
modalBody.html(msg_pools.html)
})
$modal.on('shown.bs.modal', () => {
channel.push('render_claim_reward', {})
})
$modal.on('hidden.bs.modal', () => {
$(this).remove()
})
openModal($modal);

@ -11,8 +11,6 @@ defmodule BlockScoutWeb.StakesChannel do
alias Explorer.Staking.ContractState
alias Phoenix.View
import BlockScoutWeb.Gettext
intercept(["staking_update"])
def join("stakes:staking_update", _params, socket) do
@ -236,16 +234,8 @@ defmodule BlockScoutWeb.StakesChannel do
html = if data["preload"] do
View.render_to_string(StakesView, "_stakes_modal_claim_reward.html", %{})
else
task = Task.async(__MODULE__, :find_claim_reward_pools, [])
case Task.yield(task, data["timeout"]) do
{:ok, html} ->
html
{:exit, _} ->
gettext("<p>Unknown error. Please, contact Support.</p>")
nil ->
Task.shutdown(task, :brutal_kill)
gettext("<p>Unable to find the pools in a reasonable time. Please, contact Support.</p>")
end
Task.async(__MODULE__, :find_claim_reward_pools, [socket])
"OK"
end
result = %{html: html}
{:reply, {:ok, result}, socket}
@ -285,10 +275,13 @@ defmodule BlockScoutWeb.StakesChannel do
{:noreply, socket}
end
def find_claim_reward_pools() do
def find_claim_reward_pools(socket) do
pools = []
:timer.sleep(20000) # emulate working
View.render_to_string(StakesView, "_stakes_modal_claim_reward_content.html", pools: pools)
html = View.render_to_string(StakesView, "_stakes_modal_claim_reward_content.html", pools: pools)
push(socket, "claim_reward_pools", %{
html: html
})
end
defp push_staking_contract(socket) do

@ -6,7 +6,7 @@
<h5 class="modal-title"><%= gettext("Claim Reward") %></h5>
</div>
<div class="modal-body">
<p><%= gettext("Searching for pools you ever staked into. Please, wait...") %></p>
<p><%= gettext("Searching for pools you have ever staked into. Please, wait...") %></p>
</div>
</div>
</div>

Loading…
Cancel
Save