WIP
This commit is contained in:
parent
9fa365e83f
commit
9365c33351
@ -298,7 +298,7 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
|
||||
#w{name = mnemonic} -> show_mnemonic(State);
|
||||
#w{name = rename} -> rename_key(State);
|
||||
#w{name = drop_key} -> drop_key(State);
|
||||
#w{name = copy} -> copy(State);
|
||||
#w{name = copy} -> copy_pk(State);
|
||||
#w{name = www} -> www(State);
|
||||
#w{name = send} -> spend(State);
|
||||
#w{name = grids} -> grids_dialogue(State);
|
||||
@ -588,7 +588,7 @@ show_mnemonic(Selected, State = #s{frame = Frame, j = J, accounts = Accounts}) -
|
||||
ok =
|
||||
case wxDialog:showModal(Dialog) of
|
||||
?wxID_CANCEL -> ok;
|
||||
?wxID_OK -> copy_to_clipboard(Mnemonic)
|
||||
?wxID_OK -> gd_lib:copy_to_clipboard(Mnemonic)
|
||||
end,
|
||||
ok = wxDialog:destroy(Dialog),
|
||||
State.
|
||||
@ -656,28 +656,11 @@ drop_key(Selected, State = #s{frame = Frame, j = J, accounts = Accounts, prefs =
|
||||
State#s{prefs = NewPrefs}.
|
||||
|
||||
|
||||
copy(State = #s{id = {_, #w{wx = ID_T}}}) ->
|
||||
copy_pk(State = #s{id = {_, #w{wx = ID_T}}}) ->
|
||||
String = wxStaticText:getLabel(ID_T),
|
||||
ok = copy_to_clipboard(String),
|
||||
ok = gd_lib:copy_to_clipboard(String),
|
||||
State.
|
||||
|
||||
copy_to_clipboard(String) ->
|
||||
CB = wxClipboard:get(),
|
||||
case wxClipboard:open(CB) of
|
||||
true ->
|
||||
Text = wxTextDataObject:new([{text, String}]),
|
||||
case wxClipboard:setData(CB, Text) of
|
||||
true ->
|
||||
R = wxClipboard:flush(CB),
|
||||
log(info, "String copied to system clipboard. Flushed: ~p", [R]);
|
||||
false ->
|
||||
log(info, "Failed to copy to clipboard")
|
||||
end,
|
||||
ok = wxClipboard:close(CB);
|
||||
false ->
|
||||
log(info, "Failed to acquire the clipboard.")
|
||||
end.
|
||||
|
||||
|
||||
www(State = #s{id = {_, #w{wx = ID_T}}, j = J}) ->
|
||||
case wxStaticText:getLabel(ID_T) of
|
||||
|
||||
@ -7,7 +7,8 @@
|
||||
|
||||
-export([is_int/1,
|
||||
mono_text/2, mono_text/3,
|
||||
button/2, button/3]).
|
||||
button/2, button/3,
|
||||
copy_to_clipboard/1]).
|
||||
|
||||
-include("$zx_include/zx_logger.hrl").
|
||||
-include("gd.hrl").
|
||||
@ -76,3 +77,24 @@ button(Parent, Label) ->
|
||||
button(Parent, Name, Label) ->
|
||||
Button = wxButton:new(Parent, ?wxID_ANY, [{label, Label}]),
|
||||
#w{name = Name, id = wxButton:getId(Button), wx = Button}.
|
||||
|
||||
|
||||
-spec copy_to_clipboard(String) -> ok
|
||||
when String :: unicode:charlist().
|
||||
|
||||
copy_to_clipboard(String) ->
|
||||
CB = wxClipboard:get(),
|
||||
case wxClipboard:open(CB) of
|
||||
true ->
|
||||
Text = wxTextDataObject:new([{text, String}]),
|
||||
case wxClipboard:setData(CB, Text) of
|
||||
true ->
|
||||
R = wxClipboard:flush(CB),
|
||||
log(info, "String copied to system clipboard. Flushed: ~p", [R]);
|
||||
false ->
|
||||
log(info, "Failed to copy to clipboard")
|
||||
end,
|
||||
ok = wxClipboard:close(CB);
|
||||
false ->
|
||||
log(info, "Failed to acquire the clipboard.")
|
||||
end.
|
||||
|
||||
@ -32,7 +32,9 @@
|
||||
gas = #w{} :: #w{},
|
||||
amount = #w{} :: #w{},
|
||||
action = #w{} :: #w{},
|
||||
tx_data = none :: none | map(),
|
||||
tx_hash = #w{} :: #w{},
|
||||
tx_info = none :: none | hz:transaction(),
|
||||
out = #w{} :: #w{},
|
||||
copy = #w{} :: #w{}}).
|
||||
|
||||
@ -117,10 +119,11 @@ init({Prefs, {FunName, FunType}, ConID, Build, Selected, Keys}) ->
|
||||
ok = wxFrame:connect(Frame, command_button_clicked),
|
||||
true = wxFrame:show(Frame),
|
||||
State =
|
||||
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||
con_id = ConID, build = Build, args = Args,
|
||||
ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT,
|
||||
action = Action, copy = Copy},
|
||||
#s{wx = Wx, frame = Frame, j = J, prefs = Prefs,
|
||||
con_id = ConID, build = Build,
|
||||
args = Args, keypicker = KeyPicker,
|
||||
ttl = TTL_T, gasprice = GasPriceT, gas = GasT, amount = AmountT,
|
||||
action = Action, copy = Copy},
|
||||
{Frame, State}.
|
||||
|
||||
|
||||
@ -217,9 +220,12 @@ handle_info(Unexpected, State) ->
|
||||
|
||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||
State = #s{action = #w{id = ID}}) ->
|
||||
NewState = engage(State);
|
||||
NewState = engage(State),
|
||||
{noreply, NewState};
|
||||
|
||||
handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID},
|
||||
State = #s{copy = #w{id = ID}}) ->
|
||||
ok = copy(State),
|
||||
{noreply, State};
|
||||
handle_event(Event, State) ->
|
||||
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||
{noreply, State}.
|
||||
@ -270,54 +276,81 @@ engage(State = #s{con_id = ConID, build = Build, fundef = {Name, Type}}, ChainID
|
||||
end.
|
||||
|
||||
|
||||
% NEXT: Complete the signature and enter check_tx/2
|
||||
params(#s{ttl = #w{wx = TTL},
|
||||
gasprice = #w{wx = GasPrice},
|
||||
gas = #w{wx = Gas},
|
||||
amount = #w{wx = Amount},
|
||||
}) ->
|
||||
|
||||
|
||||
args(#s{args = ArgFields}) ->
|
||||
|
||||
|
||||
deploy(State, ChainID, CallerID, CreateTX) ->
|
||||
SignedTX = hz:sign_tx(CreateTX, SecKey, ChainID),
|
||||
tell(info, "SignedTX: ~p", [SignedTX]),
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, Data = #{"tx_hash" := TXHash}} ->
|
||||
ok = tell("Contract deploy TX succeded with: ~p", [TXHash]),
|
||||
do_deploy3(Data);
|
||||
{ok, WTF} ->
|
||||
gd_v_devman:trouble({error, WTF});
|
||||
Error ->
|
||||
gd_v_devman:trouble(Error)
|
||||
case gd_con:sign_tx(ChainID, CallerID, CreateTX) of
|
||||
{ok, SignedTX} -> deploy2(State, SignedTX);
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
do_deploy3(#{"tx_hash" := TXHash}) ->
|
||||
case hz:tx_info(TXHash) of
|
||||
{ok, #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
||||
gd_v_devman:open_contract(ConID);
|
||||
{error, "Tx not mined"} ->
|
||||
gd_v_devman:trouble({tx_hash, TXHash});
|
||||
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
|
||||
gd_v_devman:trouble({error, Reason});
|
||||
Error ->
|
||||
gd_v_devman:trouble(Error)
|
||||
deploy2(State, SignedTX) ->
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, Data} -> check_tx(State#s{tx_data = Data});
|
||||
{ok, WTF} -> handle_troubling(State, {error, WTF});
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
|
||||
do_call(State, ChainID, CallerID, UnsignedTX) ->
|
||||
case gd_con:sign_call(ChainID, CallerID, UnsignedTX) of
|
||||
{ok, SignedTX} -> do_call(State, SignedTX);
|
||||
{ok, SignedTX} -> do_call2(State, SignedTX);
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
do_call(State, SignedTX) ->
|
||||
do_call2(State, SignedTX) ->
|
||||
case hz:post_tx(SignedTX) of
|
||||
{ok, TX_Hash} ->
|
||||
|
||||
{ok, Data} -> check_tx(SDtate = #s{tx_data = Data});
|
||||
Error -> handle_troubling(State, Error)
|
||||
end.
|
||||
|
||||
do_dry_run(State, ConID, TX) ->
|
||||
case hz:dry_run(TX) of
|
||||
{ok, Result} -> gd_v_devman:dryrun_result(ConID, Result);
|
||||
Other -> gd_v_devmam:trouble({error, ConID, Other})
|
||||
end.
|
||||
ok = gd_con:dry_run(ConID, TX),
|
||||
|
||||
|
||||
check_tx(State = #s{tx_data = #{"tx_hash" := TXHash} = TXData, tx_info = none}) ->
|
||||
ok = tell("TXData: ~p", [TXData]),
|
||||
case hz:tx_info(TXHash) of
|
||||
{ok, Info = #{"call_info" := #{"return_type" := "ok", "contract_id" := ConID}}} ->
|
||||
ok = gd_v_devman:open_contract(ConID),
|
||||
update_info(State#s{tx_info = Info});
|
||||
{error, "Tx not mined"} ->
|
||||
handle_troubling(State, {error, not_mined});
|
||||
{ok, Reason = #{"call_info" := #{"return_type" := "revert"}}} ->
|
||||
handle_troubling(State, {error, Reason});
|
||||
Error ->
|
||||
handle_troubling(State, Error)
|
||||
end;
|
||||
check_tx(State = #s{tx_info = TXInfo}) ->
|
||||
ok = tell("Nothing to check"),
|
||||
State.
|
||||
|
||||
|
||||
update_info(State = #s{tx_info = TXInfo, out = #w{wx = Out}}) ->
|
||||
Formatted = io_lib:format("TXInfo: ~p~n", [TXInfo]),
|
||||
ok = wxStaticText:setLabel(Out, Formatted),
|
||||
State.
|
||||
|
||||
|
||||
copy(State = #s{tx_info = none}) ->
|
||||
ok;
|
||||
copy(State = #s{out = #w{wx = Out}}) ->
|
||||
Output = wxStaticText:getLabel(Out),
|
||||
gd_lib:copy_to_clipboard(Output).
|
||||
|
||||
|
||||
|
||||
textify({integer, _, _}) -> "int";
|
||||
textify({boolean, _, _}) -> "bool";
|
||||
textify({{bytes, [I]}, _, _}) -> io_lib:format("bytes(~w)", [I]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user