Add first-run wallet creator
This commit is contained in:
parent
50190a5b5b
commit
45ab1a35a4
@ -3,7 +3,7 @@
|
||||
{registered,[]},
|
||||
{included_applications,[]},
|
||||
{applications,[stdlib,kernel,sasl,ssl]},
|
||||
{vsn,"0.6.6"},
|
||||
{vsn,"0.7.0"},
|
||||
{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]},
|
||||
|
@ -3,7 +3,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(gajudesk).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-behavior(application).
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
|
@ -3,7 +3,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(gd_con).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
@ -66,12 +66,13 @@ show_ui(Name) ->
|
||||
gen_server:cast(?MODULE, {show_ui, Name}).
|
||||
|
||||
|
||||
-spec open_wallet(Path, Phrase) -> ok
|
||||
-spec open_wallet(Path, Phrase) -> Result
|
||||
when Path :: file:filename(),
|
||||
Phrase :: string().
|
||||
Phrase :: string(),
|
||||
Result :: ok | {error, Reason :: term()}.
|
||||
|
||||
open_wallet(Path, Phrase) ->
|
||||
gen_server:cast(?MODULE, {open_wallet, Path, Phrase}).
|
||||
gen_server:call(?MODULE, {open_wallet, Path, Phrase}).
|
||||
|
||||
|
||||
-spec close_wallet() -> ok.
|
||||
@ -217,7 +218,7 @@ deploy(Build, Params, InitArgs) ->
|
||||
Size :: 256,
|
||||
Name :: string(),
|
||||
Seed :: string(),
|
||||
Encoding :: utf8 | base64 | base58,
|
||||
Encoding :: utf8 | base64 | base58 | none,
|
||||
Transform :: {Algo, Yugeness},
|
||||
Algo :: sha3 | sha2 | x_or | pbkdf2,
|
||||
Yugeness :: rand | non_neg_integer().
|
||||
@ -365,6 +366,9 @@ handle_call(list_keys, _, State) ->
|
||||
handle_call({nonce, ID}, _, State) ->
|
||||
Response = do_nonce(ID),
|
||||
{reply, Response, State};
|
||||
handle_call({open_wallet, Path, Phrase}, _, State) ->
|
||||
{Response, NewState} = do_open_wallet(Path, Phrase, State),
|
||||
{reply, Response, NewState};
|
||||
handle_call(network, _, State) ->
|
||||
Response = do_network(State),
|
||||
{reply, Response, State};
|
||||
@ -390,9 +394,6 @@ handle_call(Unexpected, From, State) ->
|
||||
handle_cast({show_ui, Name}, State) ->
|
||||
NewState = do_show_ui(Name, State),
|
||||
{noreply, NewState};
|
||||
handle_cast({open_wallet, Path, Phrase}, State) ->
|
||||
NewState = do_open_wallet(Path, Phrase, State),
|
||||
{noreply, NewState};
|
||||
handle_cast(close_wallet, State) ->
|
||||
NextState = do_close_wallet(State),
|
||||
ok = gd_gui:show([]),
|
||||
@ -489,7 +490,6 @@ handle_info(Unexpected, State) ->
|
||||
|
||||
|
||||
handle_down(Mon, PID, Info, State = #s{tasks = Tasks}) ->
|
||||
tell("Handling down"),
|
||||
case lists:keytake(Mon, #ui.mon, Tasks) of
|
||||
{value, #ui{}, NewTasks} ->
|
||||
State#s{tasks = NewTasks};
|
||||
@ -1024,19 +1024,12 @@ do_open_wallet(Path, Phrase, State) ->
|
||||
{ok, ChainID} -> gd_gui:chain(ChainID, Node);
|
||||
Error -> gd_gui:trouble(Error)
|
||||
end,
|
||||
State#s{pass = Pass, wallet = Recovered};
|
||||
{ok, State#s{pass = Pass, wallet = Recovered}};
|
||||
Error ->
|
||||
ok = gd_gui:trouble(Error),
|
||||
% FIXME: This is chaotically stupid.
|
||||
tell("Sending myself the show_ui message"),
|
||||
self() ! {show_ui, gd_v_wallman},
|
||||
State
|
||||
{Error, State}
|
||||
end.
|
||||
|
||||
|
||||
default_wallet() ->
|
||||
default_wallet(testnet).
|
||||
|
||||
default_wallet(mainnet) ->
|
||||
Node = #node{ip = "groot.mainnet.gajumaru.io"},
|
||||
Groot = #chain{id = <<"groot.mainnet">>,
|
||||
|
@ -37,7 +37,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(gd_grids).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
|
@ -3,7 +3,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(gd_gui).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
|
@ -15,7 +15,7 @@
|
||||
%%% translation library is retained).
|
||||
|
||||
-module(gd_jt).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-export([read_translations/1, j/2, oneshot_j/2]).
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
-module(gd_sophia_editor).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-export([new/1, update/2,
|
||||
get_text/1, set_text/2]).
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
%%% @end
|
||||
|
||||
-module(gd_sup).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-behaviour(supervisor).
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
|
@ -1,5 +1,5 @@
|
||||
-module(gd_v).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
|
@ -1,5 +1,5 @@
|
||||
-module(gd_v_devman).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <craigeverett@qpq.swiss>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
|
@ -1,5 +1,5 @@
|
||||
-module(gd_v_netman).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
|
@ -1,5 +1,5 @@
|
||||
-module(gd_v_wallman).
|
||||
-vsn("0.6.6").
|
||||
-vsn("0.7.0").
|
||||
-author("Craig Everett <zxq9@zxq9.com>").
|
||||
-copyright("QPQ AG <info@qpq.swiss>").
|
||||
-license("GPL-3.0-or-later").
|
||||
@ -7,7 +7,7 @@
|
||||
-behavior(wx_object).
|
||||
%-behavior(gd_v).
|
||||
-include_lib("wx/include/wx.hrl").
|
||||
-export([to_front/1]).
|
||||
-export([to_front/1, trouble/1]).
|
||||
-export([show/2]).
|
||||
-export([start_link/1]).
|
||||
-export([init/1, terminate/2, code_change/3,
|
||||
@ -42,6 +42,13 @@ to_front(Win) ->
|
||||
wx_object:cast(Win, to_front).
|
||||
|
||||
|
||||
-spec trouble(Info) -> ok
|
||||
when Info :: term().
|
||||
|
||||
trouble(Info) ->
|
||||
wx_object:cast(?MODULE, {trouble, Info}).
|
||||
|
||||
|
||||
-spec show(Win, Manifest) -> ok
|
||||
when Win :: wx:xw_object(),
|
||||
Manifest :: [#wr{}].
|
||||
@ -140,6 +147,9 @@ handle_cast(to_front, State = #s{frame = Frame}) ->
|
||||
ok = ensure_shown(Frame),
|
||||
ok = wxFrame:raise(Frame),
|
||||
{noreply, State};
|
||||
handle_cast({trouble, Info}, State) ->
|
||||
ok = handle_troubling(State, Info),
|
||||
{noreply, State};
|
||||
handle_cast({show, Manifest}, State) ->
|
||||
NewState = do_show(Manifest, State),
|
||||
{noreply, NewState};
|
||||
@ -191,13 +201,17 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked},
|
||||
end,
|
||||
{noreply, NewState};
|
||||
handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) ->
|
||||
ok = close_wiz(State),
|
||||
{noreply, State};
|
||||
NewState = close_wiz(State),
|
||||
{noreply, NewState};
|
||||
handle_event(Event, State) ->
|
||||
ok = tell(info, "Unexpected event ~tp State: ~tp~n", [Event, State]),
|
||||
{noreply, State}.
|
||||
|
||||
|
||||
handle_troubling(#s{frame = Frame}, Info) ->
|
||||
zxw:show_message(Frame, Info).
|
||||
|
||||
|
||||
code_change(_, State, _) ->
|
||||
{ok, State}.
|
||||
|
||||
@ -236,8 +250,7 @@ do_close(#s{frame = Frame, prefs = Prefs}) ->
|
||||
end,
|
||||
NewPrefs = maps:put(geometry, Geometry, Prefs),
|
||||
ok = gd_con:save(?MODULE, NewPrefs),
|
||||
ok = wxWindow:destroy(Frame),
|
||||
exit(normal).
|
||||
ok = wxWindow:destroy(Frame).
|
||||
|
||||
|
||||
handle_button(Name, State) ->
|
||||
@ -249,9 +262,15 @@ do_open(State = #s{wallets = []}) ->
|
||||
State;
|
||||
do_open(State = #s{wallets = [#wr{pass = true, path = Path}]}) ->
|
||||
do_open3(Path, State);
|
||||
do_open(State = #s{wallets = [#wr{pass = false, path = Path}]}) ->
|
||||
ok = gd_con:open_wallet(Path, none),
|
||||
ok = do_close(State),
|
||||
do_open(State = #s{wallets = [#wr{pass = false, path = Path}], frame = Frame}) ->
|
||||
ok =
|
||||
case gd_con:open_wallet(Path, none) of
|
||||
ok ->
|
||||
do_close(State);
|
||||
Error ->
|
||||
ok = ensure_shown(Frame),
|
||||
trouble(Error)
|
||||
end,
|
||||
State;
|
||||
do_open(State = #s{picker = Picker}) ->
|
||||
case wxListBox:getSelection(Picker) of
|
||||
@ -295,8 +314,14 @@ do_open3(Path, State = #s{frame = Frame, j = J}) ->
|
||||
State;
|
||||
Phrase ->
|
||||
ok = wxDialog:destroy(Dialog),
|
||||
ok = gd_con:open_wallet(Path, Phrase),
|
||||
ok = do_close(State),
|
||||
ok =
|
||||
case gd_con:open_wallet(Path, Phrase) of
|
||||
ok ->
|
||||
do_close(State);
|
||||
Error ->
|
||||
ok = ensure_shown(Frame),
|
||||
trouble(Error)
|
||||
end,
|
||||
State
|
||||
end;
|
||||
?wxID_CANCEL ->
|
||||
@ -314,8 +339,8 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) ->
|
||||
MainSz = wxBoxSizer:new(?wxVERTICAL),
|
||||
|
||||
ButtonTemplates =
|
||||
[{noob, J("Create a default wallet with a new account for me.")},
|
||||
{l33t, J("I know what I'm doing.\nJust show me the wallet manager.")}],
|
||||
[{noob, J("I'm new!\nCreate a new account for me.")},
|
||||
{l33t, J("Open the wallet manager.")}],
|
||||
|
||||
MakeButton =
|
||||
fun({Name, Label}) ->
|
||||
@ -347,6 +372,8 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) ->
|
||||
Path = filename:join(DefaultDir, Name ++ ".gaju"),
|
||||
case do_new2(Path, J, Wiz) of
|
||||
ok ->
|
||||
Label = J("Account 1"),
|
||||
ok = gd_con:make_key({eddsa, ed25519}, 256, Label, <<>>, none, {sha3, 256}),
|
||||
ok = do_close(State),
|
||||
State;
|
||||
abort ->
|
||||
@ -387,8 +414,8 @@ do_new(State = #s{frame = Frame, j = J, prefs = Prefs}) ->
|
||||
do_new2(Path, J, Frame) ->
|
||||
Dialog = wxDialog:new(Frame, ?wxID_ANY, J("New Wallet"), [{size, {400, 250}}]),
|
||||
Sizer = wxBoxSizer:new(?wxVERTICAL),
|
||||
|
||||
Network = wxRadioBox:new(Dialog, ?wxID_ANY, J("Network"), {0, 0}, {50, 50}, [J("Mainnet"), J("Testnet")]),
|
||||
NetworkOptions = [J("Mainnet"), J("Testnet")],
|
||||
Network = wxRadioBox:new(Dialog, ?wxID_ANY, J("Network"), {0, 0}, {50, 50}, NetworkOptions),
|
||||
NameSz = wxStaticBoxSizer:new(?wxVERTICAL, Dialog, [{label, J("Name")}]),
|
||||
NameTx = wxTextCtrl:new(Dialog, ?wxID_ANY),
|
||||
_ = wxSizer:add(NameSz, NameTx, zxw:flags(wide)),
|
||||
|
@ -4,7 +4,7 @@
|
||||
{prefix,"gd"}.
|
||||
{author,"Craig Everett"}.
|
||||
{desc,"A desktop client for the Gajumaru network of blockchain networks"}.
|
||||
{package_id,{"otpr","gajudesk",{0,6,6}}}.
|
||||
{package_id,{"otpr","gajudesk",{0,7,0}}}.
|
||||
{deps,[{"otpr","hakuzaru",{0,6,1}},
|
||||
{"otpr","eblake2",{1,0,1}},
|
||||
{"otpr","base58",{0,1,1}},
|
||||
|
Loading…
x
Reference in New Issue
Block a user