Skip to content

Commit

Permalink
feat(pool-routing): added /pools/[poolAddress] route, redirects to ma… (
Browse files Browse the repository at this point in the history
#553)

* feat(pool-routing): added /pools/[poolAddress] route, redirects to manage liquidity

* feat(pool-routing): using poolId instead of address

* feat(pool-routing): removed logs

* feat: osmo poolid redirect

* fix: redirect

* chore: switch endpoints

* feat(pool-routing): added osmo specific routing

* feat(pool-routing): removing logs and added possibility of number or poolId for osmosis

---------

Co-authored-by: nick134 <[email protected]>
  • Loading branch information
worrex and nick134-bit authored Apr 3, 2024
1 parent deba9ac commit 06164b0
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/AssetInput/WhaleInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ ref) => {
flex={1}
ref={ref}
isValidCharacter={(char) => Boolean(char.match(/[.0-9]/u))}
value={value.amount || ''}
value={value?.amount || ''}
>
<NumberInputField
color="white"
Expand Down
4 changes: 2 additions & 2 deletions components/Pages/Trade/Liquidity/DepositForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ const DepositForm = ({
}
} else {
if (reverse) {
if (!token2.amount) {
if (!token2?.amount) {
setValue('token1', { ...token1,
amount: null })
}
} else {
if (!token1.amount) {
if (!token1?.amount) {
setValue('token2', { ...token2,
amount: null })
}
Expand Down
5 changes: 4 additions & 1 deletion components/Pages/Trade/Liquidity/ManageLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ import { tokenItemState } from 'state/tokenItemState'
import { TokenItemState, TxStep } from 'types/common'
import { getDecimals } from 'util/conversion/index'

const ManageLiquidity = ({ poolIdFromUrl }) => {
interface ManageLiquidityProps {
poolIdFromUrl?: string
}
const ManageLiquidity = ({ poolIdFromUrl }: ManageLiquidityProps) => {
const [poolIdState, setPoolIdState] = useState(null)
const [isMobile] = useMediaQuery('(max-width: 640px)')
const router = useRouter()
Expand Down
4 changes: 2 additions & 2 deletions constants/endpoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
},
"osmosis": {
"rpc": [
"https://osmosis-rpc.polkachu.com"
"https://osmosis-rpc.publicnode.com:443"
],
"rest": [
"https://osmosis-api.polkachu.com"
"https://osmosis-rest.publicnode.com"
]
}
}
56 changes: 56 additions & 0 deletions pages/[chainId]/pools/[poolId].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ACTIVE_NETWORKS } from 'constants/index'
import { promises as fs } from 'fs'
import path from 'path'

export async function getServerSideProps(context) {
const { chainId, poolId } = context.params

// Construct the file path to the JSON file in the public directory
const filePath = path.join(
process.cwd(), 'public', 'mainnet', ACTIVE_NETWORKS.mainnet[chainId], 'pools_list.json',
)
try {
// Read the file from the filesystem
const jsonData = await fs.readFile(filePath, 'utf8')
const poolData = JSON.parse(jsonData)
const pool = poolData.pools.find((pool) => (chainId === 'osmosis' ? (pool.osmo_pool_id === Number(poolId) || pool.pool_id === poolId) : pool.pool_id === poolId))
if (!pool) {
// If no pool matches, redirect to a custom 404 page or another page
if (!pool) {
return {
redirect: {
destination: '/404',
permanent: false,
},
}
} else {
return {
redirect: {
destination: `/${chainId}/pools/manage_liquidity?poolId=${pool.pool_id}`,
permanent: false,
},
}
}
} else {
return {
redirect: {
destination: `/${chainId}/pools/manage_liquidity?poolId=${pool.pool_id}`,
permanent: false,
},
}
}
} catch (error) {
console.error('Failed to read pool data:', error);
return {
redirect: {
destination: '/404',
permanent: false,
},
}
}
}

export default function PoolAddressPage() {
// This component does nothing because we're redirecting server-side
return null
}
5 changes: 0 additions & 5 deletions pages/pools/manage_liquidity.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions pages/pools/new_position.tsx

This file was deleted.

8 changes: 8 additions & 0 deletions public/mainnet/osmosis-1/pools_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"pools": [
{
"pool_id": "ampOSMO-OSMO",
"osmo_pool_id": 1461,
"lpOrder": [
"ampOSMO",
"OSMO"
Expand Down Expand Up @@ -76,6 +77,7 @@
},
{
"pool_id": "SAIL-WHALE",
"osmo_pool_id": 1462,
"lpOrder": [
"SAIL",
"WHALE"
Expand Down Expand Up @@ -123,6 +125,7 @@
},
{
"pool_id": "WHALE-OSMO",
"osmo_pool_id": 1463,
"lpOrder": [
"WHALE",
"OSMO"
Expand Down Expand Up @@ -171,6 +174,7 @@
},
{
"pool_id": "ROAR-OSMO",
"osmo_pool_id": 1575,
"lpOrder": [
"ROAR",
"OSMO"
Expand Down Expand Up @@ -218,6 +222,7 @@
},
{
"pool_id": "SHARK-OSMO",
"osmo_pool_id": 1584,
"lpOrder": [
"SHARK",
"OSMO"
Expand Down Expand Up @@ -265,6 +270,7 @@
},
{
"pool_id": "bOSMO-OSMO",
"osmo_pool_id": 1643,
"lpOrder": [
"bOSMO",
"OSMO"
Expand Down Expand Up @@ -312,6 +318,7 @@
},
{
"pool_id": "WHALE-WBTC",
"osmo_pool_id": 1644,
"lpOrder": [
"WHALE",
"WBTC"
Expand Down Expand Up @@ -360,6 +367,7 @@
},
{
"pool_id": "LAB-OSMO",
"osmo_pool_id": 1642,
"lpOrder": [
"LAB",
"OSMO"
Expand Down

0 comments on commit 06164b0

Please sign in to comment.