Add refresh tic

This commit is contained in:
Craig Everett 2025-05-09 21:17:20 +09:00
parent 86e9ff3e44
commit 09d31e74e5
13 changed files with 63 additions and 27 deletions

View File

@ -3,7 +3,7 @@
{registered,[]}, {registered,[]},
{included_applications,[]}, {included_applications,[]},
{applications,[stdlib,kernel,sasl,ssl]}, {applications,[stdlib,kernel,sasl,ssl]},
{vsn,"0.6.1"}, {vsn,"0.6.2"},
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt, {modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,
gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman, gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman,
gd_v_wallman]}, gd_v_wallman]},

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gajudesk). -module(gajudesk).
-vsn("0.6.1"). -vsn("0.6.2").
-behavior(application). -behavior(application).
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gd_con). -module(gd_con).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").
@ -40,6 +40,7 @@
-record(s, -record(s,
{version = 1 :: integer(), {version = 1 :: integer(),
window = none :: none | wx:wx_object(), window = none :: none | wx:wx_object(),
timer = none :: none | reference(),
tasks = [] :: [#ui{}], tasks = [] :: [#ui{}],
selected = 0 :: non_neg_integer(), selected = 0 :: non_neg_integer(),
wallet = none :: none | #wallet{}, wallet = none :: none | #wallet{},
@ -323,7 +324,8 @@ init(none) ->
GUI_Prefs = maps:get(gd_gui, Prefs, #{}), GUI_Prefs = maps:get(gd_gui, Prefs, #{}),
Window = gd_gui:start_link(GUI_Prefs), Window = gd_gui:start_link(GUI_Prefs),
Wallets = get_prefs(wallets, Prefs, []), Wallets = get_prefs(wallets, Prefs, []),
State = #s{window = Window, wallets = Wallets, prefs = Prefs}, T = erlang:send_after(tic(), self(), tic),
State = #s{window = Window, timer = T, wallets = Wallets, prefs = Prefs},
NewState = do_show_ui(gd_v_wallman, State), NewState = do_show_ui(gd_v_wallman, State),
{ok, NewState}. {ok, NewState}.
@ -337,6 +339,10 @@ read_prefs() ->
end. end.
tic() ->
6000.
%%% gen_server Message Handling Callbacks %%% gen_server Message Handling Callbacks
@ -469,6 +475,9 @@ handle_cast(Unexpected, State) ->
%% The gen_server:handle_info/2 callback. %% The gen_server:handle_info/2 callback.
%% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2 %% See: http://erlang.org/doc/man/gen_server.html#Module:handle_info-2
handle_info(tic, State) ->
NewState = do_tic(State),
{noreply, NewState};
handle_info({'DOWN', Mon, process, PID, Info}, State) -> handle_info({'DOWN', Mon, process, PID, Info}, State) ->
NewState = handle_down(Mon, PID, Info, State), NewState = handle_down(Mon, PID, Info, State),
{noreply, NewState}; {noreply, NewState};
@ -581,7 +590,14 @@ do_refresh(State = #s{wallet = #wallet{endpoint = Node}}) ->
do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) -> do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) ->
CheckBalance = CheckBalance = check_balance(ChainID),
NewPOAs = lists:map(CheckBalance, POAs),
ok = gd_gui:show(NewPOAs),
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
State#s{wallet = NewW}.
check_balance(ChainID) ->
fun(This = #poa{id = ID}) -> fun(This = #poa{id = ID}) ->
Pucks = Pucks =
case hz:acc(ID) of case hz:acc(ID) of
@ -591,11 +607,7 @@ do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) ->
Dist = [{ChainID, Pucks}], Dist = [{ChainID, Pucks}],
Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist}, Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist},
This#poa{balances = [Gaju]} This#poa{balances = [Gaju]}
end, end.
NewPOAs = lists:map(CheckBalance, POAs),
ok = gd_gui:show(NewPOAs),
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
State#s{wallet = NewW}.
ensure_hz_set(Node = #node{ip = IP, external = Port}) -> ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
@ -614,7 +626,9 @@ ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
_ -> _ ->
ok = hz:chain_nodes([{IP, Port}]), ok = hz:chain_nodes([{IP, Port}]),
ensure_hz_set(Node) ensure_hz_set(Node)
end. end;
ensure_hz_set(none) ->
{error, no_nodes}.
%ensure_connected(ChainID, IP, Port) -> %ensure_connected(ChainID, IP, Port) ->
@ -1225,6 +1239,28 @@ read3(T) ->
end. end.
do_tic(State = #s{wallet = This = #wallet{poas = POAs, endpoint = Node}, selected = Selected}) when Selected > 0 ->
NewState =
case ensure_hz_set(Node) of
{ok, ChainID} ->
POA = #poa{id = ID} = lists:nth(Selected, POAs),
CheckBalance = check_balance(ChainID),
NewPOA = CheckBalance(POA),
NewPOAs = lists:keystore(ID, #poa.id, POAs, NewPOA),
ok = gd_gui:show(NewPOAs),
State#s{wallet = This#wallet{poas = POAs}};
Error ->
ok = log(info, "Balance update on tic failed with: ~p", [Error]),
State
end,
T = erlang:send_after(tic(), self(), tic),
NewState#s{timer = T};
do_tic(State) ->
T = erlang:send_after(tic(), self(), tic),
State#s{timer = T}.
persist(Prefs) -> persist(Prefs) ->
Path = prefs_path(), Path = prefs_path(),
ok = filelib:ensure_dir(Path), ok = filelib:ensure_dir(Path),

View File

@ -37,7 +37,7 @@
%%% @end %%% @end
-module(gd_grids). -module(gd_grids).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -3,7 +3,7 @@
%%% @end %%% @end
-module(gd_gui). -module(gd_gui).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -15,7 +15,7 @@
%%% translation library is retained). %%% translation library is retained).
-module(gd_jt). -module(gd_jt).
-vsn("0.6.1"). -vsn("0.6.2").
-export([read_translations/1, j/2, oneshot_j/2]). -export([read_translations/1, j/2, oneshot_j/2]).

View File

@ -1,5 +1,5 @@
-module(gd_sophia_editor). -module(gd_sophia_editor).
-vsn("0.6.1"). -vsn("0.6.2").
-export([new/1, update/2, -export([new/1, update/2,
get_text/1, set_text/2]). get_text/1, set_text/2]).

View File

@ -12,7 +12,7 @@
%%% @end %%% @end
-module(gd_sup). -module(gd_sup).
-vsn("0.6.1"). -vsn("0.6.2").
-behaviour(supervisor). -behaviour(supervisor).
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").

View File

@ -1,5 +1,5 @@
-module(gd_v). -module(gd_v).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -1,5 +1,5 @@
-module(gd_v_devman). -module(gd_v_devman).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>"). -author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -1,5 +1,5 @@
-module(gd_v_netman). -module(gd_v_netman).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -1,5 +1,5 @@
-module(gd_v_wallman). -module(gd_v_wallman).
-vsn("0.6.1"). -vsn("0.6.2").
-author("Craig Everett <zxq9@zxq9.com>"). -author("Craig Everett <zxq9@zxq9.com>").
-copyright("QPQ AG <info@qpq.swiss>"). -copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later"). -license("GPL-3.0-or-later").

View File

@ -2,9 +2,9 @@
{type,gui}. {type,gui}.
{modules,[]}. {modules,[]}.
{prefix,"gd"}. {prefix,"gd"}.
{author,"Craig Everett"}.
{desc,"A desktop client for the Gajumaru network of blockchain networks"}. {desc,"A desktop client for the Gajumaru network of blockchain networks"}.
{package_id,{"otpr","gajudesk",{0,6,1}}}. {author,"Craig Everett"}.
{package_id,{"otpr","gajudesk",{0,6,2}}}.
{deps,[{"otpr","hakuzaru",{0,6,1}}, {deps,[{"otpr","hakuzaru",{0,6,1}},
{"otpr","eblake2",{1,0,1}}, {"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}}, {"otpr","base58",{0,1,1}},