4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
+ "sort"
8
+ "strings"
7
9
"time"
8
10
9
11
tea "github.com/charmbracelet/bubbletea"
@@ -78,7 +80,7 @@ func NewDeleteExistingMinitiaInput(state *LaunchState) *DeleteExistingMinitiaInp
78
80
state : state ,
79
81
question : "Please type `delete existing minitia` to delete the .minitia folder and proceed with weave minitia launch" ,
80
82
}
81
- model .WithPlaceholder ("Type `delete existing minitia` to delete, Ctrl+C or q to keep the folder and quit this command." )
83
+ model .WithPlaceholder ("Type `delete existing minitia` to delete, Ctrl+C to keep the folder and quit this command." )
82
84
model .WithValidatorFn (utils .ValidateExactString ("delete existing minitia" ))
83
85
return model
84
86
}
@@ -94,7 +96,8 @@ func (m *DeleteExistingMinitiaInput) Init() tea.Cmd {
94
96
func (m * DeleteExistingMinitiaInput ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
95
97
input , cmd , done := m .TextInput .Update (msg )
96
98
if done {
97
- // TODO: Continue
99
+ // TODO: Delete .minitia folder
100
+ return NewExistingAppReplaceSelect (m .state ), nil
98
101
}
99
102
m .TextInput = input
100
103
return m , cmd
@@ -105,3 +108,160 @@ func (m *DeleteExistingMinitiaInput) View() string {
105
108
styles .Text ("Please note that once you delete, all configurations, state, keys, and other data will be \n " , styles .Yellow ) + styles .BoldText ("permanently deleted and cannot be reversed.\n " , styles .Yellow ) +
106
109
styles .RenderPrompt (m .GetQuestion (), []string {"`delete existing minitia`" , ".minitia" , "weave minitia launch" }, styles .Question ) + m .TextInput .View ()
107
110
}
111
+
112
+ type NetworkSelect struct {
113
+ utils.Selector [NetworkSelectOption ]
114
+ state * LaunchState
115
+ question string
116
+ }
117
+
118
+ type NetworkSelectOption string
119
+
120
+ var (
121
+ Testnet NetworkSelectOption = ""
122
+ Mainnet NetworkSelectOption = ""
123
+ )
124
+
125
+ func NewExistingAppReplaceSelect (state * LaunchState ) * NetworkSelect {
126
+ Testnet = NetworkSelectOption (fmt .Sprintf ("Testnet (%s)" , utils .GetConfig ("constants.chain_id.testnet" )))
127
+ Mainnet = NetworkSelectOption (fmt .Sprintf ("Mainnet (%s)" , utils .GetConfig ("constants.chain_id.mainnet" )))
128
+ return & NetworkSelect {
129
+ Selector : utils.Selector [NetworkSelectOption ]{
130
+ Options : []NetworkSelectOption {
131
+ Testnet ,
132
+ Mainnet ,
133
+ },
134
+ },
135
+ state : state ,
136
+ question : "Which Initia L1 network would you like to connect to?" ,
137
+ }
138
+ }
139
+
140
+ func (m * NetworkSelect ) GetQuestion () string {
141
+ return m .question
142
+ }
143
+
144
+ func (m * NetworkSelect ) Init () tea.Cmd {
145
+ return nil
146
+ }
147
+
148
+ func (m * NetworkSelect ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
149
+ selected , cmd := m .Select (msg )
150
+ if selected != nil {
151
+ m .state .weave .PushPreviousResponse (styles .RenderPreviousResponse (styles .ArrowSeparator , m .GetQuestion (), []string {"Initia L1 network" }, string (* selected )))
152
+ m .state .l1Network = string (* selected )
153
+ return NewVMTypeSelect (m .state ), nil
154
+ }
155
+
156
+ return m , cmd
157
+ }
158
+
159
+ func (m * NetworkSelect ) View () string {
160
+ return m .state .weave .Render () + styles .RenderPrompt (
161
+ m .GetQuestion (),
162
+ []string {"Initia L1 network" },
163
+ styles .Question ,
164
+ ) + m .Selector .View ()
165
+ }
166
+
167
+ type VMTypeSelect struct {
168
+ utils.Selector [VMTypeSelectOption ]
169
+ state * LaunchState
170
+ question string
171
+ }
172
+
173
+ type VMTypeSelectOption string
174
+
175
+ const (
176
+ Move VMTypeSelectOption = "Move"
177
+ Wasm VMTypeSelectOption = "Wasm"
178
+ EVM VMTypeSelectOption = "EVM"
179
+ )
180
+
181
+ func NewVMTypeSelect (state * LaunchState ) * VMTypeSelect {
182
+ return & VMTypeSelect {
183
+ Selector : utils.Selector [VMTypeSelectOption ]{
184
+ Options : []VMTypeSelectOption {
185
+ Move ,
186
+ Wasm ,
187
+ EVM ,
188
+ },
189
+ },
190
+ state : state ,
191
+ question : "Which VM type would you like to select?" ,
192
+ }
193
+ }
194
+
195
+ func (m * VMTypeSelect ) GetQuestion () string {
196
+ return m .question
197
+ }
198
+
199
+ func (m * VMTypeSelect ) Init () tea.Cmd {
200
+ return nil
201
+ }
202
+
203
+ func (m * VMTypeSelect ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
204
+ selected , cmd := m .Select (msg )
205
+ if selected != nil {
206
+ m .state .weave .PushPreviousResponse (styles .RenderPreviousResponse (styles .ArrowSeparator , m .GetQuestion (), []string {"VM type" }, string (* selected )))
207
+ m .state .vmType = string (* selected )
208
+ return NewRunL1NodeVersionSelect (m .state ), nil
209
+ }
210
+
211
+ return m , cmd
212
+ }
213
+
214
+ func (m * VMTypeSelect ) View () string {
215
+ return m .state .weave .Render () + styles .RenderPrompt (
216
+ m .GetQuestion (),
217
+ []string {"VM type" },
218
+ styles .Question ,
219
+ ) + m .Selector .View ()
220
+ }
221
+
222
+ type VersionSelect struct {
223
+ utils.Selector [string ]
224
+ state * LaunchState
225
+ versions utils.InitiaVersionWithDownloadURL
226
+ question string
227
+ }
228
+
229
+ func NewRunL1NodeVersionSelect (state * LaunchState ) * VersionSelect {
230
+ versions := utils .ListInitiaReleases (fmt .Sprintf ("https://api.github.com/repos/initia-labs/mini%s/releases" , strings .ToLower (state .vmType )))
231
+ options := make ([]string , 0 , len (versions ))
232
+ for key := range versions {
233
+ options = append (options , key )
234
+ }
235
+ sort .Sort (sort .Reverse (sort .StringSlice (options )))
236
+ return & VersionSelect {
237
+ Selector : utils.Selector [string ]{
238
+ Options : utils .SortVersions (versions ),
239
+ },
240
+ state : state ,
241
+ versions : versions ,
242
+ question : "Please specify the minitiad version?" ,
243
+ }
244
+ }
245
+
246
+ func (m * VersionSelect ) GetQuestion () string {
247
+ return m .question
248
+ }
249
+
250
+ func (m * VersionSelect ) Init () tea.Cmd {
251
+ return nil
252
+ }
253
+
254
+ func (m * VersionSelect ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
255
+ selected , cmd := m .Select (msg )
256
+ if selected != nil {
257
+ // TODO: Set the selected version
258
+ m .state .weave .PushPreviousResponse (styles .RenderPreviousResponse (styles .DotsSeparator , m .GetQuestion (), []string {"minitiad version" }, "" ))
259
+ return m , nil
260
+ }
261
+
262
+ return m , cmd
263
+ }
264
+
265
+ func (m * VersionSelect ) View () string {
266
+ return m .state .weave .Render () + styles .RenderPrompt (m .GetQuestion (), []string {"minitiad version" }, styles .Question ) + m .Selector .View ()
267
+ }
0 commit comments