hellbender-wallet/birch/ViewModels/ReceiveViewModel.swift
Nick Klockenga 209750c4e5
Rebrand Wallet to Birch Wallet (#28)
* step one

* progress

* minor theme enhancements

* update screenshot and icon links in README.md

* update site link

* swiftformat fixes
2026-04-30 21:00:59 -04:00

46 lines
1.1 KiB
Swift

import Foundation
import Observation
@Observable
@MainActor
final class ReceiveViewModel {
var currentAddress: String = ""
var addressIndex: UInt32 = 0
var errorMessage: String?
private var expectedProfileId: UUID?
private var bitcoinService: BitcoinService {
BitcoinService.shared
}
func loadAddress(for profileId: UUID) {
expectedProfileId = profileId
guard bitcoinService.currentProfile?.id == expectedProfileId else {
currentAddress = ""
return
}
do {
let (address, index) = try bitcoinService.getNextAddress()
currentAddress = address
addressIndex = index
} catch {
errorMessage = error.localizedDescription
}
}
func generateNewAddress() {
guard bitcoinService.currentProfile?.id == expectedProfileId else {
currentAddress = ""
errorMessage = "Wallet changed — please reload"
return
}
do {
let (address, index) = try bitcoinService.revealNextAddress()
currentAddress = address
addressIndex = index
} catch {
errorMessage = error.localizedDescription
}
}
}