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

fix position list pagination bugs #5

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions src/components/PositionsList/PositionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export const PositionsList: React.FC<IProp> = ({
setPage(initialPage)
}, [])

useEffect(() => {
handleChangePagination(initialPage)
}, [initialPage])

return (
<Grid container direction='column' className={classes.root}>
<Grid
Expand Down
15 changes: 13 additions & 2 deletions src/containers/WrappedPositionsList/WrappedPositionsList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PositionsList } from '@components/PositionsList/PositionsList'
import { POSITIONS_PER_PAGE } from '@consts/static'
import { calcYPerXPrice, printBN } from '@consts/utils'
import { calculatePriceSqrt } from '@invariant-labs/sdk-eclipse'
import { getX, getY } from '@invariant-labs/sdk-eclipse/lib/math'
Expand All @@ -12,7 +13,7 @@ import {
} from '@selectors/positions'
import { status } from '@selectors/solanaWallet'
import { openWalletSelectorModal } from '@web3/selector'
import React, { useState } from 'react'
import React, { useEffect, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useHistory } from 'react-router-dom'

Expand All @@ -34,6 +35,16 @@ export const WrappedPositionsList: React.FC = () => {
dispatch(actions.setLastPage(page))
}

useEffect(() => {
if (list.length === 0) {
setLastPage(1)
}

if (lastPage > Math.ceil(list.length / POSITIONS_PER_PAGE)) {
setLastPage(lastPage - 1)
}
}, [list])

return (
<PositionsList
initialPage={lastPage}
Expand Down Expand Up @@ -123,7 +134,7 @@ export const WrappedPositionsList: React.FC = () => {
})}
loading={isLoading}
showNoConnected={walletStatus !== Status.Initialized}
itemsPerPage={5}
itemsPerPage={POSITIONS_PER_PAGE}
noConnectedBlockerProps={{
onConnect: openWalletSelectorModal,
descCustomText: 'You have no positions.'
Expand Down
27 changes: 9 additions & 18 deletions src/store/consts/static.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PublicKey } from '@solana/web3.js'
import { BN } from '@project-serum/anchor'
import { FEE_TIERS } from '@invariant-labs/sdk-eclipse/lib/utils'
import { BN } from '@project-serum/anchor'
import { PublicKey } from '@solana/web3.js'

declare global {
interface Window {
Expand Down Expand Up @@ -157,32 +157,21 @@ export const bestTiers: Record<NetworkType, BestTier[]> = {
}

export const commonTokensForNetworks: Record<NetworkType, PublicKey[]> = {
Devnet: [
USDC_DEV.address,
BTC_DEV.address,
WETH_DEV.address
],
Mainnet: [
],
Devnet: [USDC_DEV.address, BTC_DEV.address, WETH_DEV.address],
Mainnet: [],
Testnet: [],
Localnet: []
}

export const airdropTokens: Record<NetworkType, PublicKey[]> = {
Devnet: [
USDC_DEV.address,
BTC_DEV.address
],
Devnet: [USDC_DEV.address, BTC_DEV.address],
Mainnet: [],
Testnet: [],
Localnet: []
}

export const airdropQuantities: Record<NetworkType, number[]> = {
Devnet: [
100 * 10 ** USDC_DEV.decimals,
0.0025 * 10 ** BTC_DEV.decimals
],
Devnet: [100 * 10 ** USDC_DEV.decimals, 0.0025 * 10 ** BTC_DEV.decimals],
Mainnet: [],
Testnet: [],
Localnet: []
Expand All @@ -201,4 +190,6 @@ export const ALL_FEE_TIERS_DATA = FEE_TIERS.map((tier, index) => ({
primaryIndex: index
}))

export { EclipseNetworks, DEFAULT_PUBLICKEY, MAX_U64, NetworkType }
export { DEFAULT_PUBLICKEY, EclipseNetworks, MAX_U64, NetworkType }

export const POSITIONS_PER_PAGE = 5
Loading