Skip to content

Commit

Permalink
refactor: ios 17.0 migration to observable
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Aug 21, 2023
1 parent 25b06c9 commit f03386d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 23 deletions.
3 changes: 3 additions & 0 deletions BDKSwiftExampleWallet/View Model/OnboardingViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import Foundation
import BitcoinDevKit
import SwiftUI

// Can't make @Observable yet
// https://developer.apple.com/forums/thread/731187
// Feature or Bug?
class OnboardingViewModel: ObservableObject {
@AppStorage("isOnboarding") var isOnboarding: Bool?

Expand Down
5 changes: 3 additions & 2 deletions BDKSwiftExampleWallet/View Model/ReceiveViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import Foundation

class ReceiveViewModel: ObservableObject {
@Published var address: String = ""
@Observable
class ReceiveViewModel {
var address: String = ""

func getAddress() {
do {
Expand Down
5 changes: 3 additions & 2 deletions BDKSwiftExampleWallet/View Model/SendViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import Foundation
import BitcoinDevKit

class SendViewModel: ObservableObject {
@Published var balanceTotal: UInt64 = 0
@Observable
class SendViewModel {
var balanceTotal: UInt64 = 0

func getBalance() {
do {
Expand Down
25 changes: 9 additions & 16 deletions BDKSwiftExampleWallet/View Model/WalletViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
import Foundation
import BitcoinDevKit

class WalletViewModel: ObservableObject {

// Balance
@Published var balanceTotal: UInt64 = 0

// Sync
@Published var lastSyncTime: Date? = nil
@Published var walletSyncState: WalletSyncState = .notStarted

// Transactions
@Published var transactionDetails: [TransactionDetails] = []

// Price
@Published var price: Double = 0.0
@Published var time: Int?
@Published var satsPrice: String = "0"
@Observable
class WalletViewModel {
var balanceTotal: UInt64 = 0
var lastSyncTime: Date? = nil
var walletSyncState: WalletSyncState = .notStarted
var transactionDetails: [TransactionDetails] = []
var price: Double = 0.0
var time: Int?
var satsPrice: String = "0"
let priceService: PriceService

init(priceService: PriceService) {
Expand Down
2 changes: 1 addition & 1 deletion BDKSwiftExampleWallet/View/ReceiveView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct ReceiveView: View {
@ObservedObject var viewModel: ReceiveViewModel
@Bindable var viewModel: ReceiveViewModel
@State private var isCopied = false
@State private var showCheckmark = false

Expand Down
2 changes: 1 addition & 1 deletion BDKSwiftExampleWallet/View/SendView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import WalletUI

struct SendView: View {
@ObservedObject var viewModel: SendViewModel
@Bindable var viewModel: SendViewModel
@State private var amount: String = ""
@State private var address: String = ""

Expand Down
2 changes: 1 addition & 1 deletion BDKSwiftExampleWallet/View/WalletView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import WalletUI

struct WalletView: View {
@ObservedObject var viewModel: WalletViewModel
@Bindable var viewModel: WalletViewModel
@State private var isAnimating: Bool = false

var body: some View {
Expand Down

0 comments on commit f03386d

Please sign in to comment.