Skip to content

Commit 4f52028

Browse files
authored
Merge pull request #65 from initia-labs/feat/proofreading
Refactor and Proofreading
2 parents a991410 + 171ab9d commit 4f52028

13 files changed

+82
-61
lines changed

analytics/amplitude.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func Initialize(weaveVersion string) {
4747

4848
type EventAttributes map[string]interface{}
4949

50-
// Event represents an event with some attributes
50+
// AmplitudeEvent represents an event with some attributes
5151
type AmplitudeEvent struct {
5252
Attributes EventAttributes
5353
}
@@ -113,7 +113,7 @@ func TrackCompletedEvent(cmd *cobra.Command, component Component) {
113113

114114
// Add adds a key-value pair to the event's attributes
115115
func (e *AmplitudeEvent) Add(key string, value interface{}) *AmplitudeEvent {
116-
if key != string(ModelNameKey) {
116+
if key != ModelNameKey {
117117
if str, ok := value.(string); ok {
118118
value = strings.ToLower(str) // Convert string value to lowercase
119119
}

analytics/constant.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ const (
1818
CommandEventKey string = "command"
1919
OptionEventKey string = "option"
2020
L1ChainIdEventKey string = "l1-chain-id"
21-
L1ExistingEventKey string = "existing-l1-app"
2221
ErrorEventKey string = "panic-error"
23-
L1NodeVersionKey string = "l1-node-version"
24-
EmptyInputKey string = "empty-input"
2522
ModelNameKey string = "model-name"
2623
GenerateKeyfileKey string = "generate-key-file"
2724
KeyFileKey string = "key-file"
@@ -48,7 +45,7 @@ const (
4845

4946
// Rollup Event
5047
VmTypeSelected Event = "vm-type-selected"
51-
OpBridgeBatchSubmissionTargetSelected Event = "op-bridge-batch-sumission-selected"
48+
OpBridgeBatchSubmissionTargetSelected Event = "op-bridge-batch-submission-selected"
5249
EnableOracleSelected Event = "enable-oracle-selected"
5350
SystemKeysSelected Event = "system-keys-selected"
5451
AccountsFundingPresetSelected Event = "accounts-funding-preset-selected"

cmd/gas_station_integration_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ import (
1818
func TestGasStationSetup(t *testing.T) {
1919
userHome, _ := os.UserHomeDir()
2020
weaveDir := filepath.Join(userHome, common.WeaveDirectory)
21+
weaveDirBackup := filepath.Join(userHome, weaveDirectoryBackup)
22+
if _, err := os.Stat(weaveDir); !os.IsNotExist(err) {
23+
// remove the backup directory if it exists
24+
os.RemoveAll(weaveDirBackup)
25+
// rename the weave directory to back up
26+
if err := os.Rename(weaveDir, weaveDirBackup); err != nil {
27+
t.Fatalf("Failed to backup weave directory: %v", err)
28+
}
29+
30+
// restore the weave directory
31+
defer func() {
32+
os.RemoveAll(weaveDir)
33+
os.Rename(weaveDirBackup, weaveDir)
34+
}()
35+
}
2136

2237
finalModel := testutil.SetupGasStation(t)
2338

cmd/opinit_bots.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func OPInitBotsKeysSetupCommand() *cobra.Command {
133133
return setupCmd
134134
}
135135

136-
func generateKeyFile(userHome string, keyPath string, botName string) (opinit_bots.KeyFile, error) {
136+
func generateKeyFile(keyPath string, botName string) (opinit_bots.KeyFile, error) {
137137
keyFile, err := opinit_bots.GenerateMnemonicKeyfile(botName)
138138
if err != nil {
139139
return keyFile, err
@@ -192,7 +192,7 @@ func handleWithConfig(cmd *cobra.Command, userHome, opInitHome, configPath, keyF
192192
var keyFile opinit_bots.KeyFile
193193
if isGenerateKeyFile {
194194
keyPath := filepath.Join(userHome, common.WeaveDataDirectory, fmt.Sprintf("%s.%s.keyfile", common.OpinitGeneratedKeyFilename, botName))
195-
keyFile, err = generateKeyFile(userHome, keyPath, botName)
195+
keyFile, err = generateKeyFile(keyPath, botName)
196196
if err != nil {
197197
return err
198198
}

cmd/upgrade.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ func VersionCommand() *cobra.Command {
2525
Use: "version",
2626
Short: "Print the Weave binary version",
2727
RunE: func(cmd *cobra.Command, args []string) error {
28-
fmt.Fprintln(cmd.OutOrStdout(), Version)
28+
_, err := fmt.Fprintln(cmd.OutOrStdout(), Version)
29+
if err != nil {
30+
return err
31+
}
2932
return nil
3033
},
3134
}

cosmosutils/cli_tx.go

-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func (te *InitiadTxExecutor) waitForTransactionInclusion(rpcURL, txHash string)
170170
return fmt.Errorf("failed to unmarshal transaction JSON response: %v", err)
171171
}
172172
if txResponse.Code == 0 { // Successful transaction
173-
// Transaction successfully included in block
174173
return nil
175174
} else {
176175
return fmt.Errorf("tx failed with error: %v", txResponse.RawLog)

io/filesystem.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ func ExtractTarGz(src string, dest string) error {
7373
return err
7474
}
7575
_, err = io.Copy(file, tarReader)
76-
file.Close()
76+
if err != nil {
77+
return err
78+
}
79+
err = file.Close()
7780
if err != nil {
7881
return err
7982
}

models/initia/run_l1_node.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ var (
5959

6060
const Local L1NodeNetworkOption = "Local"
6161

62-
func (option L1NodeNetworkOption) GetNetworkType() string {
63-
switch option {
62+
func (l L1NodeNetworkOption) GetNetworkType() string {
63+
switch l {
6464
case Mainnet:
6565
return "mainnet"
6666
case Testnet:
@@ -204,9 +204,9 @@ func (m *RunL1NodeVersionSelect) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
204204
}
205205
selected, cmd := m.Select(msg)
206206
if selected != nil {
207-
analytics.TrackEvent(analytics.L1NodeVersionSelected, analytics.NewEmptyEvent().Add(analytics.OptionEventKey, string(*selected)))
207+
analytics.TrackEvent(analytics.L1NodeVersionSelected, analytics.NewEmptyEvent().Add(analytics.OptionEventKey, *selected))
208208
state := weavecontext.PushPageAndGetState[RunL1NodeState](m)
209-
state.initiadVersion = string(*selected)
209+
state.initiadVersion = *selected
210210
state.initiadEndpoint = m.versions[*selected]
211211
state.weave.PushPreviousResponse(styles.RenderPreviousResponse(styles.DotsSeparator, m.GetQuestion(), m.highlights, state.initiadVersion))
212212

@@ -230,15 +230,15 @@ type RunL1NodeChainIdInput struct {
230230
}
231231

232232
func NewRunL1NodeChainIdInput(ctx context.Context) *RunL1NodeChainIdInput {
233-
tooltip := tooltip.L1ChainIdTooltip
233+
toolTip := tooltip.L1ChainIdTooltip
234234
model := &RunL1NodeChainIdInput{
235235
TextInput: ui.NewTextInput(false),
236236
BaseModel: weavecontext.BaseModel{Ctx: ctx},
237237
question: "Specify the chain ID",
238238
highlights: []string{"chain ID"},
239239
}
240240
model.WithPlaceholder("Enter your chain ID ex. local-initia-1")
241-
model.WithTooltip(&tooltip)
241+
model.WithTooltip(&toolTip)
242242
return model
243243
}
244244

@@ -377,7 +377,7 @@ type RunL1NodeMonikerInput struct {
377377
}
378378

379379
func NewRunL1NodeMonikerInput(ctx context.Context) *RunL1NodeMonikerInput {
380-
tooltip := tooltip.MonikerTooltip
380+
toolTip := tooltip.MonikerTooltip
381381
model := &RunL1NodeMonikerInput{
382382
TextInput: ui.NewTextInput(false),
383383
BaseModel: weavecontext.BaseModel{Ctx: ctx},
@@ -386,7 +386,7 @@ func NewRunL1NodeMonikerInput(ctx context.Context) *RunL1NodeMonikerInput {
386386
}
387387
model.WithPlaceholder("Enter moniker ex. my-initia-node")
388388
model.WithValidatorFn(common.ValidateEmptyString)
389-
model.WithTooltip(&tooltip)
389+
model.WithTooltip(&toolTip)
390390
return model
391391
}
392392

@@ -438,7 +438,7 @@ type MinGasPriceInput struct {
438438
}
439439

440440
func NewMinGasPriceInput(ctx context.Context) *MinGasPriceInput {
441-
tooltip := tooltip.L1MinGasPriceTooltip
441+
toolTip := tooltip.L1MinGasPriceTooltip
442442
model := &MinGasPriceInput{
443443
TextInput: ui.NewTextInput(false),
444444
BaseModel: weavecontext.BaseModel{Ctx: ctx},
@@ -447,7 +447,7 @@ func NewMinGasPriceInput(ctx context.Context) *MinGasPriceInput {
447447
}
448448
model.WithPlaceholder("Enter a number with its denom ex. 0.15uinit")
449449
model.WithValidatorFn(common.ValidateDecCoin)
450-
model.WithTooltip(&tooltip)
450+
model.WithTooltip(&toolTip)
451451
return model
452452
}
453453

@@ -569,15 +569,15 @@ type SeedsInput struct {
569569
}
570570

571571
func NewSeedsInput(ctx context.Context) *SeedsInput {
572-
tooltip := tooltip.L1SeedsTooltip
572+
toolTip := tooltip.L1SeedsTooltip
573573
model := &SeedsInput{
574574
TextInput: ui.NewTextInput(false),
575575
BaseModel: weavecontext.BaseModel{Ctx: ctx},
576576
question: "Specify seeds",
577577
highlights: []string{"seeds"},
578578
}
579579
model.WithValidatorFn(common.IsValidPeerOrSeed)
580-
model.WithTooltip(&tooltip)
580+
model.WithTooltip(&toolTip)
581581

582582
state := weavecontext.GetCurrentState[RunL1NodeState](ctx)
583583
if state.network != string(Local) {
@@ -633,15 +633,15 @@ type PersistentPeersInput struct {
633633
}
634634

635635
func NewPersistentPeersInput(ctx context.Context) *PersistentPeersInput {
636-
tooltip := tooltip.L1PersistentPeersTooltip
636+
toolTip := tooltip.L1PersistentPeersTooltip
637637
model := &PersistentPeersInput{
638638
TextInput: ui.NewTextInput(false),
639639
BaseModel: weavecontext.BaseModel{Ctx: ctx},
640640
question: "Specify persistent peers",
641641
highlights: []string{"persistent peers"},
642642
}
643643
model.WithValidatorFn(common.IsValidPeerOrSeed)
644-
model.WithTooltip(&tooltip)
644+
model.WithTooltip(&toolTip)
645645

646646
state := weavecontext.GetCurrentState[RunL1NodeState](ctx)
647647
if state.network != string(Local) {
@@ -929,7 +929,7 @@ type GenesisEndpointInput struct {
929929
}
930930

931931
func NewGenesisEndpointInput(ctx context.Context) *GenesisEndpointInput {
932-
tooltip := tooltip.L1GenesisEndpointTooltip
932+
toolTip := tooltip.L1GenesisEndpointTooltip
933933
model := &GenesisEndpointInput{
934934
TextInput: ui.NewTextInput(true),
935935
BaseModel: weavecontext.BaseModel{Ctx: ctx, CannotBack: true},
@@ -938,7 +938,7 @@ func NewGenesisEndpointInput(ctx context.Context) *GenesisEndpointInput {
938938
highlights: []string{"genesis.json"},
939939
}
940940
model.WithPlaceholder("Enter a valid URL")
941-
model.WithTooltip(&tooltip)
941+
model.WithTooltip(&toolTip)
942942
return model
943943
}
944944

0 commit comments

Comments
 (0)