diff --git a/config/default.json b/config/default.json index 8513119..b6dcf8a 100644 --- a/config/default.json +++ b/config/default.json @@ -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" + } } diff --git a/src/pages/api/v1/[[...all]].js b/src/pages/api/v1/[[...all]].js index 12bfb86..0d53b3b 100644 --- a/src/pages/api/v1/[[...all]].js +++ b/src/pages/api/v1/[[...all]].js @@ -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')) @@ -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) => { diff --git a/src/pages/ticker/[market_pair].jsx b/src/pages/ticker/[market_pair].jsx new file mode 100644 index 0000000..4450923 --- /dev/null +++ b/src/pages/ticker/[market_pair].jsx @@ -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 diff --git a/src/utils/misc.js b/src/utils/misc.js new file mode 100644 index 0000000..adb340c --- /dev/null +++ b/src/utils/misc.js @@ -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] ] +}