From 493290a998b84226139447bc7309078585a50379 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Thu, 28 Aug 2025 10:36:04 +1000 Subject: [PATCH 1/3] Don't create 'Account 1' --- src/gd_v_wallman.erl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/gd_v_wallman.erl b/src/gd_v_wallman.erl index cdf8514..39856a7 100644 --- a/src/gd_v_wallman.erl +++ b/src/gd_v_wallman.erl @@ -394,8 +394,6 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) -> Path = filename:join(DefaultDir, Name), 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 -> -- 2.30.2 From e2c0634cb3f983d542d13c67b9614b21e919ecb6 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Thu, 28 Aug 2025 17:16:22 +1000 Subject: [PATCH 2/3] Ugly import wizard --- src/gd_v_wallman.erl | 96 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 7 deletions(-) diff --git a/src/gd_v_wallman.erl b/src/gd_v_wallman.erl index 39856a7..26f7314 100644 --- a/src/gd_v_wallman.erl +++ b/src/gd_v_wallman.erl @@ -203,7 +203,7 @@ handle_event(#wx{event = #wxClose{}}, State = #s{wiz = none}) -> {noreply, State}; handle_event(#wx{event = #wxCommand{type = command_button_clicked}, id = ID}, - State = #s{wiz = {_, WizButtons}}) -> + State = #s{wiz = {_, WizButtons, _}}) -> NewState = case lists:keyfind(ID, #w.id, WizButtons) of #w{name = noob} -> wiz_noob_assist(State); @@ -211,7 +211,7 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked}, false -> State end, {noreply, NewState}; -handle_event(#wx{event = #wxClose{}}, State = #s{wiz = {_, _}}) -> +handle_event(#wx{event = #wxClose{}}, State = #s{wiz = WizTuple}) when is_tuple(WizTuple) -> NewState = close_wiz(State), {noreply, NewState}; handle_event(Event, State) -> @@ -257,7 +257,7 @@ do_first_run(State = #s{frame = Frame, wallets = Manifest}) -> end. -close_wiz(State = #s{frame = Frame, wiz = {Wiz, _}}) -> +close_wiz(State = #s{frame = Frame, wiz = {Wiz, _, _}}) -> ok = wxWindow:destroy(Wiz), true = wxFrame:show(Frame), State#s{wiz = none}. @@ -355,7 +355,15 @@ do_open3(Path, State = #s{frame = Frame, j = J}) -> end. -do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) -> +do_wiz(State) -> + case find_wallet_files(State) of + false -> + do_wiz_create(State); + {true, WalletDir} -> + do_wiz_import(State, WalletDir) + end. + +do_wiz_create(State = #s{wx = WX, lang = Lang, wiz = none}) -> Trans = gd_jt:read_translations(?MODULE), J = gd_jt:j(Lang, Trans), @@ -385,10 +393,80 @@ do_wiz(State = #s{wx = WX, lang = Lang, wiz = none}) -> ok = wxFrame:setSize(Wiz, {300, 300}), ok = wxFrame:center(Wiz), true = wxFrame:show(Wiz), - State#s{wiz = {Wiz, Buttons}}. + State#s{wiz = {Wiz, Buttons, create}}. + +do_wiz_import(State = #s{wx = WX, lang = Lang, wiz = none}, WalletDir) -> + Trans = gd_jt:read_translations(?MODULE), + J = gd_jt:j(Lang, Trans), + + Wiz = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")), + MainSz = wxBoxSizer:new(?wxVERTICAL), + + Explanation = wxStaticText:new(Wiz, ?wxID_ANY, "Reinstall detected. Do you want to import an old wallet?"), + wxBoxSizer:add(MainSz, Explanation, zxw:flags(wide)), + + ButtonTemplates = + [{noob, J("Import an old wallet.")}, + {l33t, J("Open the wallet manager.")}], + + MakeButton = + fun({Name, Label}) -> + B = wxButton:new(Wiz, ?wxID_ANY, [{label, Label}]), + #w{name = Name, id = wxButton:getId(B), wx = B} + end, + + Buttons = lists:map(MakeButton, ButtonTemplates), + + Add = fun(#w{wx = Button}) -> wxBoxSizer:add(MainSz, Button, zxw:flags(wide)) end, + ok = lists:foreach(Add, Buttons), + + ok = wxFrame:setSizer(Wiz, MainSz), + ok = wxSizer:layout(MainSz), + + ok = wxFrame:connect(Wiz, command_button_clicked), + ok = wxFrame:connect(Wiz, close_window), + ok = wxFrame:setSize(Wiz, {300, 300}), + ok = wxFrame:center(Wiz), + true = wxFrame:show(Wiz), + State#s{wiz = {Wiz, Buttons, {import, WalletDir}}}. -wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) -> +find_wallet_files(#s{prefs = Prefs}) -> + DefaultDir = zx_lib:path(var, "otpr", "gajudesk"), + case maps:find(dir, Prefs) of + {ok, DefaultDir} -> find_wallet_files3(DefaultDir); + error -> find_wallet_files3(DefaultDir); + {ok, PrefDir} -> find_wallet_files2(PrefDir, DefaultDir) + end. + +find_wallet_files2(PrefDir, DefaultDir) -> + case has_wallet_file(PrefDir) of + true -> {true, PrefDir}; + false -> find_wallet_files3(DefaultDir) + end. + +find_wallet_files3(DefaultDir) -> + case has_wallet_file(DefaultDir) of + true -> {true, DefaultDir}; + false -> false + end. + +has_wallet_file(Dir) -> + case file:list_dir_all(Dir) of + {ok, Filenames} -> + lists:any(fun path_is_wallet_file/1, Filenames); + {error, _} -> + false + end. + +path_is_wallet_file(Path) -> + case filename:extension(Path) of + ".gaju" -> true; + <<".gaju">> -> true; + _ -> false + end. + +wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _, create}}) -> DefaultDir = zx_lib:path(var, "otpr", "gajudesk"), Name = default_name(), Path = filename:join(DefaultDir, Name), @@ -398,7 +476,11 @@ wiz_noob_assist(State = #s{j = J, wiz = {Wiz, _}}) -> State; abort -> State - end. + end; +wiz_noob_assist(State = #s{prefs = Prefs, wiz = {_, _, {import, WalletDir}}}) -> + NewPrefs = maps:put(dir, WalletDir, Prefs), + NewState = State#s{prefs = NewPrefs}, + do_import(NewState). default_name() -> {{YY, MM, DD}, {Hr, Mn, Sc}} = calendar:local_time(), -- 2.30.2 From 4220c71417cebe34aba799c44d4b96a61af35cb7 Mon Sep 17 00:00:00 2001 From: Jarvis Carroll Date: Fri, 29 Aug 2025 12:02:50 +1000 Subject: [PATCH 3/3] differently ugly --- src/gd_v_wallman.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gd_v_wallman.erl b/src/gd_v_wallman.erl index 26f7314..e6e531c 100644 --- a/src/gd_v_wallman.erl +++ b/src/gd_v_wallman.erl @@ -402,8 +402,10 @@ do_wiz_import(State = #s{wx = WX, lang = Lang, wiz = none}, WalletDir) -> Wiz = wxFrame:new(WX, ?wxID_ANY, J("Initializing Wallet")), MainSz = wxBoxSizer:new(?wxVERTICAL), - Explanation = wxStaticText:new(Wiz, ?wxID_ANY, "Reinstall detected. Do you want to import an old wallet?"), - wxBoxSizer:add(MainSz, Explanation, zxw:flags(wide)), + Explanation = wxStaticText:new(Wiz, ?wxID_ANY, + "Reinstall detected.\nDo you want to import an old wallet?", + [{style, ?wxALIGN_CENTRE_HORIZONTAL}]), + wxBoxSizer:add(MainSz, Explanation, zxw:flags(base)), ButtonTemplates = [{noob, J("Import an old wallet.")}, -- 2.30.2