Skip to content

Commit

Permalink
feat: Network unavailability handling (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek authored Jun 5, 2024
1 parent baca7b1 commit 145722e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
31 changes: 25 additions & 6 deletions src/components/TheHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,43 @@
class="header__warning">
Some services are currently being synced and data accuracy might be affected. Please check again later.
</div>
<div
v-if="!isOnline"
class="header__warning">
You are currently offline. Please check your connection.
</div>
<div
v-if="nodeStatus === false"
class="header__warning">
The Node is currently unavailable. Please check again later.
</div>
<div
v-if="middlewareStatus === false"
class="header__warning">
The Middleware is currently unavailable. Please check again later.
</div>
<div
v-if="isMarketCapAvailable === false"
class="header__warning">
Market Cap data are currently not available. Fiat price might not be up to date. Please check again later.
</div>
</header>
</template>

<script setup>
import { storeToRefs } from 'pinia'
import TheNavigation from '@/components/TheNavigation'
import AppLink from '@/components/AppLink'
import AppIcon from '@/components/AppIcon'
import NetworkSelect from '@/components/NetworkSelect'
import { useOnline } from '@vueuse/core'
import { useUiStore } from '@/stores/ui'
import { useStatus } from '@/stores/status'
import { MENU_HASH } from '@/utils/constants'
import { useMarketStatsStore } from '@/stores/marketStats'
const route = useRoute()
const router = useRouter()
const { isMobileMenuOpen } = storeToRefs(useUiStore())
const { isSyncing } = storeToRefs(useStatus())
const isOnline = useOnline()
const { isSyncing, nodeStatus, middlewareStatus } = storeToRefs(useStatus())
const { isMarketCapAvailable } = storeToRefs(useMarketStatsStore())
onMounted(() => {
window.addEventListener('resize', closeNavigation)
Expand Down
11 changes: 9 additions & 2 deletions src/stores/marketStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const useMarketStatsStore = defineStore('marketStats', () => {
const price = ref(null)
const priceChange = ref(null)
const marketCap = ref(null)
const isMarketCapAvailable = ref(null)

const blockchainStatsStore = useBlockchainStatsStore()

Expand All @@ -38,8 +39,13 @@ export const useMarketStatsStore = defineStore('marketStats', () => {

async function fetchPrice() {
if (!cache.get(CACHE_KEY_PRICE_DATA)) {
const { data } = await axios.get(`${MARKET_STATS_ADDRESS}/simple/price?ids=aeternity&vs_currencies=usd&include_24hr_change=true`)
cache.put(CACHE_KEY_PRICE_DATA, data.aeternity, MARKET_STATS_CACHE_TTL)
try {
const { data } = await axios.get(`${MARKET_STATS_ADDRESS}/simple/price?ids=aeternity&vs_currencies=usd&include_24hr_change=true`)
cache.put(CACHE_KEY_PRICE_DATA, data.aeternity, MARKET_STATS_CACHE_TTL)
isMarketCapAvailable.value = true
} catch (e) {
isMarketCapAvailable.value = false
}
}

const cachedAeternityPriceData = cache.get(CACHE_KEY_PRICE_DATA)
Expand All @@ -64,5 +70,6 @@ export const useMarketStatsStore = defineStore('marketStats', () => {
marketCap,
distribution,
distributionPercentage,
isMarketCapAvailable,
}
})
16 changes: 12 additions & 4 deletions src/stores/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ export const useStatus = defineStore('status', () => {
const nodeStatus = ref(null)

async function fetchMdwStatus() {
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/status`)
middlewareStatus.value = data
try {
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/status`)
middlewareStatus.value = data
} catch (e) {
middlewareStatus.value = false
}
}

async function fetchNodeStatus() {
const { data } = await axios.get(`${NODE_URL}/v3/status`)
nodeStatus.value = data
try {
const { data } = await axios.get(`${NODE_URL}/v3/status`)
nodeStatus.value = data
} catch (e) {
nodeStatus.value = false
}
}

const isSyncing = computed(() => {
Expand Down

0 comments on commit 145722e

Please sign in to comment.