forked from chrisleekr/binance-trading-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SymbolDeleteIcon.js
115 lines (98 loc) · 2.65 KB
/
SymbolDeleteIcon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* eslint-disable no-unused-vars */
/* eslint-disable react/jsx-no-undef */
/* eslint-disable no-undef */
class SymbolDeleteIcon extends React.Component {
constructor(props) {
super(props);
this.state = {
showModal: false
};
this.handleModalShow = this.handleModalShow.bind(this);
this.handleModalClose = this.handleModalClose.bind(this);
this.handleDelete = this.handleDelete.bind(this);
}
handleModalShow() {
this.setState({
showModal: true
});
}
handleModalClose() {
this.setState({
showModal: false
});
}
canDelete() {
const { symbolInfo } = this.props;
if (
symbolInfo.buy.openOrders.length === 0 &&
symbolInfo.sell.lastBuyPrice <= 0 &&
symbolInfo.sell.openOrders.length === 0
) {
return true;
}
return false;
}
handleDelete(e) {
e.preventDefault();
const {
symbolInfo: { symbol }
} = this.props;
const authToken = localStorage.getItem('authToken') || '';
axios
.delete(`/symbol/${symbol}`, {
data: {
authToken
}
})
.catch(e => {
console.log(e);
});
this.handleModalClose();
}
render() {
const { isAuthenticated, symbolInfo } = this.props;
if (isAuthenticated === false) {
return '';
}
if (this.canDelete()) {
return (
<div className='header-column-icon-wrapper symbol-delete-wrapper'>
<button
type='button'
className='btn btn-sm btn-link p-0 pl-1'
onClick={this.handleModalShow}>
<i className='fas fa-times-circle'></i>
</button>
<Modal show={this.state.showModal} onHide={this.handleModalClose}>
<Modal.Header className='pt-1 pb-1'>
<Modal.Title>Remove Symbol - {symbolInfo.symbol}</Modal.Title>
</Modal.Header>
<Modal.Body>
Are you sure to remove this symbol from the cache?
<br />
Note that it is simply removing cache values for the symbol.
<br />
If the symbol is still monitoring, then it will show up again.
</Modal.Body>
<Modal.Footer>
<Button
variant='secondary'
size='sm'
onClick={this.handleModalClose}>
Close
</Button>
<Button
type='button'
variant='danger'
size='sm'
onClick={this.handleDelete}>
Remove
</Button>
</Modal.Footer>
</Modal>
</div>
);
}
return '';
}
}