Skip to content

Commit b164039

Browse files
committed
qt: decouple address type from combo index
1 parent 79580c0 commit b164039

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/qt/receivecoinsdialog.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
8888
&ReceiveCoinsDialog::recentRequestsView_selectionChanged);
8989

9090
// Populate address type dropdown and select default
91-
ui->addressType->insertItem((int)OutputType::LEGACY, "Base58 (Legacy)");
92-
ui->addressType->setItemData((int)OutputType::LEGACY, "Not recommended due to higher fees and less protection against typos.", Qt::ToolTipRole);
93-
ui->addressType->insertItem((int)OutputType::P2SH_SEGWIT, "Base58 (P2SH-SegWit)");
94-
ui->addressType->setItemData((int)OutputType::P2SH_SEGWIT, "Generates an address compatible with older wallets.", Qt::ToolTipRole);
95-
ui->addressType->insertItem((int)OutputType::BECH32, "Bech32 (SegWit)");
96-
ui->addressType->setItemData((int)OutputType::BECH32, "Generates a native segwit addresses (BIP-173), which reduces your transaction fees later on and offers better protection against typos, but some old wallets don't support it.", Qt::ToolTipRole);
91+
auto add_address_type = [&](OutputType type, const QString& text, const QString& tooltip) {
92+
const auto index = ui->addressType->count();
93+
ui->addressType->addItem(text, (int) type);
94+
ui->addressType->setItemData(index, tooltip, Qt::ToolTipRole);
95+
if (model->wallet().getDefaultAddressType() == type) ui->addressType->setCurrentIndex(index);
96+
};
97+
add_address_type(OutputType::LEGACY, "Base58 (Legacy)", "Not recommended due to higher fees and less protection against typos.");
98+
add_address_type(OutputType::P2SH_SEGWIT, "Base58 (P2SH-SegWit)", "Generates an address compatible with older wallets.");
99+
add_address_type(OutputType::BECH32, "Bech32 (SegWit)", "Generates a native segwit addresses (BIP-173), which reduces your transaction fees later on and offers better protection against typos, but some old wallets don't support it.");
97100
if (model->wallet().taprootEnabled()) {
98-
ui->addressType->insertItem((int)OutputType::BECH32M, "Bech32m (Taproot)");
99-
ui->addressType->setItemData((int)OutputType::BECH32M, "Although Bech32m (BIP-350) looks similar to Bech32, there is a slight difference and only some newer wallets support it.", Qt::ToolTipRole);
101+
add_address_type(OutputType::BECH32M, "Bech32m (Taproot)", "Although Bech32m (BIP-350) looks similar to Bech32, there is a slight difference and only some newer wallets support it.");
100102
}
101-
ui->addressType->setCurrentIndex((int)model->wallet().getDefaultAddressType());
102103

103104
// Set the button to be enabled or disabled based on whether the wallet can give out new addresses.
104105
ui->receiveButton->setEnabled(model->wallet().canGetAddresses());
@@ -151,7 +152,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
151152
QString address;
152153
QString label = ui->reqLabel->text();
153154
/* Generate new receiving address */
154-
const OutputType address_type = (OutputType)ui->addressType->currentIndex();
155+
const OutputType address_type = (OutputType)ui->addressType->currentData().toInt();
155156
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
156157

157158
switch(model->getAddressTableModel()->getEditStatus())

0 commit comments

Comments
 (0)