Skip to content

Commit 2cc62de

Browse files
authored
Merge pull request #784 from Adamant-im/trello.com/c/AvS5QpYb
[trello.com/c/AvS5QpYb] Bug: Warning window "No active nodes" on Pull-to-Refresh on Account screen
2 parents 9bcf084 + 5d3d455 commit 2cc62de

File tree

11 files changed

+121
-49
lines changed

11 files changed

+121
-49
lines changed

Adamant/Modules/Account/AccountViewController/AccountViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,9 @@ final class AccountViewController: FormViewController {
979979
}
980980

981981
Task { @MainActor in
982-
accountService.update()
983-
refreshControl.endRefreshing()
982+
accountService.updateWithRefreshUI()
984983
}
984+
refreshControl.endRefreshing()
985985
}
986986
}
987987

Adamant/Modules/Wallets/Adamant/AdmWalletService.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +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
}
166-
174+
167175
let isRaised: Bool
168176

169177
if let wallet = admWallet {

Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift

Lines changed: 17 additions & 8 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
}
@@ -291,7 +297,12 @@ final class BtcWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @unc
291297
case .upToDate:
292298
break
293299
}
294-
300+
301+
if updateWithRefreshUIBalance {
302+
wallet.isBalanceInitialized = false
303+
walletUpdateSender.send()
304+
}
305+
295306
setState(.updating)
296307

297308
if let balance = try? await getBalance() {
@@ -301,18 +312,16 @@ final class BtcWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @unc
301312

302313
wallet.balance = balance
303314
markBalanceAsFresh(wallet)
304-
} else {
305-
wallet.isBalanceInitialized = false
306315
}
307-
316+
317+
walletUpdateSender.send()
318+
308319
NotificationCenter.default.post(
309320
name: walletUpdatedNotification,
310321
object: self,
311322
userInfo: [AdamantUserInfoKey.WalletService.wallet: wallet]
312323
)
313-
314-
walletUpdateSender.send()
315-
324+
316325
setState(.upToDate)
317326

318327
if let rate = try? await getFeeRate() {

Adamant/Modules/Wallets/Dash/DashWalletService.swift

Lines changed: 17 additions & 8 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
}
@@ -239,7 +245,12 @@ final class DashWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
239245
case .upToDate:
240246
break
241247
}
242-
248+
249+
if updateWithRefreshUIBalance{
250+
wallet.isBalanceInitialized = false
251+
walletUpdateSender.send()
252+
}
253+
243254
setState(.updating)
244255

245256
if let balance = try? await getBalance() {
@@ -249,18 +260,16 @@ final class DashWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
249260

250261
wallet.balance = balance
251262
markBalanceAsFresh(wallet)
252-
253-
walletUpdateSender.send()
254-
} else {
255-
wallet.isBalanceInitialized = false
256263
}
257-
264+
265+
walletUpdateSender.send()
266+
258267
NotificationCenter.default.post(
259268
name: walletUpdatedNotification,
260269
object: self,
261270
userInfo: [AdamantUserInfoKey.WalletService.wallet: wallet]
262271
)
263-
272+
264273
setState(.upToDate)
265274
}
266275

Adamant/Modules/Wallets/Doge/DogeWalletService.swift

Lines changed: 16 additions & 7 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
}
@@ -259,7 +265,12 @@ final class DogeWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
259265
case .upToDate:
260266
break
261267
}
262-
268+
269+
if updateWithRefreshUIBalance {
270+
wallet.isBalanceInitialized = false
271+
walletUpdateSender.send()
272+
}
273+
263274
setState(.updating)
264275

265276
if let balance = try? await getBalance() {
@@ -269,12 +280,10 @@ final class DogeWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, @un
269280

270281
wallet.balance = balance
271282
markBalanceAsFresh(wallet)
272-
273-
walletUpdateSender.send()
274-
} else {
275-
wallet.isBalanceInitialized = false
276283
}
277-
284+
285+
walletUpdateSender.send()
286+
278287
NotificationCenter.default.post(
279288
name: walletUpdatedNotification,
280289
object: self,

Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift

Lines changed: 16 additions & 7 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
}
@@ -268,7 +274,12 @@ final class ERC20WalletService: WalletCoreProtocol, ERC20GasAlgorithmComputable,
268274
case .upToDate:
269275
break
270276
}
271-
277+
278+
if updateWithRefreshUIBalance {
279+
wallet.isBalanceInitialized = false
280+
walletUpdateSender.send()
281+
}
282+
272283
setState(.updating)
273284

274285
if let balance = try? await getBalance(forAddress: wallet.ethAddress) {
@@ -278,12 +289,10 @@ final class ERC20WalletService: WalletCoreProtocol, ERC20GasAlgorithmComputable,
278289

279290
wallet.balance = balance
280291
markBalanceAsFresh(wallet)
281-
282-
walletUpdateSender.send()
283-
} else {
284-
wallet.isBalanceInitialized = false
285292
}
286-
293+
294+
walletUpdateSender.send()
295+
287296
NotificationCenter.default.post(
288297
name: walletUpdatedNotification,
289298
object: self,

Adamant/Modules/Wallets/Ethereum/EthWalletService.swift

Lines changed: 16 additions & 7 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
}
@@ -305,7 +311,12 @@ final class EthWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, ERC2
305311
case .upToDate:
306312
break
307313
}
308-
314+
315+
if updateWithRefreshUIBalance {
316+
wallet.isBalanceInitialized = false
317+
walletUpdateSender.send()
318+
}
319+
309320
setState(.updating)
310321

311322
if let balance = try? await getBalance(forAddress: wallet.ethAddress) {
@@ -315,12 +326,10 @@ final class EthWalletService: WalletCoreProtocol, WalletStaticCoreProtocol, ERC2
315326

316327
wallet.balance = balance
317328
markBalanceAsFresh(wallet)
318-
319-
walletUpdateSender.send()
320-
} else {
321-
wallet.isBalanceInitialized = false
322329
}
323-
330+
331+
walletUpdateSender.send()
332+
324333
NotificationCenter.default.post(
325334
name: walletUpdatedNotification,
326335
object: self,

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

Lines changed: 16 additions & 7 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
}
@@ -262,7 +268,12 @@ extension KlyWalletService {
262268
case .upToDate:
263269
break
264270
}
265-
271+
272+
if updateWithRefreshUIBalance {
273+
wallet.isBalanceInitialized = false
274+
walletUpdateSender.send()
275+
}
276+
266277
setState(.updating)
267278

268279
if let balance = try? await getBalance() {
@@ -272,12 +283,10 @@ extension KlyWalletService {
272283

273284
wallet.balance = balance
274285
markBalanceAsFresh(wallet)
275-
276-
walletUpdateSender.send()
277-
} else {
278-
wallet.isBalanceInitialized = false
279286
}
280-
287+
288+
walletUpdateSender.send()
289+
281290
NotificationCenter.default.post(
282291
name: walletUpdatedNotification,
283292
object: self,

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)