diff --git a/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js b/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js index 1b776b4269..46013d4dd0 100644 --- a/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js +++ b/apps/block_scout_web/assets/js/pages/stakes/claim_reward.js @@ -33,14 +33,18 @@ export function openClaimRewardModal(store) { closeButton.hide() lockModal($modal) + 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', () => { - const timeout = 15000; // ms - channel.push('render_claim_reward', { timeout: timeout }, timeout * 2).receive('ok', msg_pools => { - closeButton.show() - unlockModal($modal) - clearInterval(dotCounterInterval) - modalBody.html(msg_pools.html) - }) + channel.push('render_claim_reward', {}) + }) + $modal.on('hidden.bs.modal', () => { + $(this).remove() }) openModal($modal); 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 2975bfb540..b9e15950dd 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 @@ -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("

Unknown error. Please, contact Support.

") - nil -> - Task.shutdown(task, :brutal_kill) - gettext("

Unable to find the pools in a reasonable time. Please, contact Support.

") - 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 diff --git a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward.html.eex b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward.html.eex index b7523ead1f..96b80f1017 100644 --- a/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward.html.eex +++ b/apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_claim_reward.html.eex @@ -6,7 +6,7 @@