From 6925fc048a792b757e95a4750a573caa922c6efc Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Fri, 26 Apr 2024 12:40:25 -0700 Subject: [PATCH 01/48] feat: set the last fetched block as the start block --- frontend/src/pages/AccountReceive.vue | 4 ++++ frontend/src/store/settings.ts | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/AccountReceive.vue b/frontend/src/pages/AccountReceive.vue index 63442477..7f3cc7e1 100644 --- a/frontend/src/pages/AccountReceive.vue +++ b/frontend/src/pages/AccountReceive.vue @@ -318,6 +318,7 @@ function useScan() { const latestBlock: Block = await getLastBlock(provider.value!); mostRecentBlockNumber.value = latestBlock.number; mostRecentBlockTimestamp.value = latestBlock.timestamp; + // Default scan behavior for await (const announcementsBatch of umbra.value.fetchSomeAnnouncements( signer.value, @@ -358,6 +359,9 @@ function useScan() { scanStatus.value = 'scanning'; await filterUserAnnouncementsAsync(spendingPubKey, viewingPrivKey, announcementsQueue); scanStatus.value = 'complete'; + + // Save the latest block (plus 1 to mitigate overlap) to localStorage for future scans as the start block + setScanBlocks(latestBlock.number + 1); } } catch (e) { scanStatus.value = 'waiting'; // reset to the default state because we were unable to fetch announcements diff --git a/frontend/src/store/settings.ts b/frontend/src/store/settings.ts index 308bf265..867d2f37 100644 --- a/frontend/src/store/settings.ts +++ b/frontend/src/store/settings.ts @@ -12,6 +12,7 @@ const settings = { language: 'language', sendHistorySave: 'send-history-save', UmbraApiVersion: 'umbra-api-version', + lastFetchedBlock: 'last-fetched-block', }; // Shared state between instances @@ -41,6 +42,10 @@ export default function useSettingsStore() { lastWallet.value = LocalStorage.getItem(settings.lastWallet) ? String(LocalStorage.getItem(settings.lastWallet)) : undefined; + + // Load the last fetched block from localStorage to use as the default start block + const lastFetchedBlock = LocalStorage.getItem(settings.lastFetchedBlock); + startBlock.value = lastFetchedBlock !== null ? Number(lastFetchedBlock) : undefined; }); setLanguage( paramLocale @@ -92,9 +97,12 @@ export default function useSettingsStore() { return ''; } - function setScanBlocks(startBlock_: number, endBlock_: number) { + function setScanBlocks(startBlock_: number, endBlock_?: number) { startBlock.value = startBlock_; - endBlock.value = endBlock_ || undefined; + endBlock.value = endBlock_; + + // Save the last fetched block to localStorage so we can use it as the default start block next time + LocalStorage.set(settings.lastFetchedBlock, startBlock_); } function setScanPrivateKey(key: string) { @@ -118,6 +126,9 @@ export default function useSettingsStore() { startBlock.value = undefined; endBlock.value = undefined; scanPrivateKey.value = undefined; + + // Clear the last fetched block from localStorage + LocalStorage.remove(settings.lastFetchedBlock); } function getUmbraApiVersion(): UmbraApiVersion | null { From 9932c0784f6481ca72b2af6970da6ddbae502dba Mon Sep 17 00:00:00 2001 From: marcomariscal Date: Tue, 30 Apr 2024 12:32:29 -0700 Subject: [PATCH 02/48] feat: handle caching user announcements and latest fetched block --- frontend/src/pages/AccountReceive.vue | 71 ++++++++++++++++++++++++--- frontend/src/store/settings.ts | 2 + 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/AccountReceive.vue b/frontend/src/pages/AccountReceive.vue index 7f3cc7e1..fcac3fb2 100644 --- a/frontend/src/pages/AccountReceive.vue +++ b/frontend/src/pages/AccountReceive.vue @@ -119,7 +119,7 @@