From 22bd36d556a756cc96071f340c49a1ffa05c9bbf Mon Sep 17 00:00:00 2001 From: Norton Andreev Date: Wed, 21 Aug 2024 13:04:57 +0300 Subject: [PATCH] Update sync to syncStatus --- .../StakeContract/StakeContract.svelte | 6 ++--- web-wallet/src/lib/stores/stores.d.ts | 4 +-- web-wallet/src/lib/stores/walletStore.js | 13 ++++++---- .../src/routes/(app)/dashboard/+layout.svelte | 25 ++++++++++--------- .../src/routes/(app)/dashboard/+page.svelte | 4 +-- .../(app)/dashboard/transactions/+page.svelte | 4 +-- .../setup/restore/NetworkSyncProgress.svelte | 10 ++++---- 7 files changed, 35 insertions(+), 31 deletions(-) diff --git a/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte b/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte index 8ed7edffa6..524e699fa5 100644 --- a/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte +++ b/web-wallet/src/lib/containers/StakeContract/StakeContract.svelte @@ -124,8 +124,8 @@ $: ({ currentOperation } = $operationsStore); $: [gasSettings, language, minAllowedStake] = collectSettings($settingsStore); const { hideStakingNotice } = $settingsStore; - $: ({ balance, error, sync } = $walletStore); - $: isSyncOK = !(sync.inProgress || !!error); + $: ({ balance, error, syncStatus } = $walletStore); + $: isSyncOK = !(syncStatus.isInProgress || !!error); $: duskFormatter = createCurrencyFormatter(language, "DUSK", 9); @@ -136,7 +136,7 @@ waitFor={walletStore.getStakeInfo()} > - {#if !sync.inProgress && !error} + {#if !syncStatus.isInProgress && !error} {:else}

Data will load after a successful sync.

diff --git a/web-wallet/src/lib/stores/stores.d.ts b/web-wallet/src/lib/stores/stores.d.ts index f49a237ee4..3aa034a406 100644 --- a/web-wallet/src/lib/stores/stores.d.ts +++ b/web-wallet/src/lib/stores/stores.d.ts @@ -41,8 +41,8 @@ type WalletStoreContent = { maximum: number; value: number; }; - sync: { - inProgress: boolean; + syncStatus: { + isInProgress: boolean; current: number; latest: number; }; diff --git a/web-wallet/src/lib/stores/walletStore.js b/web-wallet/src/lib/stores/walletStore.js index 6f4ecfe5eb..436b43e8ba 100644 --- a/web-wallet/src/lib/stores/walletStore.js +++ b/web-wallet/src/lib/stores/walletStore.js @@ -20,7 +20,7 @@ const initialState = { maximum: 0, value: 0, }, - sync: { inProgress: false, current: 0, latest: 0 }, + syncStatus: { isInProgress: false, current: 0, latest: 0 }, currentAddress: "", error: null, initialized: false, @@ -57,7 +57,7 @@ async function updateAfterSync() { set({ ...store, balance, - sync: { inProgress: false, current: 0, latest: 0 }, + syncStatus: { isInProgress: false, current: 0, latest: 0 }, }); } @@ -148,7 +148,7 @@ function sync(from) { set({ ...store, error: null, - sync: { inProgress: true, current: 0, latest: 0 }, + syncStatus: { isInProgress: true, current: 0, latest: 0 }, }); syncController = new AbortController(); @@ -158,14 +158,17 @@ function sync(from) { signal: syncController.signal, onblock: (current, latest) => { console.log("Syncing", current, latest); - set({ ...store, sync: { inProgress: true, current, latest } }); + set({ + ...store, + syncStatus: { isInProgress: true, current, latest }, + }); }, }) .then(updateAfterSync, (error) => { set({ ...store, error, - sync: { inProgress: false, current: 0, latest: 0 }, + syncStatus: { isInProgress: false, current: 0, latest: 0 }, }); }) .finally(() => { diff --git a/web-wallet/src/routes/(app)/dashboard/+layout.svelte b/web-wallet/src/routes/(app)/dashboard/+layout.svelte index c288c6e28d..5989895e4c 100644 --- a/web-wallet/src/routes/(app)/dashboard/+layout.svelte +++ b/web-wallet/src/routes/(app)/dashboard/+layout.svelte @@ -11,10 +11,10 @@ import { AppAnchorButton } from "$lib/components"; $: ({ network } = $settingsStore); - $: ({ sync, error } = $walletStore); + $: ({ syncStatus, error } = $walletStore); /** @type {null | string} */ - let syncStatus = null; + let syncStatusLabel = null; /** @type {string} */ let networkStatusIconPath = ""; @@ -22,18 +22,18 @@ /** @type {string} */ let iconVariant = ""; - $: if (sync.inProgress) { + $: if (syncStatus.isInProgress) { iconVariant = "warning"; networkStatusIconPath = mdiTimerSand; - syncStatus = null; + syncStatusLabel = null; } else if (error) { iconVariant = "error"; networkStatusIconPath = mdiAlertOutline; - syncStatus = `Dusk ${network} - Sync Failed`; + syncStatusLabel = `Dusk ${network} - Sync Failed`; } else { iconVariant = "success"; networkStatusIconPath = mdiLink; - syncStatus = `Dusk ${network}`; + syncStatusLabel = `Dusk ${network}`; } @@ -58,21 +58,22 @@ size="large" />