Skip to content

Commit

Permalink
Merge pull request #146 from initia-labs/feat/opinit-keyfile
Browse files Browse the repository at this point in the history
feat: move opinit keyfile generation to the confirmation step
  • Loading branch information
WasinWatt authored Feb 13, 2025
2 parents 9aa435b + 3c2790f commit e51628f
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions models/opinit_bots/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,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)
Expand Down

0 comments on commit e51628f

Please sign in to comment.