-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create new validator address (CLI and GUI) (#757)
- Loading branch information
Showing
9 changed files
with
266 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.