Skip to content

Commit

Permalink
0.3.0 refactoring: create order
Browse files Browse the repository at this point in the history
  • Loading branch information
suenot committed Nov 17, 2018
1 parent 18dfc5b commit 765373e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 59 deletions.
4 changes: 1 addition & 3 deletions react-client/src/core_components/CreateOrder/CreateOrder.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { observer } from 'mobx-react'
import Button from '@material-ui/core/Button'
import Preloader from '../Preloader'
import TextField from '@material-ui/core/TextField'
import InputAdornment from '@material-ui/core/InputAdornment'

Expand All @@ -13,12 +12,11 @@ class CreateOrder extends React.Component {
render() {
const {stock, pair, type} = this.props.data
const key = `${stock}--${pair}--${type}`
console.log(JSON.stringify(CreateOrderStore.form[key]))
if (CreateOrderStore.form[key] === undefined) this.initForm(key)
return (
<div className="simpleForm">
<div className="createOrder-header">
Available: {(type === 'buy' ? CreateOrderStore.availableBuy : CreateOrderStore.availableSell).toFixed(8)} {type === 'buy' ? pair.split('_')[1] : pair.split('_')[0]}
Available: {(type === 'buy' ? BalanceStore.available(stock, pair).buy : BalanceStore.available(stock, pair).sell).toFixed(8)} {type === 'buy' ? pair.split('_')[1] : pair.split('_')[0]}
</div>
<div className="simpleForm-formGroup">
<TextField
Expand Down
70 changes: 14 additions & 56 deletions react-client/src/stores/BalanceStore.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
import { observable, action, computed } from 'mobx'
import axios from 'axios'
import _ from 'lodash'
import DashboardsStore from './DashboardsStore'

import SettingsStore from './SettingsStore'

class BalanceStore {
constructor() {
// const fetchBalanceStock = () => {
// this.fetchBalance(this.stock)
// this.available()
// }
// if (this.balanceTotal_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalance('TOTAL')
// if (this.balanceStock_counter > 0 && (SettingsStore.fetchEnabled.value)) fetchBalanceStock()
// if (this.balanceHistoryTotal_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalanceHistory('TOTAL')
// if (this.balanceHistoryStock_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalanceHistory(this.stock)
// setInterval(() => {
// if (this.balanceTotal_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalance('TOTAL')
// if (this.balanceStock_counter > 0 && (SettingsStore.fetchEnabled.value)) fetchBalanceStock()
// if (this.balanceHistoryTotal_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalanceHistory('TOTAL')
// if (this.balanceHistoryStock_counter > 0 && (SettingsStore.fetchEnabled.value)) this.fetchBalanceHistory(this.stock)
// }, 5000)
const start = () => {
_.forEach(this.counters, (counter, key) => {
if ( counter > 0 && (SettingsStore.fetchEnabled.value) ) {
Expand All @@ -34,33 +20,25 @@ class BalanceStore {
}, 2000)
}

// @computed get stock() {return DashboardsStore.stock }
// @computed get pair() {return DashboardsStore.pair }
@computed get terminalBackend() {return SettingsStore.terminalBackend.value }

// fetchBalanceStock_hash = ''
// fetchBalanceTotal_hash = ''
// fetchBalanceHistoryStock_hash = ''
// fetchBalanceHistoryTotal_hash = ''
hashes = {}

@observable precision = 8
balance = {}
// @observable balanceTotal = {'totalBTC': 0, 'totalUSD': 0, 'datetime': 0, 'data': []}
// @observable balanceStock = {'totalBTC': 0, 'totalUSD': 0, 'datetime': 0, 'data': []}
// @observable balanceHistoryTotal = []
// @observable balanceHistoryStock = []

@observable availableBuy = 0
@observable availableSell = 0

@action available() {
var current = this.pair.split('_')
var availableBuy = _.find(this.balanceStock.data, {'shortName': current[1]})
var availableSell = _.find(this.balanceStock.data, {'shortName': current[0]})

this.availableBuy = availableBuy ? availableBuy.free : 0
this.availableSell = availableSell ? availableSell.free : 0
@action available(stock, pair) {
var key = `now--${stock}`
var current = pair.split('_')
var availableBuy
var availableSell
if (this.balance[key] !== undefined && this.balance[key].data !== undefined) {
availableBuy = _.find(this.balance[key].data, {'shortName': current[1]})
availableSell = _.find(this.balance[key].data, {'shortName': current[0]})
}
return {
buy: availableBuy ? availableBuy.free : 0,
sell: availableSell ? availableSell.free : 0
}
}

@action fetchBalance(stock, key, type){
Expand All @@ -75,26 +53,6 @@ class BalanceStore {
})
}

// @action fetchBalanceHistory(stock, key){
// axios.get(`${this.terminalBackend}/balance/history/${type}/${stock}`)
// .then((response) => {
// if (this.hashes[key] === JSON.stringify(response.data)) return true
// this.hashes[key] = JSON.stringify(response.data)
// this.balance[key] = response.data
// })
// .catch((error) => {
// this.balance[key] = {}
// })
// }

// counters
// balanceTotal_counter = 0
// balanceStock_counter = 0
// balanceHistoryTotal_counter = 0
// balanceHistoryStock_counter = 0
// @action count(counterName, n) {
// this[counterName] += n
// }
counters = {}
@action count(n, data) {
const {type, stock} = data
Expand Down

0 comments on commit 765373e

Please sign in to comment.