Skip to content

Commit 5f94c9c

Browse files
committed
impv: add weave init
1 parent 2dc6386 commit 5f94c9c

File tree

4 files changed

+105
-54
lines changed

4 files changed

+105
-54
lines changed

models/homepage.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ type Homepage struct {
1414
type HomepageOption string
1515

1616
const (
17-
Init HomepageOption = "Weave Init"
17+
InitOption HomepageOption = "Weave Init"
1818
)
1919

2020
func NewHomepage() tea.Model {
2121
return &Homepage{
2222
Selector: utils.Selector[HomepageOption]{
2323
Options: []HomepageOption{
24-
Init,
24+
InitOption,
2525
},
2626
Cursor: 0,
2727
},
@@ -36,8 +36,8 @@ func (m *Homepage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
3636
selected, cmd := m.Select(msg)
3737
if selected != nil {
3838
switch *selected {
39-
case Init:
40-
return weaveinit.NewInitSelect(&weaveinit.State{}), nil
39+
case InitOption:
40+
return weaveinit.NewWeaveInit(&weaveinit.State{}), nil
4141
}
4242
}
4343

models/weaveinit/init_select.go

-50
This file was deleted.

models/weaveinit/run_l1_node.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package weaveinit
2+
3+
import (
4+
"fmt"
5+
tea "github.com/charmbracelet/bubbletea"
6+
"github.com/initia-labs/weave/utils"
7+
)
8+
9+
type RunL1Node struct {
10+
utils.TextInput
11+
state *State
12+
}
13+
14+
func NewRunL1Node(state *State) *RunL1Node {
15+
return &RunL1Node{
16+
TextInput: "",
17+
state: state,
18+
}
19+
}
20+
21+
func (m *RunL1Node) Init() tea.Cmd {
22+
return nil
23+
}
24+
25+
func (m *RunL1Node) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
26+
input, done := m.TextInput.Update(msg)
27+
if done {
28+
m.state.gasStationMnemonic = string(input)
29+
fmt.Println("[info] state ", m.state)
30+
return m, tea.Quit
31+
}
32+
m.TextInput = input
33+
return m, nil
34+
}
35+
36+
func (m *RunL1Node) View() string {
37+
return fmt.Sprintf("? Please set up a Gas Station account\n %s\n", m.TextInput)
38+
}

models/weaveinit/weaveinit.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package weaveinit
2+
3+
import (
4+
tea "github.com/charmbracelet/bubbletea"
5+
"github.com/initia-labs/weave/utils"
6+
)
7+
8+
type WeaveInit struct {
9+
utils.Selector[WeaveInitOption]
10+
state *State
11+
}
12+
13+
type WeaveInitOption string
14+
15+
const (
16+
RunL1NodeOption WeaveInitOption = "Run L1 Node"
17+
LaunchNewMinitiaOption WeaveInitOption = "Launch New Minitia"
18+
InitializeOPBotsOption WeaveInitOption = "Initialize OP Bots"
19+
StartRelayerOption WeaveInitOption = "Start a Relayer"
20+
)
21+
22+
func NewWeaveInit(state *State) *WeaveInit {
23+
return &WeaveInit{
24+
Selector: utils.Selector[WeaveInitOption]{
25+
Options: []WeaveInitOption{
26+
RunL1NodeOption,
27+
LaunchNewMinitiaOption,
28+
InitializeOPBotsOption,
29+
StartRelayerOption,
30+
},
31+
Cursor: 0,
32+
},
33+
state: state,
34+
}
35+
}
36+
37+
func (m *WeaveInit) Init() tea.Cmd {
38+
return nil
39+
}
40+
41+
func (m *WeaveInit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
42+
selected, cmd := m.Select(msg)
43+
if selected != nil {
44+
switch *selected {
45+
case RunL1NodeOption:
46+
return NewRunL1Node(&State{}), nil
47+
}
48+
}
49+
50+
return m, cmd
51+
}
52+
53+
func (m *WeaveInit) View() string {
54+
view := "? What action would you like to perform?\n"
55+
for i, option := range m.Options {
56+
if i == m.Cursor {
57+
view += "(•) " + string(option) + "\n"
58+
} else {
59+
view += "( ) " + string(option) + "\n"
60+
}
61+
}
62+
return view + "\nPress Enter to select, or q to quit."
63+
}

0 commit comments

Comments
 (0)