Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gui): Network ID #1

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions cmd/gtk/assets/ui/dialog_wallet_create_address.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="id_dialog_wallet_create_address">
<property name="can-focus">False</property>
<property name="title" translatable="yes">New address</property>
<property name="default-width">320</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">4</property>
<property name="margin-bottom">4</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="id_button_cancel">
<property name="label">_Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="focus-on-click">False</property>
<property name="receives-default">False</property>
<property name="use-underline">True</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="on_cancel" swapped="no"/>
<signal name="clicked" handler="on_cancel" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="id_button_ok">
<property name="label">_Ok</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="focus-on-click">False</property>
<property name="can-default">True</property>
<property name="has-default">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
<property name="always-show-image">True</property>
<signal name="activate" handler="on_ok" swapped="no"/>
<signal name="clicked" handler="on_ok" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=3 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="row-spacing">8</property>
<property name="column-spacing">8</property>
<child>
<object class="GtkLabel" id="id_label_account_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Label:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_account_label">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="activates-default">True</property>
<property name="width-chars">24</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Type:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="id_combo_address_type">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">8</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-2">id_button_cancel</action-widget>
<action-widget response="-3">id_button_ok</action-widget>
</action-widgets>
</object>
</interface>
46 changes: 38 additions & 8 deletions cmd/gtk/assets/ui/widget_node.ui
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
Expand All @@ -118,7 +118,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
Expand All @@ -133,7 +133,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
Expand All @@ -147,7 +147,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">3</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
Expand All @@ -162,7 +162,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
Expand All @@ -176,7 +176,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">4</property>
<property name="top-attach">5</property>
</packing>
</child>
<child>
Expand All @@ -191,7 +191,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
Expand All @@ -204,7 +204,7 @@
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">5</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -237,6 +237,36 @@
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="label" translatable="yes">Network ID:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="id_label_network_id">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">start</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="selectable">True</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
</object>
</child>
<child type="label">
Expand Down
73 changes: 73 additions & 0 deletions cmd/gtk/dialog_wallet_create_address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//go:build gtk

package main

import (
_ "embed"
"fmt"

"github.com/gotk3/gotk3/gtk"

"github.com/pactus-project/pactus/wallet"
)

//go:embed assets/ui/dialog_wallet_create_address.ui
var uiWalletCreateAddressDialog []byte

func createAddress(ww *widgetWallet) {
builder, err := gtk.BuilderNewFromString(string(uiWalletCreateAddressDialog))
fatalErrorCheck(err)

dlg := getDialogObj(builder, "id_dialog_wallet_create_address")
addressLabel := getEntryObj(builder, "id_entry_account_label")

addressTypeCombo := getComboBoxTextObj(builder, "id_combo_address_type")
addressTypeCombo.Append(wallet.AddressTypeBLSAccount, "Account")
addressTypeCombo.Append(wallet.AddressTypeValidator, "Validator")

addressTypeCombo.SetActive(0)

getButtonObj(builder, "id_button_ok").SetImage(OkIcon())
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())

onOk := func() {
walletAddressLabel, err := addressLabel.GetText()
fatalErrorCheck(err)

walletAddressType := addressTypeCombo.GetActiveID()
fatalErrorCheck(err)

if walletAddressType == wallet.AddressTypeBLSAccount {
_, err = ww.model.wallet.NewBLSAccountAddress(walletAddressLabel)
} else if walletAddressType == wallet.AddressTypeValidator {
_, err = ww.model.wallet.NewValidatorAddress(walletAddressLabel)
} else {
err = fmt.Errorf("invalid address type '%s'", walletAddressType)
}

errorCheck(err)

err = ww.model.wallet.Save()
errorCheck(err)

ww.model.rebuildModel()

dlg.Close()
}

onCancel := func() {
dlg.Close()
}

// Map the handlers to callback functions, and connect the signals
// to the Builder.
signals := map[string]interface{}{
"on_ok": onOk,
"on_cancel": onCancel,
}
builder.ConnectSignals(signals)

dlg.SetModal(true)

dlg.Run()
}
34 changes: 0 additions & 34 deletions cmd/gtk/model_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,37 +84,3 @@ func (model *walletModel) rebuildModel() {
})
}()
}

func (model *walletModel) createAddress() error {
address, err := model.wallet.NewBLSAccountAddress("")
if err != nil {
return err
}

iter := model.listStore.Append()
err = model.listStore.Set(iter,
[]int{
IDAddressesColumnNo,
IDAddressesColumnAddress,
IDAddressesColumnLabel,
IDAddressesColumnBalance,
IDAddressesColumnStake,
},
[]interface{}{
fmt.Sprintf("%v", model.wallet.AddressCount()+1),
address,
"",
"0",
"0",
})
if err != nil {
return err
}

err = model.wallet.Save()
if err != nil {
return err
}

return nil
}
2 changes: 2 additions & 0 deletions cmd/gtk/widget_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ func buildWidgetNode(model *nodeModel) (*widgetNode, error) {
box := getBoxObj(builder, "id_box_node")
labelLocation := getLabelObj(builder, "id_label_working_directory")
labelNetwork := getLabelObj(builder, "id_label_network")
labelNetworkID := getLabelObj(builder, "id_label_network_id")

cwd, err := os.Getwd()
if err != nil {
return nil, err
}
labelLocation.SetText(cwd)
labelNetwork.SetText(model.node.State().Genesis().ChainType().String())
labelNetworkID.SetText(model.node.Network().SelfID().String())

w := &widgetNode{
Box: box,
Expand Down
9 changes: 4 additions & 5 deletions cmd/gtk/widget_wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ func buildWidgetWallet(model *walletModel) (*widgetWallet, error) {
return w, nil
}

func (ww *widgetWallet) onNewAddress() {
err := ww.model.createAddress()
errorCheck(err)
}

func (ww *widgetWallet) onChangePassword() {
changePassword(ww.model.wallet)
}

func (ww *widgetWallet) onNewAddress() {
createAddress(ww)
}

func (ww *widgetWallet) onShowSeed() {
password, ok := getWalletPassword(ww.model.wallet)
if !ok {
Expand Down
Loading