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,[]},
{included_applications,[]},
{applications,[stdlib,kernel,sasl,ssl]},
{vsn,"0.6.1"},
{vsn,"0.6.2"},
{modules,[gajudesk,gd_con,gd_grids,gd_gui,gd_jt,
gd_sophia_editor,gd_sup,gd_v,gd_v_devman,gd_v_netman,
gd_v_wallman]},

View File

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

View File

@ -3,7 +3,7 @@
%%% @end
-module(gd_con).
-vsn("0.6.1").
-vsn("0.6.2").
-author("Craig Everett <craigeverett@qpq.swiss>").
-copyright("QPQ AG <info@qpq.swiss>").
-license("GPL-3.0-or-later").
@ -40,6 +40,7 @@
-record(s,
{version = 1 :: integer(),
window = none :: none | wx:wx_object(),
timer = none :: none | reference(),
tasks = [] :: [#ui{}],
selected = 0 :: non_neg_integer(),
wallet = none :: none | #wallet{},
@ -323,7 +324,8 @@ init(none) ->
GUI_Prefs = maps:get(gd_gui, Prefs, #{}),
Window = gd_gui:start_link(GUI_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),
{ok, NewState}.
@ -337,6 +339,10 @@ read_prefs() ->
end.
tic() ->
6000.
%%% gen_server Message Handling Callbacks
@ -469,6 +475,9 @@ handle_cast(Unexpected, State) ->
%% The gen_server:handle_info/2 callback.
%% 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) ->
NewState = handle_down(Mon, PID, Info, State),
{noreply, NewState};
@ -581,23 +590,26 @@ do_refresh(State = #s{wallet = #wallet{endpoint = Node}}) ->
do_refresh2(ChainID, State = #s{wallet = W = #wallet{poas = POAs}}) ->
CheckBalance =
fun(This = #poa{id = ID}) ->
Pucks =
case hz:acc(ID) of
{ok, #{"balance" := P}} -> P;
{error, "Account not found"} -> 0
end,
Dist = [{ChainID, Pucks}],
Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist},
This#poa{balances = [Gaju]}
end,
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}) ->
Pucks =
case hz:acc(ID) of
{ok, #{"balance" := P}} -> P;
{error, "Account not found"} -> 0
end,
Dist = [{ChainID, Pucks}],
Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist},
This#poa{balances = [Gaju]}
end.
ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
case hz:chain_nodes() of
[{IP, Port}] ->
@ -614,7 +626,9 @@ ensure_hz_set(Node = #node{ip = IP, external = Port}) ->
_ ->
ok = hz:chain_nodes([{IP, Port}]),
ensure_hz_set(Node)
end.
end;
ensure_hz_set(none) ->
{error, no_nodes}.
%ensure_connected(ChainID, IP, Port) ->
@ -1225,6 +1239,28 @@ read3(T) ->
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) ->
Path = prefs_path(),
ok = filelib:ensure_dir(Path),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,9 +2,9 @@
{type,gui}.
{modules,[]}.
{prefix,"gd"}.
{author,"Craig Everett"}.
{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}},
{"otpr","eblake2",{1,0,1}},
{"otpr","base58",{0,1,1}},