mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Added initial ability to request rate of credits from Credits component.
This commit is contained in:
parent
05fa2c381a
commit
fb66c85567
2 changed files with 27 additions and 0 deletions
|
@ -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;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue