Skip to content

Commit

Permalink
Merge pull request #722 from invariant-labs/staging
Browse files Browse the repository at this point in the history
Sync prod env
  • Loading branch information
wojciech-cichocki authored Sep 3, 2024
2 parents 07e4470 + 5fb8778 commit 6c70f77
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
14 changes: 7 additions & 7 deletions src/containers/WrappedStats/WrappedStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export const WrappedStats: React.FC = () => {
<Grid container className={classes.row}>
<TokensList
data={tokensList.map(tokenData => ({
icon: tokenData.tokenDetails.logoURI,
name: tokenData.tokenDetails.name,
symbol: tokenData.tokenDetails.symbol,
icon: tokenData.tokenDetails?.logoURI,
name: tokenData.tokenDetails?.name,
symbol: tokenData.tokenDetails?.symbol,
price: tokenData.price,
volume: tokenData.volume24,
TVL: tokenData.tvl
Expand All @@ -128,10 +128,10 @@ export const WrappedStats: React.FC = () => {
<Typography className={classes.subheader}>Top pools</Typography>
<PoolList
data={poolsList.map(poolData => ({
symbolFrom: poolData.tokenXDetails.symbol,
symbolTo: poolData.tokenYDetails.symbol,
iconFrom: poolData.tokenXDetails.logoURI,
iconTo: poolData.tokenYDetails.logoURI,
symbolFrom: poolData.tokenXDetails?.symbol,
symbolTo: poolData.tokenYDetails?.symbol,
iconFrom: poolData.tokenXDetails?.logoURI,
iconTo: poolData.tokenYDetails?.logoURI,
volume: poolData.volume24,
TVL: poolData.tvl,
fee: poolData.fee,
Expand Down
55 changes: 28 additions & 27 deletions src/store/sagas/stats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { actions, PoolStatsData, TimeData, TokenStatsData } from '@reducers/stats'
import { call, put, select, takeEvery } from 'typed-redux-saga'
import { all, call, put, select, takeEvery } from 'typed-redux-saga'
import { network, rpcAddress } from '@selectors/solanaConnection'
import {
getJupPricesData,
Expand All @@ -21,8 +21,10 @@ export function* getStats(): Generator {
const connection = yield* call(getConnection)
const currentNetwork = yield* select(network)
const rpc = yield* select(rpcAddress)
const data = yield* call(getNetworkStats, currentNetwork.toLowerCase())
const poolsApy = yield* call(getPoolsAPY, currentNetwork.toLowerCase())
const { data, poolsApy } = yield* all({
data: call(getNetworkStats, currentNetwork.toLowerCase()),
poolsApy: call(getPoolsAPY, currentNetwork.toLowerCase())
})

const marketProgram = yield* call(getMarketProgram, currentNetwork, rpc)

Expand All @@ -36,24 +38,6 @@ export function* getStats(): Generator {
poolsDataObject[pool.address.toString()] = pool
})

let allTokens = yield* select(tokens)

const unknownTokens = new Set<PublicKey>()

allPoolsData.forEach(pool => {
if (!allTokens[pool.tokenX.toString()]) {
unknownTokens.add(pool.tokenX)
}

if (!allTokens[pool.tokenY.toString()]) {
unknownTokens.add(pool.tokenY)
}
})

const newTokens = yield* call(getFullNewTokensData, [...unknownTokens], connection)
yield* put(poolsActions.addTokens(newTokens))
allTokens = yield* select(tokens)

const volume24 = {
value: 0,
change: 0
Expand Down Expand Up @@ -116,17 +100,17 @@ export function* getStats(): Generator {
return
}

const tokenX = allTokens[poolsDataObject[address].tokenX.toString()]
const tokenY = allTokens[poolsDataObject[address].tokenY.toString()]
const tokenX = poolsDataObject[address].tokenX.toString()
const tokenY = poolsDataObject[address].tokenY.toString()

const lastSnapshot = snapshots[snapshots.length - 1]

tokensDataObject[tokenX.address.toString()].volume24 +=
tokensDataObject[tokenX].volume24 +=
lastSnapshot.timestamp === lastTimestamp ? lastSnapshot.volumeX.usdValue24 : 0
tokensDataObject[tokenY.address.toString()].volume24 +=
tokensDataObject[tokenY].volume24 +=
lastSnapshot.timestamp === lastTimestamp ? lastSnapshot.volumeY.usdValue24 : 0
tokensDataObject[tokenX.address.toString()].tvl += lastSnapshot.liquidityX.usdValue24
tokensDataObject[tokenY.address.toString()].tvl += lastSnapshot.liquidityY.usdValue24
tokensDataObject[tokenX].tvl += lastSnapshot.liquidityX.usdValue24
tokensDataObject[tokenY].tvl += lastSnapshot.liquidityY.usdValue24

poolsData.push({
volume24:
Expand Down Expand Up @@ -218,6 +202,23 @@ export function* getStats(): Generator {
liquidityPlot
})
)

const allTokens = yield* select(tokens)

const unknownTokens = new Set<PublicKey>()

allPoolsData.forEach(pool => {
if (!allTokens[pool.tokenX.toString()]) {
unknownTokens.add(pool.tokenX)
}

if (!allTokens[pool.tokenY.toString()]) {
unknownTokens.add(pool.tokenY)
}
})

const newTokens = yield* call(getFullNewTokensData, [...unknownTokens], connection)
yield* put(poolsActions.addTokens(newTokens))
} catch (error) {
console.log(error)
}
Expand Down

0 comments on commit 6c70f77

Please sign in to comment.