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() closeButton.hide()
lockModal($modal) lockModal($modal)
$modal.on('shown.bs.modal', () => { channel.on('claim_reward_pools', msg_pools => {
const timeout = 15000; // ms channel.off('claim_reward_pools')
channel.push('render_claim_reward', { timeout: timeout }, timeout * 2).receive('ok', msg_pools => {
closeButton.show() closeButton.show()
unlockModal($modal) unlockModal($modal)
clearInterval(dotCounterInterval) clearInterval(dotCounterInterval)
modalBody.html(msg_pools.html) modalBody.html(msg_pools.html)
}) })
$modal.on('shown.bs.modal', () => {
channel.push('render_claim_reward', {})
})
$modal.on('hidden.bs.modal', () => {
$(this).remove()
}) })
openModal($modal); openModal($modal);

@ -11,8 +11,6 @@ defmodule BlockScoutWeb.StakesChannel do
alias Explorer.Staking.ContractState alias Explorer.Staking.ContractState
alias Phoenix.View alias Phoenix.View
import BlockScoutWeb.Gettext
intercept(["staking_update"]) intercept(["staking_update"])
def join("stakes:staking_update", _params, socket) do def join("stakes:staking_update", _params, socket) do
@ -236,16 +234,8 @@ defmodule BlockScoutWeb.StakesChannel do
html = if data["preload"] do html = if data["preload"] do
View.render_to_string(StakesView, "_stakes_modal_claim_reward.html", %{}) View.render_to_string(StakesView, "_stakes_modal_claim_reward.html", %{})
else else
task = Task.async(__MODULE__, :find_claim_reward_pools, []) Task.async(__MODULE__, :find_claim_reward_pools, [socket])
case Task.yield(task, data["timeout"]) do "OK"
{: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
end end
result = %{html: html} result = %{html: html}
{:reply, {:ok, result}, socket} {:reply, {:ok, result}, socket}
@ -285,10 +275,13 @@ defmodule BlockScoutWeb.StakesChannel do
{:noreply, socket} {:noreply, socket}
end end
def find_claim_reward_pools() do def find_claim_reward_pools(socket) do
pools = [] pools = []
:timer.sleep(20000) # emulate working :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 end
defp push_staking_contract(socket) do defp push_staking_contract(socket) do

@ -6,7 +6,7 @@
<h5 class="modal-title"><%= gettext("Claim Reward") %></h5> <h5 class="modal-title"><%= gettext("Claim Reward") %></h5>
</div> </div>
<div class="modal-body"> <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> </div>
</div> </div>

Loading…
Cancel
Save