Skip to content

Commit

Permalink
feat: query if necessary
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
  • Loading branch information
peterpeterparker committed Aug 24, 2024
1 parent 0162098 commit 64782a9
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/frontend/src/lib/components/hosting/HostingCount.svelte
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
<script lang="ts">
import { fade } from 'svelte/transition';
import { onMount } from 'svelte';
import { countCollectionAssets } from '$lib/api/satellites.api';
import { countCollectionAssets, satelliteVersion } from '$lib/api/satellites.api';
import type { Satellite } from '$declarations/mission_control/mission_control.did';
import { authStore } from '$lib/stores/auth.store';
import { i18n } from '$lib/stores/i18n.store';
import { toasts } from '$lib/stores/toasts.store';
import { compare } from 'semver';
import { versionStore } from '$lib/stores/version.store';
export let satellite: Satellite;
let assets = 0n;
onMount(async () => {
try {
// TODO: load versions globally and use store value instead of fetching version again
const version =
$versionStore.satellites[satellite.satellite_id.toText()]?.current ??
(await satelliteVersion({
satelliteId: satellite.satellite_id,
identity: $authStore.identity
}));
if (compare(version, '0.0.20') < 0) {
// For simplicity reasons we do not display the information for not up-to-date Satellite.
// In Satellite v0.0.20, the endpoint to list the number of assets in a collection was renamed from `count_assets` to `count_collection_assets`.
return;
}
assets = await countCollectionAssets({
satelliteId: satellite.satellite_id,
collection: '#dapp',
identity: $authStore.identity
});
} catch (err: unknown) {
// We do not toast the error for simplicity reasons.
// In Satellite v0.0.20, the endpoint to list the number of assets in a collection was renamed from `count_assets` to `count_collection_assets`.
console.error($i18n.errors.hosting_count_assets, err);
toasts.error({
text: $i18n.errors.hosting_count_assets,
detail: err
});
}
});
</script>
Expand Down

0 comments on commit 64782a9

Please sign in to comment.