forked from ynzheng/EtherDelta.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·160 lines (159 loc) · 5.62 KB
/
script.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* eslint-env browser */
/* global $, bundle */
$(() => {
$('body').on('click', '#accountSubmit', (e) => {
e.preventDefault();
$('#accountModal').modal('hide');
bundle.EtherDelta.addAccount($('#accountAddr').val(), $('#accountPk').val());
});
});
function buyChange() { // eslint-disable-line no-unused-vars
const amount = Number($('#buyAmount').val());
const price = Number($('#buyPrice').val());
const total = (amount * price).toFixed(3);
const isInCross = bundle.EtherDelta.isInCross(price, 'buy');
if (isInCross) {
$('#buyInCross').html(`Your order is in cross with the best sell order in the order book (price = ${isInCross}).`);
} else {
$('#buyInCross').html('');
}
$('#buyTotal').val(total);
}
function sellChange() { // eslint-disable-line no-unused-vars
const amount = Number($('#sellAmount').val());
const price = Number($('#sellPrice').val());
const total = (amount * price).toFixed(3);
const isInCross = bundle.EtherDelta.isInCross(price, 'sell');
if (isInCross) {
$('#sellInCross').html(`Your order is in cross with the best buy order in the order book (price = ${isInCross}).`);
} else {
$('#sellInCross').html('');
}
$('#sellTotal').val(total);
}
$(() => {
$('body').on('click', '#buySubmit', (e) => {
e.preventDefault();
bundle.EtherDelta.order(
'buy',
$('#buyAmount').val(),
$('#buyPrice').val(),
$('#buyExpires').val(),
false);
});
});
$(() => {
$('body').on('click', '#sellSubmit', (e) => {
e.preventDefault();
bundle.EtherDelta.order(
'sell',
$('#sellAmount').val(),
$('#sellPrice').val(),
$('#sellExpires').val(),
false);
});
});
$('#buyCrossModal').on('show.bs.modal', (e) => {
const order = $(e.relatedTarget).data('order');
const amount = $(e.relatedTarget).data('amount');
const desc = $(e.relatedTarget).data('desc');
const token = $(e.relatedTarget).data('token');
const base = $(e.relatedTarget).data('base');
const price = $(e.relatedTarget).data('price');
$('#buyCrossOrder').val(JSON.stringify(order.order));
$('#buyCrossAmount').val(amount);
$('#buyCrossDesc').html(desc);
$('.buyCrossToken').html(token);
$('.buyCrossBase').html(base);
$('#buyCrossBaseAmount').val((amount * price).toFixed(3));
$('#buyCrossFee').val((amount * price * 0.003).toFixed(3));
$('#buyCrossBaseAmount').change(() => {
$('#buyCrossAmount').val((Number($('#buyCrossBaseAmount').val()) / price).toFixed(3));
$('#buyCrossFee').val(($('#buyCrossBaseAmount').val() * 0.003).toFixed(3));
});
$('#buyCrossAmount').change(() => {
$('#buyCrossBaseAmount').val((Number($('#buyCrossAmount').val()) * price).toFixed(3));
$('#buyCrossFee').val(($('#buyCrossBaseAmount').val() * 0.003).toFixed(3));
});
});
$('#sellCrossModal').on('show.bs.modal', (e) => {
const order = $(e.relatedTarget).data('order');
const amount = $(e.relatedTarget).data('amount');
const desc = $(e.relatedTarget).data('desc');
const token = $(e.relatedTarget).data('token');
const base = $(e.relatedTarget).data('base');
const price = $(e.relatedTarget).data('price');
$('#sellCrossOrder').val(JSON.stringify(order.order));
$('#sellCrossAmount').val(amount);
$('#sellCrossDesc').html(desc);
$('.sellCrossToken').html(token);
$('.sellCrossBase').html(base);
$('#sellCrossBaseAmount').val((amount * price).toFixed(3));
$('#sellCrossFee').val((amount * 0.003).toFixed(3));
$('#sellCrossBaseAmount').change(() => {
$('#sellCrossAmount').val((Number($('#sellCrossBaseAmount').val()) / price).toFixed(3));
$('#sellCrossFee').val(($('#sellCrossAmount').val() * 0.003).toFixed(3));
});
$('#sellCrossAmount').change(() => {
$('#sellCrossBaseAmount').val((Number($('#sellCrossAmount').val()) * price).toFixed(3));
$('#sellCrossFee').val(($('#sellCrossAmount').val() * 0.003).toFixed(3));
});
});
$(() => {
$('body').on('click', '#buyCrossSubmit', (e) => {
e.preventDefault();
$('#buyCrossModal').modal('hide');
bundle.EtherDelta.trade('buy', JSON.parse($('#buyCrossOrder').val()), $('#buyCrossAmount').val());
});
});
$(() => {
$('body').on('click', '#sellCrossSubmit', (e) => {
e.preventDefault();
$('#sellCrossModal').modal('hide');
bundle.EtherDelta.trade(
'sell',
JSON.parse($('#sellCrossOrder').val()),
$('#sellCrossAmount').val());
});
});
$(() => {
$('body').on('click', '#otherTokenSubmit', (e) => {
e.preventDefault();
$('#otherTokenModal').modal('hide');
bundle.EtherDelta.selectToken(
$('#otherTokenAddr').val(),
$('#otherTokenName').val(),
$('#otherTokenDecimals').val());
});
});
$(() => {
$('body').on('click', '#otherBaseSubmit', (e) => {
e.preventDefault();
$('#otherBaseModal').modal('hide');
bundle.EtherDelta.selectBase(
$('#otherBaseAddr').val(),
$('#otherBaseName').val(),
$('#otherBaseDecimals').val());
});
});
$('#gasPriceModal').on('show.bs.modal', () => {
$('#gasPrice').val(bundle.EtherDelta.config.ethGasPrice / 1000000000);
});
$(() => {
$('body').on('click', '#gasPriceSubmit', (e) => {
e.preventDefault();
$('#gasPriceModal').modal('hide');
bundle.EtherDelta.setGasPrice(
$('#gasPrice').val());
});
});
function depositClick(addr) { // eslint-disable-line no-unused-vars
bundle.EtherDelta.deposit(addr, $(`#depositAmount${addr}`).val());
}
function withdrawClick(addr) { // eslint-disable-line no-unused-vars
bundle.EtherDelta.withdraw(addr, $(`#withdrawAmount${addr}`).val());
}
function transferClick(addr) { // eslint-disable-line no-unused-vars
bundle.EtherDelta.transfer(addr, $(`#transferAmount${addr}`).val(), $(`#transferTo${addr}`).val());
}
$(() => {});