Skip to content

Commit

Permalink
Update sync to syncStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
nortonandreev committed Aug 21, 2024
1 parent 1bb1a6c commit 22bd36d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
</script>
Expand All @@ -136,7 +136,7 @@
waitFor={walletStore.getStakeInfo()}
>
<svelte:fragment slot="pending-content">
{#if !sync.inProgress && !error}
{#if !syncStatus.isInProgress && !error}
<Throbber />
{:else}
<p>Data will load after a successful sync.</p>
Expand Down
4 changes: 2 additions & 2 deletions web-wallet/src/lib/stores/stores.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type WalletStoreContent = {
maximum: number;
value: number;
};
sync: {
inProgress: boolean;
syncStatus: {
isInProgress: boolean;
current: number;
latest: number;
};
Expand Down
13 changes: 8 additions & 5 deletions web-wallet/src/lib/stores/walletStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -57,7 +57,7 @@ async function updateAfterSync() {
set({
...store,
balance,
sync: { inProgress: false, current: 0, latest: 0 },
syncStatus: { isInProgress: false, current: 0, latest: 0 },
});
}

Expand Down Expand Up @@ -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();
Expand All @@ -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(() => {
Expand Down
25 changes: 13 additions & 12 deletions web-wallet/src/routes/(app)/dashboard/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
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 = "";
/** @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}`;
}
</script>

Expand All @@ -58,21 +58,22 @@
size="large"
/>
<div class="footer__network-message">
{#if syncStatus}
<span>{syncStatus}</span>
{#if syncStatusLabel}
<span>{syncStatusLabel}</span>
{/if}
{#if sync.inProgress}
{#if !sync.current || !sync.latest}
{#if syncStatus.isInProgress}
{#if !syncStatus.current || !syncStatus.latest}
<span>Syncing</span>
{:else}
<span>
Syncing: <b
>{sync.current.toLocaleString()}/{sync.latest.toLocaleString()}</b
>{syncStatus.current.toLocaleString()}/{syncStatus.latest.toLocaleString()}</b
>
</span>
<ProgressBar
className="footer__sync-status-progress-bar"
currentPercentage={(sync.current / sync.latest) * 100}
currentPercentage={(syncStatus.current / syncStatus.latest) *
100}
/>
{/if}
{/if}
Expand Down
4 changes: 2 additions & 2 deletions web-wallet/src/routes/(app)/dashboard/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
let selectedTab = tabItems[0]?.id ?? "";
$: selectedContract = find(enabledContracts, hasKeyValue("id", selectedTab));
$: ({ balance, currentAddress, addresses, sync, error } = $walletStore);
$: ({ balance, currentAddress, addresses, syncStatus, error } = $walletStore);
$: ({ currentOperation } = $operationsStore);
onDestroy(() => {
Expand Down Expand Up @@ -127,7 +127,7 @@
items={walletStore.getTransactionsHistory()}
{language}
limit={dashboardTransactionLimit}
isSyncing={sync.inProgress}
isSyncing={syncStatus.isInProgress}
syncError={error}
/>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
fiatPrice = prices[currency.toLowerCase()];
});
$: ({ balance, sync, error } = $walletStore);
$: ({ balance, syncStatus, error } = $walletStore);
</script>

<div class="transactions">
Expand All @@ -33,7 +33,7 @@
<Transactions
items={walletStore.getTransactionsHistory()}
{language}
isSyncing={sync.inProgress}
isSyncing={syncStatus.isInProgress}
syncError={error}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { mdiCubeOutline } from "@mdi/js";
import { onDestroy } from "svelte";
$: ({ sync } = $walletStore);
$: ({ syncStatus } = $walletStore);
/** @type {boolean} */
export let isValid = false;
Expand All @@ -15,25 +15,25 @@
syncStarted = true;
}
$: isValid = syncStarted && !sync.inProgress;
$: isValid = syncStarted && !syncStatus.isInProgress;
onDestroy(() => {
walletStore.abortSync();
});
</script>

<IconHeadingCard iconPath={mdiCubeOutline} heading="Network Sync">
{#if !syncStarted || (sync.inProgress && (!sync.current || !sync.latest))}
{#if !syncStarted || (syncStatus.isInProgress && (!syncStatus.current || !syncStatus.latest))}
<span>Syncing...</span>
{:else if sync.inProgress}
<span>
Syncing: <b
>{sync.current.toLocaleString()}/{sync.latest.toLocaleString()}</b
>{syncStatus.current.toLocaleString()}/{syncStatus.latest.toLocaleString()}</b
>
</span>
<ProgressBar
className="footer__sync-status-progress-bar"
currentPercentage={(sync.current / sync.latest) * 100}
currentPercentage={(syncStatus.current / syncStatus.latest) * 100}
/>
{:else}
<span>Sync completed!</span>
Expand Down

0 comments on commit 22bd36d

Please sign in to comment.