Skip to content

Commit

Permalink
contextual health indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Oct 26, 2024
1 parent 6cb9596 commit a9d0c2f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 44 deletions.
41 changes: 41 additions & 0 deletions components/ui/HealthIndicator.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<div v-if="contextualHealth === Health.Healthy">
<div class="bg-green-500 w-4 h-4 rounded-full" title="all good"></div>
</div>
<div v-else-if="contextualHealth === Health.Warning">
<div class="bg-yellow-500 w-4 h-4 rounded-full" title="warnings"></div>
</div>
<div v-else-if="contextualHealth === Health.Critical">
<div class="bg-red-500 w-4 h-4 rounded-full" title="critical"></div>
</div>
<div v-else>
<div class="bg-gray-500 w-4 h-4 rounded-full" title="health unknown"></div>
</div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useSystemHealth, Health } from "@/store/systemHealth.ts";
import { useRouter } from 'vue-router';
const systemHealth = useSystemHealth();
const router = useRouter();
const contextualHealth = computed(() => {
switch (router.currentRoute.value.path) {
case '/':
return systemHealth.getAggregatedSystemHealth;
case '/teerdays':
return systemHealth.getIntegriteeSystemHealth;
default:
return Health.Unknown;
}
});
</script>


<style scoped>
</style>
22 changes: 21 additions & 1 deletion layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<header class="header">
<div class="header-content">
<Incognitee class="logo" />
<HealthIndicator/>
<div class="flex items-center">
<svg
xmlns="http://www.w3.org/2000/svg"
Expand Down Expand Up @@ -138,8 +139,10 @@ import Incognitee from "@/assets/img/incognitee-mask.svg";
import TEERdays from "@/public/img/index/TEERdays-icon-white.svg";
import { useAccount } from "@/store/account.ts";
import { eventBus } from "@/helpers/eventBus";
import { connectExtension } from "~/lib/signerExtensionUtils";
import HealthIndicator from "@/components/ui/HealthIndicator.vue";
const accountStore = useAccount();
const emitAddressClicked = () => {
eventBus.emit("addressClicked");
};
Expand Down Expand Up @@ -203,4 +206,21 @@ const emitAddressClicked = () => {
padding: 0;
list-style-type: none;
}
.bg-green-500 {
background-color: #2dad24; /* Adjust the color as needed */
}
.w-4 {
width: 1rem; /* Adjust the size as needed */
}
.h-4 {
height: 1rem; /* Adjust the size as needed */
}
.rounded-full {
border-radius: 9999px; /* Makes the element a circle */
}
</style>
8 changes: 4 additions & 4 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1403,10 +1403,10 @@ const fetchNetworkStatus = async () => {
const getter = incogniteeStore.api.parentchainsInfoGetter(
incogniteeShard.value,
);
getter.send().then((info) => {
console.log(`parentchains info: ${info}`);
parentchainsInfo.value = info;
});
// getter.send().then((info) => {
// console.log(`parentchains info: ${info}`);
// parentchainsInfo.value = info;
// });
api.rpc.chain.getFinalizedHead().then((head) => {
api.rpc.chain.getBlock(head).then((block) => {
console.log(
Expand Down
6 changes: 6 additions & 0 deletions pages/teerdays.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,12 @@ const summaryTeerBonded = ref(0);
const summaryTeerDays = ref(0);
const isChoosingAccount = ref(false);
const isMobile = ref(false);
// Überwache die Bildschirmgröße und aktualisiere den isMobile-Wert
const checkIfMobile = () => {
isMobile.value = window.matchMedia("(max-width: 768px)").matches;
};
const dropSubscriptions = async () => {
console.log("dropping subscriptions");
api?.disconnect();
Expand Down
40 changes: 40 additions & 0 deletions store/systemHealth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { defineStore } from "pinia";
import { ChainId } from "@/configs/chains";

class ObservableNumber {
value: number;
timestamp: Date;
constructor(value: number) {
this.value = value;
}
observe(new_value: number) {
this.value = new_value;
this.timestamp = new Date();
}
}

export enum Health {
Unknown,
Healthy,
Warning,
Critical,
}

export const useSystemHealth = defineStore("system-health", {
state: () => ({
shieldingTargetFinalizedBlockNumber: <ObservableNumber | null>null,
}),
getters: {
getAggregatedSystemHealth({ shieldingTargetFinalizedBlockNumber }): Health {
return Health.Healthy;
},
getIntegriteeSystemHealth({ shieldingTargetFinalizedBlockNumber }): Health {
return Health.Warning;
}
},
actions: {
setShieldingTargetFinalizedBlockNumber(block_number: number) {
this.shieldingTargetFinalizedBlockNumber.observe(block_number);
}
},
});
39 changes: 0 additions & 39 deletions store/teerAccount.ts

This file was deleted.

0 comments on commit a9d0c2f

Please sign in to comment.