diff --git a/.gitignore b/.gitignore index fa173c5978a5218a9ff4c5edd323d14f07a2bf8b..0ad6433dc8e7bd97b823f78bc2a141bc6fc86000 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ # Dependency directories (remove the comment below to include it) vendor/ - -mainnet-commitments-client.log +*.log mainnet-commitments-ui mainnet-commitments-ui.exe \ No newline at end of file diff --git a/css/style.css b/css/style.css index 5e52dfd9aaf184eda776342a761e98bc79cd2543..13dc4bb534e57c38d62c623d14373b0bdc1481e9 100644 --- a/css/style.css +++ b/css/style.css @@ -1,6 +1,5 @@ body { font-family: "Roboto", "Franklin Gothic Medium", Tahoma, sans-serif; - padding:2em; background: #08CDD7; } @@ -15,12 +14,15 @@ body { box-shadow: 0 0 64px rgb(0 0 0 / 20%); border-radius: 50px; min-width: 300px; + box-sizing: border-box; + margin: 2em; } .fakeFileInput { font-family: sans-serif; font-weight: normal; color: #555555; + margin:0; } .fileInput:focus + .fakeFileInput, .fakeFileInput:focus { @@ -54,9 +56,9 @@ p.help-block { font-weight: 600; font-size: 120%; background: #ff4e4e; - display: inline-block; + display: block; padding: 1px 5px; - margin: 0 0 0 10px; + margin:10px; } div.contractContainer { @@ -68,4 +70,36 @@ div.contractContainer { border-radius: 4px; box-shadow: inset 0 1px 1px rgb(0 0 0 / 8%); transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s; +} + +h1 { + margin-top:5px; +} + +p.contractText { + margin-top:25px; +} + +.submitButton { + position: relative; + left: 50%; + transform: translateX(-50%); +} + +.formErrors{ + color: #ffffff; + font-weight: 600; + font-size: 110%; + background: #ff4e4e; + display: inline-block; + margin: 0 0 10px; +} + +.success { + font-size: 200%; + color: green; + font-weight: 600; + text-align: center; + margin: 0 auto; + display: block; } \ No newline at end of file diff --git a/fileInput.go b/fileButton.go similarity index 77% rename from fileInput.go rename to fileButton.go index 9dc438b8c36a4aff4778881a2c07a7095059709a..4c11ec334fa872b40fa3e60e2a069b4a3f666a9b 100644 --- a/fileInput.go +++ b/fileButton.go @@ -12,8 +12,8 @@ import ( // <p class="help-block">Example block-level help text here.</p> // </div> -// FormInput is a bootstrap "form-group" input -type FormInput struct { +// FileButton is a bootstrap "form-group" input +type FileButton struct { *gowd.Element input *gowd.Element txt *gowd.Element @@ -21,9 +21,9 @@ type FormInput struct { helpTxt *gowd.Element } -// NewFormInput creates a bootstrap "form-group" containing an input with a given type and caption -func NewFormInput(caption string, value *string) *FormInput { - i := new(FormInput) +// NewFileButton creates a bootstrap "form-group" containing an input with a given type and caption +func NewFileButton(caption string, value *string) *FileButton { + i := new(FileButton) i.Element = bootstrap.NewElement("div", "form-group") i.lbl2 = gowd.NewElement("label") @@ -41,8 +41,6 @@ func NewFormInput(caption string, value *string) *FormInput { i.input = bootstrap.NewElement("input", "form-control fileInput") i.input.SetAttribute("type", "file") - // i.input.SetAttribute("style", "display:none;") - // i.input.SetAttribute("style", "visibility:hidden;") i.input.SetAttribute("style", "width:0;height:0;padding:0;border:0;") i.helpTxt = bootstrap.NewElement("p", "help-block") @@ -67,32 +65,32 @@ func NewFormInput(caption string, value *string) *FormInput { } // SetPlaceHolder sets the input placeholder text -func (i *FormInput) SetPlaceHolder(placeHolder string) { +func (i *FileButton) SetPlaceHolder(placeHolder string) { i.input.SetAttribute("placeHolder", placeHolder) } // SetHelpText sets the input help text -func (i *FormInput) SetHelpText(help string) { +func (i *FileButton) SetHelpText(help string) { i.helpTxt.SetText(help) i.helpTxt.Hidden = false } // HideHelpText hides the input help text -func (i *FormInput) HideHelpText() { +func (i *FileButton) HideHelpText() { i.helpTxt.Hidden = true } // SetValue sets the input value -func (i *FormInput) SetValue(value string) { +func (i *FileButton) SetValue(value string) { i.input.SetAttribute("value", value) } // GetValue returns the input value -func (i *FormInput) GetValue() string { +func (i *FileButton) GetValue() string { return i.input.GetValue() } // SetFile sets the input file value -func (i *FormInput) SetFile(value string) { +func (i *FileButton) SetFile(value string) { i.lbl2.SetText(value) } diff --git a/go.mod b/go.mod index db7f8499c47db695e56cc6a61a42c6454f7538ef..3f1f935b16160b918493475e0d733be4206220f8 100644 --- a/go.mod +++ b/go.mod @@ -7,17 +7,57 @@ require ( github.com/dtylman/gowd v0.0.0-20190619113956-15e38debca22 github.com/spf13/cobra v1.3.0 github.com/spf13/jwalterweatherman v1.1.0 + gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b ) require ( + github.com/ChainSafe/go-schnorrkel v0.0.0-20201021020641-d3c6d3118d10 // indirect + github.com/btcsuite/btcutil v1.0.2 // indirect + github.com/cosmos/go-bip39 v1.0.0 // indirect + github.com/decred/base58 v1.0.3 // indirect + github.com/decred/dcrd/crypto/blake256 v1.0.0 // indirect + github.com/gin-contrib/cors v1.3.1 // indirect + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-gonic/gin v1.7.4 // indirect + github.com/go-playground/locales v0.13.0 // indirect + github.com/go-playground/universal-translator v0.17.0 // indirect + github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/go-resty/resty/v2 v2.6.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/gtank/merlin v0.1.1 // indirect + github.com/gtank/ristretto255 v0.1.2 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect + github.com/jackc/chunkreader/v2 v2.0.1 // indirect + github.com/jackc/pgconn v1.10.0 // indirect + github.com/jackc/pgio v1.0.0 // indirect + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgproto3/v2 v2.1.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect + github.com/jackc/pgtype v1.8.1 // indirect + github.com/jackc/pgx/v4 v4.13.0 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.2 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/leodido/go-urn v1.2.0 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/tyler-smith/go-bip39 v1.1.0 // indirect + github.com/ugorji/go/codec v1.1.7 // indirect + github.com/vedhavyas/go-subkey v1.0.2 // indirect + github.com/xx-labs/sleeve v0.1.1-0.20211013215902-d22a28ed32ff // indirect + github.com/zeebo/blake3 v0.1.1 // indirect gitlab.com/xx_network/crypto v0.0.5-0.20210914231859-c309efac46c4 // indirect - gitlab.com/xx_network/primitives v0.0.4-0.20210915220237-70cb4551d6f3 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect + golang.org/x/text v0.3.7 // indirect + google.golang.org/protobuf v1.27.1 // indirect + gopkg.in/yaml.v2 v2.4.0 // indirect + gorm.io/driver/postgres v1.1.1 // indirect + gorm.io/gorm v1.21.15 // indirect ) diff --git a/go.sum b/go.sum index 9a2a34136bcf3e3ac0416d550ed29c36f5a76fb4..c2c6f5cdeb3cca443c466d2be7952dd57a5695cc 100644 --- a/go.sum +++ b/go.sum @@ -622,8 +622,9 @@ gitlab.com/xx_network/primitives v0.0.0-20200803231956-9b192c57ea7c/go.mod h1:wt gitlab.com/xx_network/primitives v0.0.0-20200804183002-f99f7a7284da/go.mod h1:OK9xevzWCaPO7b1wiluVJGk7R5ZsuC7pHY5hteZFQug= gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVkHy+QogOB6F/qc= gitlab.com/xx_network/primitives v0.0.4-0.20210913211733-42dc24dd47df/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= -gitlab.com/xx_network/primitives v0.0.4-0.20210915220237-70cb4551d6f3 h1:kM2NuV2erfhZ6d2wAd/B7CjxJJwKshupFyqfismPWls= gitlab.com/xx_network/primitives v0.0.4-0.20210915220237-70cb4551d6f3/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= +gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b h1:shZZ3xZNNKYVpEp4Mqu/G9+ZR+J8QA8mmPk/4Cit8+Y= +gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs= go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g= diff --git a/index.go b/index.go index 66c3502ec44c1d745028b21e64a80f11f958612a..5487348d78b871eca1016ed9f7db1b7ee622a40e 100644 --- a/index.go +++ b/index.go @@ -7,6 +7,7 @@ import ( "github.com/dtylman/gowd" "github.com/dtylman/gowd/bootstrap" jww "github.com/spf13/jwalterweatherman" + utils2 "gitlab.com/xx_network/primitives/utils" "time" ) @@ -23,17 +24,28 @@ func buildPage() error { // add some elements using the object model // keyPathInput := bootstrap.NewFileButton(bootstrap.ButtonDefault, "keyPath", false) - keyPathInput := NewFormInput("keyPath", &inputs.keyPath) - idfPathInput := NewFormInput("idfPath", &inputs.idfPath) + keyPathInput := NewFileButton("keyPath", &inputs.keyPath) + idfPathInput := NewFileButton("idfPath", &inputs.idfPath) nominatorWalletInput := bootstrap.NewFormInput("text", "nominatorWallet") validatorWalletInput := bootstrap.NewFormInput("text", "validatorWallet") serverAddressInput := bootstrap.NewFormInput("text", "serverAddress") - serverCertPathInput := NewFormInput("serverCertPath", &inputs.serverCertPath) - agreeInput := bootstrap.NewCheckBox("Agree", false) - submit := bootstrap.NewButton(bootstrap.ButtonPrimary, "Submit") + serverCertPathInput := NewFileButton("serverCertPath", &inputs.serverCertPath) + + agreeInput := bootstrap.NewCheckBox("agree", false) + agreeHelpText := bootstrap.NewElement("p", "help-block") + agreeHelpText.Hidden = true + agreeBox := bootstrap.NewElement("div", "form-group", agreeInput.Element, agreeHelpText) + submit := bootstrap.NewButton(bootstrap.ButtonPrimary, "Submit") errBox := bootstrap.NewElement("span", "errorBox") errBox.Hidden = true + submitBox := bootstrap.NewElement("div", "", submit, errBox) + submitBox.SetAttribute("style", "text-align:center;") + + formErrors := bootstrap.NewElement("p", "formErrors") + formErrors.Hidden = true + + divWell := bootstrap.NewElement("div", "well") submit.OnEvent(gowd.OnClick, func(_ *gowd.Element, event *gowd.EventElement) { var errs int @@ -42,12 +54,25 @@ func buildPage() error { errs++ } else { keyPathInput.HideHelpText() + + _, err := utils2.ReadFile(inputs.keyPath) + if err != nil { + jww.ERROR.Printf("keyPath error: %+v", err) + keyPathInput.SetHelpText(err.Error()) + errs++ + } } if len(inputs.idfPath) == 0 { idfPathInput.SetHelpText("Required.") errs++ } else { idfPathInput.HideHelpText() + _, err := utils2.ReadFile(inputs.idfPath) + if err != nil { + jww.ERROR.Printf("idfPath error: %+v", err) + idfPathInput.SetHelpText(err.Error()) + errs++ + } } inputs.nominatorWallet = nominatorWalletInput.GetValue() if len(inputs.nominatorWallet) == 0 { @@ -55,7 +80,7 @@ func buildPage() error { errs++ } else { if len(nominatorWalletInput.Kids) > 2 { - nominatorWalletInput.RemoveElement(nominatorWalletInput.Kids[2]) + nominatorWalletInput.Kids[2].Hidden = true } } inputs.validatorWallet = validatorWalletInput.GetValue() @@ -64,7 +89,7 @@ func buildPage() error { errs++ } else { if len(validatorWalletInput.Kids) > 2 { - validatorWalletInput.RemoveElement(validatorWalletInput.Kids[2]) + validatorWalletInput.Kids[2].Hidden = true } } inputs.serverAddress = serverAddressInput.GetValue() @@ -73,7 +98,7 @@ func buildPage() error { errs++ } else { if len(serverAddressInput.Kids) > 2 { - serverAddressInput.RemoveElement(serverAddressInput.Kids[2]) + serverAddressInput.Kids[2].Hidden = true } } if len(inputs.serverCertPath) == 0 { @@ -81,34 +106,55 @@ func buildPage() error { errs++ } else { serverCertPathInput.HideHelpText() + + data, err := utils2.ReadFile(inputs.serverCertPath) + if err != nil { + jww.ERROR.Printf("serverCertPath error: %+v", err) + serverCertPathInput.SetHelpText(err.Error()) + errs++ + } else { + inputs.serverCert = string(data) + } } inputs.agree = agreeInput.Checked() if inputs.agree == false { - // TODO: print error + agreeHelpText.SetText("Required.") + agreeHelpText.Hidden = false errs++ } else { - if len(serverAddressInput.Kids) > 2 { - serverAddressInput.RemoveElement(serverAddressInput.Kids[2]) - } + agreeHelpText.Hidden = true } jww.INFO.Printf("Inputs set: %+v", inputs) if errs == 0 { + formErrors.Hidden = true err := client.SignAndTransmit( inputs.keyPath, inputs.idfPath, inputs.nominatorWallet, inputs.validatorWallet, inputs.serverAddress, - inputs.serverCertPath, + inputs.serverCert, utils.Contract) if err != nil { + jww.ERROR.Printf("Submit error: %+v", err) errBox.SetText(err.Error()) errBox.Hidden = false + formErrors.SetText("The were errors in the form input. Please correct them to continue.") + formErrors.Hidden = false + } else { + divWell.RemoveElements() + success := bootstrap.NewElement("span", "success", gowd.NewText("MainNet Commitments Successful.")) + divWell.AddElement(success) } + + } else { + formErrors.SetText("The were errors in the form input. Please correct them to continue.") + formErrors.Hidden = false } }) + contractText := bootstrap.NewElement("p", "contractText", gowd.NewText("Read through the entire contract below and accept the terms.")) contract := bootstrap.NewElement("div", "contractContainer") _, err := contract.AddHTML(utils.Contract, nil) if err != nil { @@ -116,26 +162,32 @@ func buildPage() error { } form := bootstrap.NewFormGroup( + formErrors, keyPathInput.Element, idfPathInput.Element, nominatorWalletInput.Element, validatorWalletInput.Element, serverAddressInput.Element, serverCertPathInput.Element, + contractText, contract, - agreeInput.Element, - submit, - errBox, + agreeBox, + submitBox, ) + form.SetAttribute("style", "margin-top:35px") + h1 := bootstrap.NewElement("h1", "") - h1.SetText("MainNet Commitments") + h1.SetText("xx network MainNet Commitments") logo := bootstrap.NewElement("img", "logo") logo.SetAttribute("src", "img/xx-logo.svg") h1.AddElement(logo) p := bootstrap.NewElement("p", "blurb") p.SetText(blurbText) - row := bootstrap.NewRow(bootstrap.NewElement("div", "well", h1, p, form)) + divWell.AddElement(h1) + divWell.AddElement(p) + divWell.AddElement(form) + row := bootstrap.NewRow(divWell) body.AddElement(row) // Start the UI loop @@ -148,8 +200,8 @@ func buildPage() error { } type Inputs struct { - keyPath, idfPath, nominatorWallet, validatorWallet, serverAddress, serverCertPath string - agree bool + keyPath, idfPath, nominatorWallet, validatorWallet, serverAddress, serverCert, serverCertPath string + agree bool } // happens when the 'start' button is clicked diff --git a/package.json b/package.json index f13c0ed1039cceb64ae7ea539a281b3fc29d2ec6..461693f108bf40c68b7caca723425af63563d872 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "single-instance": true, "window": { "position": "center", - "width": 850, + "width": 995, "height": 750, "frame": true, "icon": "img/favicon-32x32.png"