-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/bob-gateway
- Loading branch information
Showing
61 changed files
with
4,429 additions
and
253 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const fsp = fs.promises; | ||
|
||
async function deleteDir(dir) { | ||
if (fs.existsSync(dir)) { | ||
await fsp.rmdir(dir, { recursive: true }); | ||
console.log(`Deleted directory: ${dir}`); | ||
} | ||
} | ||
|
||
async function copyDir(src, dest) { | ||
await fsp.mkdir(dest, { recursive: true }); | ||
const entries = await fsp.readdir(src, { withFileTypes: true }); | ||
|
||
for (const entry of entries) { | ||
const srcPath = path.join(src, entry.name); | ||
const destPath = path.join(dest, entry.name); | ||
|
||
if (entry.isDirectory()) { | ||
await copyDir(srcPath, destPath); | ||
} else { | ||
await fsp.copyFile(srcPath, destPath); | ||
} | ||
} | ||
} | ||
|
||
async function copyLibs() { | ||
const chartingLibrarySrc = path.resolve( | ||
__dirname, | ||
'../../../node_modules/@sovryn/charting-library/public/charting_library', | ||
); | ||
const chartingLibraryDest = path.resolve( | ||
__dirname, | ||
'../public/charting_library', | ||
); | ||
|
||
const datafeedsSrc = path.resolve( | ||
__dirname, | ||
'../../../node_modules/@sovryn/charting-library/public/datafeeds', | ||
); | ||
const datafeedsDest = path.resolve(__dirname, '../public/datafeeds'); | ||
|
||
if (fs.existsSync(chartingLibrarySrc)) { | ||
await deleteDir(chartingLibraryDest); | ||
await copyDir(chartingLibrarySrc, chartingLibraryDest); | ||
console.log('Charting Library copied.'); | ||
} else { | ||
console.error('Charting Library source not found.'); | ||
} | ||
|
||
if (fs.existsSync(datafeedsSrc)) { | ||
await deleteDir(datafeedsDest); | ||
await copyDir(datafeedsSrc, datafeedsDest); | ||
console.log('Datafeeds copied.'); | ||
} else { | ||
console.error('Datafeeds source not found.'); | ||
} | ||
} | ||
|
||
copyLibs(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
apps/frontend/src/app/2_molecules/TradingChart/TradingChart.constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { storageFactory } from 'storage-factory'; | ||
|
||
import { ResolutionString } from '@sovryn/charting-library/src/charting_library'; | ||
|
||
import { INDEXER_SERVICE } from '../../../constants/infrastructure'; | ||
import { Environments } from '../../../types/global'; | ||
import { CandleDuration } from './dictionary'; | ||
|
||
export const REFRESH_RATE = 15 * 1e3; | ||
export const MAXIMUM_CHUNK_SIZE = 1e3; | ||
export const endTimeCache = new Map<string, number>(); | ||
export const supportedResolutions = [ | ||
'1', | ||
'5', | ||
'10', | ||
'15', | ||
'30', | ||
'60', | ||
'240', | ||
'720', | ||
'1D', | ||
'3D', | ||
'1W', | ||
'1M', | ||
] as ResolutionString[]; | ||
|
||
export const resolutionMap: { [key: string]: CandleDuration } = { | ||
'1': CandleDuration.M_1, | ||
'5': CandleDuration.M_1, | ||
'10': CandleDuration.M_10, | ||
'15': CandleDuration.M_15, | ||
'30': CandleDuration.M_30, | ||
'60': CandleDuration.H_1, | ||
H: CandleDuration.H_1, | ||
'240': CandleDuration.H_4, | ||
'720': CandleDuration.H_12, | ||
'1440': CandleDuration.D_1, | ||
D: CandleDuration.D_1, | ||
'1D': CandleDuration.D_1, | ||
'3D': CandleDuration.D_3, | ||
W: CandleDuration.W_1, | ||
'1W': CandleDuration.W_1, | ||
M: CandleDuration.D_30, | ||
'1M': CandleDuration.D_30, | ||
}; | ||
|
||
export const local = storageFactory(() => localStorage); | ||
|
||
export const chartStorageKey = 'sovryn.charts'; | ||
|
||
export const config = { | ||
exchanges: [], | ||
symbols_types: [], | ||
supported_resolutions: supportedResolutions, | ||
supports_time: false, | ||
}; | ||
|
||
export const SOVRYN_INDEXER_MAINNET = `${ | ||
INDEXER_SERVICE[Environments.Mainnet] | ||
}chart`; | ||
|
||
export const SOVRYN_INDEXER_TESTNET = `${ | ||
INDEXER_SERVICE[Environments.Testnet] | ||
}chart`; |
82 changes: 82 additions & 0 deletions
82
apps/frontend/src/app/2_molecules/TradingChart/TradingChart.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { useApolloClient } from '@apollo/client'; | ||
|
||
import React, { FC, useEffect, useLayoutEffect, useRef, useState } from 'react'; | ||
|
||
import { | ||
ChartingLibraryWidgetOptions, | ||
IChartingLibraryWidget, | ||
ResolutionString, | ||
widget, | ||
} from '@sovryn/charting-library/src/charting_library'; | ||
import { noop } from '@sovryn/ui'; | ||
|
||
import { SeriesStyle, TradingChartProps } from './TradingChart.types'; | ||
import Datafeed from './datafeed'; | ||
|
||
export const TradingChart: FC<TradingChartProps> = ({ pair }) => { | ||
const chartContainerRef = | ||
useRef<HTMLDivElement>() as React.MutableRefObject<HTMLInputElement>; | ||
|
||
const [hasCharts, setHasCharts] = useState(false); | ||
const [chart, setChart] = useState<IChartingLibraryWidget | null>(null); | ||
const client = useApolloClient(); | ||
|
||
useEffect(() => { | ||
try { | ||
const widgetOptions: ChartingLibraryWidgetOptions = { | ||
symbol: pair, | ||
datafeed: Datafeed(client), | ||
interval: '1D' as ResolutionString, | ||
container: chartContainerRef.current, | ||
library_path: '/charting_library/', | ||
load_last_chart: true, //last chart layout (if present) | ||
theme: 'dark', | ||
locale: 'en', | ||
disabled_features: ['header_symbol_search', 'header_compare'], | ||
enabled_features: [ | ||
'study_templates', | ||
'side_toolbar_in_fullscreen_mode', | ||
], | ||
charts_storage_url: 'https://saveload.tradingview.com', | ||
charts_storage_api_version: '1.1', | ||
client_id: 'tradingview.com', | ||
user_id: 'public_user_id', | ||
fullscreen: false, | ||
autosize: true, | ||
studies_overrides: {}, | ||
}; | ||
|
||
const myChart = new widget(widgetOptions); | ||
setChart(myChart); | ||
myChart.onChartReady(() => { | ||
setHasCharts(true); | ||
}); | ||
|
||
return () => { | ||
myChart.remove(); | ||
setHasCharts(false); | ||
setChart(null); | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
setHasCharts(false); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [client]); | ||
|
||
useLayoutEffect(() => { | ||
if (chart && hasCharts) { | ||
chart.chart().resetData(); | ||
|
||
chart.chart().setChartType(SeriesStyle.Candles as number); | ||
|
||
chart.chart().setSymbol(pair, noop); | ||
} | ||
}, [chart, hasCharts, pair]); | ||
|
||
return ( | ||
<div className="w-full p-0 sm:border sm:border-gray-50 sm:rounded sm:p-6 sm:bg-gray-90"> | ||
<div ref={chartContainerRef} className="h-full min-h-96" /> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.