mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Replaced api for credits rate.
This commit is contained in:
parent
3a7a485dd0
commit
838d5669ed
2 changed files with 12 additions and 34 deletions
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "api/api_credits.h"
|
#include "api/api_credits.h"
|
||||||
#include "data/data_user.h"
|
#include "data/data_user.h"
|
||||||
|
#include "main/main_app_config.h"
|
||||||
#include "main/main_session.h"
|
#include "main/main_session.h"
|
||||||
|
|
||||||
namespace Data {
|
namespace Data {
|
||||||
|
@ -31,26 +32,10 @@ void Credits::apply(const MTPDupdateStarsBalance &data) {
|
||||||
|
|
||||||
rpl::producer<float64> Credits::rateValue(
|
rpl::producer<float64> Credits::rateValue(
|
||||||
not_null<PeerData*> ownedBotOrChannel) {
|
not_null<PeerData*> ownedBotOrChannel) {
|
||||||
// Should be replaced in the future.
|
return rpl::single(
|
||||||
if (_rate > 0) {
|
_session->appConfig().get<float64>(
|
||||||
return rpl::single(_rate);
|
u"stars_usd_withdraw_rate_x1000"_q,
|
||||||
}
|
1200) / 1000.);
|
||||||
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) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#include "ui/boxes/edit_invite_link_session.h"
|
#include "ui/boxes/edit_invite_link_session.h"
|
||||||
|
|
||||||
#include "api/api_credits.h"
|
#include "data/components/credits.h"
|
||||||
#include "data/data_peer.h"
|
#include "data/data_peer.h"
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/stickers/data_custom_emoji.h"
|
#include "data/stickers/data_custom_emoji.h"
|
||||||
|
@ -39,7 +39,7 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle(
|
||||||
not_null<Ui::GenericBox*> box,
|
not_null<Ui::GenericBox*> box,
|
||||||
not_null<PeerData*> peer) {
|
not_null<PeerData*> peer) {
|
||||||
struct State final {
|
struct State final {
|
||||||
float64 usdRate = 0;
|
rpl::variable<float64> usdRate = 0;
|
||||||
};
|
};
|
||||||
const auto state = box->lifetime().make_state<State>();
|
const auto state = box->lifetime().make_state<State>();
|
||||||
const auto currency = u"USD"_q;
|
const auto currency = u"USD"_q;
|
||||||
|
@ -101,7 +101,7 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle(
|
||||||
});
|
});
|
||||||
priceOverlay->paintRequest(
|
priceOverlay->paintRequest(
|
||||||
) | rpl::start_with_next([=, right = st::boxRowPadding.right()] {
|
) | rpl::start_with_next([=, right = st::boxRowPadding.right()] {
|
||||||
if (state->usdRate <= 0) {
|
if (state->usdRate.current() <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto amount = input->getLastText().toDouble();
|
const auto amount = input->getLastText().toDouble();
|
||||||
|
@ -111,7 +111,9 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle(
|
||||||
const auto text = tr::lng_group_invite_subscription_price(
|
const auto text = tr::lng_group_invite_subscription_price(
|
||||||
tr::now,
|
tr::now,
|
||||||
lt_cost,
|
lt_cost,
|
||||||
Ui::FillAmountAndCurrency(amount * state->usdRate, currency));
|
Ui::FillAmountAndCurrency(
|
||||||
|
amount * state->usdRate.current(),
|
||||||
|
currency));
|
||||||
auto p = QPainter(priceOverlay);
|
auto p = QPainter(priceOverlay);
|
||||||
p.setFont(st.placeholderFont);
|
p.setFont(st.placeholderFont);
|
||||||
p.setPen(st.placeholderFg);
|
p.setPen(st.placeholderFg);
|
||||||
|
@ -120,16 +122,7 @@ InviteLinkSubscriptionToggle FillCreateInviteLinkSubscriptionToggle(
|
||||||
p.drawText(priceOverlay->rect() - m, text, style::al_right);
|
p.drawText(priceOverlay->rect() - m, text, style::al_right);
|
||||||
}, priceOverlay->lifetime());
|
}, priceOverlay->lifetime());
|
||||||
|
|
||||||
{
|
state->usdRate = peer->session().credits().rateValue(peer);
|
||||||
auto &lifetime = priceOverlay->lifetime();
|
|
||||||
const auto api = lifetime.make_state<Api::CreditsEarnStatistics>(
|
|
||||||
peer);
|
|
||||||
api->request(
|
|
||||||
) | rpl::start_with_done([=] {
|
|
||||||
state->usdRate = api->data().usdRate;
|
|
||||||
priceOverlay->update();
|
|
||||||
}, priceOverlay->lifetime());
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto arrow = Ui::Text::SingleCustomEmoji(
|
const auto arrow = Ui::Text::SingleCustomEmoji(
|
||||||
peer->owner().customEmojiManager().registerInternalEmoji(
|
peer->owner().customEmojiManager().registerInternalEmoji(
|
||||||
|
|
Loading…
Add table
Reference in a new issue