Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to stop scanning announcements #642

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"fetching-latest": "Fetching latest 10,000 announcements...",
"scanning": "Scanning all announcements for funds...",
"scanning-latest": "Scanning latest announcements for funds...",
"wait": "This may take a couple of minutes depending on your connection and device. This is normal— please be patient."
"wait": "This may take a couple of minutes depending on your connection and device. This is normal— please be patient.",
"stop": "Stop"
},
"Setup": {
"setup": "Setup",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
"fetching-latest": "在获取最新的 10,000 条公告...",
"scanning": "在所有的公告中扫描资金...",
"scanning-latest": "在最新公告中扫描资金...",
"wait": "这可能需要几分钟,具体取决于您的连接和设备。这是正常的 — 请耐心等待。"
"wait": "这可能需要几分钟,具体取决于您的连接和设备。这是正常的 — 请耐心等待。",
"stop": "停止"
},
"Setup": {
"setup": "注册",
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/pages/AccountReceive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@
</div>
<div v-else class="text-center text-italic">{{ $t('Receive.fetching-latest') }}</div>
</div>
<div>
<base-button
garyghayrat marked this conversation as resolved.
Show resolved Hide resolved
v-if="scanStatus != 'complete' && scanStatus != 'waiting'"
@click="terminateWorkers()"
class="text-center q-pt-md"
:label="$t('Receive.stop')"
/>
</div>
</div>
</q-page>
</template>
Expand Down Expand Up @@ -130,6 +138,8 @@ function useScan() {
const scanStatus = ref<ScanStatus>('waiting');
const scanPercentage = ref<number>(0);
const userAnnouncements = ref<UserAnnouncement[]>([]);
const workers: Worker[] = [];
const paused = ref(false);

// Start and end blocks for advanced mode settings
const { advancedMode, startBlock, endBlock, setScanBlocks, setScanPrivateKey, scanPrivateKey, resetScanSettings } =
Expand Down Expand Up @@ -199,7 +209,19 @@ function useScan() {
await scan();
}

function terminateWorkers() {
workers.forEach((worker) => worker.terminate());
paused.value = true;
if (scanStatus.value == 'fetching latest') {
scanStatus.value = 'waiting';
} else {
scanStatus.value = 'complete';
}
}

async function scan() {
// Reset paused state
paused.value = false;
if (!umbra.value) throw new Error('No umbra instance found. Please make sure you are on a supported network');
scanStatus.value = 'fetching latest';

Expand Down Expand Up @@ -228,6 +250,7 @@ function useScan() {
spendingPublicKey,
viewingPrivateKey,
announcements,
workers,
(percent) => {
scanPercentage.value = Math.floor(percent);
},
Expand Down Expand Up @@ -282,6 +305,9 @@ function useScan() {
userWalletAddress.value,
overrides
)) {
if (paused.value) {
return;
}
announcementsCount += announcementsBatch.length; // Increment count
announcementsQueue = [...announcementsQueue, ...announcementsBatch];
if (announcementsCount == 10000) {
Expand All @@ -296,6 +322,8 @@ function useScan() {
}
// Wait for the first batch of web workers to finish scanning before creating new workers
await firstScanPromise;
// Clear out existing workers
workers.length = 0;
garyghayrat marked this conversation as resolved.
Show resolved Hide resolved
scanStatus.value = 'scanning';
await filterUserAnnouncementsAsync(spendingPubKey, viewingPrivKey, announcementsQueue);
scanStatus.value = 'complete';
Expand Down Expand Up @@ -337,6 +365,7 @@ function useScan() {
startBlockLocal,
userAddress,
userAnnouncements,
terminateWorkers,
};
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const filterUserAnnouncements = (
spendingPublicKey: string,
viewingPrivateKey: string,
announcements: AnnouncementDetail[],
workers: Worker[],
progress: (percentage: number) => void,
completion: (userAnnouncements: UserAnnouncement[]) => void
) => {
Expand Down Expand Up @@ -58,7 +59,6 @@ export const filterUserAnnouncements = (
}

// assign tasks to workers
const workers: Worker[] = [];
const progressRecorder: number[] = [];
let progressSum = 0;
// Here we will initialize `nCores` workers by constructing `Worker()` imported from worker script `filter.worker.ts`
Expand Down
Loading