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(gtk): support create Ed25519 in gtk #1489

Merged
merged 9 commits into from
Sep 4, 2024
Merged
29 changes: 20 additions & 9 deletions cmd/gtk/dialog_wallet_create_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package main

import (
_ "embed"
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/wallet"
Expand All @@ -17,31 +16,43 @@ func createAddress(ww *widgetWallet) {
builder, err := gtk.BuilderNewFromString(string(uiWalletCreateAddressDialog))
fatalErrorCheck(err)

passwordFetcher := func(wlt *wallet.Wallet) (string, bool) {
if *passwordOpt != "" {
return *passwordOpt, true
}

return getWalletPassword(wlt)
}

password, ok := passwordFetcher(ww.model.wallet)
if !ok {
return
}

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.AddressTypeEd25519Account, "ED25519 Account")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can define String function for Address Types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address types in wallet is not enum and don't have specific type for define String method.

We can use crypto.AddressType in future.

addressTypeCombo.Append(wallet.AddressTypeBLSAccount, "BLS Account")
addressTypeCombo.Append(wallet.AddressTypeValidator, "Validator")

addressTypeCombo.SetActive(0)

getButtonObj(builder, "id_button_ok").SetImage(OkIcon())
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved

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

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

if walletAddressType == wallet.AddressTypeBLSAccount {
switch walletAddressType {
case wallet.AddressTypeEd25519Account:
_, err = ww.model.wallet.NewEd25519AccountAddress(walletAddressLabel, password)
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
case wallet.AddressTypeBLSAccount:
_, err = ww.model.wallet.NewBLSAccountAddress(walletAddressLabel)
} else if walletAddressType == wallet.AddressTypeValidator {
case wallet.AddressTypeValidator:
_, err = ww.model.wallet.NewValidatorAddress(walletAddressLabel)
} else {
err = fmt.Errorf("invalid address type '%s'", walletAddressType)
}

errorCheck(err)
Expand Down
Loading