Skip to content

Commit

Permalink
DEX service redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
1aerostorm committed Nov 21, 2023
1 parent fd64e1f commit 01228d8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
5 changes: 4 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
"coinmarketcap_requests": {
"api_key": "7dcec520-90cd-4e38-b43a-0ff6bdb2731b"
},
"golos_usd": ["GOLOS", "YMUSDT"]
"golos_usd": ["GOLOS", "YMUSDT"],
"dex_service": {
"host": "https://dex.golos.app"
}
}
9 changes: 1 addition & 8 deletions src/pages/api/v1/[[...all]].js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import git from 'git-rev-sync'
import golos from 'golos-lib-js'

import nextConnect from '@/nextConnect'
import { parseMarketPair } from '@/utils/misc'

golos.config.set('websocket', config.get('node_url'))

Expand All @@ -19,14 +20,6 @@ class APIError {
}
}

const parseMarketPair = (pair) => {
if (!cfgPairs.includes(pair)) {
return []
}
const [ base, quote ] = pair.split('_')
return [ cfgSymbols.get(base)[0], cfgSymbols.get(quote)[0] ]
}

let handler = nextConnect({ attachParams: true, })

.get('/api/v1', async (req, res) => {
Expand Down
28 changes: 28 additions & 0 deletions src/pages/ticker/[market_pair].jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import config from 'config'
import { parseMarketPair } from '@/utils/misc'

export const getServerSideProps = async ({ req, res, params, }) => {
const host = config.get('dex_service.host')
const parsed = parseMarketPair(params.market_pair)
if (!parsed.length) {
return {
notFound: true
}
}
const url = new URL('/#/trade/' + parsed.join('_'), host)
return {
redirect: {
destination: url.toString(),
permanent: false,
},
}
}

class TickerRedirect extends React.Component {
render() {
return null
}
}

export default TickerRedirect
12 changes: 12 additions & 0 deletions src/utils/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import config from 'config'

const cfgSymbols = config.get('symbols')
const cfgPairs = config.get('pairs')

export const parseMarketPair = (pair) => {
if (!cfgPairs.includes(pair)) {
return []
}
const [ base, quote ] = pair.split('_')
return [ cfgSymbols.get(base)[0], cfgSymbols.get(quote)[0] ]
}

0 comments on commit 01228d8

Please sign in to comment.