Skip to content

Commit

Permalink
feat(gtk): add fee entry for transfer, bond and withdraw (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Nov 1, 2024
1 parent d8f993d commit ee8353d
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 30 deletions.
58 changes: 55 additions & 3 deletions cmd/gtk/assets/ui/dialog_transaction_bond.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="id_dialog_transaction_bond">
Expand Down Expand Up @@ -272,7 +272,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Memo (Up to 64 characters, Optional):</property>
<property name="label" translatable="yes">Fee (Optional):</property>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -281,18 +281,70 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_memo">
<object class="GtkEntry" id="id_entry_fee">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="caps-lock-warning">False</property>
<property name="input-purpose">number</property>
<signal name="changed" handler="on_fee_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">16</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="id_hint_fee">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">17</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">18</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">Memo (Up to 64 characters, Optional):</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">19</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_memo">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="caps-lock-warning">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">20</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down
58 changes: 55 additions & 3 deletions cmd/gtk/assets/ui/dialog_transaction_transfer.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="id_dialog_transaction_transfer">
Expand Down Expand Up @@ -231,7 +231,7 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Memo (Up to 64 characters, Optional):</property>
<property name="label" translatable="yes">Fee (Optional):</property>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -240,18 +240,70 @@
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_memo">
<object class="GtkEntry" id="id_entry_fee">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="caps-lock-warning">False</property>
<property name="input-purpose">number</property>
<signal name="changed" handler="on_fee_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">13</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="id_hint_fee">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">14</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">15</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">Memo (Up to 64 characters, Optional):</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">16</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_memo">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="caps-lock-warning">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">17</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down
58 changes: 55 additions & 3 deletions cmd/gtk/assets/ui/dialog_transaction_withdraw.ui
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkDialog" id="id_dialog_transaction_withdraw">
Expand Down Expand Up @@ -221,6 +221,58 @@
<property name="position">10</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">Fee (Optional):</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">12</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="id_entry_fee">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="caps-lock-warning">False</property>
<property name="input-purpose">number</property>
<signal name="changed" handler="on_fee_changed" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">13</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="id_hint_fee">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">14</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">15</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
Expand All @@ -231,7 +283,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">11</property>
<property name="position">16</property>
</packing>
</child>
<child>
Expand All @@ -244,7 +296,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">12</property>
<property name="position">17</property>
</packing>
</child>
</object>
Expand Down
18 changes: 16 additions & 2 deletions cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/wallet"
Expand All @@ -28,6 +29,8 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
publicKeyEntry := getEntryObj(builder, "id_entry_public_key")
amountEntry := getEntryObj(builder, "id_entry_amount")
amountHint := getLabelObj(builder, "id_hint_amount")
feeEntry := getEntryObj(builder, "id_entry_fee")
feeHint := getLabelObj(builder, "id_hint_fee")
memoEntry := getEntryObj(builder, "id_entry_memo")
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())
Expand All @@ -54,8 +57,11 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
}

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wlt, payload.TypeBond)
updateAmountHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onFeeChanged := func() {
updateFeeHint(feeHint, wlt, payload.TypeTransfer)
}

onSend := func() {
Expand All @@ -77,6 +83,13 @@ func broadcastTransactionBond(wlt *wallet.Wallet) {
wallet.OptionMemo(memo),
}

fee, _ := feeEntry.GetText()
if fee != "" {
feeAmount, err := amount.FromString(fee)
cmd.FatalErrorCheck(err)
opts = append(opts, wallet.OptionFee(feeAmount))
}

trx, err := wlt.MakeBondTx(sender, receiver, publicKey, amt, opts...)
if err != nil {
errorCheck(err)
Expand Down Expand Up @@ -108,6 +121,7 @@ Memo: %s
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
"on_fee_changed": onFeeChanged,
"on_send": onSend,
"on_cancel": onClose,
}
Expand Down
18 changes: 16 additions & 2 deletions cmd/gtk/dialog_transaction_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/cmd"
"github.com/pactus-project/pactus/types/amount"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/wallet"
Expand All @@ -27,6 +28,8 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
receiverHint := getLabelObj(builder, "id_hint_receiver")
amountEntry := getEntryObj(builder, "id_entry_amount")
amountHint := getLabelObj(builder, "id_hint_amount")
feeEntry := getEntryObj(builder, "id_entry_fee")
feeHint := getLabelObj(builder, "id_hint_fee")
memoEntry := getEntryObj(builder, "id_entry_memo")
getButtonObj(builder, "id_button_cancel").SetImage(CancelIcon())
getButtonObj(builder, "id_button_send").SetImage(SendIcon())
Expand All @@ -47,8 +50,11 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
}

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wlt, payload.TypeTransfer)
updateAmountHint(amountHint, senderEntry.GetActiveID(), wlt)
}

onFeeChanged := func() {
updateFeeHint(feeHint, wlt, payload.TypeTransfer)
}

onSend := func() {
Expand All @@ -68,6 +74,13 @@ func broadcastTransactionTransfer(wlt *wallet.Wallet) {
wallet.OptionMemo(memo),
}

fee, _ := feeEntry.GetText()
if fee != "" {
feeAmount, err := amount.FromString(fee)
cmd.FatalErrorCheck(err)
opts = append(opts, wallet.OptionFee(feeAmount))
}

trx, err := wlt.MakeTransferTx(sender, receiver, amt, opts...)
if err != nil {
errorCheck(err)
Expand Down Expand Up @@ -99,6 +112,7 @@ Memo: %s
"on_sender_changed": onSenderChanged,
"on_receiver_changed": onReceiverChanged,
"on_amount_changed": onAmountChanged,
"on_fee_changed": onFeeChanged,
"on_send": onSend,
"on_cancel": onClose,
}
Expand Down
Loading

0 comments on commit ee8353d

Please sign in to comment.