diff --git a/page.go b/page.go index db48c59..95aa946 100644 --- a/page.go +++ b/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 } diff --git a/simulation.go b/simulation.go index a9967cd..259a55d 100644 --- a/simulation.go +++ b/simulation.go @@ -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(), } diff --git a/widgets/simulation.go b/widgets/simulation.go index 615de18..604d574 100644 --- a/widgets/simulation.go +++ b/widgets/simulation.go @@ -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 = ""