From 76b433ab63afce266eeae32092c6016b6f2e7179 Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 28 Jun 2023 07:12:14 +0330 Subject: [PATCH 1/7] refactor: separate pages into one function for SRP --- cmd/gtk/startup_assistant.go | 367 ++++++++++++++++++++++------------- 1 file changed, 229 insertions(+), 138 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index ae89518f4..bfa02c1d6 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -15,6 +15,9 @@ import ( "github.com/pactus-project/pactus/wallet" ) +type assistantFunc func(assistant *gtk.Assistant, content gtk.IWidget, name, + title, subject, desc string) *gtk.Widget + func setMargin(widget gtk.IWidget, top, bottom, start, end int) { widget.ToWidget().SetMarginTop(top) widget.ToWidget().SetMarginBottom(bottom) @@ -24,8 +27,168 @@ func setMargin(widget gtk.IWidget, top, bottom, start, end int) { func startupAssistant(workingDir string, chain genesis.ChainType) bool { successful := false - createPage := func(assistant *gtk.Assistant, content gtk.IWidget, name, - title, subject, desc string) *gtk.Widget { + assistant, err := gtk.AssistantNew() + fatalErrorCheck(err) + + assistant.Hide() + assistant.SetDefaultSize(600, 400) + assistant.SetTitle("Pactus - Init Wizard") + + assistFunc := pageAssistant() + + // --- PageMode + mode, radio, pageModeName := pageMode(assistant, assistFunc) + assistant.AppendPage(mode) + + // --- seedGenerate + seedGenerate, textViewSeed, pageSeedName := pageSeed(assistant, assistFunc) + + // -- seedGenerate restore + seedRestore, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) + + // --- seedConfirm + seedConfirm, pageSeedConfirmName := pageSeedConfirm(assistant, assistFunc, textViewSeed) + + // --- PagePassword + password, entryPassword, pagePasswordName := pagePassword(assistant, assistFunc) + + // --- numValidators + numValidators, lsNumValidators, comboNumValidators, pageNumValidatorsName := pageNumValidators(assistant, assistFunc) + + // --- final + final, textViewNodeInfo, pageFinalName := pageFinal(assistant, assistFunc) + + assistant.Connect("cancel", func() { + assistant.Close() + assistant.Destroy() + gtk.MainQuit() + }) + assistant.Connect("close", func() { + assistant.Close() + assistant.Destroy() + gtk.MainQuit() + }) + + mnemonic := wallet.GenerateMnemonic(128) + + assistant.Connect("prepare", func(assistant *gtk.Assistant, page *gtk.Widget) { + name, err := page.GetName() + fatalErrorCheck(err) + + log.Printf("%v - %v\n", assistant.GetCurrentPage(), name) + switch name { + case pageModeName: + { + assistant.SetPageComplete(mode, true) + } + case pageSeedName: + { + text := getTextViewContent(textViewSeed) + if text == "" { + setTextViewContent(textViewSeed, mnemonic) + } + assistant.SetPageComplete(seedGenerate, true) + } + case pageSeedRestoreName: + { + assistant.SetPageComplete(seedRestore, true) + } + case pageSeedConfirmName: + { + assistant.SetPageComplete(seedConfirm, true) + } + case pagePasswordName: + { + assistant.SetPageComplete(password, true) + } + case pageNumValidatorsName: + { + assistant.SetPageComplete(numValidators, true) + } + + case pageFinalName: + { + iter, err := comboNumValidators.GetActiveIter() + fatalErrorCheck(err) + + val, err := lsNumValidators.GetValue(iter, 0) + fatalErrorCheck(err) + + valueInterface, err := val.GoValue() + fatalErrorCheck(err) + + numValidators := valueInterface.(int) + + fmt.Println("number of validators:", numValidators) + + walletPassword, err := entryPassword.GetText() + fatalErrorCheck(err) + + validatorAddrs, rewardAddrs, err := cmd.CreateNode(numValidators, chain, workingDir, mnemonic, walletPassword) + fatalErrorCheck(err) + + // Done! showing the node information + successful = true + nodeInfo := fmt.Sprintf("Working directory: %s\n", workingDir) + nodeInfo += fmt.Sprintf("Network: %s\n", chain.String()) + nodeInfo += "\nValidator addresses:\n" + for i, addr := range validatorAddrs { + nodeInfo += fmt.Sprintf("%v- %s\n", i+1, addr) + } + + nodeInfo += "\nReward addresses:\n" + for i, addr := range rewardAddrs { + nodeInfo += fmt.Sprintf("%v- %s\n", i+1, addr) + } + + setTextViewContent(textViewNodeInfo, nodeInfo) + } + } + }) + + pageAppender := func(restoreMode bool) { + fmt.Println("called appender ", restoreMode) + if restoreMode { + assistant.RemovePage(1) + assistant.RemovePage(2) + + assistant.InsertPage(seedRestore, 1) + assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) + + } else { + assistant.RemovePage(1) + + assistant.InsertPage(seedGenerate, 1) + assistant.InsertPage(seedConfirm, 2) + assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) + } + + } + + pageAppender(false) + + radio.Connect("toggled", func() { + pageAppender(radio.GetActive()) + }) + + assistant.AppendPage(password) + assistant.AppendPage(numValidators) + assistant.AppendPage(final) + assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) + + assistant.SetModal(true) + assistant.ShowAll() + + gtk.Main() + return successful +} + +func pageAssistant() assistantFunc { + return func(assistant *gtk.Assistant, content gtk.IWidget, name, title, subject, desc string) *gtk.Widget { page, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 20) fatalErrorCheck(err) @@ -53,58 +216,45 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { box.Add(frame) box.Add(labelDesc) page.Add(box) - page.SetName(name) - assistant.AppendPage(page) - assistant.SetPageTitle(page, title) return page.ToWidget() } +} - assistant, err := gtk.AssistantNew() - fatalErrorCheck(err) - - assistant.SetDefaultSize(600, 400) - assistant.SetTitle("Pactus - Init Wizard") - - var pageMode *gtk.Widget - var pagePassword *gtk.Widget - var pageSeed *gtk.Widget - var pageSeedConfirm *gtk.Widget - var pageNumValidators *gtk.Widget - var pageFinal *gtk.Widget - - // --- PageMode +func pageMode(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.RadioButton, string) { + mode := new(gtk.Widget) newWalletRadio, err := gtk.RadioButtonNewWithLabel(nil, "Create a new wallet from the scratch") fatalErrorCheck(err) - recoverWalletRadio, err := gtk.RadioButtonNewWithLabelFromWidget(newWalletRadio, + restoreWalletRadio, err := gtk.RadioButtonNewWithLabelFromWidget(newWalletRadio, "Restore a wallet from the seed phrase") fatalErrorCheck(err) - recoverWalletRadio.SetSensitive(false) - radioBox, err := gtk.BoxNew(gtk.ORIENTATION_VERTICAL, 0) fatalErrorCheck(err) radioBox.Add(newWalletRadio) setMargin(newWalletRadio, 6, 6, 6, 6) - radioBox.Add(recoverWalletRadio) - setMargin(recoverWalletRadio, 6, 6, 6, 6) + radioBox.Add(restoreWalletRadio) + setMargin(restoreWalletRadio, 6, 6, 6, 6) pageModeName := "page_mode" pageModeTitle := "Initialize mode" pageModeSubject := "How to create your wallet?" pageModeDesc := "If you are running the node for the first time, choose the first option." - pageMode = createPage( + mode = assistFunc( assistant, radioBox, pageModeName, pageModeTitle, pageModeSubject, pageModeDesc) + return mode, restoreWalletRadio, pageModeName +} - // --- pageSeed +func pageSeed(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { + seed := new(gtk.Widget) textViewSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -124,15 +274,44 @@ This seed will allow you to recover your wallet in case of computer failure. - Never type it on a website. - Do not store it electronically.` - pageSeed = createPage( + seed = assistFunc( + assistant, + textViewSeed, + pageSeedName, + pageSeedTitle, + pageSeedSubject, + pageSeedDesc) + return seed, textViewSeed, pageSeedName +} + +func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, string) { + seed := new(gtk.Widget) + textViewSeed, err := gtk.TextViewNew() + fatalErrorCheck(err) + + setMargin(textViewSeed, 6, 6, 6, 6) + textViewSeed.SetWrapMode(gtk.WRAP_WORD) + textViewSeed.SetEditable(true) + textViewSeed.SetMonospace(true) + textViewSeed.SetSizeRequest(0, 80) + + pageSeedName := "page_seed_restore" + pageSeedTitle := "Wallet seed restore" + pageSeedSubject := "Please enter your seed:" + pageSeedDesc := "Please enter your 12 words mnemonics backup to restore your wallet." + + seed = assistFunc( assistant, textViewSeed, pageSeedName, pageSeedTitle, pageSeedSubject, pageSeedDesc) + return seed, pageSeedName +} - // --- pageSeedConfirm +func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textViewSeed *gtk.TextView) (*gtk.Widget, string) { + confirm := new(gtk.Widget) textViewConfirmSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -157,9 +336,9 @@ This seed will allow you to recover your wallet in case of computer failure. mnemonic2 = space.ReplaceAllString(mnemonic2, " ") mnemonic2 = strings.TrimSpace(mnemonic2) if mnemonic1 == mnemonic2 { - assistant.SetPageComplete(pageSeedConfirm, true) + assistant.SetPageComplete(confirm, true) } else { - assistant.SetPageComplete(pageSeedConfirm, false) + assistant.SetPageComplete(confirm, false) } }) @@ -169,15 +348,18 @@ This seed will allow you to recover your wallet in case of computer failure. pageSeedConfirmDesc := `Your seed is important! To make sure that you have properly saved your seed, please retype it here.` - pageSeedConfirm = createPage( + confirm = assistFunc( assistant, textViewConfirmSeed, pageSeedConfirmName, pageSeedConfirmTitle, pageSeedConfirmSubject, pageSeedConfirmDesc) + return confirm, pageSeedConfirmName +} - // --- PagePassword +func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.Entry, string) { + password := new(gtk.Widget) entryPassword, err := gtk.EntryNew() fatalErrorCheck(err) @@ -216,9 +398,9 @@ To make sure that you have properly saved your seed, please retype it here.` fatalErrorCheck(err) if pass1 == pass2 { - assistant.SetPageComplete(pagePassword, true) + assistant.SetPageComplete(password, true) } else { - assistant.SetPageComplete(pagePassword, false) + assistant.SetPageComplete(password, false) } } entryPassword.Connect("changed", func(entry *gtk.Entry) { @@ -234,15 +416,18 @@ To make sure that you have properly saved your seed, please retype it here.` pagePasswordSubject := "Enter password for your wallet:" pagePsswrdDesc := "Please choose a strong password for your wallet." - pagePassword = createPage( + password = assistFunc( assistant, grid, pagePasswordName, pagePasswordTitle, pagePasswordSubject, pagePsswrdDesc) + return password, entryPassword, pagePasswordName +} - // --- pageNumValidators +func pageNumValidators(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.ListStore, *gtk.ComboBox, string) { + validator := new(gtk.Widget) lsNumValidators, err := gtk.ListStoreNew(glib.TYPE_INT) fatalErrorCheck(err) @@ -270,7 +455,7 @@ To make sure that you have properly saved your seed, please retype it here.` setMargin(labelNumValidators, 6, 6, 6, 6) setMargin(comboNumValidators, 6, 6, 6, 6) - grid, err = gtk.GridNew() + grid, err := gtk.GridNew() fatalErrorCheck(err) grid.Add(labelNumValidators) @@ -283,15 +468,18 @@ To make sure that you have properly saved your seed, please retype it here.` You can define validators based on the amount of coins you want to stake. For more information, look here` - pageNumValidators = createPage( + validator = assistFunc( assistant, grid, pageNumValidatorsName, pageNumValidatorsTitle, pageNumValidatorsSubject, pageNumValidatorsDesc) + return validator, lsNumValidators, comboNumValidators, pageNumValidatorsName +} - // --- pageFinal +func pageFinal(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { + final := new(gtk.Widget) textViewNodeInfo, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -312,109 +500,12 @@ For more information, look Date: Wed, 28 Jun 2023 07:56:07 +0330 Subject: [PATCH 2/7] fix: append and remove index pages --- cmd/gtk/startup_assistant.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index bfa02c1d6..5e3f3a641 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -39,6 +39,7 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { // --- PageMode mode, radio, pageModeName := pageMode(assistant, assistFunc) assistant.AppendPage(mode) + assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) // --- seedGenerate seedGenerate, textViewSeed, pageSeedName := pageSeed(assistant, assistFunc) @@ -146,18 +147,30 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { } }) + assistant.AppendPage(seedGenerate) + assistant.AppendPage(seedConfirm) + assistant.AppendPage(seedRestore) + assistant.AppendPage(password) + assistant.AppendPage(numValidators) + assistant.AppendPage(final) + assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) + pageAppender := func(restoreMode bool) { fmt.Println("called appender ", restoreMode) if restoreMode { - assistant.RemovePage(1) assistant.RemovePage(2) - + assistant.RemovePage(1) + fmt.Println("restore") assistant.InsertPage(seedRestore, 1) assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) - } else { assistant.RemovePage(1) - + fmt.Println("create") assistant.InsertPage(seedGenerate, 1) assistant.InsertPage(seedConfirm, 2) assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) @@ -172,14 +185,6 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { pageAppender(radio.GetActive()) }) - assistant.AppendPage(password) - assistant.AppendPage(numValidators) - assistant.AppendPage(final) - assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) - assistant.SetModal(true) assistant.ShowAll() From 67f3e3184ec4b896761ee88139bde29b136c7375 Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 28 Jun 2023 09:47:16 +0330 Subject: [PATCH 3/7] fix: page index for restore and create --- cmd/gtk/startup_assistant.go | 207 +++++++++++++++++++++-------------- 1 file changed, 122 insertions(+), 85 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index 5e3f3a641..f7eeb3956 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -37,14 +37,12 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { assistFunc := pageAssistant() // --- PageMode - mode, radio, pageModeName := pageMode(assistant, assistFunc) - assistant.AppendPage(mode) - assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) + mode, restoreRadio, pageModeName := pageMode(assistant, assistFunc) // --- seedGenerate - seedGenerate, textViewSeed, pageSeedName := pageSeed(assistant, assistFunc) + seedGenerate, textViewSeed, pageSeedGenerateName := pageSeedGenerate(assistant, assistFunc) - // -- seedGenerate restore + // -- seedRestore seedRestore, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) // --- seedConfirm @@ -70,33 +68,97 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { gtk.MainQuit() }) - mnemonic := wallet.GenerateMnemonic(128) + assistant.AppendPage(mode) // page 0 + assistant.AppendPage(seedGenerate) // page 1 + assistant.AppendPage(seedConfirm) // page 2 + assistant.AppendPage(seedRestore) // page 3 + assistant.AppendPage(password) // page 4 + assistant.AppendPage(numValidators) // page 5 + assistant.AppendPage(final) // page 6 + + assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) + assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) + mnemonic := "" + prevPageName := "" assistant.Connect("prepare", func(assistant *gtk.Assistant, page *gtk.Widget) { - name, err := page.GetName() + isRestoreMode := restoreRadio.GetActive() + curPageName, err := page.GetName() fatalErrorCheck(err) - log.Printf("%v - %v\n", assistant.GetCurrentPage(), name) - switch name { + log.Printf("%v - %v (restore: %v, prev: %v)\n", + assistant.GetCurrentPage(), curPageName, isRestoreMode, prevPageName) + switch curPageName { case pageModeName: { assistant.SetPageComplete(mode, true) + assistant.UpdateButtonsState() } - case pageSeedName: + + case pageSeedGenerateName: { - text := getTextViewContent(textViewSeed) - if text == "" { + if isRestoreMode { + if prevPageName == pageSeedGenerateName { + // backward + log.Printf("jumping backward from seedGenerate page") + assistant.PreviousPage() + } else if prevPageName == pageModeName { + // forward + log.Printf("jumping forward from seedGenerate page") + assistant.NextPage() + } else { + log.Fatalf("invalid1 page order, pageName: %v, prevPageName: %v", + curPageName, prevPageName) + } + } else { + mnemonic = wallet.GenerateMnemonic(128) setTextViewContent(textViewSeed, mnemonic) } assistant.SetPageComplete(seedGenerate, true) } - case pageSeedRestoreName: + case pageSeedConfirmName: { - assistant.SetPageComplete(seedRestore, true) + if isRestoreMode { + if prevPageName == pageSeedGenerateName { + // backward + log.Printf("jumping backward from seedConfirm page") + assistant.PreviousPage() + } else if prevPageName == pageModeName { + // forward + log.Printf("jumping forward from seedConfirm page") + assistant.NextPage() + } else { + log.Fatalf("invalid2 page order, pageName: %v, prevPageName: %v", + curPageName, prevPageName) + } + } else { + assistant.SetPageComplete(seedConfirm, false) + } } - case pageSeedConfirmName: + case pageSeedRestoreName: { - assistant.SetPageComplete(seedConfirm, true) + if !isRestoreMode { + if prevPageName == pageSeedRestoreName { + // backward + log.Printf("jumping backward from seedRestore page") + assistant.PreviousPage() + } else if prevPageName == pageSeedConfirmName { + // forward + log.Printf("jumping forward from seedRestore page") + assistant.NextPage() + } else { + log.Fatalf("invalid page order, pageName: %v, prevPageName: %v", + curPageName, prevPageName) + } + } else { + assistant.SetPageComplete(seedGenerate, true) + } + } case pagePasswordName: { @@ -145,44 +207,7 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { setTextViewContent(textViewNodeInfo, nodeInfo) } } - }) - - assistant.AppendPage(seedGenerate) - assistant.AppendPage(seedConfirm) - assistant.AppendPage(seedRestore) - assistant.AppendPage(password) - assistant.AppendPage(numValidators) - assistant.AppendPage(final) - assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) - - pageAppender := func(restoreMode bool) { - fmt.Println("called appender ", restoreMode) - if restoreMode { - assistant.RemovePage(2) - assistant.RemovePage(1) - fmt.Println("restore") - assistant.InsertPage(seedRestore, 1) - assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) - } else { - assistant.RemovePage(1) - fmt.Println("create") - assistant.InsertPage(seedGenerate, 1) - assistant.InsertPage(seedConfirm, 2) - assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) - } - - } - - pageAppender(false) - - radio.Connect("toggled", func() { - pageAppender(radio.GetActive()) + prevPageName = curPageName }) assistant.SetModal(true) @@ -258,8 +283,8 @@ func pageMode(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, return mode, restoreWalletRadio, pageModeName } -func pageSeed(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { - seed := new(gtk.Widget) +func pageSeedGenerate(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { + pageWidget := new(gtk.Widget) textViewSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -269,7 +294,7 @@ func pageSeed(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, textViewSeed.SetMonospace(true) textViewSeed.SetSizeRequest(0, 80) - pageSeedName := "page_seed" + pageSeedName := "page_seed_generate" pageSeedTitle := "Wallet seed" pageSeedSubject := "Your wallet generation seed is:" pageSeedDesc := `Please write these 12 words on paper. @@ -279,44 +304,56 @@ This seed will allow you to recover your wallet in case of computer failure. - Never type it on a website. - Do not store it electronically.` - seed = assistFunc( + pageWidget = assistFunc( assistant, textViewSeed, pageSeedName, pageSeedTitle, pageSeedSubject, pageSeedDesc) - return seed, textViewSeed, pageSeedName + return pageWidget, textViewSeed, pageSeedName } func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, string) { - seed := new(gtk.Widget) - textViewSeed, err := gtk.TextViewNew() + pageWidget := new(gtk.Widget) + textViewRestoreSeed, err := gtk.TextViewNew() fatalErrorCheck(err) - setMargin(textViewSeed, 6, 6, 6, 6) - textViewSeed.SetWrapMode(gtk.WRAP_WORD) - textViewSeed.SetEditable(true) - textViewSeed.SetMonospace(true) - textViewSeed.SetSizeRequest(0, 80) + setMargin(textViewRestoreSeed, 6, 6, 6, 6) + textViewRestoreSeed.SetWrapMode(gtk.WRAP_WORD) + textViewRestoreSeed.SetEditable(true) + textViewRestoreSeed.SetMonospace(true) + textViewRestoreSeed.SetSizeRequest(0, 80) + + textViewRestoreSeed.Connect("paste_clipboard", func(textView *gtk.TextView) { + showInfoDialog(assistant, "Opps, no copy paste!") + textViewRestoreSeed.StopEmission("paste_clipboard") + }) + + seedConfirmTextBuffer, err := textViewRestoreSeed.GetBuffer() + fatalErrorCheck(err) + + seedConfirmTextBuffer.Connect("changed", func(buf *gtk.TextBuffer) { + + }) pageSeedName := "page_seed_restore" pageSeedTitle := "Wallet seed restore" pageSeedSubject := "Please enter your seed:" pageSeedDesc := "Please enter your 12 words mnemonics backup to restore your wallet." - seed = assistFunc( + pageWidget = assistFunc( assistant, - textViewSeed, + textViewRestoreSeed, pageSeedName, pageSeedTitle, pageSeedSubject, pageSeedDesc) - return seed, pageSeedName + return pageWidget, pageSeedName } func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textViewSeed *gtk.TextView) (*gtk.Widget, string) { - confirm := new(gtk.Widget) + pageWidget := new(gtk.Widget) textViewConfirmSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -341,9 +378,9 @@ func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textVie mnemonic2 = space.ReplaceAllString(mnemonic2, " ") mnemonic2 = strings.TrimSpace(mnemonic2) if mnemonic1 == mnemonic2 { - assistant.SetPageComplete(confirm, true) + assistant.SetPageComplete(pageWidget, true) } else { - assistant.SetPageComplete(confirm, false) + assistant.SetPageComplete(pageWidget, false) } }) @@ -353,18 +390,18 @@ func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textVie pageSeedConfirmDesc := `Your seed is important! To make sure that you have properly saved your seed, please retype it here.` - confirm = assistFunc( + pageWidget = assistFunc( assistant, textViewConfirmSeed, pageSeedConfirmName, pageSeedConfirmTitle, pageSeedConfirmSubject, pageSeedConfirmDesc) - return confirm, pageSeedConfirmName + return pageWidget, pageSeedConfirmName } func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.Entry, string) { - password := new(gtk.Widget) + pageWidget := new(gtk.Widget) entryPassword, err := gtk.EntryNew() fatalErrorCheck(err) @@ -403,9 +440,9 @@ func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widg fatalErrorCheck(err) if pass1 == pass2 { - assistant.SetPageComplete(password, true) + assistant.SetPageComplete(pageWidget, true) } else { - assistant.SetPageComplete(password, false) + assistant.SetPageComplete(pageWidget, false) } } entryPassword.Connect("changed", func(entry *gtk.Entry) { @@ -421,18 +458,18 @@ func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widg pagePasswordSubject := "Enter password for your wallet:" pagePsswrdDesc := "Please choose a strong password for your wallet." - password = assistFunc( + pageWidget = assistFunc( assistant, grid, pagePasswordName, pagePasswordTitle, pagePasswordSubject, pagePsswrdDesc) - return password, entryPassword, pagePasswordName + return pageWidget, entryPassword, pagePasswordName } func pageNumValidators(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.ListStore, *gtk.ComboBox, string) { - validator := new(gtk.Widget) + pageWidget := new(gtk.Widget) lsNumValidators, err := gtk.ListStoreNew(glib.TYPE_INT) fatalErrorCheck(err) @@ -473,18 +510,18 @@ func pageNumValidators(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk You can define validators based on the amount of coins you want to stake. For more information, look here` - validator = assistFunc( + pageWidget = assistFunc( assistant, grid, pageNumValidatorsName, pageNumValidatorsTitle, pageNumValidatorsSubject, pageNumValidatorsDesc) - return validator, lsNumValidators, comboNumValidators, pageNumValidatorsName + return pageWidget, lsNumValidators, comboNumValidators, pageNumValidatorsName } func pageFinal(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { - final := new(gtk.Widget) + pageWidget := new(gtk.Widget) textViewNodeInfo, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -505,12 +542,12 @@ func pageFinal(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, pageFinalDesc := `Congratulation. Your node is initialized successfully. Now you are ready to start the node!` - final = assistFunc( + pageWidget = assistFunc( assistant, scrolledWindow, pageFinalName, pageFinalTitle, pageFinalSubject, pageFinalDesc) - return final, textViewNodeInfo, pageFinalName + return pageWidget, textViewNodeInfo, pageFinalName } From af090ae09b0765774180577abf3f6fd8da80c6c1 Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 28 Jun 2023 11:11:28 +0330 Subject: [PATCH 4/7] feat: implemented restore wallet base on input seed fixed #522 --- cmd/gtk/startup_assistant.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index f7eeb3956..ccb3026e0 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -43,7 +43,7 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { seedGenerate, textViewSeed, pageSeedGenerateName := pageSeedGenerate(assistant, assistFunc) // -- seedRestore - seedRestore, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) + seedRestore, textViewRestoreSeed, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) // --- seedConfirm seedConfirm, pageSeedConfirmName := pageSeedConfirm(assistant, assistFunc, textViewSeed) @@ -112,13 +112,12 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { log.Printf("jumping forward from seedGenerate page") assistant.NextPage() } else { - log.Fatalf("invalid1 page order, pageName: %v, prevPageName: %v", + log.Fatalf("invalid page order, pageName: %v, prevPageName: %v", curPageName, prevPageName) } - } else { - mnemonic = wallet.GenerateMnemonic(128) - setTextViewContent(textViewSeed, mnemonic) } + mnemonic = wallet.GenerateMnemonic(128) + setTextViewContent(textViewSeed, mnemonic) assistant.SetPageComplete(seedGenerate, true) } case pageSeedConfirmName: @@ -162,6 +161,14 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { } case pagePasswordName: { + if isRestoreMode { + mnemonic = getTextViewContent(textViewRestoreSeed) + + if err := wallet.CheckMnemonic(mnemonic); err != nil { + showErrorDialog(assistant, "mnemonic is invalid: "+err.Error()) + assistant.PreviousPage() + } + } assistant.SetPageComplete(password, true) } case pageNumValidatorsName: @@ -314,7 +321,7 @@ This seed will allow you to recover your wallet in case of computer failure. return pageWidget, textViewSeed, pageSeedName } -func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, string) { +func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { pageWidget := new(gtk.Widget) textViewRestoreSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -330,11 +337,15 @@ func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.W textViewRestoreSeed.StopEmission("paste_clipboard") }) - seedConfirmTextBuffer, err := textViewRestoreSeed.GetBuffer() + seedRestoreTextBuffer, err := textViewRestoreSeed.GetBuffer() fatalErrorCheck(err) - seedConfirmTextBuffer.Connect("changed", func(buf *gtk.TextBuffer) { - + seedRestoreTextBuffer.Connect("changed", func(buf *gtk.TextBuffer) { + if len(strings.Split(getTextViewContent(textViewRestoreSeed), " ")) == 12 { + assistant.SetPageComplete(pageWidget, true) + } else { + assistant.SetPageComplete(pageWidget, false) + } }) pageSeedName := "page_seed_restore" @@ -349,7 +360,7 @@ func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.W pageSeedTitle, pageSeedSubject, pageSeedDesc) - return pageWidget, pageSeedName + return pageWidget, textViewRestoreSeed, pageSeedName } func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textViewSeed *gtk.TextView) (*gtk.Widget, string) { From c65330529a529c477782201207dbeabee39579fc Mon Sep 17 00:00:00 2001 From: Javad Date: Wed, 28 Jun 2023 12:00:39 +0330 Subject: [PATCH 5/7] fix: lint error ineffectual assignment to pageWidget --- cmd/gtk/startup_assistant.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index ccb3026e0..6c522fce4 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -157,7 +157,6 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { } else { assistant.SetPageComplete(seedGenerate, true) } - } case pagePasswordName: { @@ -260,7 +259,7 @@ func pageAssistant() assistantFunc { } func pageMode(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.RadioButton, string) { - mode := new(gtk.Widget) + var mode *gtk.Widget newWalletRadio, err := gtk.RadioButtonNewWithLabel(nil, "Create a new wallet from the scratch") fatalErrorCheck(err) @@ -291,7 +290,7 @@ func pageMode(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, } func pageSeedGenerate(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { - pageWidget := new(gtk.Widget) + var pageWidget *gtk.Widget textViewSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -363,7 +362,8 @@ func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.W return pageWidget, textViewRestoreSeed, pageSeedName } -func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, textViewSeed *gtk.TextView) (*gtk.Widget, string) { +func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, + textViewSeed *gtk.TextView) (*gtk.Widget, string) { pageWidget := new(gtk.Widget) textViewConfirmSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -479,8 +479,9 @@ func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widg return pageWidget, entryPassword, pagePasswordName } -func pageNumValidators(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.ListStore, *gtk.ComboBox, string) { - pageWidget := new(gtk.Widget) +func pageNumValidators(assistant *gtk.Assistant, + assistFunc assistantFunc) (*gtk.Widget, *gtk.ListStore, *gtk.ComboBox, string) { + var pageWidget *gtk.Widget lsNumValidators, err := gtk.ListStoreNew(glib.TYPE_INT) fatalErrorCheck(err) @@ -532,7 +533,7 @@ For more information, look Date: Fri, 30 Jun 2023 10:41:55 +0330 Subject: [PATCH 7/7] fix: crash on setup assistant --- cmd/gtk/startup_assistant.go | 153 ++++++++++++++++------------------- 1 file changed, 71 insertions(+), 82 deletions(-) diff --git a/cmd/gtk/startup_assistant.go b/cmd/gtk/startup_assistant.go index 6c522fce4..4c34e383e 100644 --- a/cmd/gtk/startup_assistant.go +++ b/cmd/gtk/startup_assistant.go @@ -30,31 +30,30 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { assistant, err := gtk.AssistantNew() fatalErrorCheck(err) - assistant.Hide() assistant.SetDefaultSize(600, 400) assistant.SetTitle("Pactus - Init Wizard") assistFunc := pageAssistant() - // --- PageMode + // --- page_mode mode, restoreRadio, pageModeName := pageMode(assistant, assistFunc) - // --- seedGenerate + // --- page_seed_generate seedGenerate, textViewSeed, pageSeedGenerateName := pageSeedGenerate(assistant, assistFunc) - // -- seedRestore - seedRestore, textViewRestoreSeed, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) - - // --- seedConfirm + // --- page_seed_confirm seedConfirm, pageSeedConfirmName := pageSeedConfirm(assistant, assistFunc, textViewSeed) - // --- PagePassword + // -- page_seed_restore + seedRestore, textViewRestoreSeed, pageSeedRestoreName := pageSeedRestore(assistant, assistFunc) + + // --- page_password password, entryPassword, pagePasswordName := pagePassword(assistant, assistFunc) - // --- numValidators + // --- page_num_validators numValidators, lsNumValidators, comboNumValidators, pageNumValidatorsName := pageNumValidators(assistant, assistFunc) - // --- final + // --- page_final final, textViewNodeInfo, pageFinalName := pageFinal(assistant, assistFunc) assistant.Connect("cancel", func() { @@ -68,94 +67,93 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { gtk.MainQuit() }) - assistant.AppendPage(mode) // page 0 - assistant.AppendPage(seedGenerate) // page 1 - assistant.AppendPage(seedConfirm) // page 2 - assistant.AppendPage(seedRestore) // page 3 - assistant.AppendPage(password) // page 4 - assistant.AppendPage(numValidators) // page 5 - assistant.AppendPage(final) // page 6 - - assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) - assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) + assistant.SetPageType(mode, gtk.ASSISTANT_PAGE_INTRO) // page 0 + assistant.SetPageType(seedGenerate, gtk.ASSISTANT_PAGE_CONTENT) // page 1 + assistant.SetPageType(seedConfirm, gtk.ASSISTANT_PAGE_CONTENT) // page 2 + assistant.SetPageType(seedRestore, gtk.ASSISTANT_PAGE_CONTENT) // page 3 + assistant.SetPageType(password, gtk.ASSISTANT_PAGE_CONTENT) // page 4 + assistant.SetPageType(numValidators, gtk.ASSISTANT_PAGE_CONTENT) // page 5 + assistant.SetPageType(final, gtk.ASSISTANT_PAGE_SUMMARY) // page 6 mnemonic := "" - prevPageName := "" + prevPageIndex := -1 + prevPageAdjust := 0 assistant.Connect("prepare", func(assistant *gtk.Assistant, page *gtk.Widget) { isRestoreMode := restoreRadio.GetActive() curPageName, err := page.GetName() + curPageIndex := assistant.GetCurrentPage() fatalErrorCheck(err) - log.Printf("%v - %v (restore: %v, prev: %v)\n", - assistant.GetCurrentPage(), curPageName, isRestoreMode, prevPageName) + isForward := true + if curPageIndex > 0 && curPageIndex < prevPageIndex { + isForward = false + } + + log.Printf("%v (restore: %v, prev: %v, cur: %v)\n", + curPageName, isRestoreMode, prevPageIndex, curPageIndex) switch curPageName { case pageModeName: { - assistant.SetPageComplete(mode, true) - assistant.UpdateButtonsState() + assistantPageComplete(assistant, mode, true) } case pageSeedGenerateName: { if isRestoreMode { - if prevPageName == pageSeedGenerateName { - // backward - log.Printf("jumping backward from seedGenerate page") - assistant.PreviousPage() - } else if prevPageName == pageModeName { + if isForward { // forward log.Printf("jumping forward from seedGenerate page") assistant.NextPage() + prevPageAdjust = 1 } else { - log.Fatalf("invalid page order, pageName: %v, prevPageName: %v", - curPageName, prevPageName) + // backward + log.Printf("jumping backward from seedGenerate page") + assistant.PreviousPage() + prevPageAdjust = -1 } + assistantPageComplete(assistant, seedGenerate, false) + } else { + mnemonic = wallet.GenerateMnemonic(128) + setTextViewContent(textViewSeed, mnemonic) + assistantPageComplete(assistant, seedGenerate, true) } - mnemonic = wallet.GenerateMnemonic(128) - setTextViewContent(textViewSeed, mnemonic) - assistant.SetPageComplete(seedGenerate, true) } case pageSeedConfirmName: { if isRestoreMode { - if prevPageName == pageSeedGenerateName { - // backward - log.Printf("jumping backward from seedConfirm page") - assistant.PreviousPage() - } else if prevPageName == pageModeName { + if isForward { // forward log.Printf("jumping forward from seedConfirm page") assistant.NextPage() + prevPageAdjust = 1 } else { - log.Fatalf("invalid2 page order, pageName: %v, prevPageName: %v", - curPageName, prevPageName) + // backward + log.Printf("jumping backward from seedConfirm page") + assistant.PreviousPage() + prevPageAdjust = -1 } + assistantPageComplete(assistant, seedConfirm, false) } else { - assistant.SetPageComplete(seedConfirm, false) + assistantPageComplete(assistant, seedConfirm, false) } } case pageSeedRestoreName: { if !isRestoreMode { - if prevPageName == pageSeedRestoreName { - // backward - log.Printf("jumping backward from seedRestore page") - assistant.PreviousPage() - } else if prevPageName == pageSeedConfirmName { + if isForward { // forward log.Printf("jumping forward from seedRestore page") assistant.NextPage() + prevPageAdjust = 1 } else { - log.Fatalf("invalid page order, pageName: %v, prevPageName: %v", - curPageName, prevPageName) + // backward + log.Printf("jumping backward from seedRestore page") + assistant.PreviousPage() + prevPageAdjust = -1 } + assistantPageComplete(assistant, seedConfirm, false) } else { - assistant.SetPageComplete(seedGenerate, true) + assistantPageComplete(assistant, seedRestore, true) } } case pagePasswordName: @@ -164,15 +162,15 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { mnemonic = getTextViewContent(textViewRestoreSeed) if err := wallet.CheckMnemonic(mnemonic); err != nil { - showErrorDialog(assistant, "mnemonic is invalid: "+err.Error()) + showErrorDialog(assistant, "mnemonic is invalid") assistant.PreviousPage() } } - assistant.SetPageComplete(password, true) + assistantPageComplete(assistant, password, true) } case pageNumValidatorsName: { - assistant.SetPageComplete(numValidators, true) + assistantPageComplete(assistant, numValidators, true) } case pageFinalName: @@ -213,7 +211,7 @@ func startupAssistant(workingDir string, chain genesis.ChainType) bool { setTextViewContent(textViewNodeInfo, nodeInfo) } } - prevPageName = curPageName + prevPageIndex = curPageIndex + prevPageAdjust }) assistant.SetModal(true) @@ -253,6 +251,8 @@ func pageAssistant() assistantFunc { box.Add(labelDesc) page.Add(box) page.SetName(name) + assistant.AppendPage(page) + assistant.SetPageTitle(page, title) return page.ToWidget() } @@ -321,7 +321,7 @@ This seed will allow you to recover your wallet in case of computer failure. } func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widget, *gtk.TextView, string) { - pageWidget := new(gtk.Widget) + var pageWidget *gtk.Widget textViewRestoreSeed, err := gtk.TextViewNew() fatalErrorCheck(err) @@ -331,25 +331,9 @@ func pageSeedRestore(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.W textViewRestoreSeed.SetMonospace(true) textViewRestoreSeed.SetSizeRequest(0, 80) - textViewRestoreSeed.Connect("paste_clipboard", func(textView *gtk.TextView) { - showInfoDialog(assistant, "Opps, no copy paste!") - textViewRestoreSeed.StopEmission("paste_clipboard") - }) - - seedRestoreTextBuffer, err := textViewRestoreSeed.GetBuffer() - fatalErrorCheck(err) - - seedRestoreTextBuffer.Connect("changed", func(buf *gtk.TextBuffer) { - if len(strings.Split(getTextViewContent(textViewRestoreSeed), " ")) == 12 { - assistant.SetPageComplete(pageWidget, true) - } else { - assistant.SetPageComplete(pageWidget, false) - } - }) - pageSeedName := "page_seed_restore" pageSeedTitle := "Wallet seed restore" - pageSeedSubject := "Please enter your seed:" + pageSeedSubject := "Enter your wallet seed:" pageSeedDesc := "Please enter your 12 words mnemonics backup to restore your wallet." pageWidget = assistFunc( @@ -389,9 +373,9 @@ func pageSeedConfirm(assistant *gtk.Assistant, assistFunc assistantFunc, mnemonic2 = space.ReplaceAllString(mnemonic2, " ") mnemonic2 = strings.TrimSpace(mnemonic2) if mnemonic1 == mnemonic2 { - assistant.SetPageComplete(pageWidget, true) + assistantPageComplete(assistant, pageWidget, true) } else { - assistant.SetPageComplete(pageWidget, false) + assistantPageComplete(assistant, pageWidget, false) } }) @@ -451,9 +435,9 @@ func pagePassword(assistant *gtk.Assistant, assistFunc assistantFunc) (*gtk.Widg fatalErrorCheck(err) if pass1 == pass2 { - assistant.SetPageComplete(pageWidget, true) + assistantPageComplete(assistant, pageWidget, true) } else { - assistant.SetPageComplete(pageWidget, false) + assistantPageComplete(assistant, pageWidget, false) } } entryPassword.Connect("changed", func(entry *gtk.Entry) { @@ -563,3 +547,8 @@ Now you are ready to start the node!` pageFinalDesc) return pageWidget, textViewNodeInfo, pageFinalName } + +func assistantPageComplete(assistant *gtk.Assistant, page gtk.IWidget, completed bool) { + assistant.SetPageComplete(page, completed) + assistant.UpdateButtonsState() +}