Fix issue with wallet loading

Changelog-Changed: Increased transaction list limit to 50 transactions
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Daniel D’Aquino
2025-09-05 13:10:02 -07:00
parent 2550d613b2
commit 7eb759a8a0
9 changed files with 180 additions and 95 deletions

View File

@@ -85,8 +85,8 @@ class NostrNetworkManager {
self.pool.send_raw_to_local_ndb(.typical(.event(event)))
}
func send(event: NostrEvent) {
self.pool.send(.event(event))
func send(event: NostrEvent, to targetRelays: [RelayURL]? = nil, skipEphemeralRelays: Bool = true) {
self.pool.send(.event(event), to: targetRelays, skip_ephemeral: skipEphemeralRelays)
}
func query(filters: [NostrFilter], to: [RelayURL]? = nil) async -> [NostrEvent] {
@@ -208,14 +208,6 @@ class NostrNetworkManager {
WalletConnect.pay(url: url, pool: self.pool, post: post, invoice: invoice, zap_request: nil)
}
func requestTransactionList(url: WalletConnectURL, delay: TimeInterval? = 0.0, on_flush: OnFlush? = nil) {
WalletConnect.request_transaction_list(url: url, pool: self.pool, post: self.postbox, delay: delay, on_flush: on_flush)
}
func requestBalanceInformation(url: WalletConnectURL, delay: TimeInterval? = 0.0, on_flush: OnFlush? = nil) {
WalletConnect.request_balance_information(url: url, pool: self.pool, post: self.postbox, delay: delay, on_flush: on_flush)
}
/// Send a donation zap to the Damus team
func send_donation_zap(nwc: WalletConnectURL, percent: Int, base_msats: Int64) async {
let percent_f = Double(percent) / 100.0

View File

@@ -25,6 +25,28 @@ extension NostrNetworkManager {
// MARK: - Reading data from Nostr
/// Subscribes to data from user's relays, for a maximum period of time after which the stream will end.
///
/// This is useful when waiting for some specific data from Nostr, but not indefinitely.
func subscribe(filters: [NostrFilter], to desiredRelays: [RelayURL]? = nil, timeout: Duration) -> AsyncStream<StreamItem> {
return AsyncStream<StreamItem> { continuation in
let streamingTask = Task {
for await item in self.subscribe(filters: filters, to: desiredRelays) {
try Task.checkCancellation()
continuation.yield(item)
}
}
let timeoutTask = Task {
try await Task.sleep(for: timeout)
continuation.finish() // End the stream due to timeout.
}
continuation.onTermination = { @Sendable _ in
timeoutTask.cancel()
streamingTask.cancel()
}
}
}
/// Subscribes to data from the user's relays
///
/// ## Implementation notes
@@ -112,10 +134,16 @@ extension NostrNetworkManager {
}
let streamTask = Task {
do {
for await _ in self.pool.subscribe(filters: filters, to: desiredRelays) {
for await item in self.pool.subscribe(filters: filters, to: desiredRelays) {
// NO-OP. Notes will be automatically ingested by NostrDB
// TODO: Improve efficiency of subscriptions?
try Task.checkCancellation()
switch item {
case .event(let event):
Log.debug("Session subscribe: Received kind %d event with id %s from the network", for: .subscription_manager, event.kind, event.id.hex())
case .eose:
Log.debug("Session subscribe: Received EOSE from the network", for: .subscription_manager)
}
}
}
catch {

View File

@@ -207,7 +207,10 @@ class RelayPool {
func subscribe(sub_id: String, filters: [NostrFilter], handler: @escaping (RelayURL, NostrConnectionEvent) -> (), to: [RelayURL]? = nil) {
Task {
await register_handler(sub_id: sub_id, handler: handler)
send(.subscribe(.init(filters: filters, sub_id: sub_id)), to: to)
// When the caller specifies no relays, it is implied that the user wants to use the ones in the user relay list. Skip ephemeral relays in that case.
// When the caller specifies specific relays, do not skip ephemeral relays to respect the exact list given by the caller.
let shouldSkipEphemeralRelays = to == nil ? true : false
send(.subscribe(.init(filters: filters, sub_id: sub_id)), to: to, skip_ephemeral: shouldSkipEphemeralRelays)
}
}

View File

@@ -72,7 +72,9 @@ class DamusState: HeadlessDamusState {
self.favicon_cache = FaviconCache()
let networkManagerDelegate = NostrNetworkManagerDelegate(settings: settings, contacts: contacts, ndb: ndb, keypair: keypair, relayModelCache: relay_model_cache, relayFilters: relay_filters)
self.nostrNetwork = NostrNetworkManager(delegate: networkManagerDelegate)
let nostrNetwork = NostrNetworkManager(delegate: networkManagerDelegate)
self.nostrNetwork = nostrNetwork
self.wallet.nostrNetwork = nostrNetwork
}
@MainActor
@@ -122,7 +124,7 @@ class DamusState: HeadlessDamusState {
events: EventCache(ndb: ndb),
bookmarks: BookmarksManager(pubkey: pubkey),
replies: ReplyCounter(our_pubkey: pubkey),
wallet: WalletModel(settings: settings),
wallet: WalletModel(settings: settings), // nostrNetwork is connected after initialization
nav: navigationCoordinator,
music: MusicController(onChange: { _ in }),
video: DamusVideoCoordinator(),