diff --git a/src/qt/bitcoinamountfield.cpp b/src/qt/bitcoinamountfield.cpp index 80d25d6b01..c389d0bd71 100644 --- a/src/qt/bitcoinamountfield.cpp +++ b/src/qt/bitcoinamountfield.cpp @@ -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& allowed_assets) +{ + std::set 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() : 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; diff --git a/src/qt/bitcoinamountfield.h b/src/qt/bitcoinamountfield.h index b6a8b6c90e..cb3b3c98cf 100644 --- a/src/qt/bitcoinamountfield.h +++ b/src/qt/bitcoinamountfield.h @@ -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& allowed_assets); + /** Change unit used to display amount. */ void setDisplayUnit(const CAsset&); void setDisplayUnit(int unit);