Skip to content

Commit

Permalink
Added support for DefaultButton on Confirm() boxes.
Browse files Browse the repository at this point in the history
Added some default values for Uniswap v3.. still to be tested.
  • Loading branch information
Alexandre Bourget committed Sep 12, 2024
1 parent 0060348 commit 29fc4be
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 248 deletions.
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins:
- Msf/codegen/conversation/v1/conversation.proto=github.com/streamingfast/substreams-codegen/pb/sf/codegen/conversation/v1;pbconvo
- Msf/codegen/remotebuild/v1/remotebuild.proto=github.com/streamingfast/substreams-codegen/pb/sf/codegen/remotebuild/v1;pbbuild

- plugin: buf.build/grpc/go
- plugin: buf.build/grpc/go:v1.4.0
out: pb
opt:
- paths=source_relative
Expand Down
150 changes: 0 additions & 150 deletions conversation/v1/conversation.proto

This file was deleted.

27 changes: 18 additions & 9 deletions evm-events-calls/convo.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd {
return loop.Seq(
c.Msg().Messagef("We're tackling the %s contract.", humanize.Ordinal(c.State.currentContractIdx+1)).Cmd(),
c.Action(InputContractAddress{}).TextInput("Please enter the contract address", "Submit").
Description("Format it with 0x prefix and make sure it's a valid Ethereum address.\nFor example, the Uniswap v3 factory address: 0x1f98431c8ad98523631ae4a59f267346ea31f984").
Description("Format it with 0x prefix and make sure it's a valid Ethereum address.\nThe default value is the Uniswap v3 factory address.").
DefaultValue("0x1f98431c8ad98523631ae4a59f267346ea31f984").
Validation("^0x[a-fA-F0-9]{40}$", "Please enter a valid Ethereum address").Cmd(),
Validation("^0x[a-fA-F0-9]{40}$", "Please enter a valid Ethereum address: 0x followed by 40 hex characters.").Cmd(),
)

case AskDynamicContractAddress:
Expand All @@ -254,8 +254,9 @@ func (c *Convo) Update(msg loop.Msg) loop.Cmd {
return QuitInvalidContext
}
return c.Action(InputDynamicContractAddress{}).TextInput(fmt.Sprintf("Please enter an example contract created by the %q factory", factory.Name), "Submit").
Description("Format it with 0x prefix and make sure it's a valid Ethereum address.\nFor example, the USDC/ETH pool at: 0x88e6A0c2dDD26FEEb64F039a2c41296FcB3f5640").
Validation("^0x[a-fA-F0-9]{40}$", "Please enter a valid Ethereum address").Cmd()
Description("Format it with 0x prefix and make sure it's a valid Ethereum address.\nThe default value is the USDC/ETH pool address.").
DefaultValue("0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640").
Validation("^0x[a-fA-F0-9]{40}$", "Please enter a valid Ethereum address: 0x followed by 40 hex characters.").Cmd()

case InputDynamicContractAddress:
factory := c.contextContract()
Expand Down Expand Up @@ -471,7 +472,7 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
}
{{- end}}
`+"```"+`
`, map[string]any{"events": evt, "calls": calls}).Cmd()
`, map[string]any{"events": evt, "calls": calls}).Cmd()
return loop.Seq(peekABI, cmd(AskConfirmContractABI{}))

case AskConfirmContractABI:
Expand Down Expand Up @@ -591,9 +592,13 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
if contract == nil {
return QuitInvalidContext
}
return c.Action(InputContractName{}).TextInput(fmt.Sprintf("Choose a short name for the contract at address %q (lowercase and numbers only)", contract.Address), "Submit").
act := c.Action(InputContractName{}).TextInput(fmt.Sprintf("Choose a short name for the contract at address %q (lowercase and numbers only)", contract.Address), "Submit").
Description("Lowercase and numbers only").
Validation(`^([a-z][a-z0-9_]{0,63})$`, "The name should be short, and contain only lowercase characters and numbers, and not start with a number.").Cmd()
Validation(`^([a-z][a-z0-9_]{0,63})$`, "The name should be short, and contain only lowercase characters and numbers, and not start with a number.")
if contract.Address == "0x1f98431c8ad98523631ae4a59f267346ea31f984" {
act = act.DefaultValue("factory")
}
return act.Cmd()

case InputContractName:
contract := c.contextContract()
Expand All @@ -617,9 +622,13 @@ message {{.Proto.MessageName}} {{.Proto.OutputModuleFieldName}} {
if factory == nil {
return QuitInvalidContext
}
return c.Action(InputDynamicContractName{}).TextInput(fmt.Sprintf("Choose a short name for the contract that will be created by the factory %q (lowercase and numbers only)", factory.Name), "Submit").
act := c.Action(InputDynamicContractName{}).TextInput(fmt.Sprintf("Choose a short name for the contract that will be created by the factory %q (lowercase and numbers only)", factory.Name), "Submit").
Description("Lowercase and numbers only").
Validation(`^([a-z][a-z0-9_]{0,63})$`, "The name should be short, and contain only lowercase characters and numbers, and not start with a number.").Cmd()
Validation(`^([a-z][a-z0-9_]{0,63})$`, "The name should be short, and contain only lowercase characters and numbers, and not start with a number.")
if factory.Address == "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" {
act = act.DefaultValue("pool")
}
return act.Cmd()

case InputDynamicContractName:
factory := c.contextContract()
Expand Down
20 changes: 20 additions & 0 deletions msgwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,26 @@ func (w *MsgWrap) Confirm(prompt string, acceptLabel, declineLabel string) *MsgW
return w
}

func (w *MsgWrap) DefaultAccept() *MsgWrap {
switch entry := w.Msg.Entry.(type) {
case *pbconvo.SystemOutput_Confirm_:
entry.Confirm.DefaultButton = pbconvo.SystemOutput_Confirm_CONFIRM
default:
panic("unsupported message type for this method")
}
return w
}

func (w *MsgWrap) DefaultDecline() *MsgWrap {
switch entry := w.Msg.Entry.(type) {
case *pbconvo.SystemOutput_Confirm_:
entry.Confirm.DefaultButton = pbconvo.SystemOutput_Confirm_DECLINE
default:
panic("unsupported message type for this method")
}
return w
}

func (w *MsgWrap) DownloadFiles() *MsgWrap {
// TODO: to a type assertion on the `lastType`, to make sure it matches what we're asking here..
w.Msg.Entry = &pbconvo.SystemOutput_DownloadFiles_{
Expand Down
Loading

0 comments on commit 29fc4be

Please sign in to comment.