|
1 | | -import { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; |
| 1 | +import NDK, { NDKEvent, NDKKind, NDKUser } from '@nostr-dev-kit/ndk'; |
2 | 2 | import { useNDK } from './ndk'; |
3 | 3 | import { NDKEventWithFrom } from './subscribe'; |
4 | 4 | import { useNDKSessionStore } from '../stores/session'; |
| 5 | +import { useNDKWallet } from './wallet'; |
| 6 | +import { walletFromLoadingString } from '@nostr-dev-kit/ndk-wallet'; |
| 7 | +import { SessionInitOpts, SessionInitCallbacks } from '../stores/session/types'; |
| 8 | +import { SettingsStore } from '../types'; |
5 | 9 |
|
6 | 10 | const useNDKSession = () => { |
7 | 11 | const init = useNDKSessionStore(s => s.init); |
8 | 12 | const mutePubkey = useNDKSessionStore(s => s.mutePubkey); |
9 | 13 |
|
10 | | - return { init, mutePubkey }; |
| 14 | + const { setActiveWallet } = useNDKWallet(); |
| 15 | + |
| 16 | + const wrappedInit = (ndk: NDK, user: NDKUser, settingsStore: SettingsStore, opts: SessionInitOpts, on: SessionInitCallbacks) => { |
| 17 | + init(ndk, user, settingsStore, opts, on); |
| 18 | + |
| 19 | + const walletString = settingsStore?.getSync('wallet'); |
| 20 | + if (walletString) { |
| 21 | + walletFromLoadingString(ndk, walletString).then((wallet) => { |
| 22 | + if (wallet) setActiveWallet(wallet); |
| 23 | + }).catch((e) => { |
| 24 | + console.error('error setting active wallet', e); |
| 25 | + }); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + return { init: wrappedInit, mutePubkey }; |
11 | 30 | } |
12 | 31 |
|
13 | 32 | const useFollows = () => useNDKSessionStore(s => s.follows); |
|
0 commit comments