Skip to content

Commit

Permalink
[PWN-9343] Cancel rates update when view is disappeared
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizaveta Semenova committed Jul 25, 2023
1 parent f0d02f3 commit 42af027
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ struct WithdrawCalculatorView: View {
.padding(.horizontal, 16)
}
.onAppear {
viewModel.isViewAppeared.send(true)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
// We need delay because BigInputView is UITextField
viewModel.isFromFirstResponder = true
}
}
.onDisappear {
viewModel.isViewAppeared.send(false)
}
}

var contentView: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class WithdrawCalculatorViewModel: BaseViewModel, ObservableObject {
let openBankTransfer = PassthroughSubject<Void, Never>()
let openWithdraw = PassthroughSubject<StrigaWithdrawalInfo, Never>()
let proceedWithdraw = PassthroughSubject<Void, Never>()
let isViewAppeared = PassthroughSubject<Bool, Never>()

@Published var actionData = WithdrawCalculatorAction.zero
@Published var isLoading = false
Expand Down Expand Up @@ -55,7 +56,6 @@ final class WithdrawCalculatorViewModel: BaseViewModel, ObservableObject {

override init() {
super.init()
loadRates()
bindProperties()
bindReachibility()
bindAccounts()
Expand Down Expand Up @@ -190,6 +190,16 @@ private extension WithdrawCalculatorViewModel {
.receive(on: RunLoop.main)
.assignWeak(to: \.actionData, on: self)
.store(in: &subscriptions)

isViewAppeared
.sink { [weak self] isAppeared in
if isAppeared {
self?.loadRates()
} else {
self?.cancelUpdate()
}
}
.store(in: &subscriptions)
}

func bindAccounts() {
Expand Down

0 comments on commit 42af027

Please sign in to comment.