mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Subtract stars balance automatically
This commit is contained in:
@@ -957,6 +957,7 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
|
||||
private var topOffsetDistance: CGFloat?
|
||||
|
||||
private var balance: Int64?
|
||||
private var amount: Int64 = 1
|
||||
private var isAnonymous: Bool = false
|
||||
private var cachedStarImage: (UIImage, PresentationTheme)?
|
||||
@@ -964,6 +965,8 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
|
||||
private var isPastTopCutoff: Bool?
|
||||
|
||||
private var balanceDisposable: Disposable?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
self.bottomOverscrollLimit = 200.0
|
||||
|
||||
@@ -1018,6 +1021,10 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.balanceDisposable?.dispose()
|
||||
}
|
||||
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
if !self.ignoreScrolling {
|
||||
self.updateScrolling(transition: .immediate)
|
||||
@@ -1126,10 +1133,26 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
let sideInset: CGFloat = 16.0
|
||||
|
||||
if self.component == nil {
|
||||
self.balance = component.balance
|
||||
self.amount = 50
|
||||
if let myTopPeer = component.myTopPeer {
|
||||
self.isAnonymous = myTopPeer.isAnonymous
|
||||
}
|
||||
|
||||
if let starsContext = component.context.starsContext {
|
||||
self.balanceDisposable = (starsContext.state
|
||||
|> deliverOnMainQueue).startStrict(next: { [weak self] state in
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
if let state {
|
||||
if self.balance != state.balance {
|
||||
self.balance = state.balance
|
||||
self.state?.updated(transition: .immediate)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
self.component = component
|
||||
@@ -1334,7 +1357,7 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
context: component.context,
|
||||
theme: environment.theme,
|
||||
strings: environment.strings,
|
||||
balance: component.balance
|
||||
balance: self.balance
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: 120.0, height: 100.0)
|
||||
@@ -1750,7 +1773,7 @@ private final class ChatSendStarsScreenComponent: Component {
|
||||
guard let self, let component = self.component else {
|
||||
return
|
||||
}
|
||||
guard let balance = component.balance else {
|
||||
guard let balance = self.balance else {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user