From 83f2a589f7ba27c2e6084aaff794ec75aa4091f2 Mon Sep 17 00:00:00 2001 From: Mothana Date: Tue, 8 Oct 2024 17:52:32 +0400 Subject: [PATCH 1/2] backups fix --- src/Api/nostrHandler.ts | 22 ++++++++++++++-------- src/State/backupMiddleware.ts | 29 ++++++++++++++++++++--------- src/helpers/remoteBackups.ts | 9 ++++----- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/Api/nostrHandler.ts b/src/Api/nostrHandler.ts index 50a7f31..78797c0 100644 --- a/src/Api/nostrHandler.ts +++ b/src/Api/nostrHandler.ts @@ -289,16 +289,22 @@ export const newNip78ChangelogEvent = (data: string, pubkey: string) => { } export const subToNip78Changelogs = (pubkey: string, relays: string[], timestamp: number, onEvent: (e: Event) => Promise) => { - return pool.subscribeMany(relays, [ + return pool.subscribeMany( + relays, + [ + { + since: timestamp, + kinds: [2121], + '#d': [changelogsTag], + authors: [pubkey] + } + ], { - since: timestamp, - kinds: [2121], - '#d': [changelogsTag], - authors: [pubkey] + onevent: (e) => { + onEvent(e) + }, } - ], { - onevent: (e) => { onEvent(e) } - }) + ) } diff --git a/src/State/backupMiddleware.ts b/src/State/backupMiddleware.ts index 0166ade..d36194a 100644 --- a/src/State/backupMiddleware.ts +++ b/src/State/backupMiddleware.ts @@ -413,7 +413,7 @@ const syncNewDeviceWithRemote = async (api: ListenerEffectAPI { return ( @@ -434,8 +434,6 @@ export const backupMiddleware = { ); }, effect: async (action: AnyAction, listenerApi: ListenerEffectAPI>) => { - - console.log("changelog sending triggered", action) const state = listenerApi.getState(); const newHash = getStateHash(state); @@ -443,7 +441,19 @@ export const backupMiddleware = { localStorage.setItem(STATE_HASH, newHash) const id = getDeviceId() const changelog: Changelog = { action: { type: action.type, payload: action.payload }, id, previousHash: previousHash!, newHash: getStateHash(listenerApi.getState()) } - await shardAndBackupState(state, newHash, [changelog]) + changelogsTasksQueue.push(changelog) + try { + await listenerApi.delay(100) + console.log("Releasing") + } catch(err) { + if (err instanceof TaskAbortError) { + return; + } + } + listenerApi.cancelActiveListeners(); + + await shardAndBackupState(state, newHash, changelogsTasksQueue) + changelogsTasksQueue = [] } } @@ -529,10 +539,13 @@ export const backupPollingMiddleware = { localStorage.setItem(CHANGELOG_TIMESTAMP, timestamp.toString()); } - const pollingTask = listenerApi.fork(async (forkApi) => { + const pollingTask = listenerApi.fork(async () => { + let subCloser = { + close: () => {} + } try { console.log("Now stable device, listenting for changelogs") - const unsubFunc = await subscribeToRemoteChangelogs( + subCloser = await subscribeToRemoteChangelogs( Number(timestamp), async (decrypted, eventTimestamp) => { const changelog = JSON.parse(decrypted) as Changelog; @@ -546,11 +559,9 @@ export const backupPollingMiddleware = { } ); - forkApi.signal.addEventListener("abort", () => { - unsubFunc(); - }) } catch (err) { + subCloser.close() listenerApi.subscribe() if (err instanceof TaskAbortError) { console.log("task was aborted") diff --git a/src/helpers/remoteBackups.ts b/src/helpers/remoteBackups.ts index fc2ea6a..21c1d14 100644 --- a/src/helpers/remoteBackups.ts +++ b/src/helpers/remoteBackups.ts @@ -1,3 +1,4 @@ +import { SubCloser } from "nostr-tools/lib/types/abstract-pool" import logger from "../Api/helpers/logger" import { getNip78Event, newNip78ChangelogEvent, newNip78Event, publishNostrEvent, pubServiceTag, subToNip78Changelogs } from "../Api/nostrHandler" import { getDeviceId } from "../constants" @@ -23,20 +24,18 @@ export const fetchRemoteBackup = async (dTag?: string): Promise<{ result: 'acces export const subscribeToRemoteChangelogs = async ( latestTimestamp: number, handleChangelogCallback: (decrypted: string, eventTimestamp: number) => Promise, -): Promise<() => void> => { +): Promise => { const ext = getSanctumNostrExtention() if (!ext.valid) { throw new Error("accessTokenMissing") } const pubkey = await ext.getPublicKey() const relays = await ext.getRelays() - const closer = subToNip78Changelogs(pubkey, Object.keys(relays), latestTimestamp, async event => { + const subCloser = subToNip78Changelogs(pubkey, Object.keys(relays), latestTimestamp, async event => { const decrypted = await ext.decrypt(pubkey, event.content); await handleChangelogCallback(decrypted, event.created_at); }); - return () => { - closer.close() - } + return subCloser } export const saveChangelog = async (changelog: string): Promise => { From 461764f1929482023fc8e5380becc6eadaa11816 Mon Sep 17 00:00:00 2001 From: Mothana Date: Tue, 8 Oct 2024 20:40:58 +0400 Subject: [PATCH 2/2] ui and lnurl-w source to noffer send fix --- src/Components/SwItem/SwItem.scss | 26 +++++++++++++++++++++----- src/Components/SwItem/index.tsx | 2 +- src/Pages/Send/index.tsx | 4 ++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Components/SwItem/SwItem.scss b/src/Components/SwItem/SwItem.scss index c69fd4b..da98f39 100644 --- a/src/Components/SwItem/SwItem.scss +++ b/src/Components/SwItem/SwItem.scss @@ -1,7 +1,10 @@ .SwItem{ font-size: 1.2rem; border: none; - display: flow-root; + display: flex; + justify-content: space-between; + align-items: center; + flex-wrap: nowrap; margin: auto; width: 100%; cursor: pointer; @@ -19,19 +22,21 @@ } &_left{ - float: left; display: flex; margin-top: 5px; + max-width: 80%; + flex: 1; } &_right{ - margin-right: 5px; - float: right; margin-top: 5px; + flex-shrink: 0; + max-width: 20%; } &_text{ margin-left: 5px; + width: 100%; } &_date{ @@ -41,8 +46,16 @@ &_station{ margin-top: 7px; - font-size: 18px; + font-size: clamp(14px, 3vw, 18px); color: #2aabe1; + width: 80%; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + + + + } &_price{ @@ -58,6 +71,9 @@ text-align: right; font-size: 16px; margin-bottom: 2px; + @media (max-width: 480px) { + font-size: 14px; + } } &_divider { diff --git a/src/Components/SwItem/index.tsx b/src/Components/SwItem/index.tsx index 50dc831..648f1a5 100644 --- a/src/Components/SwItem/index.tsx +++ b/src/Components/SwItem/index.tsx @@ -52,7 +52,7 @@ export const SwItem = ({ if (link !== operation.identifier) { return link } - if ((operation.type === Types.UserOperationType.INCOMING_INVOICE || operation.type === Types.UserOperationType.OUTGOING_INVOICE)) { + if ((operation.type === Types.UserOperationType.INCOMING_INVOICE || operation.type === Types.UserOperationType.OUTGOING_INVOICE) && operation.identifier.startsWith("lnbc") || operation.identifier.startsWith("lntbs")) { let network = undefined if (operation.identifier.startsWith("lntbs")) { network = { diff --git a/src/Pages/Send/index.tsx b/src/Pages/Send/index.tsx index 916380b..480d5de 100644 --- a/src/Pages/Send/index.tsx +++ b/src/Pages/Send/index.tsx @@ -262,7 +262,7 @@ export const Send = () => { case InputClassification.LN_ADDRESS: case InputClassification.LNURL: { let invoice = ""; - if (destination.noffer) { + if (destination.noffer && selectedSource.pubSource) { invoice = await createNofferInvoice(destination.noffer, selectedSource.keys, amount); } else { invoice = await createLnurlInvoice(amount, destination); @@ -293,7 +293,7 @@ export const Send = () => { pub: selectedSource.id, operation: { amount, - identifier: destination.data, + identifier: payRes.data, inbound: false, operationId: `${destination.data}-${amount}-${timestamp}`, paidAtUnix: timestamp,