Skip to content

Commit

Permalink
fetch main user's relay lists in order to get a better clue of where …
Browse files Browse the repository at this point in the history
…the user's wallets are
  • Loading branch information
pablof7z committed Jul 31, 2024
1 parent 341a6fd commit f233ad8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ndk-wallet/src/wallet/lifecycle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NDK, { NDKCashuMintList, NDKEvent, NDKEventId, NDKKind, NDKRelaySet, NDKSubscription, NDKSubscriptionCacheUsage, NDKUser } from "@nostr-dev-kit/ndk";
import NDK, { getRelayListForUser, NDKCashuMintList, NDKEvent, NDKEventId, NDKKind, NDKRelaySet, NDKSubscription, NDKSubscriptionCacheUsage, NDKUser } from "@nostr-dev-kit/ndk";
import NDKWallet from "../index.js";
import handleMintList from "./mint-list.js";
import handleWalletEvent from "./wallet.js";
Expand Down Expand Up @@ -40,16 +40,16 @@ class NDKWalletLifecycle {
this.nutzap = new NutzapHandler(this);
}

public start() {
this.debug("starting wallet lifecycle", this.user.pubkey);
async start() {
const userRelayList = await getRelayListForUser(this.user.pubkey, this.ndk);
this.sub = this.ndk.subscribe([
{ kinds: [ NDKKind.CashuMintList, NDKKind.CashuWallet ], authors: [this.user.pubkey] },
{ kinds: [NDKKind.WalletChange], authors: [this.user!.pubkey], limit: 10 },
], {
subId: 'ndk-wallet',
groupable: false,
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL
}, undefined, false);
}, userRelayList.relaySet, false);

this.sub.on("event", this.eventHandler.bind(this));
this.sub.on("eose", this.eoseHandler.bind(this));
Expand Down Expand Up @@ -84,7 +84,10 @@ class NDKWalletLifecycle {
}

private eoseHandler() {
this.debug("main sub eose")
this.debug("Loaded wallets", {
defaultWallet: this.defaultWallet?.rawEvent(),
wallets: Array.from(this.wallets.values()).map(w => w.rawEvent())
})
this.eosed = true;

if (this.tokensSub) {
Expand Down

0 comments on commit f233ad8

Please sign in to comment.