Fix silly state bug
This commit is contained in:
parent
df44118463
commit
34a73a8e99
@ -632,23 +632,26 @@ 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 = check_balance(ChainID),
|
CheckBalance = check_balance(ChainID, "gaju"),
|
||||||
NewPOAs = lists:map(CheckBalance, POAs),
|
NewPOAs = lists:map(CheckBalance, POAs),
|
||||||
ok = gd_gui:show(NewPOAs),
|
ok = gd_gui:show(NewPOAs),
|
||||||
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
|
NewW = W#wallet{chain_id = ChainID, poas = NewPOAs},
|
||||||
State#s{wallet = NewW}.
|
State#s{wallet = NewW}.
|
||||||
|
|
||||||
|
|
||||||
check_balance(ChainID) ->
|
check_balance(ChainID, Coin) ->
|
||||||
fun(This = #poa{id = ID, balances = [#balance{coin = "gaju", total = OldBalance}]}) ->
|
fun(This = #poa{id = ID, balances = Balances}) ->
|
||||||
|
#balance{dist = Dist} = lists:keyfind(Coin, #balance.coin, Balances),
|
||||||
|
Old = proplists:get_value(ChainID, Dist, 0),
|
||||||
Pucks =
|
Pucks =
|
||||||
case hz:acc(ID) of
|
case hz:acc(ID) of
|
||||||
{ok, #{"balance" := P}} -> P;
|
{ok, #{"balance" := Old}} -> Old;
|
||||||
|
{ok, #{"balance" := New}} -> New;
|
||||||
{error, "Account not found"} -> 0;
|
{error, "Account not found"} -> 0;
|
||||||
{error, timeout} -> OldBalance
|
{error, timeout} -> Old
|
||||||
end,
|
end,
|
||||||
Dist = [{ChainID, Pucks}],
|
NewDist = [{ChainID, Pucks}],
|
||||||
Gaju = #balance{coin = "gaju", total = Pucks, dist = Dist},
|
Gaju = #balance{coin = "gaju", total = Pucks, dist = NewDist},
|
||||||
This#poa{balances = [Gaju]}
|
This#poa{balances = [Gaju]}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -1291,13 +1294,17 @@ do_close_wallet(State = #s{wallet = Current, wallets = Wallets, pass = Pass}) ->
|
|||||||
State#s{selected = 0, pass = none, wallet = none}.
|
State#s{selected = 0, pass = none, wallet = none}.
|
||||||
|
|
||||||
|
|
||||||
save_wallet(#wr{path = Path, pass = false}, none, Wallet) ->
|
save_wallet(#wr{path = Path, pass = false}, none, Wallet = #wallet{name = Name}) ->
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
file:write_file(Path, term_to_binary(Wallet));
|
ok = log(info, "Saving plain wallet ~ts file to disk...", [Name]),
|
||||||
save_wallet(#wr{path = Path, pass = true}, Pass, Wallet) ->
|
ok = file:write_file(Path, term_to_binary(Wallet)),
|
||||||
|
log(info, "Wallet ~ts file written.", [Name]);
|
||||||
|
save_wallet(#wr{path = Path, pass = true}, Pass, Wallet = #wallet{name = Name}) ->
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
Cipher = encrypt(Pass, term_to_binary(Wallet)),
|
Cipher = encrypt(Pass, term_to_binary(Wallet)),
|
||||||
file:write_file(Path, Cipher).
|
ok = log(info, "Saving cipher wallet ~ts file to disk.", [Name]),
|
||||||
|
ok = file:write_file(Path, Cipher),
|
||||||
|
log(info, "Wallet ~ts file written.", [Name]).
|
||||||
|
|
||||||
|
|
||||||
read(Path, none) ->
|
read(Path, none) ->
|
||||||
@ -1357,15 +1364,17 @@ handle_tic(State = #s{wallet = This = #wallet{poas = POAs, endpoint = Node},
|
|||||||
timer = {T, MS},
|
timer = {T, MS},
|
||||||
selected = Selected})
|
selected = Selected})
|
||||||
when Selected > 0 ->
|
when Selected > 0 ->
|
||||||
|
% TODO: The closure below is kind of silly. The internal hz:acc/1 account will
|
||||||
|
% Expand to become hz:acc/2, accepting a chain ID later.
|
||||||
NewState =
|
NewState =
|
||||||
case ensure_hz_set(Node) of
|
case ensure_hz_set(Node) of
|
||||||
{ok, ChainID} ->
|
{ok, ChainID} ->
|
||||||
POA = #poa{id = ID} = lists:nth(Selected, POAs),
|
POA = #poa{id = ID} = lists:nth(Selected, POAs),
|
||||||
CheckBalance = check_balance(ChainID),
|
CheckBalance = check_balance(ChainID, "gaju"),
|
||||||
NewPOA = CheckBalance(POA),
|
NewPOA = CheckBalance(POA),
|
||||||
NewPOAs = lists:keystore(ID, #poa.id, POAs, NewPOA),
|
NewPOAs = lists:keystore(ID, #poa.id, POAs, NewPOA),
|
||||||
ok = gd_gui:show(NewPOAs),
|
ok = gd_gui:show(NewPOAs),
|
||||||
State#s{wallet = This#wallet{poas = POAs}};
|
State#s{wallet = This#wallet{poas = NewPOAs}};
|
||||||
Error ->
|
Error ->
|
||||||
ok = log(info, "Balance update on tic failed with: ~p", [Error]),
|
ok = log(info, "Balance update on tic failed with: ~p", [Error]),
|
||||||
State
|
State
|
||||||
@ -1390,6 +1399,7 @@ cancel_timer(T) ->
|
|||||||
persist(Prefs) ->
|
persist(Prefs) ->
|
||||||
Path = prefs_path(),
|
Path = prefs_path(),
|
||||||
ok = filelib:ensure_dir(Path),
|
ok = filelib:ensure_dir(Path),
|
||||||
|
ok = log(info, "Writing prefs to disk."),
|
||||||
zx_lib:write_terms(Path, proplists:from_map(Prefs)).
|
zx_lib:write_terms(Path, proplists:from_map(Prefs)).
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user