Skip to content

Commit

Permalink
GUI: BitcoinAmountField: Allow changing allowed assets after construc…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
luke-jr authored and instagibbs committed Apr 9, 2019
1 parent 3e669cd commit 7f00087
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/qt/bitcoinamountfield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,30 @@ void BitcoinAmountField::removeAssetChoice(const CAsset& asset)
unit->removeItem(unit->findData(QVariant::fromValue(asset), Qt::UserRole));
}

void BitcoinAmountField::setAllowedAssets(const std::set<CAsset>& allowed_assets)
{
std::set<CAsset> assets_to_remove;
for (const auto& asset : m_allowed_assets) {
if (!allowed_assets.count(asset)) {
assets_to_remove.insert(asset);
}
}
m_allowed_assets = allowed_assets;
const QVariant& sel_userdata = unit->itemData(unit->currentIndex(), Qt::UserRole);
const CAsset sel_asset = (sel_userdata.type() == QVariant::UserType) ? sel_userdata.value<CAsset>() : Params().GetConsensus().pegged_asset;
for (const auto& asset : assets_to_remove) {
// Leave it in place for now if it's selected
if (sel_asset == asset) continue;

removeAssetChoice(asset);
}
for (const auto& asset : allowed_assets) {
if (!hasAssetChoice(asset)) {
addAssetChoice(asset);
}
}
}

void BitcoinAmountField::unitChanged(int idx)
{
const CAsset previous_asset = amount->value().first;
Expand Down
2 changes: 2 additions & 0 deletions src/qt/bitcoinamountfield.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class BitcoinAmountField: public QWidget
/** Perform input validation, mark field as invalid if entered value is not valid. */
bool validate();

void setAllowedAssets(const std::set<CAsset>& allowed_assets);

/** Change unit used to display amount. */
void setDisplayUnit(const CAsset&);
void setDisplayUnit(int unit);
Expand Down

0 comments on commit 7f00087

Please sign in to comment.