From 824dcac37993e7f68efa11ebeba1729ca15c9a89 Mon Sep 17 00:00:00 2001 From: traviolus <42636319+traviolus@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:24:47 +0700 Subject: [PATCH 1/2] feat(opinit): move keyfile generation to the confirmation step --- models/opinit_bots/init.go | 50 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/models/opinit_bots/init.go b/models/opinit_bots/init.go index 11ffa38..8a42afa 100644 --- a/models/opinit_bots/init.go +++ b/models/opinit_bots/init.go @@ -1099,31 +1099,6 @@ func WaitStartingInitBot(ctx context.Context) tea.Cmd { } } - keyFilePath, err := weavecontext.GetOPInitKeyFileJson(ctx) - if err != nil { - return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to get key file path for OPinit: %w", err)} - } - - keyFile := io.NewKeyFile() - err = keyFile.Load(keyFilePath) - if err != nil { - return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to load key file for OPinit: %w", err)} - } - - for _, botName := range BotNames { - if res, ok := state.SetupOpinitResponses[botName]; ok { - keyInfo := strings.Split(res, "\n") - address := strings.Split(keyInfo[0], ": ") - mnemonic := keyInfo[1] - keyFile.AddKey(string(BotNameToKeyName[botName]), io.NewKey(address[1], mnemonic)) - } - } - - err = keyFile.Write(keyFilePath) - if err != nil { - return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to write key file: %w", err)} - } - if state.InitExecutorBot { srv, err := service.NewService(service.OPinitExecutor) if err != nil { @@ -1373,6 +1348,31 @@ func (m *SetupOPInitBotsMissingKey) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: if msg.String() == "enter" { + keyFilePath, err := weavecontext.GetOPInitKeyFileJson(m.Ctx) + if err != nil { + return m, m.HandlePanic(fmt.Errorf("failed to get key file path for OPinit: %w", err)) + } + + keyFile := io.NewKeyFile() + err = keyFile.Load(keyFilePath) + if err != nil { + return m, m.HandlePanic(fmt.Errorf("failed to load key file for OPinit: %w", err)) + } + + for _, botName := range BotNames { + if res, ok := state.SetupOpinitResponses[botName]; ok { + keyInfo := strings.Split(res, "\n") + address := strings.Split(keyInfo[0], ": ") + mnemonic := keyInfo[1] + keyFile.AddKey(string(BotNameToKeyName[botName]), io.NewKey(address[1], mnemonic)) + } + } + + err = keyFile.Write(keyFilePath) + if err != nil { + return m, m.HandlePanic(fmt.Errorf("failed to write key file: %w", err)) + } + model, err := handleBotInitSelection(m.Loading.EndContext, state) if err != nil { return m, m.HandlePanic(err) From 3c2790fe41b66899684bc32029ef58c5a0e325a1 Mon Sep 17 00:00:00 2001 From: traviolus <42636319+traviolus@users.noreply.github.com> Date: Thu, 13 Feb 2025 18:26:48 +0700 Subject: [PATCH 2/2] feat(opinit): also save keyfile after init step --- models/opinit_bots/init.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/models/opinit_bots/init.go b/models/opinit_bots/init.go index 8a42afa..cf39e95 100644 --- a/models/opinit_bots/init.go +++ b/models/opinit_bots/init.go @@ -1099,6 +1099,31 @@ func WaitStartingInitBot(ctx context.Context) tea.Cmd { } } + keyFilePath, err := weavecontext.GetOPInitKeyFileJson(ctx) + if err != nil { + return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to get key file path for OPinit: %w", err)} + } + + keyFile := io.NewKeyFile() + err = keyFile.Load(keyFilePath) + if err != nil { + return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to load key file for OPinit: %w", err)} + } + + for _, botName := range BotNames { + if res, ok := state.SetupOpinitResponses[botName]; ok { + keyInfo := strings.Split(res, "\n") + address := strings.Split(keyInfo[0], ": ") + mnemonic := keyInfo[1] + keyFile.AddKey(string(BotNameToKeyName[botName]), io.NewKey(address[1], mnemonic)) + } + } + + err = keyFile.Write(keyFilePath) + if err != nil { + return ui.NonRetryableErrorLoading{Err: fmt.Errorf("failed to write key file: %w", err)} + } + if state.InitExecutorBot { srv, err := service.NewService(service.OPinitExecutor) if err != nil {