2025-10-21 15:11:46 +07:00
|
|
|
<script setup lang="ts">
|
2025-10-24 22:49:46 +07:00
|
|
|
import { ref, computed, onMounted } from 'vue'
|
2025-10-21 15:11:46 +07:00
|
|
|
import { formatNumberToLocaleString } from '@/utils'
|
2025-10-24 22:49:46 +07:00
|
|
|
import { SpinnerCommon } from '@/components'
|
|
|
|
|
import { useNeptuneStore } from '@/stores/neptuneStore'
|
|
|
|
|
import { useNeptuneWallet } from '@/composables/useNeptuneWallet'
|
|
|
|
|
import { message } from 'ant-design-vue'
|
2025-10-31 21:56:47 +07:00
|
|
|
import { get_network_info } from '@neptune/wasm'
|
2025-10-24 22:49:46 +07:00
|
|
|
|
|
|
|
|
const neptuneStore = useNeptuneStore()
|
|
|
|
|
const { getBlockHeight, getNetworkInfo } = useNeptuneWallet()
|
2025-10-22 14:35:27 +07:00
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
const blockHeight = ref(0)
|
|
|
|
|
const networkInfo = ref<any>(null)
|
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-10-24 22:49:46 +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 {
|
|
|
|
|
error.value = ''
|
2025-10-24 22:49:46 +07:00
|
|
|
const [heightResult, infoResult] = await Promise.all([getBlockHeight(), getNetworkInfo()])
|
2025-10-22 14:35:27 +07:00
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
if (heightResult !== undefined) {
|
|
|
|
|
blockHeight.value =
|
|
|
|
|
typeof heightResult === 'number'
|
|
|
|
|
? heightResult
|
|
|
|
|
: heightResult.height || heightResult || 0
|
|
|
|
|
}
|
2025-10-22 14:35:27 +07:00
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
if (infoResult) {
|
|
|
|
|
networkInfo.value = infoResult
|
|
|
|
|
}
|
2025-10-22 14:35:27 +07:00
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
lastUpdate.value = new Date()
|
2025-10-22 14:35:27 +07:00
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
if (loading.value) {
|
|
|
|
|
loading.value = false
|
|
|
|
|
}
|
|
|
|
|
} 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-10-24 22:49:46 +07:00
|
|
|
// const startPolling = () => {
|
|
|
|
|
// pollingInterval = window.setInterval(() => {
|
|
|
|
|
// if (!loading.value) {
|
|
|
|
|
// loadNetworkData()
|
|
|
|
|
// }
|
|
|
|
|
// }, 10000)
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// const stopPolling = () => {
|
|
|
|
|
// if (pollingInterval) {
|
|
|
|
|
// clearInterval(pollingInterval)
|
|
|
|
|
// pollingInterval = null
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await loadNetworkData()
|
|
|
|
|
// startPolling()
|
2025-10-22 14:35:27 +07:00
|
|
|
})
|
|
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
// onUnmounted(() => {
|
|
|
|
|
// stopPolling()
|
|
|
|
|
// })
|
2025-10-21 15:11:46 +07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="content-card">
|
|
|
|
|
<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">
|
2025-10-24 22:49:46 +07:00
|
|
|
<span class="status-label">Block Height</span>
|
|
|
|
|
<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="networkInfo?.version" class="status-item">
|
|
|
|
|
<span class="status-label">Version</span>
|
|
|
|
|
<span class="status-value">{{ networkInfo.version }}</span>
|
2025-10-21 15:11:46 +07:00
|
|
|
</div>
|
|
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
<div v-if="networkInfo?.peer_count !== undefined" class="status-item">
|
|
|
|
|
<span class="status-label">Peers</span>
|
|
|
|
|
<span class="status-value">{{ networkInfo.peer_count }}</span>
|
2025-10-21 15:11:46 +07:00
|
|
|
</div>
|
|
|
|
|
|
2025-10-24 22:49:46 +07:00
|
|
|
<div v-if="networkInfo?.chain_id" class="status-item">
|
|
|
|
|
<span class="status-label">Chain ID</span>
|
|
|
|
|
<span class="status-value">{{ networkInfo.chain_id }}</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>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.content-card {
|
|
|
|
|
@include card-base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.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;
|
|
|
|
|
font-family: var(--font-mono);
|
|
|
|
|
}
|
|
|
|
|
}
|
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>
|