mirror of
https://github.com/status-im/whispervis.git
synced 2025-02-12 13:07:35 +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()
|
backend := p.simulationWidget.Address()
|
||||||
sim, err := p.runSimulation(backend)
|
ttl := p.simulationWidget.TTL()
|
||||||
|
sim, err := p.runSimulation(backend, ttl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ type SimulationRequest struct {
|
|||||||
|
|
||||||
// runSimulation starts whisper message propagation simulation,
|
// runSimulation starts whisper message propagation simulation,
|
||||||
// remotely talking to simulation backend with given address.
|
// remotely talking to simulation backend with given address.
|
||||||
func (p *Page) runSimulation(address string) (*Simulation, error) {
|
func (p *Page) runSimulation(address string, ttl int) (*Simulation, error) {
|
||||||
buf, err := p.newPOSTSimulationRequest()
|
buf, err := p.newPOSTSimulationRequest(ttl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Internal error. See console output.")
|
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
|
// newPOSTSimulationRequest generates SimulationReqeust and
|
||||||
// prepares it as io.Reader for usage with http.Post.
|
// 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{
|
req := SimulationRequest{
|
||||||
SenderIdx: 0,
|
SenderIdx: 0,
|
||||||
TTL: 10,
|
TTL: ttl,
|
||||||
MsgSize: 400,
|
MsgSize: 400,
|
||||||
Network: p.currentNetworkJSON(),
|
Network: p.currentNetworkJSON(),
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package widgets
|
package widgets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/gopherjs/vecty"
|
"github.com/gopherjs/vecty"
|
||||||
"github.com/gopherjs/vecty/elem"
|
"github.com/gopherjs/vecty/elem"
|
||||||
"github.com/gopherjs/vecty/event"
|
"github.com/gopherjs/vecty/event"
|
||||||
@ -53,8 +55,19 @@ func (s *Simulation) Render() vecty.ComponentOrHTML {
|
|||||||
),
|
),
|
||||||
vecty.Class("input", "is-small"),
|
vecty.Class("input", "is-small"),
|
||||||
prop.Value(s.address),
|
prop.Value(s.address),
|
||||||
vecty.Attribute("placehoder", "backend url"),
|
event.Input(s.onAddressChange),
|
||||||
event.Input(s.onEditInput),
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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()
|
value := event.Target.Get("value").String()
|
||||||
|
|
||||||
s.address = value
|
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.
|
// Address returns the current backend address.
|
||||||
func (s *Simulation) Address() string {
|
func (s *Simulation) Address() string {
|
||||||
return s.address
|
return s.address
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TTL returns the current TTL value.
|
||||||
|
func (s *Simulation) TTL() int {
|
||||||
|
return s.ttl
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Simulation) onSimulateClick(e *vecty.Event) {
|
func (s *Simulation) onSimulateClick(e *vecty.Event) {
|
||||||
go func() {
|
go func() {
|
||||||
s.errMsg = ""
|
s.errMsg = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user