Skip to content

Commit e4e7fd9

Browse files
authored
Merge pull request #124 from initia-labs/fix/minievm-default-denom
feat: update rollup default denom validation
2 parents 967c37a + a9784b2 commit e4e7fd9

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

common/validate.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ func ValidateDenom(denom string) error {
7676
return nil
7777
}
7878

79+
func ValidateDenomWithReserved(reservedDenoms []string) func(denom string) error {
80+
return func(denom string) error {
81+
if !reDnm.MatchString(denom) {
82+
return fmt.Errorf("invalid denom: %s", denom)
83+
}
84+
85+
for _, reserved := range reservedDenoms {
86+
if denom == reserved {
87+
return fmt.Errorf("denom %s is reserved and cannot be used (reserved denom for this rollup: %v)", denom, reservedDenoms)
88+
}
89+
}
90+
91+
return nil
92+
}
93+
}
94+
7995
func NoOps(_ string) error {
8096
return nil
8197
}

models/minitia/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ const (
3434
DefaultMinitiaLCD string = "http://localhost:1317"
3535
DefaultMinitiaRPC string = "http://localhost:26657"
3636
DefaultMinitiaJsonRPC string = "http://localhost:8545"
37+
38+
DefaultRollupDenom string = "umin"
39+
DefaultMinievmDenom string = "GAS"
3740
)
3841

3942
var (

models/minitia/launch.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,8 @@ func (m *VMTypeSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
344344

345345
state.weave.PushPreviousResponse(styles.RenderPreviousResponse(styles.ArrowSeparator, m.GetQuestion(), m.highlights, string(*selected)))
346346
state.vmType = string(*selected)
347-
model := NewLatestVersionLoading(weavecontext.SetCurrentState(m.Ctx, state))
348347

348+
model := NewLatestVersionLoading(weavecontext.SetCurrentState(m.Ctx, state))
349349
return model, model.Init()
350350
}
351351

@@ -485,16 +485,28 @@ type GasDenomInput struct {
485485
}
486486

487487
func NewGasDenomInput(ctx context.Context) *GasDenomInput {
488+
var defaultDenom string
489+
var validateFn func(s string) error
490+
491+
state := weavecontext.GetCurrentState[LaunchState](ctx)
492+
if state.vmType == string(EVM) {
493+
defaultDenom = DefaultMinievmDenom
494+
validateFn = common.ValidateDenomWithReserved([]string{DefaultRollupDenom})
495+
} else {
496+
defaultDenom = DefaultRollupDenom
497+
validateFn = common.ValidateDenom
498+
}
499+
488500
toolTip := tooltip.RollupGasDenomTooltip
489501
model := &GasDenomInput{
490502
TextInput: ui.NewTextInput(false),
491503
BaseModel: weavecontext.BaseModel{Ctx: ctx},
492504
question: "Specify rollup gas denom",
493505
highlights: []string{"rollup gas denom"},
494506
}
495-
model.WithPlaceholder(`Press tab to use "umin"`)
496-
model.WithDefaultValue("umin")
497-
model.WithValidatorFn(common.ValidateDenom)
507+
model.WithPlaceholder(fmt.Sprintf(`Press tab to use "%s"`, defaultDenom))
508+
model.WithDefaultValue(defaultDenom)
509+
model.WithValidatorFn(validateFn)
498510
model.WithTooltip(&toolTip)
499511
return model
500512
}

0 commit comments

Comments
 (0)