-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: derive satellites and orbiters with canister sync data
- Loading branch information
1 parent
12f9261
commit 84f4898
Showing
5 changed files
with
112 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { canisterSyncDataUncertifiedStore } from '$lib/stores/canister-sync-data.store'; | ||
import { derived } from 'svelte/store'; | ||
|
||
export const canisterSyncDataUncertifiedLoaded = derived( | ||
[canisterSyncDataUncertifiedStore], | ||
([$canisterSyncDataUncertifiedStore]) => $canisterSyncDataUncertifiedStore !== undefined | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Orbiter } from '$declarations/mission_control/mission_control.did'; | ||
import { orbiterStore } from '$lib/derived/orbiter.derived'; | ||
import { canisterSyncDataUncertifiedStore } from '$lib/stores/canister-sync-data.store'; | ||
import type { SegmentWithSyncData } from '$lib/types/satellite'; | ||
import { isNullish } from '@dfinity/utils'; | ||
import { derived } from 'svelte/store'; | ||
|
||
export const orbiterWithSyncData = derived( | ||
[orbiterStore, canisterSyncDataUncertifiedStore], | ||
([$orbiterStore, $canisterSyncDataUncertifiedStore]) => { | ||
if (isNullish($orbiterStore)) { | ||
return undefined; | ||
} | ||
|
||
const { orbiter_id, ...rest } = $orbiterStore; | ||
|
||
const canister = $canisterSyncDataUncertifiedStore?.[orbiter_id.toText()]?.data; | ||
|
||
if (isNullish(canister)) { | ||
return undefined; | ||
} | ||
|
||
return <SegmentWithSyncData<Orbiter>>{ | ||
segment: { orbiter_id, ...rest }, | ||
canister | ||
}; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Satellite } from '$declarations/mission_control/mission_control.did'; | ||
import { sortedSatellites } from '$lib/derived/satellites.derived'; | ||
import { canisterSyncDataUncertifiedStore } from '$lib/stores/canister-sync-data.store'; | ||
import type { SegmentWithSyncData } from '$lib/types/satellite'; | ||
import { nonNullish } from '@dfinity/utils'; | ||
import { derived } from 'svelte/store'; | ||
|
||
export const satellitesWithSyncData = derived( | ||
[sortedSatellites, canisterSyncDataUncertifiedStore], | ||
([$sortedSatellites, $canisterSyncDataUncertifiedStore]) => | ||
$sortedSatellites.reduce<SegmentWithSyncData<Satellite>[]>((acc, { satellite_id, ...rest }) => { | ||
const canister = $canisterSyncDataUncertifiedStore?.[satellite_id.toText()]?.data; | ||
|
||
return [ | ||
...acc, | ||
...(nonNullish(canister) | ||
? [ | ||
{ | ||
segment: { satellite_id, ...rest }, | ||
canister | ||
} | ||
] | ||
: []) | ||
]; | ||
}, []) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
import type { Orbiter, Satellite } from '$declarations/mission_control/mission_control.did'; | ||
import type { CanisterSyncData } from '$lib/types/canister'; | ||
|
||
export type SatelliteIdText = string; | ||
|
||
export interface SegmentWithSyncData<T extends Satellite | Orbiter> { | ||
segment: T; | ||
canister: CanisterSyncData; | ||
} |