Skip to content

Commit 9948f11

Browse files
committed
Merge bitcoin-core#390: Add SubFeeFromAmount to options
62b125f qt, refactor: Fix indentation (Prateek Sancheti) ad28b66 qt: Add SubFeeFromAmount option (Prateek Sancheti) Pull request description: This PR adds **_SubFeeFromAmount_** option which lets the user select their preferred setting of whether fee for a transaction is to be subtracted from the amount or not for future transactions. The setting chosen by the user is remembered even when the GUI mode is turned off. **_Functionality and Usage:_** - Go to `Settings > Options > Wallet` on _Windows/Linux_ or `bitcoin-qt > Preferences > Wallet` on _macOS_. - The checkbox **Subtract Fee From Amount** corresponds to the added option **SubFeeFromAmount**. - The preferred setting intended to be the default for all future send transactions should be selected by the user. - Click on **OK**. - Go to the **Send** tab in the wallet. - You shall notice, any new Send transaction created will have the preferred setting as chosen by the user.<br> (Try clicking on Add recipient or even restarting the Node in GUI) Attaching ScreenRecordings to explain the added feature. > Master.mov: Master Branch https://user-images.githubusercontent.com/54016434/127763378-be91837d-d0ab-4ae5-87c0-d303fa70a336.mov > PR.mov: PullRequest https://user-images.githubusercontent.com/54016434/127763404-05b834c1-4082-4fbd-9b05-1528ac898a21.mov Close bitcoin-core#386 ACKs for top commit: Talkless: tACK 62b125f, tested on Debian Sid with 5.15.2 and it works as described. hebasto: re-ACK 62b125f, only removed the unused `SubFeeFromAmountChanged` signal since my [previous](bitcoin-core#390 (review)) review. meshcollider: utACK 62b125f Tree-SHA512: 932ca89ae578a1e1c426561400d87cf005c231944feaf0f662ff8d88f32bdd65a927a090ea41510a15f8ec0ebcd5529672e9917720eb5ea85f413f081e45d5bb
2 parents e614cc8 + 62b125f commit 9948f11

File tree

5 files changed

+63
-36
lines changed

5 files changed

+63
-36
lines changed

src/qt/forms/optionsdialog.ui

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,20 @@
5151
</spacer>
5252
</item>
5353
<item>
54-
<layout class="QHBoxLayout" name="horizontalLayout_Main_Prune">
55-
<item>
56-
<widget class="QCheckBox" name="prune">
57-
<property name="toolTip">
58-
<string>Enabling pruning significantly reduces the disk space required to store transactions. All blocks are still fully validated. Reverting this setting requires re-downloading the entire blockchain.</string>
59-
</property>
60-
<property name="text">
61-
<string>Prune &amp;block storage to</string>
62-
</property>
63-
</widget>
64-
</item>
65-
<item>
66-
<widget class="QSpinBox" name="pruneSize"/>
67-
</item>
54+
<layout class="QHBoxLayout" name="horizontalLayout_Main_Prune">
55+
<item>
56+
<widget class="QCheckBox" name="prune">
57+
<property name="toolTip">
58+
<string>Enabling pruning significantly reduces the disk space required to store transactions. All blocks are still fully validated. Reverting this setting requires re-downloading the entire blockchain.</string>
59+
</property>
60+
<property name="text">
61+
<string>Prune &amp;block storage to</string>
62+
</property>
63+
</widget>
64+
</item>
65+
<item>
66+
<widget class="QSpinBox" name="pruneSize"/>
67+
</item>
6868
<item>
6969
<widget class="QLabel" name="pruneSizeUnitLabel">
7070
<property name="text">
@@ -200,6 +200,16 @@
200200
<string>W&amp;allet</string>
201201
</attribute>
202202
<layout class="QVBoxLayout" name="verticalLayout_Wallet">
203+
<item>
204+
<widget class="QCheckBox" name="subFeeFromAmount">
205+
<property name="toolTip">
206+
<string extracomment="Tooltip text for Options window setting that sets subtracting the fee from a sending amount as default.">Whether to set subtract fee from amount as default or not.</string>
207+
</property>
208+
<property name="text">
209+
<string extracomment="An Options window setting to set subtracting the fee from a sending amount as default.">Subtract &amp;fee from amount by default</string>
210+
</property>
211+
</widget>
212+
</item>
203213
<item>
204214
<widget class="QGroupBox" name="groupBox">
205215
<property name="title">
@@ -235,27 +245,27 @@
235245
<string>External Signer (e.g. hardware wallet)</string>
236246
</property>
237247
<layout class="QVBoxLayout" name="verticalLayoutHww">
238-
<item>
239-
<layout class="QHBoxLayout" name="horizontalLayoutHww">
240-
<item>
241-
<widget class="QLabel" name="externalSignerPathLabel">
242-
<property name="text">
243-
<string>&amp;External signer script path</string>
244-
</property>
245-
<property name="buddy">
246-
<cstring>externalSignerPath</cstring>
247-
</property>
248-
</widget>
249-
</item>
250-
<item>
251-
<widget class="QLineEdit" name="externalSignerPath">
252-
<property name="toolTip">
253-
<string>Full path to a Bitcoin Core compatible script (e.g. C:\Downloads\hwi.exe or /Users/you/Downloads/hwi.py). Beware: malware can steal your coins!</string>
254-
</property>
255-
</widget>
256-
</item>
257-
</layout>
258-
</item>
248+
<item>
249+
<layout class="QHBoxLayout" name="horizontalLayoutHww">
250+
<item>
251+
<widget class="QLabel" name="externalSignerPathLabel">
252+
<property name="text">
253+
<string>&amp;External signer script path</string>
254+
</property>
255+
<property name="buddy">
256+
<cstring>externalSignerPath</cstring>
257+
</property>
258+
</widget>
259+
</item>
260+
<item>
261+
<widget class="QLineEdit" name="externalSignerPath">
262+
<property name="toolTip">
263+
<string>Full path to a Bitcoin Core compatible script (e.g. C:\Downloads\hwi.exe or /Users/you/Downloads/hwi.py). Beware: malware can steal your coins!</string>
264+
</property>
265+
</widget>
266+
</item>
267+
</layout>
268+
</item>
259269
</layout>
260270
</widget>
261271
</item>

src/qt/optionsdialog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ void OptionsDialog::setMapper()
239239
/* Wallet */
240240
mapper->addMapping(ui->spendZeroConfChange, OptionsModel::SpendZeroConfChange);
241241
mapper->addMapping(ui->coinControlFeatures, OptionsModel::CoinControlFeatures);
242+
mapper->addMapping(ui->subFeeFromAmount, OptionsModel::SubFeeFromAmount);
242243
mapper->addMapping(ui->externalSignerPath, OptionsModel::ExternalSignerPath);
243244

244245
/* Network */

src/qt/optionsmodel.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ void OptionsModel::Init(bool resetSettings)
124124
if (!gArgs.SoftSetArg("-signer", settings.value("external_signer_path").toString().toStdString())) {
125125
addOverriddenOption("-signer");
126126
}
127+
128+
if (!settings.contains("SubFeeFromAmount")) {
129+
settings.setValue("SubFeeFromAmount", false);
130+
}
131+
m_sub_fee_from_amount = settings.value("SubFeeFromAmount", false).toBool();
127132
#endif
128133

129134
// Network
@@ -335,6 +340,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
335340
return settings.value("bSpendZeroConfChange");
336341
case ExternalSignerPath:
337342
return settings.value("external_signer_path");
343+
case SubFeeFromAmount:
344+
return m_sub_fee_from_amount;
338345
#endif
339346
case DisplayUnit:
340347
return nDisplayUnit;
@@ -460,6 +467,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
460467
setRestartRequired(true);
461468
}
462469
break;
470+
case SubFeeFromAmount:
471+
m_sub_fee_from_amount = value.toBool();
472+
settings.setValue("SubFeeFromAmount", m_sub_fee_from_amount);
473+
break;
463474
#endif
464475
case DisplayUnit:
465476
setDisplayUnit(value);

src/qt/optionsmodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class OptionsModel : public QAbstractListModel
6161
Language, // QString
6262
UseEmbeddedMonospacedFont, // bool
6363
CoinControlFeatures, // bool
64+
SubFeeFromAmount, // bool
6465
ThreadsScriptVerif, // int
6566
Prune, // bool
6667
PruneSize, // int
@@ -88,6 +89,7 @@ class OptionsModel : public QAbstractListModel
8889
QString getThirdPartyTxUrls() const { return strThirdPartyTxUrls; }
8990
bool getUseEmbeddedMonospacedFont() const { return m_use_embedded_monospaced_font; }
9091
bool getCoinControlFeatures() const { return fCoinControlFeatures; }
92+
bool getSubFeeFromAmount() const { return m_sub_fee_from_amount; }
9193
const QString& getOverriddenByCommandLine() { return strOverriddenByCommandLine; }
9294

9395
/* Explicit setters */
@@ -112,6 +114,7 @@ class OptionsModel : public QAbstractListModel
112114
QString strThirdPartyTxUrls;
113115
bool m_use_embedded_monospaced_font;
114116
bool fCoinControlFeatures;
117+
bool m_sub_fee_from_amount;
115118
/* settings that were overridden by command-line */
116119
QString strOverriddenByCommandLine;
117120

src/qt/sendcoinsentry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ void SendCoinsEntry::clear()
9797
ui->payTo->clear();
9898
ui->addAsLabel->clear();
9999
ui->payAmount->clear();
100-
ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
100+
if (model && model->getOptionsModel()) {
101+
ui->checkboxSubtractFeeFromAmount->setChecked(model->getOptionsModel()->getSubFeeFromAmount());
102+
}
101103
ui->messageTextLabel->clear();
102104
ui->messageTextLabel->hide();
103105
ui->messageLabel->hide();

0 commit comments

Comments
 (0)