Skip to content

Commit 1039537

Browse files
committed
CLIENT-359: fix routing
1 parent 55bb199 commit 1039537

1 file changed

Lines changed: 52 additions & 27 deletions

File tree

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

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @param {app.utils} utils
88
* @param {JQuery} $element
99
* @param $scope
10+
* @param {$state} $state
11+
* @param {$location} $location
1012
* @return {DexWatchlist}
1113
*/
1214
const controller = function (Base, waves, utils, $element, $scope, $state, $location) {
@@ -104,29 +106,20 @@
104106
_activeWatchListId: 'dex.watchlist.activeWatchListId'
105107
});
106108

107-
if ($state.params.assetId1 && $state.params.assetId2) {
108-
this._amountAssetId = $state.params.assetId1;
109-
this._priceAssetId = $state.params.assetId2;
110-
const list = this._idWatchList.slice();
111-
utils.addUniqueToArray([this._amountAssetId, this._priceAssetId], list);
112-
this._idWatchList = list;
113-
} else {
114-
$location.search('assetId2', this._priceAssetId);
115-
$location.search('assetId1', this._amountAssetId);
116-
}
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);
117118

118-
this.observe(['_amountAssetId', '_priceAssetId'], () => {
119-
$location.search('assetId2', this._priceAssetId);
120-
$location.search('assetId1', this._amountAssetId);
119+
this._initRowId();
120+
this._onChangeBaseAsset();
121+
this._onChangeIdWatchList();
121122
});
122-
this.observe('activeRowId', this._onChangeActiveRow);
123-
this.observe('baseAssetId', this._onChangeBaseAsset);
124-
this.observe('_idWatchList', this._onChangeIdWatchList);
125-
this.observe('_activeWatchListId', this._onChangeActiveWatchList);
126-
127-
this._initRowId();
128-
this._onChangeBaseAsset();
129-
this._onChangeIdWatchList();
130123
}
131124

132125
removeWatchedAsset(event, asset) {
@@ -143,16 +136,48 @@
143136
* @param value
144137
* @private
145138
*/
146-
_onChangeSearchFocus({ value }) {
139+
_onChangeSearchFocus({value}) {
147140
const state = !value || !this._$searchList.children().length;
148141
this._$searchList.toggleClass('hidden', state);
149142
}
150143

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+
151176
/**
152177
* @param value
153178
* @private
154179
*/
155-
_onChangeSearch({ value }) {
180+
_onChangeSearch({value}) {
156181
if (this._activeXHR) {
157182
this._activeXHR.abort();
158183
this._activeXHR = null;
@@ -183,17 +208,17 @@
183208
});
184209
this._$searchList.empty();
185210
this._$searchList.append($elements);
186-
this._onChangeSearchFocus({ value: this._parent.focused });
211+
this._onChangeSearchFocus({value: this._parent.focused});
187212
}, () => {
188213
this._$searchList.empty();
189214
this._$searchList
190215
.append('<div class="not-found footnote-1 basic-500">No assets found</div>');
191-
this._onChangeSearchFocus({ value: this._parent.focused });
216+
this._onChangeSearchFocus({value: this._parent.focused});
192217
});
193218
}, 500);
194219
} else {
195220
this._$searchList.empty();
196-
this._onChangeSearchFocus({ value: this._parent.focused });
221+
this._onChangeSearchFocus({value: this._parent.focused});
197222
}
198223
}
199224

@@ -203,7 +228,7 @@
203228
* @param isWatched
204229
* @private
205230
*/
206-
_clickSearchItem({ id }, isChangeBase, isWatched) {
231+
_clickSearchItem({id}, isChangeBase, isWatched) {
207232
if (isChangeBase) {
208233
this.baseAssetId = id;
209234
if (this.activeRowId === id) {

0 commit comments

Comments
 (0)