Skip to content

Commit 5033252

Browse files
committed
feat: min-gas-prices
1 parent 5fd0b96 commit 5033252

File tree

2 files changed

+58
-28
lines changed

2 files changed

+58
-28
lines changed

models/weaveinit/run_l1_node.go

+51-24
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ func (m *RunL1NodeMonikerInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
148148
input, done := m.TextInput.Update(msg)
149149
if done {
150150
m.state.moniker = string(input)
151-
fmt.Println("\n[info] state", m.state)
152151
return NewExistingAppChecker(m.state), utils.DoTick()
153152
}
154153
m.TextInput = input
@@ -160,14 +159,12 @@ func (m *RunL1NodeMonikerInput) View() string {
160159
}
161160

162161
type ExistingAppChecker struct {
163-
checkComplete bool
164-
state *RunL1NodeState
162+
state *RunL1NodeState
165163
}
166164

167165
func NewExistingAppChecker(state *RunL1NodeState) *ExistingAppChecker {
168166
return &ExistingAppChecker{
169-
checkComplete: false,
170-
state: state,
167+
state: state,
171168
}
172169
}
173170

@@ -178,26 +175,20 @@ func (m *ExistingAppChecker) Init() tea.Cmd {
178175
func (m *ExistingAppChecker) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
179176
switch msg.(type) {
180177
case utils.TickMsg:
181-
if !m.checkComplete {
182-
homeDir, err := os.UserHomeDir()
183-
if err != nil {
184-
fmt.Printf("[error] Failed to get user home directory: %v\n", err)
185-
return m, tea.Quit
186-
}
187-
188-
configTomlPath := filepath.Join(homeDir, ".initia", "config", "config.toml")
189-
if !utils.FileOrFolderExists(configTomlPath) {
190-
fmt.Println("\n[info] No existing Initia app found")
191-
} else {
192-
return NewExistingAppReplaceSelect(m.state), nil
193-
}
194-
195-
m.checkComplete = true
178+
homeDir, err := os.UserHomeDir()
179+
if err != nil {
180+
fmt.Printf("[error] Failed to get user home directory: %v\n", err)
181+
return m, tea.Quit
196182
}
197-
if m.checkComplete {
198-
return NewRunL1NodeNetworkSelect(m.state), nil
183+
184+
configTomlPath := filepath.Join(homeDir, ".initia", "config", "config.toml")
185+
if !utils.FileOrFolderExists(configTomlPath) {
186+
m.state.existingApp = false
187+
return NewMinGasPriceInput(m.state), nil
188+
} else {
189+
m.state.existingApp = true
190+
return NewExistingAppReplaceSelect(m.state), nil
199191
}
200-
return m, nil
201192
default:
202193
return m, nil
203194
}
@@ -240,9 +231,11 @@ func (m *ExistingAppReplaceSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
240231
if selected != nil {
241232
switch *selected {
242233
case UseCurrent:
234+
m.state.replaceExistingApp = false
243235
fmt.Println("\n[info] Using current files")
244236
case Replace:
245-
fmt.Println("\n[info] Replacing files")
237+
m.state.replaceExistingApp = true
238+
return NewMinGasPriceInput(m.state), nil
246239
}
247240
return m, tea.Quit
248241
}
@@ -261,3 +254,37 @@ func (m *ExistingAppReplaceSelect) View() string {
261254
}
262255
return view + "\nPress Enter to select, or q to quit."
263256
}
257+
258+
type MinGasPriceInput struct {
259+
utils.TextInput
260+
state *RunL1NodeState
261+
}
262+
263+
func NewMinGasPriceInput(state *RunL1NodeState) *MinGasPriceInput {
264+
return &MinGasPriceInput{
265+
TextInput: "",
266+
state: state,
267+
}
268+
}
269+
270+
func (m *MinGasPriceInput) Init() tea.Cmd {
271+
return nil
272+
}
273+
274+
func (m *MinGasPriceInput) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
275+
input, done := m.TextInput.Update(msg)
276+
if done {
277+
m.state.minGasPrice = string(input)
278+
return m, tea.Quit
279+
}
280+
m.TextInput = input
281+
return m, nil
282+
}
283+
284+
func (m *MinGasPriceInput) View() string {
285+
preText := ""
286+
if !m.state.existingApp {
287+
preText += "No existing .initia directory found. Creating a new one.\n"
288+
}
289+
return fmt.Sprintf("%s? Please specify min-gas-price (uinit)\n> %s\n", preText, string(m.TextInput))
290+
}

models/weaveinit/state.go

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

33
type RunL1NodeState struct {
4-
network string
5-
initiadVersion string
6-
chainId string
7-
moniker string
4+
network string
5+
initiadVersion string
6+
chainId string
7+
moniker string
8+
existingApp bool
9+
replaceExistingApp bool
10+
minGasPrice string
811
}

0 commit comments

Comments
 (0)