mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-07-24 06:22:59 +02:00
Added support of usd rate for withdrawal from app config.
This commit is contained in:
parent
9d7aab4326
commit
a11d3efed6
7 changed files with 36 additions and 5 deletions
|
@ -36,6 +36,10 @@ rpl::producer<float64> Credits::rateValue(
|
|||
return rpl::single(_session->appConfig().starsWithdrawRate());
|
||||
}
|
||||
|
||||
float64 Credits::usdRate() const {
|
||||
return _session->appConfig().currencyWithdrawRate();
|
||||
}
|
||||
|
||||
void Credits::load(bool force) {
|
||||
if (_loader
|
||||
|| (!force
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
[[nodiscard]] CreditsAmount balance() const;
|
||||
[[nodiscard]] CreditsAmount balance(PeerId peerId) const;
|
||||
[[nodiscard]] rpl::producer<CreditsAmount> balanceValue() const;
|
||||
[[nodiscard]] float64 usdRate() const;
|
||||
[[nodiscard]] rpl::producer<float64> rateValue(
|
||||
not_null<PeerData*> ownedBotOrChannel);
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace Data {
|
|||
|
||||
using EarnInt = uint64;
|
||||
|
||||
constexpr auto kEarnMultiplier = EarnInt(1000000000);
|
||||
constexpr auto kEarnMultiplier = EarnInt(1);
|
||||
|
||||
struct EarnHistoryEntry final {
|
||||
enum class Type {
|
||||
|
|
|
@ -70,10 +70,10 @@ QString ToUsd(
|
|||
const auto result = int64(base::SafeRound(value.value() * rate));
|
||||
return QString(kApproximately)
|
||||
+ QChar('$')
|
||||
+ MajorPart(result)
|
||||
+ ((afterFloat > 0)
|
||||
? MinorPart(result).left(afterFloat)
|
||||
: MinorPart(result));
|
||||
+ QString::number(
|
||||
value.value() * rate,
|
||||
'f',
|
||||
afterFloat ? afterFloat : 2);
|
||||
}
|
||||
|
||||
} // namespace Info::ChannelEarn
|
||||
|
|
|
@ -93,6 +93,10 @@ float64 AppConfig::starsWithdrawRate() const {
|
|||
return get<float64>(u"stars_usd_withdraw_rate_x1000"_q, 1300) / 1000.;
|
||||
}
|
||||
|
||||
float64 AppConfig::currencyWithdrawRate() const {
|
||||
return get<float64>(u"ton_usd_rate"_q, 1);
|
||||
}
|
||||
|
||||
bool AppConfig::paidMessagesAvailable() const {
|
||||
return get<bool>(u"stars_paid_messages_available"_q, false);
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
[[nodiscard]] int starrefCommissionMax() const;
|
||||
|
||||
[[nodiscard]] float64 starsWithdrawRate() const;
|
||||
[[nodiscard]] float64 currencyWithdrawRate() const;
|
||||
[[nodiscard]] bool paidMessagesAvailable() const;
|
||||
[[nodiscard]] int paidMessageStarsMax() const;
|
||||
[[nodiscard]] int paidMessageCommission() const;
|
||||
|
|
|
@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "info/bot/starref/info_bot_starref_common.h"
|
||||
#include "info/bot/starref/info_bot_starref_join_widget.h"
|
||||
#include "info/channel_statistics/boosts/giveaway/boost_badge.h" // InfiniteRadialAnimationWidget.
|
||||
#include "info/channel_statistics/earn/earn_format.h"
|
||||
#include "info/channel_statistics/earn/earn_icons.h"
|
||||
#include "info/settings/info_settings_widget.h" // SectionCustomTopBarData.
|
||||
#include "info/statistics/info_statistics_list_controllers.h"
|
||||
|
@ -57,6 +58,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "styles/style_settings.h"
|
||||
#include "styles/style_statistics.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_channel_earn.h"
|
||||
|
||||
namespace Settings {
|
||||
namespace {
|
||||
|
@ -517,6 +519,25 @@ void Credits::setupContent() {
|
|||
textSt,
|
||||
st::defaultPopupMenu,
|
||||
std::move(context))));
|
||||
if (isCurrency) {
|
||||
const auto rate = _controller->session().credits().usdRate();
|
||||
const auto wrap = content->add(
|
||||
object_ptr<Ui::SlideWrap<>>(
|
||||
content,
|
||||
object_ptr<Ui::CenterWrap<>>(
|
||||
content,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
content,
|
||||
_controller->session().credits().tonBalanceValue(
|
||||
) | rpl::map([=](CreditsAmount value) {
|
||||
using namespace Info::ChannelEarn;
|
||||
return value ? ToUsd(value, rate, 3) : QString();
|
||||
}),
|
||||
st::channelEarnOverviewSubMinorLabel))));
|
||||
wrap->toggleOn(_controller->session().credits().tonBalanceValue(
|
||||
) | rpl::map(rpl::mappers::_1 > CreditsAmount(0)));
|
||||
wrap->finishAnimating();
|
||||
}
|
||||
Ui::AddSkip(content, st::lineWidth);
|
||||
Ui::AddSkip(content, st::lineWidth);
|
||||
Ui::AddSkip(content);
|
||||
|
|
Loading…
Add table
Reference in a new issue