Skip to content

Commit

Permalink
improve connection
Browse files Browse the repository at this point in the history
  • Loading branch information
reyamir committed Nov 25, 2023
1 parent 24b21a9 commit 9112c1c
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lume",
"description": "the communication app",
"private": true,
"version": "2.1.3",
"version": "2.1.4",
"scripts": {
"dev": "vite",
"build": "vite build",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lume"
version = "2.1.3"
version = "2.1.4"
description = "the communication app"
authors = ["Ren Amamiya"]
license = "GPL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"package": {
"productName": "Lume",
"version": "2.1.3"
"version": "2.1.4"
},
"plugins": {
"fs": {
Expand Down
3 changes: 2 additions & 1 deletion src/app/auth/import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions src/app/auth/onboarding/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +40,6 @@ export function OnboardingListScreen() {
<div className="flex flex-col gap-3">
{newuser ? <SuggestFollow /> : <FollowList />}
<FavoriteHashtag />
<Circle />
<OutboxModel />
<AllowNotification />
<button
Expand Down
44 changes: 15 additions & 29 deletions src/libs/ndk/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,64 +61,50 @@ 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);
const instance = new NDK({
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/storage/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);',
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion src/stores/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const FULL_RELAYS = [
'wss://relay.damus.io',
'wss://relayable.org',
'wss://relay.nostr.band/all',
'wss://nostr.mutinywallet.com',
];
Expand Down

0 comments on commit 9112c1c

Please sign in to comment.