Skip to content

Commit

Permalink
Merge pull request #88 from RealToken-Community/develop
Browse files Browse the repository at this point in the history
chore: release v2.4.1
  • Loading branch information
jycssu-com authored Oct 23, 2024
2 parents 2f930b5 + 3048c6f commit d8628cb
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 68 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "realtoken-dashboard-v2",
"version": "2.4.0",
"version": "2.4.1",
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/rmm.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const getBalanceOfStableRMM3 = useCacheWithLocalStorage(
}
},
{
duration: 1000 * 60 * 60, // 1 hour
duration: 1000 * 60 * 60 * 24, // 24 hours
key: 'BalanceOfStableRMM3',
usePreviousValueOnError: true,
},
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/subgraphs/queries/levinswap.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const executeQuery = useCacheWithLocalStorage(
variables: { addressList },
}),
{
duration: 1000 * 60 * 60 * 12, // 12 hours
duration: 1000 * 60 * 60 * 24, // 24 hours
usePreviousValueOnError: true,
key: 'LevinSwapQuery',
},
Expand Down
21 changes: 11 additions & 10 deletions src/repositories/subgraphs/queries/realtoken.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ export async function getRealtokenBalances(
addressList: string[],
options: { includesEth?: boolean } = {},
) {
const [gnosisResult, ethereumResult] = await executeQuery(
return executeQuery(
addressList.map((item) => item.toLowerCase()),
options,
)

return {
gnosis: formatBalances(gnosisResult.data.accounts),
ethereum: formatBalances(ethereumResult.data.accounts),
}
}

const executeQuery = useCacheWithLocalStorage(
async (addressList: string[], options: { includesEth?: boolean } = {}) =>
Promise.all([
async (addressList: string[], options: { includesEth?: boolean } = {}) => {
const [gnosisResult, ethereumResult] = await Promise.all([
GnosisClient().query<RealtokenResult>({
query: RealtokenQuery,
variables: { addressList },
Expand All @@ -32,9 +27,15 @@ const executeQuery = useCacheWithLocalStorage(
variables: { addressList },
})
: Promise.resolve({ data: { accounts: [] } }),
]),
])

return {
gnosis: formatBalances(gnosisResult.data.accounts),
ethereum: formatBalances(ethereumResult.data.accounts),
}
},
{
duration: 1000 * 60 * 60, // 1 hour
duration: 1000 * 60 * 60 * 24, // 24 hours
usePreviousValueOnError: true,
key: 'RealtokenQuery',
},
Expand Down
4 changes: 2 additions & 2 deletions src/repositories/subgraphs/queries/rmm.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const executeRMM2Query = useCacheWithLocalStorage(
variables: { addressList },
}),
{
duration: 1000 * 60 * 60 * 12, // 12 hours
duration: 1000 * 60 * 60 * 24, // 24 hours
usePreviousValueOnError: true,
key: 'Rmm2Query',
},
Expand Down Expand Up @@ -80,7 +80,7 @@ const executeRMM3Query = useCacheWithLocalStorage(
}
},
{
duration: 1000 * 60 * 60, // 1 hour
duration: 1000 * 60 * 60 * 24, // 24 hours
usePreviousValueOnError: true,
key: 'Rmm3Query',
},
Expand Down
33 changes: 18 additions & 15 deletions src/repositories/subgraphs/queries/user.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import { useCacheWithLocalStorage } from 'src/utils/useCache'
import { GnosisClient } from '../clients'

export async function getUserId(address: string): Promise<string | null> {
const result = await executeGetUserIdQuery(address.toLowerCase())
return result.data.account.userIds[0].userId ?? null
return executeGetUserIdQuery(address.toLowerCase())
}

export async function getUserDetails(id: string) {
const trustedIntermediary = '0x296033cb983747b68911244ec1a3f01d7708851b'
const userId = `${trustedIntermediary}-${id}`
const result = await executeGetUserDetailsQuery(userId)
return { id, ...formatUserDetails(result.data) }
return executeGetUserDetailsQuery(id)
}

function formatUserDetails(result: GetUserDetailsResult) {
Expand All @@ -32,26 +28,33 @@ function formatUserDetails(result: GetUserDetailsResult) {
}

const executeGetUserIdQuery = useCacheWithLocalStorage(
async (address: string) =>
GnosisClient().query<GetUserIdResult>({
async (address: string) => {
const response = await GnosisClient().query<GetUserIdResult>({
query: GetUserIdQuery,
variables: { address },
}),
})

return response.data.account.userIds[0].userId ?? null
},
{
duration: 1000 * 60 * 60 * 24, // 1 day
duration: 1000 * 60 * 60 * 24 * 7, // 7 days
key: 'GetUserIdQuery',
usePreviousValueOnError: true,
},
)

const executeGetUserDetailsQuery = useCacheWithLocalStorage(
async (userId: string) =>
GnosisClient().query<GetUserDetailsResult>({
async (userId: string) => {
const trustedIntermediary = '0x296033cb983747b68911244ec1a3f01d7708851b'
const response = await GnosisClient().query<GetUserDetailsResult>({
query: GetUserDetailsQuery,
variables: { userId },
}),
variables: { userId: `${trustedIntermediary}-${userId}` },
})

return { id: userId, ...formatUserDetails(response.data) }
},
{
duration: 1000 * 60 * 60 * 24, // 1 day
duration: 1000 * 60 * 60 * 24 * 7, // 7 days
key: 'GetUserDetailsQuery',
usePreviousValueOnError: true,
},
Expand Down
53 changes: 26 additions & 27 deletions src/repositories/subgraphs/queries/yam.queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,43 @@ const STABLE_TOKENS = [
]

export async function getRealtokenYamStatistics(address: string) {
const result = await executeQuery(address)
return result.data.token ? formatStatistics(result.data.token) : []
const result = await executeQuery()
return result.find((item) => item.address === address)?.value ?? []
}

const executeQuery = useCacheWithLocalStorage(
async (address: string) =>
YamStatisticsClient().query<YamStatisticsResult>({
async () => {
const response = await YamStatisticsClient().query<YamStatisticsResult>({
query: YamStatisticsQuery,
variables: {
address,
limitDate: getLastMonthDate(),
stables: STABLE_TOKENS,
},
}),
})

return (
response.data?.tokens?.map((item) => ({
address: item.id,
value: formatStatistics(item),
})) ?? []
)
},
{
duration: 1000 * 60 * 60, // 1 hour
duration: 1000 * 60 * 60 * 24 * 7, // 7 days
usePreviousValueOnError: true,
key: 'YamStatisticsQuery',
},
)

const YamStatisticsQuery = gql`
query GetTokenVolumes(
$address: String!
$stables: [String!]
$limitDate: String!
) {
token(id: $address) {
query GetTokenVolumes($stables: [String!], $limitDate: String!) {
tokens(first: 1000) {
id
decimals
volumes(where: { token_in: $stables }) {
token {
decimals
}
quantity
volume
volumeDays(
orderBy: date
orderDirection: desc
Expand All @@ -61,19 +63,18 @@ const YamStatisticsQuery = gql`
`

interface YamStatisticsResult {
token: {
tokens: {
id: string
decimals: string
volumes: {
token: { decimals: string }
quantity: string
volume: string
volumeDays: {
date: string
quantity: string
volume: string
}[]
}[]
}
}[]
}

function getLastMonthDate() {
Expand All @@ -85,15 +86,13 @@ function getLastMonthDate() {
return `${year}-${month}-${day}`
}

function formatStatistics(statistics: YamStatisticsResult['token']) {
function formatStatistics(statistics: YamStatisticsResult['tokens'][0]) {
const decimals = parseInt(statistics.decimals)
return statistics.volumes.map((volume) => ({
quantity: parseFloat(volume.quantity) / 10 ** decimals,
volume: parseFloat(volume.volume) / 10 ** parseInt(volume.token.decimals),
volumeDays: volume.volumeDays.map((day) => ({
return statistics.volumes.flatMap((volume) =>
volume.volumeDays.map((day) => ({
date: day.date,
quantity: parseFloat(day.quantity) / 10 ** decimals,
volume: parseFloat(day.volume) / 10 ** parseInt(volume.token.decimals),
qte: parseFloat(day.quantity) / 10 ** decimals,
vol: parseFloat(day.volume) / 10 ** parseInt(volume.token.decimals),
})),
}))
)
}
16 changes: 6 additions & 10 deletions src/repositories/yamStatistics.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ export async function GetYamStatistics(params: {

const volumes = await getRealtokenYamStatistics(address)

const parsedValues = volumes
.map((volume) =>
volume.volumeDays.map((volumeDay) => ({
date: volumeDay.date,
quantity: volumeDay.quantity,
volume: volumeDay.volume,
average: volumeDay.volume / volumeDay.quantity,
})),
)
.flat()
const parsedValues = volumes.map((item) => ({
date: item.date,
quantity: item.qte,
volume: item.vol,
average: item.vol / item.qte,
}))

const groupedValues = Object.values(_groupBy(parsedValues, 'date')).map(
(item) => ({
Expand Down
5 changes: 5 additions & 0 deletions src/store/features/settings/settingsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RentCalculation,
RentCalculationState,
} from 'src/types/RentCalculation'
import { expiresLocalStorageCaches } from 'src/utils/useCache'

const USER_LS_KEY = 'store:settings/user'
const USER_CURRENCY_LS_KEY = 'store:settings/userCurrency'
Expand Down Expand Up @@ -249,6 +250,10 @@ export const settingsReducers = createReducer(
publicRuntimeConfig?: { version: string }
}
const version = publicRuntimeConfig?.version ?? ''
const lastVersionUsed = localStorage.getItem('lastVersionUsed')
if (lastVersionUsed && lastVersionUsed !== version) {
expiresLocalStorageCaches()
}
localStorage.setItem('lastVersionUsed', version)
state.version = version

Expand Down

0 comments on commit d8628cb

Please sign in to comment.