Skip to content

Commit 0040d04

Browse files
lukechildssindresorhus
authored andcommitted
Implement GTC Orders (#481)
This PR makes all orders Good 'Till Cancelled (GTC) orders. If you place an order it will stay pending and keep re-broadcasting the order every 10 minutes until it either matches or the user cancels it.
1 parent 75395bb commit 0040d04

File tree

7 files changed

+44
-18
lines changed

7 files changed

+44
-18
lines changed

app/locales/en-US/swap.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
"matched": "Matched",
4545
"reverted": "Reverted",
4646
"pending": "Pending",
47-
"unmatched": "Unmatched"
47+
"open": "Open",
48+
"unmatched": "Unmatched",
49+
"cancelled": "Cancelled"
4850
},
4951
"statusInformation": {
5052
"reverted": "The swap was reverted due to connectivity issues."

app/renderer/api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ export default class Api {
190190

191191
return this.request({
192192
method: opts.type,
193+
gtc: 1,
193194
base: opts.baseCurrency,
194195
rel: opts.quoteCurrency,
195196
basevolume: opts.amount,

app/renderer/components/SwapList.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const SwapHeader = props => (
8383
</div>
8484
);
8585

86-
const SwapItem = ({style, swap}) => (
86+
const SwapItem = ({style, swap, showCancel}) => (
8787
<div className={`row ${swap.orderType}`} style={style}>
8888
<div className="timestamp">{formatDate(swap.timeStarted, 'HH:mm DD/MM/YY')}</div>
8989
<div className="pairs">{swap.baseCurrency}/{swap.quoteCurrency}</div>
@@ -93,13 +93,11 @@ const SwapItem = ({style, swap}) => (
9393
<div className="status__icon" data-status={swap.status}>{swap.statusFormatted}</div>
9494
</div>
9595
<div className="buttons">
96-
{/* Disabled until marketmaker v2
97-
See: https://github.com/atomiclabs/hyperdex/issues/262#issuecomment-396587751showCancel
98-
&&
96+
{showCancel && (
9997
<div className="cancel">
10098
<CancelButton swap={swap}/>
10199
</div>
102-
*/}
100+
)}
103101
<div className="view">
104102
<SwapDetails swap={swap}/>
105103
</div>

app/renderer/components/SwapList.scss

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,17 @@
116116
}
117117
}
118118

119-
@media (min-width: 1260px) {
119+
@media (min-width: 1280px) {
120120
.row {
121121
grid-template-areas: 'timestamp pairs base-amount quote-amount status buttons';
122-
grid-template-columns: 16% 14% 23% 20%;
122+
grid-template-columns: 14% 0% 23% 23%;
123123
justify-content: unset;
124124
white-space: unset;
125125

126+
.pairs {
127+
display: none;
128+
}
129+
126130
.base-amount {
127131
justify-self: start;
128132
}
@@ -132,7 +136,7 @@
132136
}
133137

134138
.status {
135-
justify-self: center;
139+
justify-self: end;
136140
}
137141

138142
.buttons {
@@ -141,6 +145,16 @@
141145
}
142146
}
143147

148+
@media (min-width: 1480px) {
149+
.row {
150+
grid-template-columns: 14% 15% 21% 21%;
151+
152+
.pairs {
153+
display: block;
154+
}
155+
}
156+
}
157+
144158
.timestamp {
145159
color: var(--text-color);
146160
}

app/renderer/swap-db.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import cryptoPouch from 'crypto-pouch';
44
import Emittery from 'emittery';
55
import PQueue from 'p-queue';
66
import roundTo from 'round-to';
7-
import {subDays, isPast, addMinutes} from 'date-fns';
7+
import {subDays, isAfter} from 'date-fns';
88
import appContainer from 'containers/App';
9+
import {appTimeStarted} from '../constants';
910
import swapTransactions from './swap-transactions';
1011
import {translate} from './translate';
1112

@@ -227,14 +228,13 @@ class SwapDB {
227228
}
228229
});
229230

230-
// Treat swaps pending for more than 5 minutes as failed.
231-
// https://github.com/jl777/SuperNET/issues/775#issuecomment-397557568
232-
const timedOut = swap.status === 'pending' && isPast(addMinutes(swap.timeStarted, 5));
233-
if (timedOut) {
231+
// Show open orders from previous session as cancelled
232+
const cancelled = swap.status === 'pending' && isAfter(appTimeStarted, swap.timeStarted);
233+
if (cancelled) {
234234
swap.status = 'failed';
235235
swap.error = {
236236
code: undefined,
237-
message: t('timedOut'),
237+
message: undefined,
238238
};
239239
}
240240

@@ -252,15 +252,22 @@ class SwapDB {
252252
}
253253

254254
if (swap.status === 'failed') {
255-
if (swap.error.code === -9999 || timedOut) {
255+
if (swap.error.code === -9999) {
256256
swap.statusFormatted = t('status.unmatched').toLowerCase();
257257
}
258+
if (swap.error.code === -9998 || cancelled) {
259+
swap.statusFormatted = t('status.cancelled').toLowerCase();
260+
}
258261
if (swap.transactions.find(tx => tx.stage === 'alicereclaim')) {
259262
swap.statusFormatted = t('status.reverted').toLowerCase();
260263
swap.statusInformation = t('statusInformation.reverted');
261264
}
262265
}
263266

267+
if (swap.status === 'pending') {
268+
swap.statusFormatted = t('status.open').toLowerCase();
269+
}
270+
264271
return swap;
265272
}
266273

app/renderer/views/Exchange/Swaps.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const TabView = ({component}) => (
3333
);
3434

3535
const All = () => (
36-
<SwapList swaps={exchangeContainer.state.swapHistory} limit={swapLimit}/>
36+
<SwapList swaps={exchangeContainer.state.swapHistory} limit={swapLimit} showCancel/>
3737
);
3838

3939
const Split = () => {
@@ -45,7 +45,7 @@ const Split = () => {
4545
);
4646

4747
return (
48-
<SwapList swaps={filteredData} limit={swapLimit}/>
48+
<SwapList swaps={filteredData} limit={swapLimit} showCancel/>
4949
);
5050
};
5151

app/renderer/views/Trades.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
justify-content: unset;
6363
white-space: unset;
6464

65+
.pairs {
66+
display: block;
67+
}
68+
6569
.base-amount {
6670
justify-self: start;
6771
}

0 commit comments

Comments
 (0)