Skip to content

Commit

Permalink
feat: move more content to rendering on the server-side (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeromanowicz authored Apr 24, 2023
1 parent f93f844 commit 878fb3b
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 48 deletions.
6 changes: 2 additions & 4 deletions src/components/AppHero.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
<the-search-bar class="hero__search-bar"/>
</div>
</div>
<client-only>
<market-stats class="hero__market-stats"/>
<stats-panel/>
</client-only>
<market-stats class="hero__market-stats"/>
<stats-panel/>
</div>
</div>
</template>
Expand Down
8 changes: 2 additions & 6 deletions src/components/TokenDetailsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
Price
</th>
<td class="token-details-panel__data">
<client-only>
{{ fiatPrice }} ({{ formatAePrice(tokenDetails.price) }})
</client-only>
{{ fiatPrice }} ({{ formatAePrice(tokenDetails.price) }})
</td>
</tr>
<tr
Expand All @@ -40,9 +38,7 @@
Market cap
</th>
<td class="token-details-panel__data">
<client-only>
{{ marketCap }}
</client-only>
{{ marketCap }}
</td>
</tr>
<tr class="token-details-panel__row">
Expand Down
2 changes: 1 addition & 1 deletion src/components/TokensPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function loadNextTokens() {
const limit = computed(() => process.client && isDesktop() ? 10 : 3)
if (process.client) {
await fetchTokens(`/v2/aex9?by=name&direction=forward&limit=${limit.value}`)
fetchTokens(`/v2/aex9?by=name&direction=forward&limit=${limit.value}`)
}
</script>
Expand Down
57 changes: 29 additions & 28 deletions src/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
The æternity blockchain supports protocol-level .chain names via the
æternity naming system (AENS).
</div>
<client-only>
<names-panel/>
</client-only>
<names-panel/>
</div>
<div class="dashboard__column">
<h2 class="dashboard__heading">
Expand All @@ -51,9 +49,7 @@
.chain names can be obtained either immediately or via an auction
process, if shorter than 13 characters.
</div>
<client-only>
<auctions-panel>Auctions ending soon</auctions-panel>
</client-only>
<auctions-panel>Auctions ending soon</auctions-panel>
</div>
</div>

Expand All @@ -72,9 +68,7 @@
Learn more
</app-link>
</div>
<client-only>
<state-channels-panel class="dashboard__state-channels-panel"/>
</client-only>
<state-channels-panel class="dashboard__state-channels-panel"/>
</div>
</div>
</div>
Expand All @@ -89,25 +83,32 @@ import StateChannelsPanel from '@/components/StateChannelsPanel'
import AppHero from '@/components/AppHero'
import AppLink from '@/components/AppLink'
if (process.client) {
const {
fetchSelectedMicroblocksInfo,
fetchDeltaStats,
} = useRecentBlocksStore()
const { fetchBlockchainStats } = useBlockchainStatsStore()
const { fetchStateChannels } = useStateChannelsStore()
const { fetchInAuctionNames, fetchRecentlyActivatedNames } = useNamesStore()
// fetch client-side only due to very dynamic nature of the data and limit difference depending on desktop/mobile view
await useAsyncData(() => Promise.all([
fetchStateChannels(),
fetchInAuctionNames(),
fetchRecentlyActivatedNames(),
fetchSelectedMicroblocksInfo(),
fetchBlockchainStats(),
fetchDeltaStats(),
]))
}
const {
fetchSelectedMicroblocksInfo,
fetchDeltaStats,
} = useRecentBlocksStore()
const {
fetchTotalStats,
fetchMaxTps,
fetchTotalTransactionsCount,
} = useBlockchainStatsStore()
const { fetchStateChannels } = useStateChannelsStore()
const { fetchInAuctionNames, fetchRecentlyActivatedNames } = useNamesStore()
await useAsyncData(() => Promise.all([
fetchStateChannels(),
fetchInAuctionNames(),
fetchRecentlyActivatedNames(),
fetchTotalStats(),
fetchMaxTps(),
]))
// fetch client-side only due to very dynamic nature of the data and limit difference depending on desktop/mobile view
await useAsyncData(() => Promise.all([
fetchSelectedMicroblocksInfo(),
fetchTotalTransactionsCount(),
fetchDeltaStats(),
]), { server: false })
</script>

<style scoped>
Expand Down
7 changes: 0 additions & 7 deletions src/stores/blockchainStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ export const useBlockchainStatsStore = defineStore('blockchainStats', {
burnedCount: null,
}),
actions: {
fetchBlockchainStats() {
return Promise.all([
this.fetchTotalStats(),
this.fetchMaxTps(),
this.fetchTotalTransactionsCount(),
])
},
async fetchTotalStats() {
const { data } = await axios.get(`${useRuntimeConfig().public.MIDDLEWARE_URL}/v2/totalstats?limit=1`)
const lastBlock = data.data[0]
Expand Down
6 changes: 4 additions & 2 deletions src/stores/contractDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export const useContractDetailsStore = defineStore('contractDetails', {
rawContractCallTransactions: null,
}),
actions: {
fetchContractDetails(contractId) {
async fetchContractDetails(contractId) {
this.contractId = contractId
return Promise.allSettled([
await Promise.allSettled([
this.fetchContractInformation(),
this.fetchContractCallsCount(),
this.fetchContractCreationTx(),
this.fetchContractType(),
])

return true
},
async fetchContractInformation() {
this.rawContractInformation = null
Expand Down

0 comments on commit 878fb3b

Please sign in to comment.