Skip to content

Commit e40e6c2

Browse files
committed
feat: weave initia init models
1 parent 0391ed5 commit e40e6c2

File tree

3 files changed

+108
-9
lines changed

3 files changed

+108
-9
lines changed

models/weaveinit/run_l1_node.go

+103-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/initia-labs/weave/utils"
77
)
88

9-
type RunL1Node struct {
9+
type RunL1NodeNetworkSelect struct {
1010
utils.Selector[L1NodeNetworkOption]
1111
state *RunL1NodeState
1212
}
@@ -19,8 +19,8 @@ const (
1919
Local L1NodeNetworkOption = "Local"
2020
)
2121

22-
func NewRunL1Node(state *RunL1NodeState) *RunL1Node {
23-
return &RunL1Node{
22+
func NewRunL1NodeNetworkSelect(state *RunL1NodeState) *RunL1NodeNetworkSelect {
23+
return &RunL1NodeNetworkSelect{
2424
Selector: utils.Selector[L1NodeNetworkOption]{
2525
Options: []L1NodeNetworkOption{
2626
Mainnet,
@@ -32,22 +32,27 @@ func NewRunL1Node(state *RunL1NodeState) *RunL1Node {
3232
}
3333
}
3434

35-
func (m *RunL1Node) Init() tea.Cmd {
35+
func (m *RunL1NodeNetworkSelect) Init() tea.Cmd {
3636
return nil
3737
}
3838

39-
func (m *RunL1Node) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
39+
func (m *RunL1NodeNetworkSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4040
selected, cmd := m.Select(msg)
4141
if selected != nil {
4242
m.state.network = string(*selected)
43-
fmt.Println("[info] state ", m.state)
43+
switch *selected {
44+
case Mainnet, Testnet:
45+
fmt.Println("\n[info] state", m.state)
46+
case Local:
47+
return NewRunL1NodeVersionInput(m.state), nil
48+
}
4449
return m, tea.Quit
4550
}
4651

4752
return m, cmd
4853
}
4954

50-
func (m *RunL1Node) View() string {
55+
func (m *RunL1NodeNetworkSelect) View() string {
5156
view := "? Which network will your node participate in?\n"
5257
for i, option := range m.Options {
5358
if i == m.Cursor {
@@ -58,3 +63,94 @@ func (m *RunL1Node) View() string {
5863
}
5964
return view + "\nPress Enter to select, or q to quit."
6065
}
66+
67+
type RunL1NodeVersionInput struct {
68+
utils.TextInput
69+
state *RunL1NodeState
70+
}
71+
72+
func NewRunL1NodeVersionInput(state *RunL1NodeState) *RunL1NodeVersionInput {
73+
return &RunL1NodeVersionInput{
74+
TextInput: "",
75+
state: state,
76+
}
77+
}
78+
79+
func (m *RunL1NodeVersionInput) Init() tea.Cmd {
80+
return nil
81+
}
82+
83+
func (m *RunL1NodeVersionInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
84+
input, done := m.TextInput.Update(msg)
85+
if done {
86+
m.state.initiadVersion = string(input)
87+
return NewRunL1NodeChainIdInput(m.state), nil
88+
}
89+
m.TextInput = input
90+
return m, nil
91+
}
92+
93+
func (m *RunL1NodeVersionInput) View() string {
94+
return fmt.Sprintf("? Please specify the initiad version\n> %s\n", string(m.TextInput))
95+
}
96+
97+
type RunL1NodeChainIdInput struct {
98+
utils.TextInput
99+
state *RunL1NodeState
100+
}
101+
102+
func NewRunL1NodeChainIdInput(state *RunL1NodeState) *RunL1NodeChainIdInput {
103+
return &RunL1NodeChainIdInput{
104+
TextInput: "",
105+
state: state,
106+
}
107+
}
108+
109+
func (m *RunL1NodeChainIdInput) Init() tea.Cmd {
110+
return nil
111+
}
112+
113+
func (m *RunL1NodeChainIdInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
114+
input, done := m.TextInput.Update(msg)
115+
if done {
116+
m.state.chainId = string(input)
117+
return NewRunL1NodeMonikerInput(m.state), nil
118+
}
119+
m.TextInput = input
120+
return m, nil
121+
}
122+
123+
func (m *RunL1NodeChainIdInput) View() string {
124+
return fmt.Sprintf("? Please specify the chain ID\n> %s\n", string(m.TextInput))
125+
}
126+
127+
type RunL1NodeMonikerInput struct {
128+
utils.TextInput
129+
state *RunL1NodeState
130+
}
131+
132+
func NewRunL1NodeMonikerInput(state *RunL1NodeState) *RunL1NodeMonikerInput {
133+
return &RunL1NodeMonikerInput{
134+
TextInput: "",
135+
state: state,
136+
}
137+
}
138+
139+
func (m *RunL1NodeMonikerInput) Init() tea.Cmd {
140+
return nil
141+
}
142+
143+
func (m *RunL1NodeMonikerInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
144+
input, done := m.TextInput.Update(msg)
145+
if done {
146+
m.state.moniker = string(input)
147+
fmt.Println("\n[info] state", m.state)
148+
return m, tea.Quit
149+
}
150+
m.TextInput = input
151+
return m, nil
152+
}
153+
154+
func (m *RunL1NodeMonikerInput) View() string {
155+
return fmt.Sprintf("? Please specify the moniker\n> %s\n", string(m.TextInput))
156+
}

models/weaveinit/state.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package weaveinit
22

33
type RunL1NodeState struct {
4-
network string
4+
network string
5+
initiadVersion string
6+
chainId string
7+
moniker string
58
}

models/weaveinit/weaveinit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (m *WeaveInit) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4141
if selected != nil {
4242
switch *selected {
4343
case RunL1NodeOption:
44-
return NewRunL1Node(&RunL1NodeState{}), nil
44+
return NewRunL1NodeNetworkSelect(&RunL1NodeState{}), nil
4545
}
4646
}
4747

0 commit comments

Comments
 (0)