Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Dex Trades per Token #876

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
d766a9e
add basic listing
janmichek Aug 1, 2024
cbddcd9
fix formatting values
janmichek Aug 5, 2024
6ba863b
move formatting functions
janmichek Aug 5, 2024
9a1f257
add loading
janmichek Aug 5, 2024
538c21a
change url
janmichek Aug 5, 2024
3cd62c7
add hints
janmichek Aug 5, 2024
d9d231a
add hint
janmichek Aug 5, 2024
2dab287
revert unwanted changes
janmichek Aug 5, 2024
e13a2a6
reuse action from response
janmichek Aug 20, 2024
aa7ea2a
revert unused code
janmichek Aug 21, 2024
7028fa8
reformat code
janmichek Aug 21, 2024
821e5e1
add basic UI
janmichek Jun 13, 2024
47c11a8
fix code style
janmichek Jun 13, 2024
337355f
merge stores
janmichek Jun 13, 2024
a8e99e6
display swap time
janmichek Jun 17, 2024
deb712c
print formatted values
janmichek Jun 18, 2024
9dd0be6
fix loading and fetching
janmichek Jun 18, 2024
a850ead
refactor naming
janmichek Jun 18, 2024
a792317
add basic UI
janmichek Aug 6, 2024
4953cbb
add mobile view
janmichek Aug 7, 2024
a2ad18c
add mobile view
janmichek Aug 7, 2024
2246022
add test
janmichek Aug 7, 2024
4cd67c5
fix test selector
janmichek Aug 7, 2024
8cc6291
fixes after rebase
janmichek Aug 22, 2024
e92c838
fix renamed attribute
janmichek Sep 3, 2024
9f5dff5
fix indent
janmichek Oct 8, 2024
d592341
add missing counter
janmichek Oct 8, 2024
5488339
add commnet
janmichek Oct 8, 2024
fe6a8ad
fixes after rebase
janmichek Nov 21, 2024
345edcd
fixes after rebase
janmichek Nov 21, 2024
1be2388
fixes after rebase
janmichek Nov 21, 2024
c2c628e
fixes after rebase
janmichek Nov 21, 2024
53fdf0a
fix markup
janmichek Nov 21, 2024
bec22fb
revert missing code
janmichek Nov 21, 2024
86def22
chenge dex link
janmichek Nov 21, 2024
9224640
change dex link
janmichek Nov 21, 2024
5dd1ec4
cleanup code
janmichek Nov 21, 2024
7ee1d60
fix price condition
janmichek Dec 10, 2024
cdf954f
fix pagination
janmichek Dec 13, 2024
596729d
increase test timeout
janmichek Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cypress/e2e/app/tokenDetail.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ describe('token detail', () => {

cy.contains('.tabs__item', 'Events').click()
cy.get('.token-events-panel .paginated-content').should('be.visible')

cy.contains('.tabs__item', 'Trades').click()
cy.get('.token-trades-panel .paginated-content').should('be.visible')
})

it('should display token not found', () => {
Expand Down
183 changes: 93 additions & 90 deletions src/components/DexTradesTable.vue
Original file line number Diff line number Diff line change
@@ -1,97 +1,100 @@
<template>
<table class="dex-trades-table">
<tr>
<th>
Hash
<hint-tooltip>
{{ dexTradesHints.hash }}
</hint-tooltip>
</th>
<th>
<time-toggle-button>Executed</time-toggle-button>
<hint-tooltip>
{{ dexTradesHints.executed }}
</hint-tooltip>
</th>
<th>
Action
<hint-tooltip>
{{ dexTradesHints.action }}
</hint-tooltip>
</th>
<thead>
<tr>
<th>
Hash
<hint-tooltip>
{{ dexTradesHints.hash }}
</hint-tooltip>
</th>
<th>
<time-toggle-button>Executed</time-toggle-button>
<hint-tooltip>
{{ dexTradesHints.executed }}
</hint-tooltip>
</th>
<th>
Action
<hint-tooltip>
{{ dexTradesHints.action }}
</hint-tooltip>
</th>

<th>
Token Amount (Out)
<hint-tooltip>
{{ dexTradesHints.tokenAmountOut }}
</hint-tooltip>
</th>
<th>
Token Amount (Out)
<hint-tooltip>
{{ dexTradesHints.tokenAmountOut }}
</hint-tooltip>
</th>

<th>
Token Amount (In)
<hint-tooltip>
{{ dexTradesHints.tokenAmountIn }}
</hint-tooltip>
</th>
<th>
Swapped Rate
<hint-tooltip>
{{ dexTradesHints.swappedRate }}
</hint-tooltip>
</th>
<th>
Value
<hint-tooltip>
{{ dexTradesHints.value }}
</hint-tooltip>
</th>
</tr>

<tr
v-for="trade in trades.data"
:key="trade.txHash">
<td>
<value-hash-ellipsed
:link-to="`/transactions/${trade.txHash}`"
:hash="trade.txHash"/>
</td>
<td>
<block-time-cell
:height="trade.height"
:timestamp="trade.timestamp"/>
</td>
<td>
<app-chip :variant="getChipVariant(trade.action)">
{{ trade.action }}
</app-chip>
</td>
<td>
<price-label
:contract-id="trade.fromContract"
:currency="trade.fromToken"
:price="trade.fromAmount"
:max-digits="4"
:has-link="true"/>
</td>
<td>
<price-label
:contract-id="trade.toContract"
:currency="trade.toToken"
:price="trade.toAmount"
:max-digits="4"
:has-link="true"/>
</td>
<td>
<not-available-label v-if="!trade.rate"/>
{{ trade.rate }}
</td>
<td>
<not-available-label v-if="!trade.value"/>
<template v-else>
$ {{ trade.value }}
</template>
</td>
</tr>
<th>
Token Amount (In)
<hint-tooltip>
{{ dexTradesHints.tokenAmountIn }}
</hint-tooltip>
</th>
<th>
Swapped Rate
<hint-tooltip>
{{ dexTradesHints.swappedRate }}
</hint-tooltip>
</th>
<th>
Value
<hint-tooltip>
{{ dexTradesHints.value }}
</hint-tooltip>
</th>
</tr>
</thead>
<tbody>
<tr
v-for="trade in trades.data"
:key="trade.txHash">
<td>
<value-hash-ellipsed
:link-to="`/transactions/${trade.txHash}`"
:hash="trade.txHash"/>
</td>
<td>
<block-time-cell
:height="trade.height"
:timestamp="trade.timestamp"/>
</td>
<td>
<app-chip :variant="getChipVariant(trade.action)">
{{ trade.action }}
</app-chip>
</td>
<td>
<price-label
:contract-id="trade.fromContract"
:currency="trade.fromToken"
:price="trade.fromAmount"
:max-digits="4"
:has-link="true"/>
</td>
<td>
<price-label
:contract-id="trade.toContract"
:currency="trade.toToken"
:price="trade.toAmount"
:max-digits="4"
:has-link="true"/>
</td>
<td>
<not-available-label v-if="!trade.rate"/>
{{ trade.rate }}
</td>
<td>
<not-available-label v-if="!trade.value"/>
<template v-else>
$ {{ trade.value }}
</template>
</td>
</tr>
</tbody>
</table>
</template>

Expand Down
6 changes: 3 additions & 3 deletions src/components/TimeToggleButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</template>

<script setup>
import { useAppStore } from '@/stores/app'
import { useUiStore } from '@/stores/ui'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to the feature, renamed confusing store name. App is too general


const { toggleTimeFormat } = useAppStore()
const { timeFormat } = storeToRefs(useAppStore())
const { toggleTimeFormat } = useUiStore()
const { timeFormat } = storeToRefs(useUiStore())
const suffix = computed(() => {
return timeFormat.value === 'relative' ? 'Age' : 'Time'
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/TimestampLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import { DateTime, Duration } from 'luxon'
import { DATETIME_UNITS } from '@/utils/constants'

import { useAppStore } from '@/stores/app'
import { useUiStore } from '@/stores/ui'

const { timeFormat } = storeToRefs(useAppStore())
const { timeFormat } = storeToRefs(useUiStore())

const props = defineProps({
timestamp: {
Expand Down
39 changes: 39 additions & 0 deletions src/components/TokenTradesPanel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<app-panel class="token-trades-panel">
<paginated-content
:entities="tokenTrades"
pagination-style="history"
@prev-clicked="loadPrevEvents"
@next-clicked="loadNextEvents">
<dex-trades-table
:trades="tokenTrades"
class="u-hidden-mobile"/>
<dex-trades-table-condensed
:trades="tokenTrades"
class="u-hidden-desktop"/>
</paginated-content>
</app-panel>
</template>
<script setup>

const tokenDetailsStore = useTokenDetailsStore()
const { tokenTrades } = storeToRefs(tokenDetailsStore)
const { fetchTokenTrades } = tokenDetailsStore
const route = useRoute()

function loadPrevEvents() {
fetchTokenTrades({ queryParameters: tokenTrades.value.prev })
}

function loadNextEvents() {
fetchTokenTrades({ queryParameters: tokenTrades.value.next })
}

if (process.client) {
const limit = computed(() => isDesktop() ? 10 : 3)
await fetchTokenTrades({
contractId: route.params.id,
limit: limit.value,
})
}
</script>
5 changes: 4 additions & 1 deletion src/pages/tokens/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<app-tab title="Events">
<token-events-panel/>
</app-tab>
<app-tab title="Trades">
<token-trades-panel/>
</app-tab>
</app-tabs>
</template>
<loader-panel v-else/>
Expand All @@ -40,7 +43,7 @@ const { tokenDetails, tokenHoldersCount } = storeToRefs(tokenDetailsStore)
const { fetchTokenDetails } = tokenDetailsStore

const { isLoading } = useLoading()
const TAB_KEYS = ['holders', 'events']
const TAB_KEYS = ['holders', 'events', 'trades']

const activeTabIndex = computed({
get() {
Expand Down
12 changes: 0 additions & 12 deletions src/stores/app.js

This file was deleted.

3 changes: 1 addition & 2 deletions src/stores/dex.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export const useDexStore = defineStore('dex', () => {
return 1
}

const { data } = await axios.get(`${DEX_BACKEND_URL}/pairs/swap-routes/${tokenId}/${AE_TOKEN_ID}`)

const { data } = await axios.get(`${DEX_BACKEND_URL}/swap-routes/${tokenId}/${AE_TOKEN_ID}`)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dex changed link just today

if (data.length === 0) {
return false
}
Expand Down
25 changes: 22 additions & 3 deletions src/stores/tokenDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useTokenDetailsStore = defineStore('tokenDetails', () => {
const rawTotalSupply = ref(null)
const rawTokenHolders = ref(null)
const tokenHoldersCount = ref(null)
const rawTokenTrades = ref(null)

const tokenDetails = computed(() => rawToken.value
? adaptTokenDetails(
Expand Down Expand Up @@ -54,11 +55,18 @@ export const useTokenDetailsStore = defineStore('tokenDetails', () => {

return Promise.all([
tokenPromise,
fetchTotalSupply(),
tokenPromise.then(() => fetchTokenPrice()),
Promise.allSettled([
fetchTotalSupply(),
tokenPromise.then(() => fetchTokenPrice()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't tokenPromise called two times?

]),
])
}

const tokenTrades = computed(() => rawTokenTrades.value && price.value
? adaptTrades(rawTokenTrades.value, price.value)
: null,
)

async function fetchTokenPrice() {
price.value = await fetchPrice(tokenId.value, rawToken.value.decimals)
}
Expand Down Expand Up @@ -99,15 +107,26 @@ export const useTokenDetailsStore = defineStore('tokenDetails', () => {
tokenHoldersCount.value = data.holders
}

async function fetchTokenTrades() {
rawTokenTrades.value = null
const { data } = await axios.get(`${MIDDLEWARE_URL}/v3/dex/${tokenId.value}/swaps`)
console.log('data', data)
rawTokenTrades.value = data

console.log('price.value', price.value)
}

return {
fetchTokenDetails,
fetchTokenHolders,
tokenHoldersCount,
fetchTokenEvents,
fetchTokenHoldersCount,
fetchTokenHoldersCount, // todo eventcounter
fetchTokenTrades,
tokenDetails,
tokenHolders,
tokenEvents,
tokenEventsCount,
tokenTrades,
}
})
8 changes: 8 additions & 0 deletions src/stores/ui.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { defineStore } from 'pinia'

export const useUiStore = defineStore('ui', () => {
const isMobileMenuOpen = ref(false)
const timeFormat = ref('relative')

function toggleTimeFormat() {
timeFormat.value = timeFormat.value === 'absolute' ? 'relative' : 'absolute'
}

return {
isMobileMenuOpen,
timeFormat,
toggleTimeFormat,
}
})
3 changes: 1 addition & 2 deletions src/utils/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
formatTemplateLimit,
formatTokenLimit,
formatTradeRate,
formatTradeValue,
} from '@/utils/format'

import { MINUTES_PER_BLOCK, SPECIAL_POINTERS_PRESET_KEYS } from '@/utils/constants'
Expand Down Expand Up @@ -438,8 +439,6 @@ export function adaptTokenEvents(events) {
}

export function adaptTokenHolders(tokenHolders, tokenDetails) {
console.log('tokenDetails', tokenDetails)
console.log('tokenHolders', tokenHolders)
const formattedData = tokenHolders.data
.map(holder => {
const percentage = (new BigNumber(holder.amount)
Expand Down
Loading