Skip to content

Commit 5d3d455

Browse files
committed
[trello.com/c/AvS5QpYb] Make balances ... only after pull to refresh update
1 parent 9014a67 commit 5d3d455

File tree

11 files changed

+88
-24
lines changed

11 files changed

+88
-24
lines changed

Adamant/Modules/Account/AccountViewController/AccountViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,9 +995,9 @@ final class AccountViewController: FormViewController {
995995
}
996996

997997
Task { @MainActor in
998-
accountService.update()
999-
refreshControl.endRefreshing()
998+
accountService.updateWithRefreshUI()
1000999
}
1000+
refreshControl.endRefreshing()
10011001
}
10021002

10031003
private func selectCurrentWallet() {

Adamant/Modules/Wallets/Adamant/AdmWalletService.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,20 @@ final class AdmWalletService: NSObject, WalletCoreProtocol, WalletStaticCoreProt
158158
.store(in: &subscriptions)
159159
}
160160

161+
func updateWithRefreshUIBalance(){
162+
Task {
163+
admWallet?.isBalanceInitialized = false
164+
await walletUpdateSender.send()
165+
update()
166+
}
167+
}
168+
161169
func update() {
162170
guard let accountService = accountService, let account = accountService.account else {
163171
admWallet = nil
164172
return
165173
}
166174

167-
admWallet?.isBalanceInitialized = false
168-
169175
let isRaised: Bool
170176

171177
if let wallet = admWallet {

Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,14 @@ final class BtcWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @unc
278278
}
279279
}
280280

281+
func updateWithRefreshUIBalance(){
282+
Task {
283+
await update(updateWithRefreshUIBalance: true)
284+
}
285+
}
286+
281287
@MainActor
282-
func update() async {
288+
func update(updateWithRefreshUIBalance: Bool = false) async {
283289
guard let wallet = btcWallet else {
284290
return
285291
}
@@ -292,8 +298,10 @@ final class BtcWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @unc
292298
break
293299
}
294300

295-
wallet.isBalanceInitialized = false
296-
walletUpdateSender.send()
301+
if updateWithRefreshUIBalance {
302+
wallet.isBalanceInitialized = false
303+
walletUpdateSender.send()
304+
}
297305

298306
setState(.updating)
299307

Adamant/Modules/Wallets/Dash/DashWalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,15 @@ final class DashWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
225225
await update()
226226
}
227227
}
228+
229+
func updateWithRefreshUIBalance(){
230+
Task {
231+
await update(updateWithRefreshUIBalance: true)
232+
}
233+
}
228234

229235
@MainActor
230-
func update() async {
236+
func update(updateWithRefreshUIBalance: Bool = false) async {
231237
guard let wallet = dashWallet else {
232238
return
233239
}
@@ -240,8 +246,10 @@ final class DashWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
240246
break
241247
}
242248

243-
wallet.isBalanceInitialized = false
244-
walletUpdateSender.send()
249+
if updateWithRefreshUIBalance{
250+
wallet.isBalanceInitialized = false
251+
walletUpdateSender.send()
252+
}
245253

246254
setState(.updating)
247255

Adamant/Modules/Wallets/Doge/DogeWalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,14 @@ final class DogeWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
246246
}
247247
}
248248

249+
func updateWithRefreshUIBalance(){
250+
Task {
251+
await update(updateWithRefreshUIBalance: true)
252+
}
253+
}
254+
249255
@MainActor
250-
func update() async {
256+
func update(updateWithRefreshUIBalance: Bool = false) async {
251257
guard let wallet = dogeWallet else {
252258
return
253259
}
@@ -260,8 +266,10 @@ final class DogeWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
260266
break
261267
}
262268

263-
wallet.isBalanceInitialized = false
264-
walletUpdateSender.send()
269+
if updateWithRefreshUIBalance {
270+
wallet.isBalanceInitialized = false
271+
walletUpdateSender.send()
272+
}
265273

266274
setState(.updating)
267275

Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,14 @@ final class ERC20WalletService: WalletCoreProtocol, ERC20GasAlgorithmComputable,
255255
}
256256
}
257257

258+
func updateWithRefreshUIBalance() {
259+
Task {
260+
await update(updateWithRefreshUIBalance: true)
261+
}
262+
}
263+
258264
@MainActor
259-
func update() async {
265+
func update(updateWithRefreshUIBalance: Bool = false) async {
260266
guard let wallet = ethWallet else {
261267
return
262268
}
@@ -269,8 +275,10 @@ final class ERC20WalletService: WalletCoreProtocol, ERC20GasAlgorithmComputable,
269275
break
270276
}
271277

272-
wallet.isBalanceInitialized = false
273-
walletUpdateSender.send()
278+
if updateWithRefreshUIBalance {
279+
wallet.isBalanceInitialized = false
280+
walletUpdateSender.send()
281+
}
274282

275283
setState(.updating)
276284

Adamant/Modules/Wallets/Ethereum/EthWalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,14 @@ final class EthWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, ERC2
292292
}
293293
}
294294

295+
func updateWithRefreshUIBalance(){
296+
Task {
297+
await update(updateWithRefreshUIBalance: true)
298+
}
299+
}
300+
295301
@MainActor
296-
func update() async {
302+
func update(updateWithRefreshUIBalance: Bool = false) async {
297303
guard let wallet = await getWallet() else {
298304
return
299305
}
@@ -306,8 +312,10 @@ final class EthWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, ERC2
306312
break
307313
}
308314

309-
wallet.isBalanceInitialized = false
310-
walletUpdateSender.send()
315+
if updateWithRefreshUIBalance {
316+
wallet.isBalanceInitialized = false
317+
walletUpdateSender.send()
318+
}
311319

312320
setState(.updating)
313321

Adamant/Modules/Wallets/Klayr/WalletService/KlyWalletService.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,14 @@ extension KlyWalletService {
249249
.store(in: &subscriptions)
250250
}
251251

252+
func updateWithRefreshUIBalance(){
253+
Task {
254+
await update(updateWithRefreshUIBalance: true)
255+
}
256+
}
257+
252258
@MainActor
253-
fileprivate func update() async {
259+
fileprivate func update(updateWithRefreshUIBalance: Bool = false) async {
254260
guard let wallet = klyWallet else {
255261
return
256262
}
@@ -263,8 +269,10 @@ extension KlyWalletService {
263269
break
264270
}
265271

266-
wallet.isBalanceInitialized = false
267-
walletUpdateSender.send()
272+
if updateWithRefreshUIBalance {
273+
wallet.isBalanceInitialized = false
274+
walletUpdateSender.send()
275+
}
268276

269277
setState(.updating)
270278

Adamant/Modules/Wallets/WalletsService/WalletCoreProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ protocol WalletCoreProtocol: AnyObject, Sendable {
301301
var walletUpdatePublisher: AnyObservable<Void> { get }
302302

303303
func update()
304+
func updateWithRefreshUIBalance()
304305

305306
// MARK: Tools
306307
func validate(address: String) -> AddressValidationResult

Adamant/ServiceProtocols/AccountService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ protocol AccountService: AnyObject, Sendable {
162162

163163
/// Update logged account info
164164
func update()
165+
func updateWithRefreshUI()
165166
func update(_ completion: (@Sendable (AccountServiceResult) -> Void)?)
166167

167168
/// Login into Adamant using passphrase.

0 commit comments

Comments
 (0)