Skip to content

Commit

Permalink
feat: Server handlers aecoin (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
janmichek authored Jan 23, 2025
1 parent d5df11a commit e0c2464
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 156 deletions.
6 changes: 0 additions & 6 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,13 @@ export default defineNuxtConfig({
routeRules: {
'/proxy/avatar/**': { proxy: 'https://avatars.z52da5wt.xyz/**', cors: true },
'/proxy/nodes': { proxy: 'http://138.68.22.27:3113/v2/debug/network', cors: true },
'/proxy/gate': { proxy: 'https://api.gateio.ws/api/v4/spot/tickers?currency_pair=AE_USDT', cors: true },
'/proxy/mexc': { proxy: 'https://api.mexc.com/api/v3/ticker/24hr?symbol=AEUSDT', cors: true },
'/proxy/coinw': { proxy: 'https://api.coinw.com/api/v1/public?command=returnTicker', cors: true },
},
},
modules: [
'@pinia/nuxt',
'@nuxtjs/plausible',
'nuxt-monaco-editor',
],
imports: {
dirs: ['./stores'],
},
plausible: {
apiHost: process.env.PLAUSIBLE_URL,
trackLocalhost: false,
Expand Down
24 changes: 4 additions & 20 deletions src/components/AeCoinMarketsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,17 @@
<template v-else>
<ae-coin-markets-table
class="u-hidden-mobile"
:gate="gate"
:mexc="mexc"
:hot-coin="hotCoin"
:coin-store="coinStore"
:coin-w="coinW"/>
:coin-markets="coinMarkets"/>
<ae-coin-markets-table-condensed
class="u-hidden-desktop"
:gate="gate"
:mexc="mexc"
:hot-coin="hotCoin"
:coin-store="coinStore"
:coin-w="coinW"/>
:coin-markets="coinMarkets"/>
</template>
</app-panel>
</template>

<script setup>
const aeCoinStore = useAeCoinStore()
const { fetchMarketStats } = aeCoinStore
const {
gate,
mexc,
hotCoin,
coinStore,
coinW,
isLoading,
} = storeToRefs(aeCoinStore)
const { fetchMarketStats } = useAeCoinStore()
const { isLoading, coinMarkets } = storeToRefs(useAeCoinStore())
await useAsyncData(async() => {
await fetchMarketStats()
Expand Down
38 changes: 11 additions & 27 deletions src/components/AeCoinMarketsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,32 @@
<tr>
<td>Gate.io</td>
<td>AE / USDT</td>
<td>$ {{ formatNullable(formatNumber(gate?.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(gate?.volume)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.gate.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.gate.volume)) }}</td>
</tr>
<tr>
<td>Mexc</td>
<td>AE / USDT</td>
<td>$ {{ formatNullable(formatNumber(mexc?.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(mexc?.volume)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.mexc.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.mexc.volume)) }}</td>
</tr>
<tr>
<td>HotCoin</td>
<td>AE / USDT</td>
<td>$ {{ formatNullable(formatNumber(hotCoin?.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(hotCoin?.volume)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.hotcoin.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.hotcoin.volume)) }}</td>
</tr>
<tr>
<td>CoinStore</td>
<td>AE / USDT</td>
<td>$ {{ formatNullable(formatNumber(coinStore?.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinStore?.volume)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.coinstore.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.coinstore.volume)) }}</td>
</tr>
<tr>
<td>CoinW</td>
<td>AE / USDT</td>
<td>$ {{ formatNullable(formatNumber(coinW?.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinW?.volume)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.coinw.price)) }}</td>
<td>$ {{ formatNullable(formatNumber(coinMarkets.coinw.volume)) }}</td>
</tr>
</tbody>
</table>
Expand All @@ -67,23 +67,7 @@
import { aeCoinHints } from '@/utils/hints/aeCoinHints'
defineProps({
gate: {
type: Object,
required: true,
},
mexc: {
type: Object,
required: true,
},
hotCoin: {
type: Object,
required: true,
},
coinStore: {
type: Object,
required: true,
},
coinW: {
coinMarkets: {
type: Object,
required: true,
},
Expand Down
38 changes: 11 additions & 27 deletions src/components/AeCoinMarketsTableCondensed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Price
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(gate?.price)) }}
$ {{ formatNullable(formatNumber(coinMarkets.gate.price)) }}
</td>
</tr>
<tr class="ae-coin-markets-table-condensed__row">
Expand All @@ -43,7 +43,7 @@
Volume (24h)
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(gate?.volume)) }}
$ {{ formatNullable(formatNumber(coinMarkets.gate.volume)) }}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -80,7 +80,7 @@
Price
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(mexc?.price)) }}
$ {{ formatNullable(formatNumber(coinMarkets.mexc.price)) }}
</td>
</tr>
<tr class="ae-coin-markets-table-condensed__row">
Expand All @@ -91,7 +91,7 @@
Volume (24h)
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(mexc?.volume)) }}
$ {{ formatNullable(formatNumber(coinMarkets.mexc.volume)) }}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -128,13 +128,13 @@
Price
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(hotCoin?.price)) }}
$ {{ formatNullable(formatNumber(coinMarkets.hotcoin.price)) }}
</td>
</tr>
<tr class="ae-coin-markets-table-condensed__row">
<th class="ae-coin-markets-table-condensed__header"/>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(hotCoin?.volume)) }}
$ {{ formatNullable(formatNumber(coinMarkets.hotcoin.volume)) }}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -171,7 +171,7 @@
Price
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(coinStore?.price)) }}
$ {{ formatNullable(formatNumber(coinMarkets.coinstore.price)) }}
</td>
</tr>
<tr class="ae-coin-markets-table-condensed__row">
Expand All @@ -182,7 +182,7 @@
Volume (24h)
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(coinStore?.volume)) }}
$ {{ formatNullable(formatNumber(coinMarkets.coinstore.volume)) }}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -219,7 +219,7 @@
Price
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(coinW?.price)) }}
$ {{ formatNullable(formatNumber(coinMarkets.coinw.price)) }}
</td>
</tr>
<tr class="ae-coin-markets-table-condensed__row">
Expand All @@ -230,7 +230,7 @@
Volume (24h)
</th>
<td class="ae-coin-markets-table-condensed__data">
$ {{ formatNullable(formatNumber(coinW?.volume)) }}
$ {{ formatNullable(formatNumber(coinMarkets.coinw.volume)) }}
</td>
</tr>
</tbody>
Expand All @@ -242,23 +242,7 @@
import { aeCoinHints } from '@/utils/hints/aeCoinHints'
defineProps({
gate: {
type: Object,
required: true,
},
mexc: {
type: Object,
required: true,
},
hotCoin: {
type: Object,
required: true,
},
coinStore: {
type: Object,
required: true,
},
coinW: {
coinMarkets: {
type: Object,
required: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/TheNavigation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const menuOptions = ref([{
submenu: [
{
name: 'AE Coin',
path: '/tokens/AE',
path: '/tokens/ae',
hidden: !featureFlags.marketStats,
},
{
Expand Down
81 changes: 6 additions & 75 deletions src/composables/aeCoin.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,17 @@
import cache from 'memory-cache'
import {
CACHE_KEY_COINSTORE_MARKET_DATA,
CACHE_KEY_COINW_MARKET_DATA,
CACHE_KEY_GATE_MARKET_DATA,
CACHE_KEY_HOTCOIN_MARKET_DATA,
CACHE_KEY_MEXC_MARKET_DATA,
MARKET_STATS_CACHE_TTL,
MARKET_STATS_COINSTORE_ADDRESS,
MARKET_STATS_HOTCOIN_ADDRESS,
} from '@/utils/constants'

export const useAeCoinStore = defineStore('aeCoin', () => {
const axios = useAxios()

const gate = ref(null)
const mexc = ref(null)
const hotCoin = ref(null)
const coinStore = ref(null)
const coinW = ref(null)

const coinMarkets = ref(null)
const isLoading = ref(true)

function fetchMarketStats() {
async function fetchMarketStats() {
isLoading.value = true
return Promise.allSettled([
fetchGate(),
fetchMexc(),
fetchHotCoin(),
fetchCoinStore(),
fetchCoinW(),
]).then(() => {
isLoading.value = false
})
}

async function fetchGate() {
if (!cache.get(CACHE_KEY_GATE_MARKET_DATA)) {
const { data } = await axios.get('/proxy/gate')
cache.put(CACHE_KEY_GATE_MARKET_DATA, adaptMarketStatsGate(data), MARKET_STATS_CACHE_TTL)
}
gate.value = cache.get(CACHE_KEY_GATE_MARKET_DATA)
}

async function fetchMexc() {
if (!cache.get(CACHE_KEY_MEXC_MARKET_DATA)) {
const { data } = await axios.get('/proxy/mexc')
cache.put(CACHE_KEY_MEXC_MARKET_DATA, adaptMarketStatsMexc(data), MARKET_STATS_CACHE_TTL)
}
mexc.value = cache.get(CACHE_KEY_MEXC_MARKET_DATA)
}

async function fetchCoinStore() {
if (!cache.get(CACHE_KEY_COINSTORE_MARKET_DATA)) {
const { data } = await axios.get(MARKET_STATS_COINSTORE_ADDRESS)
cache.put(CACHE_KEY_COINSTORE_MARKET_DATA, adaptMarketStatsCoinStore(data), MARKET_STATS_CACHE_TTL)
}
coinStore.value = cache.get(CACHE_KEY_COINSTORE_MARKET_DATA)
}

async function fetchHotCoin() {
if (!cache.get(CACHE_KEY_HOTCOIN_MARKET_DATA)) {
const { data } = await axios.get(MARKET_STATS_HOTCOIN_ADDRESS)
cache.put(CACHE_KEY_HOTCOIN_MARKET_DATA, adaptMarketStatsHotCoin(data), MARKET_STATS_CACHE_TTL)
}
hotCoin.value = cache.get(CACHE_KEY_HOTCOIN_MARKET_DATA)
}

async function fetchCoinW() {
if (!cache.get(CACHE_KEY_COINW_MARKET_DATA)) {
const { data } = await axios.get('/proxy/coinw')
cache.put(CACHE_KEY_COINW_MARKET_DATA, adaptMarketStatsCoinW(data), MARKET_STATS_CACHE_TTL)
}
coinW.value = cache.get(CACHE_KEY_COINW_MARKET_DATA)
const data = await $fetch('/api/tokens/ae')
coinMarkets.value = data
isLoading.value = false
}

return {
gate,
mexc,
hotCoin,
coinStore,
coinW,
isLoading,
coinMarkets,
fetchMarketStats,
}
})
File renamed without changes.
Loading

0 comments on commit e0c2464

Please sign in to comment.