187 lines
5.2 KiB
Vue
Raw Normal View History

2025-10-21 15:11:46 +07:00
<script setup lang="ts">
2025-11-05 04:14:37 +07:00
import { ref, computed, onMounted, onUnmounted } from 'vue'
2025-10-21 15:11:46 +07:00
import { formatNumberToLocaleString } from '@/utils'
2025-10-24 22:49:46 +07:00
import { useNeptuneStore } from '@/stores/neptuneStore'
import { useNeptuneWallet } from '@/composables/useNeptuneWallet'
import { message } from 'ant-design-vue'
import { POLLING_INTERVAL } from '@/utils'
2025-10-24 22:49:46 +07:00
const neptuneStore = useNeptuneStore()
2025-11-05 04:14:37 +07:00
const { getBlockHeight } = useNeptuneWallet()
2025-10-22 14:35:27 +07:00
2025-10-24 22:49:46 +07:00
const blockHeight = ref(0)
2025-10-22 14:35:27 +07:00
const loading = ref(true)
const error = ref('')
2025-10-24 22:49:46 +07:00
const lastUpdate = ref<Date | null>(null)
2025-10-22 14:35:27 +07:00
2025-11-05 04:14:37 +07:00
let pollingInterval: number | null = null
2025-10-22 14:35:27 +07:00
2025-10-24 22:49:46 +07:00
const network = computed(() => neptuneStore.getNetwork)
const loadNetworkData = async () => {
2025-10-22 14:35:27 +07:00
try {
2025-11-05 04:14:37 +07:00
loading.value = true
2025-10-22 14:35:27 +07:00
error.value = ''
2025-11-05 04:14:37 +07:00
const result = await getBlockHeight()
if (result.height || result) blockHeight.value = Number(result.height || result)
2025-10-22 14:35:27 +07:00
2025-10-24 22:49:46 +07:00
lastUpdate.value = new Date()
2025-11-05 04:14:37 +07:00
loading.value = false
2025-10-24 22:49:46 +07:00
} catch (err) {
const errorMsg = err instanceof Error ? err.message : 'Failed to load network data'
error.value = errorMsg
loading.value = false
message.error(errorMsg)
2025-10-22 14:35:27 +07:00
}
}
2025-10-24 22:49:46 +07:00
const retryConnection = async () => {
loading.value = true
error.value = ''
await loadNetworkData()
2025-10-22 14:35:27 +07:00
}
2025-11-05 04:14:37 +07:00
const startPolling = () => {
pollingInterval = window.setInterval(async () => {
if (!loading.value) await loadNetworkData()
}, POLLING_INTERVAL)
2025-11-05 04:14:37 +07:00
}
const stopPolling = () => {
if (pollingInterval) {
clearInterval(pollingInterval)
pollingInterval = null
}
}
2025-10-24 22:49:46 +07:00
onMounted(async () => {
await loadNetworkData()
2025-11-05 04:14:37 +07:00
startPolling()
2025-10-22 14:35:27 +07:00
})
2025-11-05 04:14:37 +07:00
onUnmounted(() => {
stopPolling()
})
2025-10-21 15:11:46 +07:00
</script>
<template>
2025-11-05 04:14:37 +07:00
<CardBase class="content-card">
2025-10-21 15:11:46 +07:00
<div class="network-status-container">
<h2 class="section-title">NETWORK STATUS</h2>
2025-10-22 14:35:27 +07:00
<!-- Loading State -->
2025-10-24 22:49:46 +07:00
<div v-if="loading && !blockHeight" class="loading-state">
<SpinnerCommon size="medium" />
2025-10-22 14:35:27 +07:00
<p>Loading network data...</p>
</div>
<!-- Error State -->
<div v-else-if="error" class="error-state">
<p>{{ error }}</p>
<button @click="retryConnection" class="retry-button">Retry Connection</button>
</div>
<!-- Data Display -->
<div v-else class="status-grid">
2025-10-21 15:11:46 +07:00
<div class="status-item">
<span class="status-label">Network</span>
2025-10-24 22:49:46 +07:00
<span class="status-value">Neptune {{ network }}</span>
2025-10-21 15:11:46 +07:00
</div>
<div class="status-item">
<span class="status-label">Block Height</span>
2025-10-24 22:49:46 +07:00
<span class="status-value">{{ formatNumberToLocaleString(blockHeight) }}</span>
2025-10-21 15:11:46 +07:00
</div>
2025-10-24 22:49:46 +07:00
<div v-if="lastUpdate" class="status-item">
<span class="status-label">Last Updated</span>
<span class="status-value">{{ lastUpdate.toLocaleTimeString() }}</span>
2025-10-22 14:35:27 +07:00
</div>
2025-10-21 15:11:46 +07:00
</div>
</div>
2025-11-05 04:14:37 +07:00
</CardBase>
2025-10-21 15:11:46 +07:00
</template>
<style lang="scss" scoped>
.network-status-container {
.section-title {
font-size: var(--font-xl);
font-weight: var(--font-bold);
color: var(--text-primary);
margin-bottom: var(--spacing-2xl);
letter-spacing: var(--tracking-wider);
text-align: center;
padding-bottom: var(--spacing-lg);
border-bottom: 3px solid var(--primary-color);
}
.status-grid {
display: flex;
flex-direction: column;
gap: var(--spacing-xl);
}
.status-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: var(--spacing-lg) var(--spacing-xl);
background: var(--bg-light);
border-radius: var(--radius-md);
transition: var(--transition-all);
&:hover {
background: var(--bg-hover);
transform: translateX(5px);
}
.status-label {
font-weight: var(--font-semibold);
color: var(--text-secondary);
font-size: var(--font-md);
}
.status-value {
font-weight: var(--font-semibold);
color: var(--text-primary);
font-size: var(--font-lg);
text-align: right;
}
}
2025-10-22 14:35:27 +07:00
// Loading State
.loading-state {
2025-10-24 22:49:46 +07:00
@include center_flex;
2025-10-22 14:35:27 +07:00
padding: var(--spacing-4xl);
color: var(--text-secondary);
}
// Error State
.error-state {
2025-10-24 22:49:46 +07:00
@include center_flex;
2025-10-22 14:35:27 +07:00
padding: var(--spacing-4xl);
color: var(--error-color);
p {
margin-bottom: var(--spacing-lg);
font-size: var(--font-md);
}
.retry-button {
padding: var(--spacing-sm) var(--spacing-lg);
background: var(--primary-color);
color: var(--text-light);
border: none;
border-radius: var(--radius-md);
cursor: pointer;
font-size: var(--font-sm);
transition: var(--transition-all);
&:hover {
background: var(--primary-hover);
}
}
}
2025-10-21 15:11:46 +07:00
}
</style>