mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-01 07:55:29 +00:00
Add TTL input
This commit is contained in:
parent
1f8ac9b3b7
commit
276e2ec3b8
3
page.go
3
page.go
@ -184,7 +184,8 @@ func (p *Page) startSimulation() error {
|
||||
}()
|
||||
|
||||
backend := p.simulationWidget.Address()
|
||||
sim, err := p.runSimulation(backend)
|
||||
ttl := p.simulationWidget.TTL()
|
||||
sim, err := p.runSimulation(backend, ttl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ type SimulationRequest struct {
|
||||
|
||||
// runSimulation starts whisper message propagation simulation,
|
||||
// remotely talking to simulation backend with given address.
|
||||
func (p *Page) runSimulation(address string) (*Simulation, error) {
|
||||
buf, err := p.newPOSTSimulationRequest()
|
||||
func (p *Page) runSimulation(address string, ttl int) (*Simulation, error) {
|
||||
buf, err := p.newPOSTSimulationRequest(ttl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Internal error. See console output.")
|
||||
}
|
||||
@ -53,10 +53,10 @@ func (p *Page) runSimulation(address string) (*Simulation, error) {
|
||||
|
||||
// newPOSTSimulationRequest generates SimulationReqeust and
|
||||
// prepares it as io.Reader for usage with http.Post.
|
||||
func (p *Page) newPOSTSimulationRequest() (io.Reader, error) {
|
||||
func (p *Page) newPOSTSimulationRequest(ttl int) (io.Reader, error) {
|
||||
req := SimulationRequest{
|
||||
SenderIdx: 0,
|
||||
TTL: 10,
|
||||
TTL: ttl,
|
||||
MsgSize: 400,
|
||||
Network: p.currentNetworkJSON(),
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gopherjs/vecty"
|
||||
"github.com/gopherjs/vecty/elem"
|
||||
"github.com/gopherjs/vecty/event"
|
||||
@ -53,8 +55,19 @@ func (s *Simulation) Render() vecty.ComponentOrHTML {
|
||||
),
|
||||
vecty.Class("input", "is-small"),
|
||||
prop.Value(s.address),
|
||||
vecty.Attribute("placehoder", "backend url"),
|
||||
event.Input(s.onEditInput),
|
||||
event.Input(s.onAddressChange),
|
||||
),
|
||||
),
|
||||
),
|
||||
InputField("TTL:", "Message time to live value (in seconds)",
|
||||
elem.Input(
|
||||
vecty.Markup(
|
||||
vecty.MarkupIf(s.inProgress,
|
||||
vecty.Attribute("disabled", "true"),
|
||||
),
|
||||
vecty.Class("input", "is-small"),
|
||||
prop.Value(fmt.Sprint(s.ttl)),
|
||||
event.Input(s.onTTLChange),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -99,17 +112,28 @@ func (s *Simulation) Render() vecty.ComponentOrHTML {
|
||||
)
|
||||
}
|
||||
|
||||
func (s *Simulation) onEditInput(event *vecty.Event) {
|
||||
func (s *Simulation) onAddressChange(event *vecty.Event) {
|
||||
value := event.Target.Get("value").String()
|
||||
|
||||
s.address = value
|
||||
}
|
||||
|
||||
func (s *Simulation) onTTLChange(event *vecty.Event) {
|
||||
value := event.Target.Get("value").Int()
|
||||
|
||||
s.ttl = value
|
||||
}
|
||||
|
||||
// Address returns the current backend address.
|
||||
func (s *Simulation) Address() string {
|
||||
return s.address
|
||||
}
|
||||
|
||||
// TTL returns the current TTL value.
|
||||
func (s *Simulation) TTL() int {
|
||||
return s.ttl
|
||||
}
|
||||
|
||||
func (s *Simulation) onSimulateClick(e *vecty.Event) {
|
||||
go func() {
|
||||
s.errMsg = ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user