Skip to content

Commit

Permalink
Merge pull request #337 from invariant-labs/staging
Browse files Browse the repository at this point in the history
Update prod env
  • Loading branch information
wojciech-cichocki authored Dec 31, 2024
2 parents 55b683d + d6f5fb5 commit 3b308a8
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
19 changes: 17 additions & 2 deletions src/pages/LeaderboardPage/components/PoolListItem/PoolListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { useNavigate } from 'react-router-dom'
import icons from '@static/icons'
import { NetworkType } from '@store/consts/static'
import { TooltipHover } from '@components/TooltipHover/TooltipHover'
import { addressToTicker, formatNumberWithCommas, parseFeeToPathFee, printBN } from '@utils/utils'
import {
addressToTicker,
formatNumberWithCommas,
initialXtoY,
parseFeeToPathFee,
printBN
} from '@utils/utils'
import { DECIMAL } from '@invariant-labs/sdk-eclipse/lib/utils'
import { apyToApr, shortenAddress } from '@utils/uiUtils'
import { VariantType } from 'notistack'
Expand Down Expand Up @@ -63,8 +69,17 @@ const PoolListItem: React.FC<IProps> = ({
const isMd = useMediaQuery(theme.breakpoints.down('md'))

const handleOpenPosition = () => {
const revertRatio = initialXtoY(addressFrom ?? '', addressTo ?? '')

const tokenA = revertRatio
? addressToTicker(network, addressTo ?? '')
: addressToTicker(network, addressFrom ?? '')
const tokenB = revertRatio
? addressToTicker(network, addressFrom ?? '')
: addressToTicker(network, addressTo ?? '')

navigate(
`/newPosition/${addressToTicker(network, addressFrom ?? '')}/${addressToTicker(network, addressTo ?? '')}/${parseFeeToPathFee(Math.round(fee * 10 ** (DECIMAL - 2)))}`,
`/newPosition/${tokenA}/${tokenB}/${parseFeeToPathFee(Math.round(fee * 10 ** (DECIMAL - 2)))}`,
{ state: { referer: 'stats' } }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import classNames from 'classnames'
import { useNavigate } from 'react-router-dom'
import { useStyles } from './style'
import { DECIMAL } from '@invariant-labs/sdk-eclipse/lib/utils'
import { addressToTicker, formatNumberWithCommas, parseFeeToPathFee, printBN } from '@utils/utils'
import {
addressToTicker,
formatNumberWithCommas,
initialXtoY,
parseFeeToPathFee,
printBN
} from '@utils/utils'
import FileCopyOutlinedIcon from '@mui/icons-material/FileCopyOutlined'
import { IProps } from '../PoolListItem'
import { BN } from '@coral-xyz/anchor'
Expand Down Expand Up @@ -36,8 +42,17 @@ export const CustomPoolListItem: React.FC<IProps> = ({
const isMd = useMediaQuery(theme.breakpoints.down('md'))

const handleOpenPosition = () => {
const revertRatio = initialXtoY(addressFrom ?? '', addressTo ?? '')

const tokenA = revertRatio
? addressToTicker(network, addressTo ?? '')
: addressToTicker(network, addressFrom ?? '')
const tokenB = revertRatio
? addressToTicker(network, addressFrom ?? '')
: addressToTicker(network, addressTo ?? '')

navigate(
`/newPosition/${addressToTicker(network, addressFrom ?? '')}/${addressToTicker(network, addressTo ?? '')}/${parseFeeToPathFee(Math.round(fee * 10 ** (DECIMAL - 2)))}`,
`/newPosition/${tokenA}/${tokenB}/${parseFeeToPathFee(Math.round(fee * 10 ** (DECIMAL - 2)))}`,
{ state: { referer: 'stats' } }
)
}
Expand Down
25 changes: 18 additions & 7 deletions src/pages/LeaderboardPage/components/YourProgress/YourProgress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@ export const YourProgress: React.FC<YourProgressProps> = ({ userStats }) => {

const isConnected = useMemo(() => walletStatus === Status.Initialized, [walletStatus])

const formatUserPoints = (points?: string) => {
if (!userStats) return '0'

try {
if (!points) return '0'

const pointsBN = new BN(points, 'hex')

if (pointsBN.isZero()) return '0'

return formatNumberWithCommas(printBN(pointsBN, LEADERBOARD_DECIMAL))
} catch (error) {
console.error('Error formatting points:', error)
return '0'
}
}

return (
<Box
sx={{
Expand All @@ -53,13 +70,7 @@ export const YourProgress: React.FC<YourProgressProps> = ({ userStats }) => {
tooltip='Points amount refreshes roughly every 30 minutes.'
desktopLabelAligment='right'
label='Total points'
value={
userStats
? formatNumberWithCommas(
printBN(new BN(userStats.points, 'hex'), LEADERBOARD_DECIMAL)
)
: 0
}
value={formatUserPoints(userStats?.points)}
/>
<ProgressItem
background={{
Expand Down
4 changes: 3 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export const printBN = (amount: BN, decimals: number): string => {
}

export const formatNumberWithCommas = (number: string) => {
return number.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
const trimmedNumber = number.replace(/(\.\d*?[1-9])0+$/, '$1').replace(/\.0+$/, '')

return trimmedNumber.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}

export const trimZeros = (numStr: string): string => {
Expand Down

0 comments on commit 3b308a8

Please sign in to comment.