ported to nodejs
This commit is contained in:
parent
1294274951
commit
698617b977
1
websrc/.eslintcache
Normal file
1
websrc/.eslintcache
Normal file
File diff suppressed because one or more lines are too long
24
websrc/.gitignore
vendored
24
websrc/.gitignore
vendored
@ -1 +1,23 @@
|
||||
*.js
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
70
websrc/README.md
Normal file
70
websrc/README.md
Normal file
@ -0,0 +1,70 @@
|
||||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.\
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `yarn build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
@ -28,7 +28,7 @@ class CoinBalance extends Component<CoinBalanceProps> {
|
||||
|
||||
return (
|
||||
<div className="flex-grow flex px-6 py-3 text-gray-800 items-center border-b -mx-4 align-middle">
|
||||
<div className={"w-1/8"}>
|
||||
<div className={"w-1/8 bg-te"}>
|
||||
{/*{icon}*/}
|
||||
</div>
|
||||
<div className="w-2/5 xl:w-1/4 px-4 flex items-center">
|
||||
|
@ -1,45 +0,0 @@
|
||||
import {Button, ButtonGroup, Dropdown} from "react-bootstrap";
|
||||
import React, {Component} from "react";
|
||||
import DropdownItem from "react-bootstrap/DropdownItem";
|
||||
import {CurrencyPair} from "../types";
|
||||
|
||||
|
||||
export type CurrencyPairProps = {
|
||||
active_pair: CurrencyPair,
|
||||
pairs: Array<CurrencyPair>
|
||||
}
|
||||
|
||||
export class CurrencyDropdown extends Component<CurrencyPairProps> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
dropdownItems() {
|
||||
return this.props.pairs.map((pair) => {
|
||||
return (
|
||||
<DropdownItem key={String(pair.base) + String(pair.quote)}> {pair.base} / {pair.quote} </DropdownItem>)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Dropdown as={ButtonGroup} className={"mr-3"}>
|
||||
<Button variant="outline-primary"><b>{this.props.active_pair.base} / {this.props.active_pair.quote}</b></Button>
|
||||
|
||||
{this.props.pairs.length > 0 &&
|
||||
|
||||
<>
|
||||
<Dropdown.Toggle split variant="primary" id="dropdown-split-basic"/>
|
||||
|
||||
<Dropdown.Menu className={"mr-3"}>
|
||||
{this.dropdownItems()}
|
||||
</Dropdown.Menu>
|
||||
</>
|
||||
}
|
||||
|
||||
</Dropdown>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
import React, {Component} from "react";
|
||||
import {Container, ListGroup} from "react-bootstrap";
|
||||
|
||||
|
||||
export type EventProp = {
|
||||
id: number,
|
||||
name: string,
|
||||
tick: number
|
||||
}
|
||||
|
||||
export class Events extends Component<{ events: Array<EventProp> }> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
state = {
|
||||
events: this.props.events
|
||||
}
|
||||
|
||||
mapEvents() {
|
||||
return this.state.events.map((event: EventProp) => {
|
||||
return (
|
||||
<ListGroup.Item action key={event.id}>
|
||||
{event.name} @ Tick {event.tick}
|
||||
</ListGroup.Item>
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<div className={"border-bottom mb-2"}>
|
||||
<h2>Events</h2>
|
||||
</div>
|
||||
<ListGroup>
|
||||
{this.mapEvents()}
|
||||
</ListGroup>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import React, {Component} from 'react';
|
||||
import {Toast} from 'react-bootstrap';
|
||||
import {socket} from "../";
|
||||
|
||||
type ToastProps = {
|
||||
title: string,
|
||||
content?: string,
|
||||
bg?: string
|
||||
}
|
||||
|
||||
type ToastState = {
|
||||
lastUpdated: Date,
|
||||
show: boolean
|
||||
}
|
||||
|
||||
|
||||
export class RToast extends Component<ToastProps, ToastState> {
|
||||
state = {
|
||||
lastUpdated: new Date(),
|
||||
show: false
|
||||
}
|
||||
|
||||
constructor(props: ToastProps) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
socket.on("connect", () => {
|
||||
this.setState({show: true})
|
||||
})
|
||||
}
|
||||
|
||||
tick() {
|
||||
this.setState({lastUpdated: new Date()})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Toast show={this.state.show} delay={5000} autohide>
|
||||
<Toast.Header>
|
||||
<strong className="mr-auto">{this.props.title}</strong>
|
||||
<small>{this.state.lastUpdated.toLocaleTimeString('en-GB')}</small>
|
||||
</Toast.Header>
|
||||
{this.props.content ? <Toast.Body> {this.props.content}</Toast.Body> : null}
|
||||
</Toast>
|
||||
)
|
||||
}
|
||||
}
|
@ -1,40 +1,55 @@
|
||||
{
|
||||
"name": "rustico",
|
||||
"version": "1.0.0",
|
||||
"main": "index.tsx",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/luxon": "^1.25.0",
|
||||
"name": "bfxbot",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.11.4",
|
||||
"@testing-library/react": "^11.1.0",
|
||||
"@testing-library/user-event": "^12.1.10",
|
||||
"@types/jest": "^26.0.19",
|
||||
"@types/node": "^14.14.16",
|
||||
"@types/react": "^17.0.0",
|
||||
"@types/react-dom": "^17.0.0",
|
||||
"@types/react-helmet": "^6.1.0",
|
||||
"@types/react-plotly.js": "^2.2.4",
|
||||
"@types/socket.io-client": "^1.4.34",
|
||||
"parcel-bundler": "^1.12.4",
|
||||
"react-plotly.js": "^2.5.1",
|
||||
"typescript": "^4.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/classnames": "^2.2.11",
|
||||
"autoprefixer": "^10.1.0",
|
||||
"classnames": "^2.2.6",
|
||||
"css": "^3.0.0",
|
||||
"luxon": "^1.25.0",
|
||||
"plotly.js": "^1.58.2",
|
||||
"postcss": "^8.2.1",
|
||||
"postcss-cli": "^8.3.1",
|
||||
"plotly.js": "^1.58.4",
|
||||
"react": "^17.0.1",
|
||||
"react-cryptocoins": "^1.0.11",
|
||||
"react-dom": "^17.0.1",
|
||||
"react-helmet": "^6.1.0",
|
||||
"socket.io-client": "~3",
|
||||
"tailwindcss": "^2.0.2"
|
||||
"react-plotly.js": "^2.5.1",
|
||||
"react-scripts": "4.0.1",
|
||||
"socket.io-client": "^3.0.4",
|
||||
"typescript": "^4.1.3",
|
||||
"web-vitals": "^0.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build:tailwind": "tailwindcss build css/index.css -o css/tailwind.css",
|
||||
"watch": "parcel watch index.tsx -d ../static",
|
||||
"prestart": "yarn run build:tailwind",
|
||||
"prebuild": "yarn run build:tailwind",
|
||||
"start": "python ../main.py & yarn run watch"
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/luxon": "^1.25.0",
|
||||
"@types/react-helmet": "^6.1.0",
|
||||
"@types/react-plotly.js": "^2.2.4",
|
||||
"luxon": "^1.25.0",
|
||||
"react-cryptocoins": "^1.0.11",
|
||||
"react-helmet": "^6.1.0",
|
||||
"react-plotly": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
BIN
websrc/public/favicon.ico
Normal file
BIN
websrc/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
43
websrc/public/index.html
Normal file
43
websrc/public/index.html
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
BIN
websrc/public/logo192.png
Normal file
BIN
websrc/public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
websrc/public/logo512.png
Normal file
BIN
websrc/public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
websrc/public/manifest.json
Normal file
25
websrc/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
websrc/public/robots.txt
Normal file
3
websrc/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
131
websrc/src/components/App.tsx
Normal file
131
websrc/src/components/App.tsx
Normal file
@ -0,0 +1,131 @@
|
||||
import React, { Component } from "react";
|
||||
import {
|
||||
Balance,
|
||||
CurrencyPair,
|
||||
EventName,
|
||||
EventProp,
|
||||
FirstConnectMessage,
|
||||
NewEventMessage,
|
||||
NewTickMessage,
|
||||
PositionProp
|
||||
} from "../types";
|
||||
import { socket } from "../index";
|
||||
import { symbolToPair } from "../utils";
|
||||
import { Helmet } from "react-helmet";
|
||||
import { Navbar, Sidebar } from "./Navbars";
|
||||
import { Statusbar } from "./Statusbar";
|
||||
import { PositionsTable } from "./Tables";
|
||||
import RPlot from "./RPlot";
|
||||
|
||||
type AppState = {
|
||||
current_price: number,
|
||||
current_tick: number,
|
||||
last_update: Date,
|
||||
positions: Array<PositionProp>,
|
||||
events: Array<EventProp>,
|
||||
active_pair: CurrencyPair,
|
||||
available_pairs: Array<CurrencyPair>,
|
||||
balances: Array<Balance>
|
||||
}
|
||||
|
||||
class App extends Component<{}, AppState> {
|
||||
event_id = 0;
|
||||
|
||||
state = {
|
||||
current_price: 0,
|
||||
current_tick: 0,
|
||||
last_update: new Date(),
|
||||
positions: [],
|
||||
events: [],
|
||||
balances: [],
|
||||
active_pair: symbolToPair("tBTCUSD"),
|
||||
available_pairs: []
|
||||
}
|
||||
|
||||
constructor(props: {}) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
socket.on(EventName.FirstConnect, (data: FirstConnectMessage) => {
|
||||
this.setState({
|
||||
current_price: data.prices[data.prices.length - 1],
|
||||
current_tick: data.ticks[data.ticks.length - 1],
|
||||
last_update: new Date(),
|
||||
positions: data.positions,
|
||||
balances: data.balances
|
||||
})
|
||||
})
|
||||
|
||||
socket.on(EventName.NewTick, (data: NewTickMessage) => {
|
||||
this.setState({
|
||||
current_price: data.price,
|
||||
current_tick: data.tick,
|
||||
last_update: new Date(),
|
||||
positions: data.positions,
|
||||
balances: data.balances
|
||||
})
|
||||
})
|
||||
|
||||
socket.on(EventName.NewEvent, (data: NewEventMessage) => {
|
||||
// ignore new tick
|
||||
if (!data.kind.toLowerCase().includes("new_tick")) {
|
||||
const new_event: EventProp = {
|
||||
id: this.event_id,
|
||||
name: data.kind,
|
||||
tick: data.tick
|
||||
}
|
||||
|
||||
this.event_id += 1
|
||||
|
||||
this.setState((state) => ({
|
||||
events: [...state.events, new_event]
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<Helmet>
|
||||
<title> Rustico
|
||||
- {String(this.state.current_price.toLocaleString())} {String(this.state.active_pair.base) + "/" + String(this.state.active_pair.quote)} </title>
|
||||
</Helmet>
|
||||
<div className="bg-gray-800">
|
||||
<div className="h-screen max-w-screen flex mx-auto">
|
||||
<Navbar />
|
||||
|
||||
<main
|
||||
className="my-1 py-2 px-10 flex-1 bg-gray-200 dark:bg-black rounded-l-lg*
|
||||
transition duration-500 ease-in-out overflow-y-auto flex flex-col">
|
||||
<div className="flex justify-center text-2xl my-2">
|
||||
<Statusbar balances={this.state.balances} positions={this.state.positions}
|
||||
price={this.state.current_price}
|
||||
tick={this.state.current_tick} />
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col flex-grow my-8 shadow-md hover:shadow-lg">
|
||||
<div
|
||||
className="py-2 flex-grow bg-white min-width dark:bg-gray-600 rounded-lg overflow-hidden">
|
||||
<RPlot />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{this.state.positions.length > 0 ?
|
||||
<PositionsTable positions={this.state.positions} /> : null}
|
||||
|
||||
<footer className="flex rounded-lg justify-center bg-gray-600 mt-4 border-t text-gray-300">
|
||||
<span className="my-1 mx-1">Made with ❤️ by the Peperone in a scantinato</span>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
<Sidebar />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
154
websrc/src/components/Cards.tsx
Normal file
154
websrc/src/components/Cards.tsx
Normal file
@ -0,0 +1,154 @@
|
||||
import React, { Component } from 'react';
|
||||
import { Balance, EventName, FirstConnectMessage, NewTickMessage } from "../types";
|
||||
import { socket } from "../index";
|
||||
|
||||
export type CoinBalanceProps = {
|
||||
name: string,
|
||||
amount: number,
|
||||
percentage: number,
|
||||
quote_equivalent: number,
|
||||
quote_symbol: string,
|
||||
}
|
||||
|
||||
class CoinBalance extends Component<CoinBalanceProps> {
|
||||
constructor(props: CoinBalanceProps) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
// do not print equivalent if this element is the quote itself
|
||||
const quoteBlock = this.props.name != this.props.quote_symbol ? this.props.quote_symbol.concat(" ").concat(this.props.quote_equivalent.toLocaleString()) : null
|
||||
|
||||
// const accessory = SymbolAccessories.filter((accessory) => {
|
||||
// return accessory.name == this.props.name
|
||||
// })
|
||||
//
|
||||
// const icon = accessory.length > 0 ? accessory.pop().icon : null
|
||||
|
||||
return (
|
||||
<div className="flex-grow flex px-6 py-3 text-gray-800 items-center border-b -mx-4 align-middle">
|
||||
<div className={"w-1/8"}>
|
||||
{/*{icon}*/}
|
||||
</div>
|
||||
<div className="w-2/5 xl:w-1/4 px-4 flex items-center">
|
||||
<span className="text-lg">{this.props.name}</span>
|
||||
</div>
|
||||
<div className="hidden md:flex lg:hidden xl:flex w-1/4 px-1 flex-col">
|
||||
<div className={"italic w-full text-center"}>
|
||||
{Math.trunc(this.props.percentage)}%
|
||||
</div>
|
||||
<div className="w-full bg-transparent mt-2">
|
||||
<div className={"bg-blue-400 rounded-lg text-xs leading-none py-1 text-center text-white"}
|
||||
style={{ width: this.props.percentage.toString().concat("%") }} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex w-3/5 md:w/12">
|
||||
<div className="w-1/2 px-4">
|
||||
<div className="text-right">
|
||||
{this.props.amount.toFixed(5)} {this.props.name}
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-1/2 px-4 my-auto">
|
||||
<div
|
||||
className={"px-2 inline-flex text-center text-xs leading-5 font-semibold rounded-full bg-gray-200 text-gray-800"}>
|
||||
{quoteBlock}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export type WalletCardProps = {
|
||||
quote: string,
|
||||
}
|
||||
|
||||
export class WalletCard extends Component
|
||||
<{}, { balances: Array<Balance> }> {
|
||||
// constructor(props) {
|
||||
// super(props);
|
||||
// }
|
||||
|
||||
state =
|
||||
{
|
||||
balances: []
|
||||
}
|
||||
|
||||
totalQuoteBalance() {
|
||||
let total = 0
|
||||
|
||||
this.state.balances.forEach((balance: Balance) => {
|
||||
if (balance.currency == balance.quote) {
|
||||
total += balance.amount
|
||||
} else {
|
||||
total += balance.quote_equivalent
|
||||
}
|
||||
})
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
renderCoinBalances() {
|
||||
return (
|
||||
this.state.balances.map((balance: Balance) => {
|
||||
const percentage_amount = balance.quote == balance.currency ? balance.amount : balance.quote_equivalent;
|
||||
|
||||
return (
|
||||
<CoinBalance key={balance.currency.concat(balance.kind)} name={balance.currency}
|
||||
amount={balance.amount} quote_equivalent={balance.quote_equivalent}
|
||||
percentage={percentage_amount / this.totalQuoteBalance() * 100}
|
||||
quote_symbol={balance.quote} />
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
socket.on(EventName.NewTick, (data: NewTickMessage) => {
|
||||
this.setState({
|
||||
balances: data.balances
|
||||
})
|
||||
})
|
||||
|
||||
socket.on(EventName.FirstConnect, (data: FirstConnectMessage) => {
|
||||
this.setState({
|
||||
balances: data.balances
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="w-full mb-6 lg:mb-0 px-4 flex flex-col">
|
||||
<div
|
||||
className="flex-grow flex bg-white flex-col border-t border-b sm:rounded-lg sm:border shadow overflow-hidden">
|
||||
<div className="border-b bg-gray-50">
|
||||
<div className="flex justify-between px-6 -mb-px">
|
||||
<h3 className="text-blue-700 py-4 font-normal text-lg">Your Wallets</h3>
|
||||
<div className="flex">
|
||||
<button type="button"
|
||||
className="appearance-none py-4 text-blue-700 border-b border-blue-dark mr-3">
|
||||
Margin
|
||||
</button>
|
||||
<button type="button"
|
||||
className="appearance-none py-4 text-gray-600 border-b border-transparent hover:border-grey-dark">
|
||||
Chart
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{this.renderCoinBalances()}
|
||||
|
||||
<div className="px-6 py-4">
|
||||
<div className="text-center text-gray-400">
|
||||
Total Balance ≈ USD {this.totalQuoteBalance().toLocaleString()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
9
websrc/src/components/Currency.tsx
Normal file
9
websrc/src/components/Currency.tsx
Normal file
@ -0,0 +1,9 @@
|
||||
import React, { Component } from "react";
|
||||
import { CurrencyPair } from "../types";
|
||||
|
||||
|
||||
export type CurrencyPairProps = {
|
||||
active_pair: CurrencyPair,
|
||||
pairs: Array<CurrencyPair>
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ class Icon extends Component <IconProps> {
|
||||
private readonly width: string;
|
||||
private readonly height: string;
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: IconProps) {
|
||||
super(props);
|
||||
|
||||
this.width = "w-" + this.props.width.toString();
|
@ -1,8 +1,8 @@
|
||||
import React, { Component } from "react";
|
||||
import { WalletCard } from "./Cards";
|
||||
|
||||
export class Navbar extends Component<any, any> {
|
||||
constructor(props) {
|
||||
export class Navbar extends Component {
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ export class Navbar extends Component<any, any> {
|
||||
}
|
||||
|
||||
export class Sidebar extends Component {
|
||||
constructor(props) {
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export type ModalProps = {
|
||||
}
|
||||
|
||||
export class ClosePositionModal extends Component<ModalProps, any> {
|
||||
constructor(props) {
|
||||
constructor(props: ModalProps) {
|
||||
super(props);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class RPlot extends Component<{}, PlotState> {
|
||||
positions_price_lines: []
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: {}) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
@ -79,24 +79,24 @@ class RPlot extends Component<{}, PlotState> {
|
||||
}
|
||||
|
||||
render() {
|
||||
let additional_shapes = []
|
||||
// let additional_shapes: ConcatArray<{ type: string; x0: number; y0: number; x1: number; y1: number; line: { color: string; width: number; dash: string; }; }> = []
|
||||
|
||||
if (this.state.positions_price_lines.length > 0) {
|
||||
additional_shapes = this.state.positions_price_lines.map((priceline: PriceLine) => {
|
||||
return {
|
||||
type: 'line',
|
||||
x0: priceline.x0,
|
||||
y0: priceline.y0,
|
||||
x1: priceline.x1,
|
||||
y1: priceline.y1,
|
||||
line: {
|
||||
color: 'rgb(1, 1, 1)',
|
||||
width: 1,
|
||||
dash: 'solid'
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// if (this.state.positions_price_lines.length > 0) {
|
||||
// additional_shapes = this.state.positions_price_lines.map((priceline: PriceLine) => {
|
||||
// return {
|
||||
// type: 'line',
|
||||
// x0: priceline.x0,
|
||||
// y0: priceline.y0,
|
||||
// x1: priceline.x1,
|
||||
// y1: priceline.y1,
|
||||
// line: {
|
||||
// color: 'rgb(1, 1, 1)',
|
||||
// width: 1,
|
||||
// dash: 'solid'
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
return (
|
||||
<Plot
|
||||
@ -117,20 +117,20 @@ class RPlot extends Component<{}, PlotState> {
|
||||
pad: 4
|
||||
},
|
||||
dragmode: "pan",
|
||||
shapes: [
|
||||
{
|
||||
type: 'line',
|
||||
x0: this.state.current_price_line.x0,
|
||||
y0: this.state.current_price_line.y0,
|
||||
x1: this.state.current_price_line.x1,
|
||||
y1: this.state.current_price_line.y1,
|
||||
line: {
|
||||
color: 'rgb(50, 171, 96)',
|
||||
width: 2,
|
||||
dash: 'dashdot'
|
||||
}
|
||||
},
|
||||
].concat(additional_shapes),
|
||||
// shapes: [
|
||||
// {
|
||||
// type: 'line',
|
||||
// x0: this.state.current_price_line.x0,
|
||||
// y0: this.state.current_price_line.y0,
|
||||
// x1: this.state.current_price_line.x1,
|
||||
// y1: this.state.current_price_line.y1,
|
||||
// line: {
|
||||
// color: 'rgb(50, 171, 96)',
|
||||
// width: 2,
|
||||
// dash: 'dashdot'
|
||||
// }
|
||||
// },
|
||||
// ].concat(additional_shapes),
|
||||
xaxis: {
|
||||
title: {
|
||||
text: 'Tick',
|
@ -17,9 +17,14 @@ export class QuoteStatus extends Component<QuoteStatusProps> {
|
||||
private sign: string;
|
||||
private signClass: string;
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: QuoteStatusProps) {
|
||||
super(props);
|
||||
|
||||
this.whole = 0;
|
||||
this.decimal = 0;
|
||||
this.sign = "";
|
||||
this.signClass = "";
|
||||
|
||||
this.deriveProps()
|
||||
}
|
||||
|
||||
@ -89,15 +94,21 @@ type DateButtonState = {
|
||||
class DateButton extends Component<DateButtonProps, DateButtonState> {
|
||||
private classSelected: string = "appearance-none py-4 text-blue-600 border-b border-blue-600 mr-3";
|
||||
private classNotSelected: string = "appearance-none py-4 text-gray-600 border-b border-transparent hover:border-gray-800 mr-3";
|
||||
private currentClass: string;
|
||||
private currentClass: string = "";
|
||||
|
||||
state = {
|
||||
selected: this.props.selected_default
|
||||
selected: false
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: DateButtonProps) {
|
||||
super(props);
|
||||
|
||||
if (this.props.selected_default) {
|
||||
this.state = {
|
||||
selected: this.props.selected_default
|
||||
}
|
||||
}
|
||||
|
||||
this.updateClass()
|
||||
}
|
||||
|
||||
@ -140,7 +151,7 @@ type StatusBarState = {
|
||||
|
||||
export class Statusbar extends Component<NewTickMessage, StatusBarState> {
|
||||
|
||||
constructor(props) {
|
||||
constructor(props: NewTickMessage) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
@ -8,7 +8,7 @@ type PositionsTableState = {
|
||||
}
|
||||
|
||||
export class PositionsTable extends Component<{ positions: Array<PositionProp> }, PositionsTableState> {
|
||||
constructor(props) {
|
||||
constructor(props: { positions: PositionProp[]; } | Readonly<{ positions: PositionProp[]; }>) {
|
||||
super(props);
|
||||
this.toggleConfirmation = this.toggleConfirmation.bind(this)
|
||||
}
|
1
websrc/src/custom.d.ts
vendored
Normal file
1
websrc/src/custom.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare module 'react-cryptocoins';
|
@ -4,7 +4,7 @@ import "./css/tailwind.css";
|
||||
import App from "./components/App";
|
||||
import io from "socket.io-client";
|
||||
|
||||
export const socket = io();
|
||||
export const socket = io.io();
|
||||
|
||||
socket.on("connect", function () {
|
||||
console.log("Connected!")
|
1
websrc/src/react-app-env.d.ts
vendored
Normal file
1
websrc/src/react-app-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="react-scripts" />
|
@ -1,4 +1,3 @@
|
||||
import {EventProp} from "./components/Events";
|
||||
|
||||
/*******************************
|
||||
* Types
|
||||
@ -18,6 +17,12 @@ export type CurrencyPair = {
|
||||
quote: string
|
||||
}
|
||||
|
||||
export type EventProp = {
|
||||
id: number,
|
||||
name: string,
|
||||
tick: number
|
||||
}
|
||||
|
||||
export type FirstConnectMessage = {
|
||||
ticks: Array<number>,
|
||||
prices: Array<number>,
|
@ -7,6 +7,10 @@ export function symbolToPair(symbol: string): CurrencyPair {
|
||||
|
||||
const match = symbol.match(symbol_regex)
|
||||
|
||||
if (!match?.groups) {
|
||||
return { base: "undefined", quote: "undefined" }
|
||||
}
|
||||
|
||||
return {
|
||||
base: match.groups.base,
|
||||
quote: match.groups.quote
|
@ -1,12 +1,29 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["esnext", "DOM"],
|
||||
"jsx": "react",
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es5",
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": [
|
||||
"src"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
]
|
||||
}
|
7966
websrc/yarn.lock
7966
websrc/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user