improve connection
This commit is contained in:
@@ -44,7 +44,8 @@ export function ImportAccountScreen() {
|
||||
try {
|
||||
const pubkey = nip19.decode(npub.split('#')[0]).data as string;
|
||||
const localSigner = NDKPrivateKeySigner.generate();
|
||||
await db.secureSave(pubkey + '-bunker', localSigner.privateKey);
|
||||
await db.createSetting('nsecbunker', '1');
|
||||
await db.secureSave(pubkey + '-nsecbunker', localSigner.privateKey);
|
||||
|
||||
const remoteSigner = new NDKNip46Signer(ndk, npub, localSigner);
|
||||
// await remoteSigner.blockUntilReady();
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useState } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
|
||||
import { AllowNotification } from '@app/auth/components/features/allowNotification';
|
||||
import { Circle } from '@app/auth/components/features/enableCircle';
|
||||
import { OutboxModel } from '@app/auth/components/features/enableOutbox';
|
||||
import { FavoriteHashtag } from '@app/auth/components/features/favoriteHashtag';
|
||||
import { FollowList } from '@app/auth/components/features/followList';
|
||||
@@ -41,7 +40,6 @@ export function OnboardingListScreen() {
|
||||
<div className="flex flex-col gap-3">
|
||||
{newuser ? <SuggestFollow /> : <FollowList />}
|
||||
<FavoriteHashtag />
|
||||
<Circle />
|
||||
<OutboxModel />
|
||||
<AllowNotification />
|
||||
<button
|
||||
|
||||
@@ -61,29 +61,26 @@ export const NDKInstance = () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function getSigner(instance: NDK) {
|
||||
if (!db.account) return null;
|
||||
|
||||
const localSignerPrivkey = await db.secureLoad(db.account.pubkey + '-bunker');
|
||||
const userPrivkey = await db.secureLoad(db.account.pubkey);
|
||||
async function getSigner(nsecbunker?: boolean) {
|
||||
if (!db.account) return;
|
||||
|
||||
// NIP-46 Signer
|
||||
if (localSignerPrivkey) {
|
||||
if (nsecbunker) {
|
||||
const localSignerPrivkey = await db.secureLoad(db.account.pubkey + '-nsecbunker');
|
||||
const localSigner = new NDKPrivateKeySigner(localSignerPrivkey);
|
||||
const remoteSigner = new NDKNip46Signer(instance, db.account.id, localSigner);
|
||||
// await remoteSigner.blockUntilReady();
|
||||
|
||||
return remoteSigner;
|
||||
return new NDKNip46Signer(ndk, db.account.id, localSigner);
|
||||
}
|
||||
|
||||
// Privkey Signer
|
||||
if (userPrivkey) {
|
||||
return new NDKPrivateKeySigner(userPrivkey);
|
||||
}
|
||||
// Private key Signer
|
||||
const userPrivkey = await db.secureLoad(db.account.pubkey);
|
||||
return new NDKPrivateKeySigner(userPrivkey);
|
||||
}
|
||||
|
||||
async function initNDK() {
|
||||
const outboxSetting = await db.getSettingValue('outbox');
|
||||
const bunkerSetting = await db.getSettingValue('nsecbunker');
|
||||
const signer = await getSigner(!!parseInt(bunkerSetting));
|
||||
const explicitRelayUrls = await getExplicitRelays();
|
||||
|
||||
const tauriAdapter = new NDKCacheAdapterTauri(db);
|
||||
@@ -91,34 +88,23 @@ export const NDKInstance = () => {
|
||||
explicitRelayUrls,
|
||||
cacheAdapter: tauriAdapter,
|
||||
outboxRelayUrls: ['wss://purplepag.es'],
|
||||
enableOutboxModel: outboxSetting === '1',
|
||||
blacklistRelayUrls: [],
|
||||
enableOutboxModel: !!parseInt(outboxSetting),
|
||||
});
|
||||
instance.signer = signer;
|
||||
|
||||
try {
|
||||
// connect
|
||||
await instance.connect(2000);
|
||||
|
||||
// add signer
|
||||
const signer = await getSigner(instance);
|
||||
instance.signer = signer;
|
||||
|
||||
// update account's metadata
|
||||
if (db.account) {
|
||||
const circleSetting = await db.getSettingValue('circles');
|
||||
|
||||
const user = instance.getUser({ pubkey: db.account.pubkey });
|
||||
const follows = await user.follows();
|
||||
const follows = [...(await user.follows())].map((user) => user.pubkey);
|
||||
const relayList = await user.relayList();
|
||||
|
||||
const followsAsArr = [];
|
||||
follows.forEach((user) => {
|
||||
followsAsArr.push(user.pubkey);
|
||||
});
|
||||
|
||||
// update user's follows
|
||||
await db.updateAccount('follows', JSON.stringify(followsAsArr));
|
||||
if (circleSetting !== '1')
|
||||
await db.updateAccount('circles', JSON.stringify(followsAsArr));
|
||||
await db.updateAccount('follows', JSON.stringify(follows));
|
||||
|
||||
// update user's relay list
|
||||
if (relayList) {
|
||||
|
||||
@@ -438,7 +438,7 @@ export class LumeStorage {
|
||||
[relay, this.account.id]
|
||||
);
|
||||
|
||||
if (existRelays.length > 0) return false;
|
||||
if (!existRelays.length) return;
|
||||
|
||||
return await this.db.execute(
|
||||
'INSERT OR IGNORE INTO relays (account_id, relay, purpose) VALUES ($1, $2, $3);',
|
||||
@@ -480,7 +480,7 @@ export class LumeStorage {
|
||||
'SELECT * FROM settings WHERE key = $1 ORDER BY id DESC LIMIT 1;',
|
||||
[key]
|
||||
);
|
||||
if (results.length < 1) return null;
|
||||
if (!results.length) return '0';
|
||||
return results[0].value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
export const FULL_RELAYS = [
|
||||
'wss://relay.damus.io',
|
||||
'wss://relayable.org',
|
||||
'wss://relay.nostr.band/all',
|
||||
'wss://nostr.mutinywallet.com',
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user