mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-09-01 15:05:56 +00:00
Added initial ability to request rate of credits from Credits component.
This commit is contained in:
@@ -29,6 +29,30 @@ void Credits::apply(const MTPDupdateStarsBalance &data) {
|
|||||||
apply(data.vbalance().v);
|
apply(data.vbalance().v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<float64> Credits::rateValue(
|
||||||
|
not_null<PeerData*> ownedBotOrChannel) {
|
||||||
|
// Should be replaced in the future.
|
||||||
|
if (_rate > 0) {
|
||||||
|
return rpl::single(_rate);
|
||||||
|
}
|
||||||
|
return [=](auto consumer) {
|
||||||
|
auto lifetime = rpl::lifetime();
|
||||||
|
|
||||||
|
const auto api = lifetime.make_state<Api::CreditsEarnStatistics>(
|
||||||
|
ownedBotOrChannel);
|
||||||
|
api->request(
|
||||||
|
) | rpl::start_with_done([=] {
|
||||||
|
_rate = api->data().usdRate;
|
||||||
|
if (_rate > 0) {
|
||||||
|
consumer.put_next_copy(_rate);
|
||||||
|
consumer.put_done();
|
||||||
|
}
|
||||||
|
}, lifetime);
|
||||||
|
|
||||||
|
return lifetime;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void Credits::load(bool force) {
|
void Credits::load(bool force) {
|
||||||
if (_loader
|
if (_loader
|
||||||
|| (!force
|
|| (!force
|
||||||
|
@@ -30,6 +30,8 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] uint64 balance() const;
|
[[nodiscard]] uint64 balance() const;
|
||||||
[[nodiscard]] rpl::producer<uint64> balanceValue() const;
|
[[nodiscard]] rpl::producer<uint64> balanceValue() const;
|
||||||
|
[[nodiscard]] rpl::producer<float64> rateValue(
|
||||||
|
not_null<PeerData*> ownedBotOrChannel);
|
||||||
|
|
||||||
void lock(int count);
|
void lock(int count);
|
||||||
void unlock(int count);
|
void unlock(int count);
|
||||||
@@ -47,6 +49,7 @@ private:
|
|||||||
rpl::variable<uint64> _locked;
|
rpl::variable<uint64> _locked;
|
||||||
rpl::event_stream<> _loadedChanges;
|
rpl::event_stream<> _loadedChanges;
|
||||||
crl::time _lastLoaded = 0;
|
crl::time _lastLoaded = 0;
|
||||||
|
float64 _rate = 0.;
|
||||||
|
|
||||||
SingleQueuedInvokation _reload;
|
SingleQueuedInvokation _reload;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user