From 1f9889c8f0568f1a9d099b7fd9285dba1fe41478 Mon Sep 17 00:00:00 2001 From: tornadocontrib Date: Wed, 20 Nov 2024 06:02:43 +0000 Subject: [PATCH] Fixed loadLastBlock --- lib/services/data.js | 10 +++++----- src/services/data.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/services/data.js b/lib/services/data.js index f55e0b9..a4aeb9d 100644 --- a/lib/services/data.js +++ b/lib/services/data.js @@ -87,18 +87,18 @@ async function loadLastBlock({ name, directory }) { } async function loadSavedEvents({ name, userDirectory, }) { const filePath = path_1.default.join(userDirectory, `${name}.json`.toLowerCase()); + const loadedBlock = await loadLastBlock({ + name, + directory: userDirectory, + }); if (!(await existsAsync(filePath))) { return { events: [], - lastBlock: 0, + lastBlock: loadedBlock || 0, }; } try { const events = JSON.parse(await (0, promises_1.readFile)(filePath, { encoding: 'utf8' })); - const loadedBlock = await loadLastBlock({ - name, - directory: userDirectory, - }); return { events, lastBlock: loadedBlock || events[events.length - 1]?.blockNumber || 0, diff --git a/src/services/data.ts b/src/services/data.ts index 6e4ef41..f78f26d 100644 --- a/src/services/data.ts +++ b/src/services/data.ts @@ -114,21 +114,21 @@ export async function loadSavedEvents({ }): Promise> { const filePath = path.join(userDirectory, `${name}.json`.toLowerCase()); + const loadedBlock = await loadLastBlock({ + name, + directory: userDirectory, + }); + if (!(await existsAsync(filePath))) { return { events: [] as T[], - lastBlock: 0, + lastBlock: loadedBlock || 0, }; } try { const events = JSON.parse(await readFile(filePath, { encoding: 'utf8' })) as T[]; - const loadedBlock = await loadLastBlock({ - name, - directory: userDirectory, - }); - return { events, lastBlock: loadedBlock || events[events.length - 1]?.blockNumber || 0,