From 45ab1a35a4bb007e020282af1b5ef7eb4f1256c8 Mon Sep 17 00:00:00 2001 From: Craig Everett Date: Thu, 7 Aug 2025 12:10:18 +0900 Subject: [PATCH] Add first-run wallet creator --- ebin/gajudesk.app | 2 +- src/gajudesk.erl | 2 +- src/gd_con.erl | 29 ++++++++------------ src/gd_grids.erl | 2 +- src/gd_gui.erl | 2 +- src/gd_jt.erl | 2 +- src/gd_sophia_editor.erl | 2 +- src/gd_sup.erl | 2 +- src/gd_v.erl | 2 +- src/gd_v_devman.erl | 2 +- src/gd_v_netman.erl | 2 +- src/gd_v_wallman.erl | 57 +++++++++++++++++++++++++++++----------- zomp.meta | 2 +- 13 files changed, 64 insertions(+), 44 deletions(-) diff --git a/ebin/gajudesk.app b/ebin/gajudesk.app index 1f70874..676fc99 100644 --- a/ebin/gajudesk.app +++ b/ebin/gajudesk.app @@ -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]}, diff --git a/src/gajudesk.erl b/src/gajudesk.erl index 995acf3..6ae95a4 100644 --- a/src/gajudesk.erl +++ b/src/gajudesk.erl @@ -3,7 +3,7 @@ %%% @end -module(gajudesk). --vsn("0.6.6"). +-vsn("0.7.0"). -behavior(application). -author("Craig Everett "). -copyright("QPQ AG "). diff --git a/src/gd_con.erl b/src/gd_con.erl index c9e40cb..b68b319 100644 --- a/src/gd_con.erl +++ b/src/gd_con.erl @@ -3,7 +3,7 @@ %%% @end -module(gd_con). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -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">>, diff --git a/src/gd_grids.erl b/src/gd_grids.erl index 7a5f3f0..e60b1aa 100644 --- a/src/gd_grids.erl +++ b/src/gd_grids.erl @@ -37,7 +37,7 @@ %%% @end -module(gd_grids). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -license("GPL-3.0-or-later"). diff --git a/src/gd_gui.erl b/src/gd_gui.erl index 0e91dae..b7650b4 100644 --- a/src/gd_gui.erl +++ b/src/gd_gui.erl @@ -3,7 +3,7 @@ %%% @end -module(gd_gui). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -license("GPL-3.0-or-later"). diff --git a/src/gd_jt.erl b/src/gd_jt.erl index d0e4858..6293b29 100644 --- a/src/gd_jt.erl +++ b/src/gd_jt.erl @@ -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]). diff --git a/src/gd_sophia_editor.erl b/src/gd_sophia_editor.erl index 1529b60..448bb7c 100644 --- a/src/gd_sophia_editor.erl +++ b/src/gd_sophia_editor.erl @@ -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]). diff --git a/src/gd_sup.erl b/src/gd_sup.erl index f3c9810..5f92335 100644 --- a/src/gd_sup.erl +++ b/src/gd_sup.erl @@ -12,7 +12,7 @@ %%% @end -module(gd_sup). --vsn("0.6.6"). +-vsn("0.7.0"). -behaviour(supervisor). -author("Craig Everett "). -copyright("QPQ AG "). diff --git a/src/gd_v.erl b/src/gd_v.erl index 5908de5..c93be9b 100644 --- a/src/gd_v.erl +++ b/src/gd_v.erl @@ -1,5 +1,5 @@ -module(gd_v). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -license("GPL-3.0-or-later"). diff --git a/src/gd_v_devman.erl b/src/gd_v_devman.erl index c2fa0a8..a5dad28 100644 --- a/src/gd_v_devman.erl +++ b/src/gd_v_devman.erl @@ -1,5 +1,5 @@ -module(gd_v_devman). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -license("GPL-3.0-or-later"). diff --git a/src/gd_v_netman.erl b/src/gd_v_netman.erl index 4de8e5e..000688a 100644 --- a/src/gd_v_netman.erl +++ b/src/gd_v_netman.erl @@ -1,5 +1,5 @@ -module(gd_v_netman). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -license("GPL-3.0-or-later"). diff --git a/src/gd_v_wallman.erl b/src/gd_v_wallman.erl index dd81ee1..e2e493c 100644 --- a/src/gd_v_wallman.erl +++ b/src/gd_v_wallman.erl @@ -1,5 +1,5 @@ -module(gd_v_wallman). --vsn("0.6.6"). +-vsn("0.7.0"). -author("Craig Everett "). -copyright("QPQ AG "). -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)), diff --git a/zomp.meta b/zomp.meta index 8f43620..7e49fef 100644 --- a/zomp.meta +++ b/zomp.meta @@ -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}},