Skip to content

Commit d0d1e61

Browse files
committed
feat: weave init now has an option to skip
1 parent b2b19a3 commit d0d1e61

File tree

1 file changed

+72
-24
lines changed

1 file changed

+72
-24
lines changed

models/initialize.go

+72-24
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,99 @@ import (
55

66
tea "github.com/charmbracelet/bubbletea"
77

8+
"github.com/initia-labs/weave/models/weaveinit"
89
"github.com/initia-labs/weave/styles"
910
"github.com/initia-labs/weave/utils"
1011
)
1112

12-
type ExistingAppChecker struct {
13-
TextInput utils.TextInput
13+
func InitHeader() string {
14+
return styles.FadeText("Welcome to Weave! 🪢\n\n") +
15+
styles.RenderPrompt("As this is your first time using Weave, we ask that you set up your Gas Station account,\nwhich will hold the necessary funds for the OPinit-bots or relayer to send transactions.\n\n", []string{"Gas Station account"}, styles.Empty) +
16+
styles.BoldText("Please note that Weave will not send any transactions without your confirmation.\n", styles.Yellow) +
17+
styles.Text("While you can complete this setup later, we recommend doing it now to ensure a smoother experience.\n\n", styles.Gray)
1418
}
1519

16-
func NewExistingAppChecker() *ExistingAppChecker {
17-
model := &ExistingAppChecker{}
18-
model.TextInput.WithValidatorFn(utils.ValidateMnemonic)
19-
return model
20+
type ExistingWeaveChecker struct {
21+
utils.Selector[ExistingWeaveOption]
22+
}
23+
24+
type ExistingWeaveOption string
25+
26+
const (
27+
Yes ExistingWeaveOption = "Yes"
28+
No ExistingWeaveOption = "No"
29+
)
30+
31+
func NewExistingAppChecker() *ExistingWeaveChecker {
32+
return &ExistingWeaveChecker{
33+
Selector: utils.Selector[ExistingWeaveOption]{
34+
Options: []ExistingWeaveOption{
35+
Yes,
36+
No,
37+
},
38+
},
39+
}
2040
}
2141

22-
func (m *ExistingAppChecker) Init() tea.Cmd {
42+
func (m *ExistingWeaveChecker) Init() tea.Cmd {
2343
return utils.DoTick()
2444
}
2545

26-
func (m *ExistingAppChecker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
27-
input, cmd, done := m.TextInput.Update(msg)
28-
if done {
29-
view := styles.RenderPreviousResponse(styles.ArrowSeparator, "Please set up a Gas Station account", []string{"Gas Station account"}, input.Text)
30-
model := NewWeaveAppInitialization(view, input.Text)
31-
return model, model.Init()
46+
func (m *ExistingWeaveChecker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
47+
selected, cmd := m.Select(msg)
48+
if selected != nil {
49+
switch *selected {
50+
case Yes:
51+
view := styles.RenderPreviousResponse(styles.ArrowSeparator, "Would you like to set up a Gas Station account", []string{"Gas Station account"}, string(*selected))
52+
return NewGasStationMnemonicInput(view), nil
53+
case No:
54+
return weaveinit.NewWeaveInit(), nil
55+
}
3256
}
33-
m.TextInput = input
3457
return m, cmd
3558
}
3659

37-
func (m *ExistingAppChecker) View() string {
38-
view := styles.FadeText("Welcome to Weave! 🪢\n\n")
60+
func (m *ExistingWeaveChecker) View() string {
61+
view := InitHeader()
62+
view += styles.RenderPrompt("Would you like to set up a Gas Station account", []string{"Gas Station account"}, styles.Question) +
63+
" " + styles.Text("(The account that will hold the funds required by the OPinit-bots or relayer to send transactions)", styles.Gray)
64+
view += m.Selector.View()
3965

40-
view += styles.RenderPrompt("As this is your first time using Weave, we ask that you set up your Gas Station account,\nwhich will hold the necessary funds for the OPinit-bots or relayer to send transactions.\n\n", []string{"Gas Station account"}, styles.Empty)
66+
return view
67+
}
4168

42-
view += styles.BoldText("Please note that Weave will not send any transactions without your confirmation.\n", styles.Yellow)
69+
type GasStationMnemonicInput struct {
70+
previousResponse string
71+
utils.TextInput
72+
}
4373

44-
view += styles.Text("While you can complete this setup later, we recommend doing it now to ensure a smoother experience.\n\n", styles.Gray)
74+
func NewGasStationMnemonicInput(previousResponse string) *GasStationMnemonicInput {
75+
model := &GasStationMnemonicInput{
76+
previousResponse: previousResponse,
77+
TextInput: utils.NewTextInput(),
78+
}
79+
model.WithPlaceholder("Add mnemonic")
80+
model.WithValidatorFn(utils.ValidateMnemonic)
81+
return model
82+
}
4583

46-
// TODO add new step to ask if user want to set up gas station account or not, if not we will skip to the next step
84+
func (m *GasStationMnemonicInput) Init() tea.Cmd {
85+
return nil
86+
}
4787

48-
view += styles.RenderPrompt("Please set up a Gas Station account", []string{"Gas Station account"}, styles.Question) +
49-
" " + styles.Text("(The account that will hold the funds required by the OPinit-bots or relayer to send transactions)", styles.Gray)
50-
view += m.TextInput.View()
88+
func (m *GasStationMnemonicInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
89+
input, cmd, done := m.TextInput.Update(msg)
90+
if done {
91+
m.previousResponse += styles.RenderPreviousResponse(styles.DotsSeparator, "Please set up a Gas Station account", []string{"Gas Station account"}, "*Mnemonic has been entered and is now hidden for security purposes.*")
92+
model := NewWeaveAppInitialization(m.previousResponse, input.Text)
93+
return model, model.Init()
94+
}
95+
m.TextInput = input
96+
return m, cmd
97+
}
5198

52-
return view
99+
func (m *GasStationMnemonicInput) View() string {
100+
return InitHeader() + m.previousResponse + styles.RenderPrompt("Please set up a Gas Station account", []string{"Gas Station account"}, styles.Question) + m.TextInput.View()
53101
}
54102

55103
type WeaveAppInitialization struct {

0 commit comments

Comments
 (0)