Skip to content

Commit

Permalink
Don't include rewards tokens in the token list (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashimi36 authored Aug 28, 2022
1 parent 734e562 commit a310369
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
4 changes: 2 additions & 2 deletions features/liquidity/components/LiquidityRewardsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ export const LiquidityRewardsCard = ({
))}
{pendingRewardsRenderedInline?.map(({ tokenInfo, tokenAmount }) => (
<UnderlyingAssetRow
key={tokenInfo.symbol}
tokenSymbol={tokenInfo.symbol}
key={tokenInfo?.symbol}
tokenInfo={tokenInfo}
tokenAmount={tokenAmount}
/>
))}
Expand Down
10 changes: 2 additions & 8 deletions features/liquidity/components/ManageLiquidityCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,8 @@ export const ManageLiquidityCard = ({
Underlying assets
</Text>
<Column gap={6} css={{ paddingBottom: '$16' }}>
<UnderlyingAssetRow
tokenSymbol={tokenA.symbol}
tokenAmount={tokenAReserve}
/>
<UnderlyingAssetRow
tokenSymbol={tokenB.symbol}
tokenAmount={tokenBReserve}
/>
<UnderlyingAssetRow tokenInfo={tokenA} tokenAmount={tokenAReserve} />
<UnderlyingAssetRow tokenInfo={tokenB} tokenAmount={tokenBReserve} />
</Column>
<Inline css={{ paddingBottom: '$12' }}>
{didProvideLiquidity && (
Expand Down
15 changes: 8 additions & 7 deletions features/liquidity/components/UnderlyingAssetRow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useTokenDollarValue } from 'hooks/useTokenDollarValue'
import { useTokenInfo } from 'hooks/useTokenInfo'
import {
Button,
dollarValueFormatterWithDecimals,
Expand All @@ -12,20 +11,22 @@ import {
Tooltip,
} from 'junoblocks'

import { TokenInfo } from '../../../queries/usePoolsListQuery'

type UnderlyingAssetRowProps = {
tokenSymbol?: string
tokenInfo?: TokenInfo
tokenAmount?: number
visible?: boolean
}

export const UnderlyingAssetRow = ({
tokenSymbol,
tokenInfo,
tokenAmount,
visible = true,
}: UnderlyingAssetRowProps) => {
const token = useTokenInfo(visible ? tokenSymbol : undefined)
const token = visible ? tokenInfo : undefined
const [tokenDollarValue] = useTokenDollarValue(
visible ? tokenSymbol : undefined
visible ? tokenInfo?.symbol : undefined
)

const tokenAmountDollarValue = dollarValueFormatterWithDecimals(
Expand All @@ -46,14 +47,14 @@ export const UnderlyingAssetRow = ({
logoURI={token?.logoURI}
alt={token?.symbol}
/>
<Text variant="link">{tokenSymbol}</Text>
<Text variant="link">{token?.symbol}</Text>
</Inline>
<Inline align="center" gap={4}>
<Inline gap={6}>
<Text variant="body">
{formatTokenBalance(tokenAmount, { includeCommaSeparation: true })}
</Text>
<Text variant="secondary">{tokenSymbol}</Text>
<Text variant="secondary">{token?.symbol}</Text>
</Inline>
<Tooltip label={infoTooltipLabel} aria-label={infoTooltipLabel}>
<Button
Expand Down
5 changes: 3 additions & 2 deletions hooks/useRewardsQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export const usePendingRewards = ({ pool }: UsePendingRewardsArgs) => {
async () => {
if (shouldQueryRewards) {
return await Promise.all(
pool.rewards_tokens.map(async ({ rewards_address, decimals }) => {
pool.rewards_tokens.map(async (rewardsToken) => {
const { rewards_address, decimals } = rewardsToken
const { pending_rewards, denom } = await getPendingRewards(
address,
rewards_address,
client
)

const tokenInfo = getTokenInfoByDenom({ denom })
const tokenInfo = getTokenInfoByDenom({ denom }) || rewardsToken
const tokenAmount = convertMicroDenomToDenom(
Number(pending_rewards),
decimals ?? tokenInfo.decimals
Expand Down
10 changes: 1 addition & 9 deletions hooks/useTokenList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,14 @@ export const useTokenList = () => {
'@token-list',
() => {
const tokenMapBySymbol = new Map()
/* serialize pool assets first */
/* serialize pool assets */
poolsListResponse.pools.forEach(({ pool_assets }) => {
pool_assets?.forEach((token) => {
if (!tokenMapBySymbol.has(token.symbol)) {
tokenMapBySymbol.set(token.symbol, token)
}
})
})
/* add unique rewards tokens if any */
poolsListResponse.pools.forEach(({ rewards_tokens }) => {
rewards_tokens?.forEach((token) => {
if (!tokenMapBySymbol.has(token.symbol)) {
tokenMapBySymbol.set(token.symbol, token)
}
})
})

return {
base_token: poolsListResponse.base_token,
Expand Down

0 comments on commit a310369

Please sign in to comment.