Skip to content

Commit c47e108

Browse files
author
just-software-dev
committed
[trello.com/c/ysg4LpCL] Vibro workaround
1 parent ba4ae3d commit c47e108

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

Adamant/Modules/Wallets/Bitcoin/BtcWalletService.swift

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ final class BtcWalletService: WalletCoreProtocol, @unchecked Sendable {
266266
}
267267
}
268268

269+
@MainActor
269270
func update() async {
270271
guard let wallet = btcWallet else {
271272
return
@@ -283,11 +284,11 @@ final class BtcWalletService: WalletCoreProtocol, @unchecked Sendable {
283284

284285
if let balance = try? await getBalance() {
285286
if wallet.balance < balance, wallet.isBalanceInitialized {
286-
await vibroService.applyVibration(.success)
287+
vibroService.applyVibration(.success)
287288
}
288289

289290
wallet.balance = balance
290-
markBalanceAsFresh()
291+
markBalanceAsFresh(wallet)
291292

292293
NotificationCenter.default.post(
293294
name: walletUpdatedNotification,
@@ -362,12 +363,12 @@ final class BtcWalletService: WalletCoreProtocol, @unchecked Sendable {
362363
return output
363364
}
364365

365-
private func markBalanceAsFresh() {
366-
btcWallet?.isBalanceInitialized = true
366+
private func markBalanceAsFresh(_ wallet: BtcWallet) {
367+
wallet.isBalanceInitialized = true
367368

368369
balanceInvalidationSubscription = Task { [weak self] in
369370
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
370-
guard let self, let wallet = btcWallet else { return }
371+
guard let self else { return }
371372
wallet.isBalanceInitialized = false
372373

373374
NotificationCenter.default.post(
@@ -535,16 +536,11 @@ extension BtcWalletService {
535536
}
536537

537538
func getBalance(address: String) async throws -> Decimal {
538-
do {
539-
let response: BtcBalanceResponse = try await btcApiService.request(waitsForConnectivity: false) { api, origin in
540-
await api.sendRequestJsonResponse(origin: origin, path: BtcApiCommands.balance(for: address))
541-
}.get()
542-
543-
return response.value / BtcWalletService.multiplier
544-
} catch {
545-
print("--debug", error.localizedDescription)
546-
return 0
547-
}
539+
let response: BtcBalanceResponse = try await btcApiService.request(waitsForConnectivity: false) { api, origin in
540+
await api.sendRequestJsonResponse(origin: origin, path: BtcApiCommands.balance(for: address))
541+
}.get()
542+
543+
return response.value / BtcWalletService.multiplier
548544
}
549545

550546
func getFeeRate() async throws -> Decimal {

Adamant/Modules/Wallets/Dash/DashWalletService.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ final class DashWalletService: WalletCoreProtocol, @unchecked Sendable {
239239
}
240240
}
241241

242+
@MainActor
242243
func update() async {
243244
guard let wallet = dashWallet else {
244245
return
@@ -256,11 +257,11 @@ final class DashWalletService: WalletCoreProtocol, @unchecked Sendable {
256257

257258
if let balance = try? await getBalance() {
258259
if wallet.balance < balance, wallet.isBalanceInitialized {
259-
await vibroService.applyVibration(.success)
260+
vibroService.applyVibration(.success)
260261
}
261262

262263
wallet.balance = balance
263-
markBalanceAsFresh()
264+
markBalanceAsFresh(wallet)
264265

265266
NotificationCenter.default.post(
266267
name: walletUpdatedNotification,
@@ -283,12 +284,12 @@ final class DashWalletService: WalletCoreProtocol, @unchecked Sendable {
283284
}
284285
}
285286

286-
private func markBalanceAsFresh() {
287-
dashWallet?.isBalanceInitialized = true
287+
private func markBalanceAsFresh(_ wallet: DashWallet) {
288+
wallet.isBalanceInitialized = true
288289

289290
balanceInvalidationSubscription = Task { [weak self] in
290291
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
291-
guard let self, let wallet = dashWallet else { return }
292+
guard let self else { return }
292293
wallet.isBalanceInitialized = false
293294

294295
NotificationCenter.default.post(

Adamant/Modules/Wallets/Doge/DogeWalletService.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ final class DogeWalletService: WalletCoreProtocol, @unchecked Sendable {
236236
}
237237
}
238238

239+
@MainActor
239240
func update() async {
240241
guard let wallet = dogeWallet else {
241242
return
@@ -253,11 +254,11 @@ final class DogeWalletService: WalletCoreProtocol, @unchecked Sendable {
253254

254255
if let balance = try? await getBalance() {
255256
if wallet.balance < balance, wallet.isBalanceInitialized {
256-
await vibroService.applyVibration(.success)
257+
vibroService.applyVibration(.success)
257258
}
258259

259260
wallet.balance = balance
260-
markBalanceAsFresh()
261+
markBalanceAsFresh(wallet)
261262

262263
NotificationCenter.default.post(
263264
name: walletUpdatedNotification,
@@ -280,12 +281,12 @@ final class DogeWalletService: WalletCoreProtocol, @unchecked Sendable {
280281
}
281282
}
282283

283-
private func markBalanceAsFresh() {
284-
dogeWallet?.isBalanceInitialized = true
284+
private func markBalanceAsFresh(_ wallet: DogeWallet) {
285+
wallet.isBalanceInitialized = true
285286

286287
balanceInvalidationSubscription = Task { [weak self] in
287288
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
288-
guard let self, let wallet = dogeWallet else { return }
289+
guard let self else { return }
289290
wallet.isBalanceInitialized = false
290291

291292
NotificationCenter.default.post(

Adamant/Modules/Wallets/ERC20/ERC20WalletService.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ final class ERC20WalletService: WalletCoreProtocol, @unchecked Sendable {
245245
}
246246
}
247247

248+
@MainActor
248249
func update() async {
249250
guard let wallet = ethWallet else {
250251
return
@@ -262,11 +263,11 @@ final class ERC20WalletService: WalletCoreProtocol, @unchecked Sendable {
262263

263264
if let balance = try? await getBalance(forAddress: wallet.ethAddress) {
264265
if wallet.balance < balance, wallet.isBalanceInitialized {
265-
await vibroService.applyVibration(.success)
266+
vibroService.applyVibration(.success)
266267
}
267268

268269
wallet.balance = balance
269-
markBalanceAsFresh()
270+
markBalanceAsFresh(wallet)
270271

271272
NotificationCenter.default.post(
272273
name: walletUpdatedNotification,
@@ -347,12 +348,12 @@ final class ERC20WalletService: WalletCoreProtocol, @unchecked Sendable {
347348
}.get()
348349
}
349350

350-
private func markBalanceAsFresh() {
351-
ethWallet?.isBalanceInitialized = true
351+
private func markBalanceAsFresh(_ wallet: EthWallet) {
352+
wallet.isBalanceInitialized = true
352353

353354
balanceInvalidationSubscription = Task { [weak self] in
354355
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
355-
guard let self, let wallet = ethWallet else { return }
356+
guard let self else { return }
356357
wallet.isBalanceInitialized = false
357358

358359
NotificationCenter.default.post(

Adamant/Modules/Wallets/Ethereum/EthWalletService.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ final class EthWalletService: WalletCoreProtocol, @unchecked Sendable {
296296
}
297297

298298
wallet.balance = balance
299-
markBalanceAsFresh()
299+
markBalanceAsFresh(wallet)
300300

301301
NotificationCenter.default.post(
302302
name: walletUpdatedNotification,
@@ -309,12 +309,12 @@ final class EthWalletService: WalletCoreProtocol, @unchecked Sendable {
309309
await calculateFee()
310310
}
311311

312-
private func markBalanceAsFresh() {
313-
ethWallet?.isBalanceInitialized = true
312+
private func markBalanceAsFresh(_ wallet: EthWallet) {
313+
wallet.isBalanceInitialized = true
314314

315315
balanceInvalidationSubscription = Task { [weak self] in
316316
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
317-
guard let self, let wallet = ethWallet else { return }
317+
guard let self else { return }
318318
wallet.isBalanceInitialized = false
319319

320320
NotificationCenter.default.post(

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ private extension KlyWalletService {
229229
.store(in: &subscriptions)
230230
}
231231

232+
@MainActor
232233
func update() async {
233234
guard let wallet = klyWallet else {
234235
return
@@ -246,11 +247,11 @@ private extension KlyWalletService {
246247

247248
if let balance = try? await getBalance() {
248249
if wallet.balance < balance, wallet.isBalanceInitialized {
249-
await vibroService.applyVibration(.success)
250+
vibroService.applyVibration(.success)
250251
}
251252

252253
wallet.balance = balance
253-
markBalanceAsFresh()
254+
markBalanceAsFresh(wallet)
254255

255256
NotificationCenter.default.post(
256257
name: walletUpdatedNotification,
@@ -274,12 +275,12 @@ private extension KlyWalletService {
274275
setState(.upToDate)
275276
}
276277

277-
func markBalanceAsFresh() {
278-
klyWallet?.isBalanceInitialized = true
278+
func markBalanceAsFresh(_ wallet: KlyWallet) {
279+
wallet.isBalanceInitialized = true
279280

280281
balanceInvalidationSubscription = Task { [weak self] in
281282
try await Task.sleep(interval: Self.balanceLifetime, pauseInBackground: true)
282-
guard let self, let wallet = klyWallet else { return }
283+
guard let self else { return }
283284
wallet.isBalanceInitialized = false
284285

285286
NotificationCenter.default.post(

0 commit comments

Comments
 (0)