From ab135bc9179afbd00ab3fe887dc4b741963d5092 Mon Sep 17 00:00:00 2001 From: Javad Rajabzadeh Date: Sun, 10 Nov 2024 13:34:56 +0330 Subject: [PATCH] fix(gtk): prevent duplicate address on enter signal in create modal (#1590) --- cmd/gtk/dialog_wallet_create_address.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/gtk/dialog_wallet_create_address.go b/cmd/gtk/dialog_wallet_create_address.go index 2e74344d2..5238bfb26 100644 --- a/cmd/gtk/dialog_wallet_create_address.go +++ b/cmd/gtk/dialog_wallet_create_address.go @@ -5,6 +5,7 @@ package main import ( _ "embed" + "github.com/gotk3/gotk3/gdk" "github.com/gotk3/gotk3/gtk" "github.com/pactus-project/pactus/crypto" ) @@ -26,10 +27,23 @@ func createAddress(wdgWallet *widgetWallet) { addressTypeCombo.SetActive(0) - getButtonObj(builder, "id_button_ok").SetImage(OkIcon()) + okBtn := getButtonObj(builder, "id_button_ok") + okBtn.SetImage(OkIcon()) + getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon()) + dlg.Connect("key-press-event", func(_ *gtk.Dialog, event *gdk.Event) { + keyEvent := &gdk.EventKey{Event: event} + // Check if the Enter key was pressed + if keyEvent.KeyVal() == gdk.KEY_Return || keyEvent.KeyVal() == gdk.KEY_KP_Enter { + // Prevent Enter from triggering default behavior twice + _, _ = okBtn.Emit("clicked") + } + }) + onOk := func() { + okBtn.SetSensitive(false) + walletAddressLabel, err := addressLabel.GetText() fatalErrorCheck(err) @@ -51,6 +65,7 @@ func createAddress(wdgWallet *widgetWallet) { } if err != nil { + okBtn.SetSensitive(true) showError(err) return