This commit is contained in:
2023-05-18 16:51:21 +01:00
parent 185e089ffd
commit 126a55f3c4
6 changed files with 64 additions and 64 deletions

View File

@ -85,7 +85,7 @@ class UserProfileCache extends FeedCache<MetadataCache> {
await svc.load();
const p = this.getFromCache(i.pubkey);
if (p) {
this.#setItem({
await this.set({
...p,
zapService: svc.zapperPubkey,
});
@ -105,7 +105,7 @@ class UserProfileCache extends FeedCache<MetadataCache> {
const nip5pk = await fetchNip05Pubkey(name, domain);
const p = this.getFromCache(i.pubkey);
if (p) {
this.#setItem({
await this.set({
...p,
isNostrAddressValid: i.pubkey === nip5pk,
});

View File

@ -80,7 +80,7 @@ export default function ZapPoolPage() {
const relayConnections = useMemo(() => {
return [...System.Sockets.values()]
.map(a => {
if (a.Info?.pubkey) {
if (a.Info?.pubkey && !a.Ephemeral) {
return {
address: a.Address,
pubkey: a.Info.pubkey,

View File

@ -97,13 +97,15 @@ export function splitByWriteRelays(filter: RawReqFilter): Array<RelayTaggedFilte
},
} as RelayTaggedFilter;
});
picked.push({
relay: "",
filter: {
...filter,
authors: missing.map(a => a.key),
},
});
if (missing.length > 0) {
picked.push({
relay: "",
filter: {
...filter,
authors: missing.map(a => a.key),
},
});
}
console.debug("GOSSIP", picked);
return picked;
}

View File

@ -1,6 +1,6 @@
import { v4 as uuid } from "uuid";
import { Connection, RawReqFilter, Nips } from "@snort/nostr";
import { unixNowMs } from "Util";
import { unixNowMs, unwrap } from "Util";
import { NoteStore } from "./NoteCollection";
/**
* Tracing for relay query status
@ -32,6 +32,9 @@ class QueryTrace {
gotEose() {
this.eose = unixNowMs();
if (this.responseTime > 5_000) {
console.debug(`Slow query ${this.subId} on ${this.relay} took ${this.responseTime.toLocaleString()}ms`);
}
}
forceEose() {
@ -66,6 +69,13 @@ class QueryTrace {
return (this.eose === undefined ? unixNowMs() : this.eose) - this.start;
}
/**
* Total time spent waiting for relay to respond
*/
get responseTime() {
return this.finished ? unwrap(this.eose) - unwrap(this.sent) : 0;
}
/**
* If tracing is finished, we got EOSE or timeout
*/
@ -193,16 +203,13 @@ export class Query {
qt?.gotEose();
if (sub === this.id) {
console.debug(`[EOSE][${sub}] ${conn.Address}`);
this.#feed.loading = this.progress < 1;
if (!this.leaveOpen && !this.#feed.loading) {
this.sendClose();
if (!this.leaveOpen) {
qt?.sendClose();
}
} else {
const subQ = this.subQueries.find(a => a.id === sub);
if (subQ) {
subQ.eose(sub, conn);
} else {
throw new Error("No query found");
}
}
}

View File

@ -1,5 +1,6 @@
import { useSyncExternalStore } from "react";
import { useEffect, useSyncExternalStore } from "react";
import ExternalStore from "ExternalStore";
import { decodeInvoice, unwrap } from "Util";
import LNDHubWallet from "./LNDHub";
import { NostrConnectWallet } from "./NostrWalletConnect";
@ -124,35 +125,19 @@ export interface WalletStoreSnapshot {
wallet?: LNWallet;
}
type WalletStateHook = (state: WalletStoreSnapshot) => void;
export class WalletStore {
export class WalletStore extends ExternalStore<WalletStoreSnapshot> {
#configs: Array<WalletConfig>;
#instance: Map<string, LNWallet>;
#hooks: Array<WalletStateHook>;
#snapshot: Readonly<WalletStoreSnapshot>;
constructor() {
super();
this.#configs = [];
this.#instance = new Map();
this.#hooks = [];
this.#snapshot = Object.freeze({
configs: [],
});
this.load(false);
setupWebLNWalletConfig(this);
this.snapshotState();
}
hook(fn: WalletStateHook) {
this.#hooks.push(fn);
return () => {
const idx = this.#hooks.findIndex(a => a === fn);
this.#hooks = this.#hooks.splice(idx, 1);
};
}
list() {
return Object.freeze([...this.#configs]);
}
@ -171,9 +156,9 @@ export class WalletStore {
const w = this.#activateWallet(activeConfig);
if (w) {
if ("then" in w) {
w.then(wx => {
w.then(async wx => {
this.#instance.set(activeConfig.id, wx);
this.snapshotState();
this.notifyChange();
});
return undefined;
}
@ -209,7 +194,7 @@ export class WalletStore {
save() {
const json = JSON.stringify(this.#configs);
window.localStorage.setItem("wallet-config", json);
this.snapshotState();
this.notifyChange();
}
load(snapshot = true) {
@ -218,7 +203,7 @@ export class WalletStore {
this.#configs = JSON.parse(cfg);
}
if (snapshot) {
this.snapshotState();
this.notifyChange();
}
}
@ -226,21 +211,12 @@ export class WalletStore {
this.#instance.forEach(w => w.close());
}
getSnapshot() {
return this.#snapshot;
}
snapshotState() {
const newState = {
takeSnapshot(): WalletStoreSnapshot {
return {
configs: [...this.#configs],
config: this.#configs.find(a => a.active),
wallet: this.get(),
} as WalletStoreSnapshot;
this.#snapshot = Object.freeze(newState);
for (const hook of this.#hooks) {
console.debug(this.#snapshot);
hook(this.#snapshot);
}
}
#activateWallet(cfg: WalletConfig): LNWallet | Promise<LNWallet> | undefined {
@ -270,8 +246,14 @@ window.document.addEventListener("close", () => {
});
export function useWallet() {
return useSyncExternalStore<WalletStoreSnapshot>(
const wallet = useSyncExternalStore<WalletStoreSnapshot>(
h => Wallets.hook(h),
() => Wallets.getSnapshot()
() => Wallets.snapshot()
);
useEffect(() => {
if (wallet.wallet?.isReady() === false && wallet.wallet.canAutoLogin()) {
wallet.wallet.login().catch(console.error);
}
}, [wallet]);
return wallet;
}