ported to nodejs

This commit is contained in:
Giulio De Pasquale 2020-12-30 12:55:24 +00:00
parent 1294274951
commit 698617b977
32 changed files with 7320 additions and 1573 deletions

1
websrc/.eslintcache Normal file

File diff suppressed because one or more lines are too long

24
websrc/.gitignore vendored
View File

@ -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
View 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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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)

View File

@ -28,7 +28,7 @@ class CoinBalance extends Component<CoinBalanceProps> {
return ( return (
<div className="flex-grow flex px-6 py-3 text-gray-800 items-center border-b -mx-4 align-middle"> <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}*/} {/*{icon}*/}
</div> </div>
<div className="w-2/5 xl:w-1/4 px-4 flex items-center"> <div className="w-2/5 xl:w-1/4 px-4 flex items-center">

View File

@ -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>
)
}
}

View File

@ -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>
)
}
}

View File

@ -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>
)
}
}

View File

@ -1,40 +1,55 @@
{ {
"name": "rustico", "name": "bfxbot",
"version": "1.0.0", "version": "0.1.0",
"main": "index.tsx", "private": true,
"license": "MIT", "dependencies": {
"devDependencies": { "@testing-library/jest-dom": "^5.11.4",
"@types/luxon": "^1.25.0", "@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": "^17.0.0",
"@types/react-dom": "^17.0.0", "@types/react-dom": "^17.0.0",
"@types/react-helmet": "^6.1.0", "plotly.js": "^1.58.4",
"@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",
"react": "^17.0.1", "react": "^17.0.1",
"react-cryptocoins": "^1.0.11",
"react-dom": "^17.0.1", "react-dom": "^17.0.1",
"react-helmet": "^6.1.0", "react-plotly.js": "^2.5.1",
"socket.io-client": "~3", "react-scripts": "4.0.1",
"tailwindcss": "^2.0.2" "socket.io-client": "^3.0.4",
"typescript": "^4.1.3",
"web-vitals": "^0.2.4"
}, },
"scripts": { "scripts": {
"build:tailwind": "tailwindcss build css/index.css -o css/tailwind.css", "start": "react-scripts start",
"watch": "parcel watch index.tsx -d ../static", "build": "react-scripts build",
"prestart": "yarn run build:tailwind", "test": "react-scripts test",
"prebuild": "yarn run build:tailwind", "eject": "react-scripts eject"
"start": "python ../main.py & yarn run watch" },
"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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

43
websrc/public/index.html Normal file
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
websrc/public/logo512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View 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
View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View 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;

View 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 &asymp; USD {this.totalQuoteBalance().toLocaleString()}
</div>
</div>
</div>
</div>
)
}
}

View File

@ -0,0 +1,9 @@
import React, { Component } from "react";
import { CurrencyPair } from "../types";
export type CurrencyPairProps = {
active_pair: CurrencyPair,
pairs: Array<CurrencyPair>
}

View File

@ -9,7 +9,7 @@ class Icon extends Component <IconProps> {
private readonly width: string; private readonly width: string;
private readonly height: string; private readonly height: string;
constructor(props) { constructor(props: IconProps) {
super(props); super(props);
this.width = "w-" + this.props.width.toString(); this.width = "w-" + this.props.width.toString();

View File

@ -1,8 +1,8 @@
import React, {Component} from "react"; import React, { Component } from "react";
import {WalletCard} from "./Cards"; import { WalletCard } from "./Cards";
export class Navbar extends Component<any, any> { export class Navbar extends Component {
constructor(props) { constructor(props: {}) {
super(props); super(props);
} }
@ -27,9 +27,9 @@ export class Navbar extends Component<any, any> {
<li className="mt-3 p-2 text-gray-400 dark:text-blue-300 rounded-lg"> <li className="mt-3 p-2 text-gray-400 dark:text-blue-300 rounded-lg">
<a href="#" className=" flex flex-col items-center"> <a href="#" className=" flex flex-col items-center">
<svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" <svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"> stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"/> d="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />
</svg> </svg>
<span className="text-xs mt-2 text-gray-300">Reports</span> <span className="text-xs mt-2 text-gray-300">Reports</span>
</a> </a>
@ -39,11 +39,11 @@ export class Navbar extends Component<any, any> {
<li className="mt-auto p-2 text-gray-400 dark:text-blue-300 rounded-lg"> <li className="mt-auto p-2 text-gray-400 dark:text-blue-300 rounded-lg">
<a href="#" className=" flex flex-col items-center"> <a href="#" className=" flex flex-col items-center">
<svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" <svg className="w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"> stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/> d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/> d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg> </svg>
<span className="text-xs mt-2 text-gray-300">Settings</span> <span className="text-xs mt-2 text-gray-300">Settings</span>
</a> </a>
@ -55,7 +55,7 @@ export class Navbar extends Component<any, any> {
} }
export class Sidebar extends Component { export class Sidebar extends Component {
constructor(props) { constructor(props: {}) {
super(props); super(props);
} }
@ -64,7 +64,7 @@ export class Sidebar extends Component {
<aside <aside
className="w-1/4 my-1 mr-1 pr-2 py-4 flex flex-col bg-gray-200 dark:bg-black className="w-1/4 my-1 mr-1 pr-2 py-4 flex flex-col bg-gray-200 dark:bg-black
dark:text-gray-400 rounded-r-lg overflow-y-auto"> dark:text-gray-400 rounded-r-lg overflow-y-auto">
<WalletCard/> <WalletCard />
</aside> </aside>
) )
} }

View File

@ -9,7 +9,7 @@ export type ModalProps = {
} }
export class ClosePositionModal extends Component<ModalProps, any> { export class ClosePositionModal extends Component<ModalProps, any> {
constructor(props) { constructor(props: ModalProps) {
super(props); super(props);
} }

View File

@ -1,8 +1,8 @@
import React, {Component} from "react" import React, { Component } from "react"
import Plot from "react-plotly.js" import Plot from "react-plotly.js"
import {socket} from '../'; import { socket } from '../';
import {EventName, NewTickMessage} from "../types"; import { EventName, NewTickMessage } from "../types";
type FirstConnectData = { type FirstConnectData = {
@ -29,11 +29,11 @@ class RPlot extends Component<{}, PlotState> {
state = { state = {
x: [], x: [],
y: [], y: [],
current_price_line: {x0: 0, x1: 0, y0: 0, y1: 0}, current_price_line: { x0: 0, x1: 0, y0: 0, y1: 0 },
positions_price_lines: [] positions_price_lines: []
} }
constructor(props) { constructor(props: {}) {
super(props) super(props)
} }
@ -79,24 +79,24 @@ class RPlot extends Component<{}, PlotState> {
} }
render() { 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) { // if (this.state.positions_price_lines.length > 0) {
additional_shapes = this.state.positions_price_lines.map((priceline: PriceLine) => { // additional_shapes = this.state.positions_price_lines.map((priceline: PriceLine) => {
return { // return {
type: 'line', // type: 'line',
x0: priceline.x0, // x0: priceline.x0,
y0: priceline.y0, // y0: priceline.y0,
x1: priceline.x1, // x1: priceline.x1,
y1: priceline.y1, // y1: priceline.y1,
line: { // line: {
color: 'rgb(1, 1, 1)', // color: 'rgb(1, 1, 1)',
width: 1, // width: 1,
dash: 'solid' // dash: 'solid'
} // }
} // }
}) // })
} // }
return ( return (
<Plot <Plot
@ -117,20 +117,20 @@ class RPlot extends Component<{}, PlotState> {
pad: 4 pad: 4
}, },
dragmode: "pan", dragmode: "pan",
shapes: [ // shapes: [
{ // {
type: 'line', // type: 'line',
x0: this.state.current_price_line.x0, // x0: this.state.current_price_line.x0,
y0: this.state.current_price_line.y0, // y0: this.state.current_price_line.y0,
x1: this.state.current_price_line.x1, // x1: this.state.current_price_line.x1,
y1: this.state.current_price_line.y1, // y1: this.state.current_price_line.y1,
line: { // line: {
color: 'rgb(50, 171, 96)', // color: 'rgb(50, 171, 96)',
width: 2, // width: 2,
dash: 'dashdot' // dash: 'dashdot'
} // }
}, // },
].concat(additional_shapes), // ].concat(additional_shapes),
xaxis: { xaxis: {
title: { title: {
text: 'Tick', text: 'Tick',
@ -158,7 +158,7 @@ class RPlot extends Component<{}, PlotState> {
displayModeBar: false, displayModeBar: false,
responsive: true, responsive: true,
}} }}
style={{width: '100%', height: '100%'}} style={{ width: '100%', height: '100%' }}
/> />
) )
} }

View File

@ -1,7 +1,7 @@
import React, {Component} from "react"; import React, { Component } from "react";
import {EventName, GetProfitLossMessage, NewTickMessage, PutProfitLossMessage} from "../types"; import { EventName, GetProfitLossMessage, NewTickMessage, PutProfitLossMessage } from "../types";
import {socket} from "../index"; import { socket } from "../index";
import {DateTime} from "luxon"; import { DateTime } from "luxon";
type QuoteStatusProps = { type QuoteStatusProps = {
percentage?: boolean, percentage?: boolean,
@ -17,9 +17,14 @@ export class QuoteStatus extends Component<QuoteStatusProps> {
private sign: string; private sign: string;
private signClass: string; private signClass: string;
constructor(props) { constructor(props: QuoteStatusProps) {
super(props); super(props);
this.whole = 0;
this.decimal = 0;
this.sign = "";
this.signClass = "";
this.deriveProps() this.deriveProps()
} }
@ -45,8 +50,8 @@ export class QuoteStatus extends Component<QuoteStatusProps> {
if (this.props.percentage) { if (this.props.percentage) {
return ( return (
<> <>
<span className="text-4xl text-bold align-top"> <span className="text-4xl text-bold align-top">
{this.renderSign()}</span> {this.renderSign()}</span>
<span className="text-5xl">{Math.abs(this.props.amount).toFixed(2)}</span> <span className="text-5xl">{Math.abs(this.props.amount).toFixed(2)}</span>
<span className="text-3xl align-top">%</span> <span className="text-3xl align-top">%</span>
</> </>
@ -89,20 +94,26 @@ type DateButtonState = {
class DateButton extends Component<DateButtonProps, 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 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 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 = { state = {
selected: this.props.selected_default selected: false
} }
constructor(props) { constructor(props: DateButtonProps) {
super(props); super(props);
if (this.props.selected_default) {
this.state = {
selected: this.props.selected_default
}
}
this.updateClass() this.updateClass()
} }
onClick() { onClick() {
this.setState({selected: !this.state.selected}, this.updateClass) this.setState({ selected: !this.state.selected }, this.updateClass)
this.props.onClick() this.props.onClick()
} }
@ -114,7 +125,7 @@ class DateButton extends Component<DateButtonProps, DateButtonState> {
render() { render() {
return ( return (
<button key={this.props.label} type="button" <button key={this.props.label} type="button"
className={this.currentClass} onClick={this.onClick.bind(this)}> className={this.currentClass} onClick={this.onClick.bind(this)}>
{this.props.label} {this.props.label}
</button> </button>
) )
@ -140,7 +151,7 @@ type StatusBarState = {
export class Statusbar extends Component<NewTickMessage, StatusBarState> { export class Statusbar extends Component<NewTickMessage, StatusBarState> {
constructor(props) { constructor(props: NewTickMessage) {
super(props); super(props);
this.state = { this.state = {
@ -223,21 +234,21 @@ export class Statusbar extends Component<NewTickMessage, StatusBarState> {
</div> </div>
<div className="hidden lg:flex"> <div className="hidden lg:flex">
<button type="button" <button type="button"
className="appearance-none py-4 text-blue-600 border-b border-blue-dark mr-6"> className="appearance-none py-4 text-blue-600 border-b border-blue-dark mr-6">
Bitcoin Bitcoin
</button> </button>
</div> </div>
<div className="flex text-sm"> <div className="flex text-sm">
<DateButton key={PeriodUnit.MINUTE} label={"1m"} <DateButton key={PeriodUnit.MINUTE} label={"1m"}
onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MINUTE)}/> onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MINUTE)} />
<DateButton key={PeriodUnit.DAY} label={"1D"} <DateButton key={PeriodUnit.DAY} label={"1D"}
onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.DAY)}/> onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.DAY)} />
<DateButton key={PeriodUnit.WEEK} label={"1W"} selected_default={true} <DateButton key={PeriodUnit.WEEK} label={"1W"} selected_default={true}
onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.WEEK)}/> onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.WEEK)} />
<DateButton key={PeriodUnit.MONTH} label={"1M"} <DateButton key={PeriodUnit.MONTH} label={"1M"}
onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MONTH)}/> onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MONTH)} />
<DateButton key={PeriodUnit.YEAR} label={"1Y"} <DateButton key={PeriodUnit.YEAR} label={"1Y"}
onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.YEAR)}/> onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.YEAR)} />
{/*<DateButton label={"ALL"} onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MINUTE)}/>*/} {/*<DateButton label={"ALL"} onClick={() => this.changeProfitLossPeriod(1, PeriodUnit.MINUTE)}/>*/}
</div> </div>
</div> </div>
@ -260,8 +271,8 @@ export class Statusbar extends Component<NewTickMessage, StatusBarState> {
</select> </select>
<div className="pointer-events-none absolute pin-y pin-r flex items-center px-2 text-gray-300"> <div className="pointer-events-none absolute pin-y pin-r flex items-center px-2 text-gray-300">
<svg className="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" <svg className="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"> viewBox="0 0 20 20">
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"/> <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
</svg> </svg>
</div> </div>
</div> </div>
@ -270,20 +281,20 @@ export class Statusbar extends Component<NewTickMessage, StatusBarState> {
<div className="w-1/3 text-center py-8"> <div className="w-1/3 text-center py-8">
<div className="border-r"> <div className="border-r">
<QuoteStatus key={this.props.price} quote_symbol={"USD"} amount={this.props.price} <QuoteStatus key={this.props.price} quote_symbol={"USD"} amount={this.props.price}
subtitle={"Bitcoin price"}/> subtitle={"Bitcoin price"} />
</div> </div>
</div> </div>
<div className="w-1/3 text-center py-8"> <div className="w-1/3 text-center py-8">
<div className="border-r"> <div className="border-r">
<QuoteStatus key={this.state.pl} quote_symbol={"USD"} sign={true} amount={this.state.pl} <QuoteStatus key={this.state.pl} quote_symbol={"USD"} sign={true} amount={this.state.pl}
subtitle={"since last ".concat(this.state.pl_period_unit)}/> subtitle={"since last ".concat(this.state.pl_period_unit)} />
</div> </div>
</div> </div>
<div className="w-1/3 text-center py-8"> <div className="w-1/3 text-center py-8">
<div> <div>
<QuoteStatus key={this.state.pl_perc} percentage={true} sign={true} <QuoteStatus key={this.state.pl_perc} percentage={true} sign={true}
amount={this.state.pl_perc} amount={this.state.pl_perc}
subtitle={"since last ".concat(this.state.pl_period_unit)}/> subtitle={"since last ".concat(this.state.pl_period_unit)} />
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
import React, {Component} from "react" import React, { Component } from "react"
import {PositionProp} from "../types"; import { PositionProp } from "../types";
import {ClosePositionModal} from "./Overlays"; import { ClosePositionModal } from "./Overlays";
type PositionsTableState = { type PositionsTableState = {
showConfirmation: boolean, showConfirmation: boolean,
@ -8,7 +8,7 @@ type PositionsTableState = {
} }
export class PositionsTable extends Component<{ positions: Array<PositionProp> }, PositionsTableState> { export class PositionsTable extends Component<{ positions: Array<PositionProp> }, PositionsTableState> {
constructor(props) { constructor(props: { positions: PositionProp[]; } | Readonly<{ positions: PositionProp[]; }>) {
super(props); super(props);
this.toggleConfirmation = this.toggleConfirmation.bind(this) this.toggleConfirmation = this.toggleConfirmation.bind(this)
} }
@ -42,13 +42,13 @@ export class PositionsTable extends Component<{ positions: Array<PositionProp> }
renderTableHead() { renderTableHead() {
return ["status", "currency pair", "base price", "amount", "Profit/Loss", "actions"].map((entry) => { return ["status", "currency pair", "base price", "amount", "Profit/Loss", "actions"].map((entry) => {
return ( return (
<th scope="col" <th scope="col"
className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
{entry} {entry}
</th> </th>
) )
} }
) )
} }
@ -65,7 +65,7 @@ export class PositionsTable extends Component<{ positions: Array<PositionProp> }
<td className="px-6 py-4 whitespace-nowrap"> <td className="px-6 py-4 whitespace-nowrap">
<span <span
className={stateClass}> className={stateClass}>
{position.state} {position.state}
</span> </span>
</td> </td>
@ -115,20 +115,20 @@ export class PositionsTable extends Component<{ positions: Array<PositionProp> }
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
<ClosePositionModal positionId={this.state.positionToClose} toggleConfirmation={this.toggleConfirmation} <ClosePositionModal positionId={this.state.positionToClose} toggleConfirmation={this.toggleConfirmation}
show={this.state.showConfirmation}/> show={this.state.showConfirmation} />
<div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8"> <div className="-my-2 overflow-x-auto sm:-mx-6 lg:-mx-8">
<div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8"> <div className="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
<div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg"> <div className="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
<table className="min-w-full divide-y divide-gray-200"> <table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50"> <thead className="bg-gray-50">
<tr> <tr>
{this.renderTableHead()} {this.renderTableHead()}
</tr> </tr>
</thead> </thead>
<tbody className="bg-white divide-y divide-gray-200"> <tbody className="bg-white divide-y divide-gray-200">
{this.renderTableRows()} {this.renderTableRows()}
</tbody> </tbody>
</table> </table>
</div> </div>

1
websrc/src/custom.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module 'react-cryptocoins';

View File

@ -4,7 +4,7 @@ import "./css/tailwind.css";
import App from "./components/App"; import App from "./components/App";
import io from "socket.io-client"; import io from "socket.io-client";
export const socket = io(); export const socket = io.io();
socket.on("connect", function () { socket.on("connect", function () {
console.log("Connected!") console.log("Connected!")

1
websrc/src/react-app-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="react-scripts" />

View File

@ -1,4 +1,3 @@
import {EventProp} from "./components/Events";
/******************************* /*******************************
* Types * Types
@ -18,6 +17,12 @@ export type CurrencyPair = {
quote: string quote: string
} }
export type EventProp = {
id: number,
name: string,
tick: number
}
export type FirstConnectMessage = { export type FirstConnectMessage = {
ticks: Array<number>, ticks: Array<number>,
prices: Array<number>, prices: Array<number>,

View File

@ -1,12 +1,16 @@
import {CurrencyPair} from "./types"; import { CurrencyPair } from "./types";
// import * as Icon from 'react-cryptocoins' // import * as Icon from 'react-cryptocoins'
import {Btc, Eth, Xmr} from 'react-cryptocoins'; import { Btc, Eth, Xmr } from 'react-cryptocoins';
export function symbolToPair(symbol: string): CurrencyPair { export function symbolToPair(symbol: string): CurrencyPair {
const symbol_regex = "t(?<base>[a-zA-Z]{3})(?<quote>[a-zA-Z]{3})" const symbol_regex = "t(?<base>[a-zA-Z]{3})(?<quote>[a-zA-Z]{3})"
const match = symbol.match(symbol_regex) const match = symbol.match(symbol_regex)
if (!match?.groups) {
return { base: "undefined", quote: "undefined" }
}
return { return {
base: match.groups.base, base: match.groups.base,
quote: match.groups.quote quote: match.groups.quote

View File

@ -1,12 +1,29 @@
{ {
"compilerOptions": { "compilerOptions": {
"lib": ["esnext", "DOM"], "target": "es5",
"jsx": "react", "lib": [
"moduleResolution": "node", "dom",
"allowSyntheticDefaultImports": true, "dom.iterable",
"esModuleInterop": true, "esnext"
},
"exclude": [
"node_modules"
], ],
} "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"
]
}

File diff suppressed because it is too large Load Diff