A lightweight, framework‑agnostic component to display the health & SLA status of your subgraphs. Works with vanilla JS, React, Next.js, or straight from a CDN.
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@chainlove/sla-widget/dist/vanilla.mjs"
></script>
<sla-widget subgraph-ids="Qm123...,Qm456..." details="full"></sla-widget>
- 🚀 Drop-in integration (Web Component or React)
- 🎨 4 themes:
light
,dark
,highContrast
,auto
- 🖼️ Flexible placement:
embedded
panel orbanner
- 🔎 Detail levels:
full
orproblemsOnly
- 🔄 Auto-refresh (configurable)
- 💬 Custom messages per health state
⚠️ Graceful degradation on API failure- 🌍 CDN or npm / yarn / pnpm
- 📦 Tiny bundle size
npm install @chainlove/sla-widget
# or
yarn add @chainlove/sla-widget
# or
pnpm add @chainlove/sla-widget
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@chainlove/sla-widget/dist/vanilla.mjs"
></script>
<sla-widget
subgraph-ids="Qm123...,Qm456..."
details="full"
theme="auto"
position="banner"
></sla-widget>
import { SLAWidget } from '@chainlove/sla-widget/react';
<SLAWidget
subgraphIds={['Qm123...', 'Qm456...']}
details="full"
theme="auto"
position="banner"
/>;
<div id="sla-container"></div>
<script type="module">
import { SLAWidget } from 'https://cdn.jsdelivr.net/npm/@chainlove/sla-widget/dist/core.mjs';
const app = new SLAWidget({
subgraphIds: ['Qm123...', 'Qm456...'],
details: 'full',
theme: 'auto',
position: 'banner',
});
app.render(document.getElementById('sla-container'));
</script>
-
React / CoreJS:
subgraphIds
→string[]
-
Web Component (HTML):
subgraph-ids
→ comma-separatedstring
- React/CoreJS →
string[]
Example:['Qm123...', 'Qm456...']
- Web Component → comma-separated
string
Example:"Qm123...,Qm456..."
List of Subgraph CIDs to display.
🔊 You can dynamically update this list:
-
React: by updating the
subgraphIds
prop -
Web Component: by calling
element.setAttribute('subgraph-ids', '...')
-
React / CoreJS:
statusEndpoint
→string
-
Web Component (HTML):
status-endpoint
→string
API endpoint URL for fetching subgraph status.
-
React / CoreJS:
refreshIntervalMs
→number
-
Web Component (HTML):
refresh-interval-ms
→number
How it works:
- The widget fetches data from API endpoint (
statusEndpoint
). - API reflects the result of an on-chain consensus, which happens once every 10-minute round on the smart contract.
- As a result, new data appears at most once every 10 minutes — regardless of how often you fetch.
Behavior:
-
If you set
refreshIntervalMs = false
(default), the widget fetches data once, when the page loads. -
If you set
refreshIntervalMs
to a value (e.g.5000
= 5 sec), the widget will fetch data at that interval, but you will likely see the same data between rounds — updates will appear only after the next consensus round. -
There is no strict requirement for the interval you choose:
- Short intervals (1-2 min) can be useful if you want to show new data as soon as possible.
- Longer intervals (>= 10 min) reduce API calls and are more bandwidth-friendly.
🔊 In practice, a value between 1 and 10 minutes works well, depending on your app's needs.
-
React / CoreJS:
theme
→'light'
|'dark'
|'highContrast'
|'auto'
-
Web Component (HTML):
theme
→ same values
Widget theme. 🔊 Can be changed dynamically.
-
React / CoreJS:
position
→'banner'
|'embedded'
-
Web Component (HTML):
position
→ same values
Widget position on the page:
-
position="banner"
→ widget is displayed as a banner at the top of the site. -
position="embedded"
→ widget is displayed as an inline block (you can place it anywhere in the page).
-
React / CoreJS:
details
→'full'
|'problemsOnly'
-
Web Component (HTML):
details
→ same values
Controls when the widget is shown:
-
details="full"
→ widget is always visible. -
details="problemsOnly"
→ widget is shown only if one or more subgraphs insubgraph ids
have Downtime or Latency. It disappears if all subgraphs are in Uptime.
-
React / CoreJS:
mode
→'simple'
|'dev'
-
Web Component (HTML):
mode
→ same values
Controls the display mode of the widget:
-
mode="simple"
→ the widget shows a compact banner or embedded block:- If any subgraph has Downtime (
error
) or Latency (warning
), the banner displays a custom message (seecustomMessages
/custom-messages
option below). - If all subgraphs are healthy (
ok
), the banner may be hidden (ifdetails='problemsOnly'
) or show a neutral state (ifdetails='full'
).
Example for customizing messages (for Web Component):
- If any subgraph has Downtime (
custom-messages='{"warning":"⚠️ Check this","error":"🚨 Critical issue"}'
Example for customizing messages (for React):
<SLAWidget
...
customMessages={{
warning: "⚠️ Check this",
error: "🚨 Critical issue",
}}
/>
-
mode="dev"
→ the widget displays a detailed panel with:- full list of all subgraphs
- current health status for each subgraph
- latency / downtime metrics
- useful for debugging and monitoring purposes.
🔊 Typical usage:
- Use
'simple'
for production websites and user-facing pages. - Use
'dev'
for internal dashboards, monitoring panels, or while testing.
-
React / CoreJS:
pinned
→'slide'
|'fixed'
-
Web Component (HTML):
pinned
→ same values
Widget pinning behavior:
-
'slide'
→ widget is placed at the top of the page, inside the normal page flow.
When the user scrolls down, the widget will scroll out of view (i.e. it moves with the page). -
'fixed'
→ widget is pinned to the viewport (CSSposition: fixed
) and remains always visible, even when the user scrolls the page.
👉 Use 'fixed'
if you want the widget to stay on screen at all times.
Use 'slide'
for more lightweight appearance (standard banner behavior at top
of page).
-
React / CoreJS:
customMessages
→{ [key in Health]?: string }
-
Web Component (HTML):
custom-messages
→ JSON string
Custom text to display for each health state. 🔊 Works only in
mode="simple"
.
You can override the default built-in labels with your own text or icons for:
-
ok
→ when all subgraphs are healthy -
warning
→ when one or more subgraphs have high latency -
error
→ when one or more subgraphs are down -
unknown
→ when the status of one or more subgraphs is unknown
export type Health = 'ok' | 'warning' | 'error' | 'unknown';
<sla-widget
...
custom-messages='{"ok":"✅ All systems operational","warning":"⚠️ Some delays","error":"🚨 Outage detected","unknown":"❔ Status unknown"}'
></sla-widget>
<SLAWidget
...
customMessages={{
ok: "✅ All systems operational",
warning: "⚠️ Some delays",
error: "🚨 Outage detected",
unknown: "❔ Status unknown",
}}
Additionally, when using the widget, you can dynamically adjust settings (mode, details) by clicking the ⚙️ settings button inside the widget.
Feel free to open issues, submit pull requests, or suggest improvements!
MIT