Skip to content

Commit

Permalink
refactor: main actor
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Aug 21, 2023
1 parent 88e81a9 commit f5acb81
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
1 change: 1 addition & 0 deletions BDKSwiftExampleWallet/View Model/ReceiveViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import Observation

@Observable
class ReceiveViewModel {
Expand Down
2 changes: 2 additions & 0 deletions BDKSwiftExampleWallet/View Model/SendViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import Foundation
import BitcoinDevKit
import Observation

@MainActor
@Observable
class SendViewModel {
var balanceTotal: UInt64 = 0
Expand Down
10 changes: 2 additions & 8 deletions BDKSwiftExampleWallet/View Model/WalletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import Foundation
import BitcoinDevKit
import Observation

@MainActor
@Observable
class WalletViewModel {
var balanceTotal: UInt64 = 0
Expand All @@ -26,10 +28,8 @@ class WalletViewModel {
func getPrices() async {
do {
let price = try await priceService.prices()
DispatchQueue.main.async {
self.price = price.usd
self.time = price.time
}
} catch {
print("getPrices error: \(error.localizedDescription)")
}
Expand Down Expand Up @@ -60,23 +60,17 @@ class WalletViewModel {
}

func sync() async {
DispatchQueue.main.async {
self.walletSyncState = .syncing
}
Task {
do {
try await BDKService.shared.sync()
DispatchQueue.main.async {
self.walletSyncState = .synced
self.lastSyncTime = Date()
self.getBalance()
self.getTransactions()
self.valueInUSD()
}
} catch {
DispatchQueue.main.async {
self.walletSyncState = .error(error)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import XCTest
@testable import BDKSwiftExampleWallet

@MainActor
final class BDKSwiftExampleWalletWalletViewModelTests: XCTestCase {

func testWalletViewModel() async {
Expand Down

0 comments on commit f5acb81

Please sign in to comment.