Skip to content

Commit 401ddcc

Browse files
authored
Merge pull request #424 from wavesplatform/client-359-dex-routing
Client 359 dex routing
2 parents c4aa17c + 1039537 commit 401ddcc

3 files changed

Lines changed: 70 additions & 15 deletions

File tree

src/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,8 @@
358358
{
359359
id: 'dex',
360360
data: {
361+
url:'/dex?assetId1&assetId2',
362+
reloadOnSearch: false,
361363
views: [{ name: 'mainContent' }]
362364
}
363365
},

src/modules/dex/directives/dexWatchlist/DexWatchlist.js

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
* @param {app.utils} utils
88
* @param {JQuery} $element
99
* @param $scope
10+
* @param {$state} $state
11+
* @param {$location} $location
1012
* @return {DexWatchlist}
1113
*/
12-
const controller = function (Base, waves, utils, $element, $scope) {
14+
const controller = function (Base, waves, utils, $element, $scope, $state, $location) {
1315

1416
class DexWatchlist extends Base {
1517

@@ -104,14 +106,20 @@
104106
_activeWatchListId: 'dex.watchlist.activeWatchListId'
105107
});
106108

107-
this.observe('activeRowId', this._onChangeActiveRow);
108-
this.observe('baseAssetId', this._onChangeBaseAsset);
109-
this.observe('_idWatchList', this._onChangeIdWatchList);
110-
this.observe('_activeWatchListId', this._onChangeActiveWatchList);
109+
this._resolveState().then(() => {
110+
this.observe(['_amountAssetId', '_priceAssetId'], () => {
111+
$location.search('assetId2', this._priceAssetId);
112+
$location.search('assetId1', this._amountAssetId);
113+
});
114+
this.observe('activeRowId', this._onChangeActiveRow);
115+
this.observe('baseAssetId', this._onChangeBaseAsset);
116+
this.observe('_idWatchList', this._onChangeIdWatchList);
117+
this.observe('_activeWatchListId', this._onChangeActiveWatchList);
111118

112-
this._initRowId();
113-
this._onChangeBaseAsset();
114-
this._onChangeIdWatchList();
119+
this._initRowId();
120+
this._onChangeBaseAsset();
121+
this._onChangeIdWatchList();
122+
});
115123
}
116124

117125
removeWatchedAsset(event, asset) {
@@ -128,16 +136,48 @@
128136
* @param value
129137
* @private
130138
*/
131-
_onChangeSearchFocus({ value }) {
139+
_onChangeSearchFocus({value}) {
132140
const state = !value || !this._$searchList.children().length;
133141
this._$searchList.toggleClass('hidden', state);
134142
}
135143

144+
/**
145+
* @returns {Promise}
146+
* @private
147+
*/
148+
_resolveState() {
149+
if ($state.params.assetId1 && $state.params.assetId2) {
150+
return Waves.AssetPair.get($state.params.assetId1, $state.params.assetId2)
151+
.then((pair) => {
152+
this._amountAssetId = pair.amountAsset.id;
153+
this._priceAssetId = pair.priceAsset.id;
154+
const list = this._idWatchList.slice();
155+
utils.addUniqueToArray([this._amountAssetId, this._priceAssetId], list);
156+
this._idWatchList = list;
157+
}).catch(() => {
158+
return Waves.AssetPair.get(WavesApp.defaultAssets.WAVES, WavesApp.defaultAssets.BTC)
159+
.then((pair) => {
160+
this._amountAssetId = pair.amountAsset.id;
161+
this._priceAssetId = pair.priceAsset.id;
162+
$location.search('assetId2', this._priceAssetId);
163+
$location.search('assetId1', this._amountAssetId);
164+
const list = this._idWatchList.slice();
165+
utils.addUniqueToArray([this._amountAssetId, this._priceAssetId], list);
166+
this._idWatchList = list;
167+
});
168+
});
169+
} else {
170+
$location.search('assetId2', this._priceAssetId);
171+
$location.search('assetId1', this._amountAssetId);
172+
return Promise.resolve();
173+
}
174+
}
175+
136176
/**
137177
* @param value
138178
* @private
139179
*/
140-
_onChangeSearch({ value }) {
180+
_onChangeSearch({value}) {
141181
if (this._activeXHR) {
142182
this._activeXHR.abort();
143183
this._activeXHR = null;
@@ -168,17 +208,17 @@
168208
});
169209
this._$searchList.empty();
170210
this._$searchList.append($elements);
171-
this._onChangeSearchFocus({ value: this._parent.focused });
211+
this._onChangeSearchFocus({value: this._parent.focused});
172212
}, () => {
173213
this._$searchList.empty();
174214
this._$searchList
175215
.append('<div class="not-found footnote-1 basic-500">No assets found</div>');
176-
this._onChangeSearchFocus({ value: this._parent.focused });
216+
this._onChangeSearchFocus({value: this._parent.focused});
177217
});
178218
}, 500);
179219
} else {
180220
this._$searchList.empty();
181-
this._onChangeSearchFocus({ value: this._parent.focused });
221+
this._onChangeSearchFocus({value: this._parent.focused});
182222
}
183223
}
184224

@@ -188,7 +228,7 @@
188228
* @param isWatched
189229
* @private
190230
*/
191-
_clickSearchItem({ id }, isChangeBase, isWatched) {
231+
_clickSearchItem({id}, isChangeBase, isWatched) {
192232
if (isChangeBase) {
193233
this.baseAssetId = id;
194234
if (this.activeRowId === id) {
@@ -332,7 +372,7 @@
332372
return new DexWatchlist();
333373
};
334374

335-
controller.$inject = ['Base', 'waves', 'utils', '$element', '$scope'];
375+
controller.$inject = ['Base', 'waves', 'utils', '$element', '$scope', '$state', '$location'];
336376

337377
angular.module('app.dex')
338378
.component('wDexWatchlist', {

src/modules/utils/services/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@
372372
});
373373
},
374374

375+
/**
376+
* @name app.utils#addUniqueToArray
377+
* @param {Array} list
378+
* @param {Array} array
379+
*/
380+
addUniqueToArray(list, array) {
381+
list.forEach((item) => {
382+
if (array.indexOf(item) === -1) {
383+
array.push(item);
384+
}
385+
});
386+
},
387+
375388
/**
376389
* @name app.utils#comparators
377390
*/

0 commit comments

Comments
 (0)