|
7 | 7 | * @param {app.utils} utils |
8 | 8 | * @param {JQuery} $element |
9 | 9 | * @param $scope |
| 10 | + * @param {$state} $state |
| 11 | + * @param {$location} $location |
10 | 12 | * @return {DexWatchlist} |
11 | 13 | */ |
12 | | - const controller = function (Base, waves, utils, $element, $scope) { |
| 14 | + const controller = function (Base, waves, utils, $element, $scope, $state, $location) { |
13 | 15 |
|
14 | 16 | class DexWatchlist extends Base { |
15 | 17 |
|
|
104 | 106 | _activeWatchListId: 'dex.watchlist.activeWatchListId' |
105 | 107 | }); |
106 | 108 |
|
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); |
111 | 118 |
|
112 | | - this._initRowId(); |
113 | | - this._onChangeBaseAsset(); |
114 | | - this._onChangeIdWatchList(); |
| 119 | + this._initRowId(); |
| 120 | + this._onChangeBaseAsset(); |
| 121 | + this._onChangeIdWatchList(); |
| 122 | + }); |
115 | 123 | } |
116 | 124 |
|
117 | 125 | removeWatchedAsset(event, asset) { |
|
128 | 136 | * @param value |
129 | 137 | * @private |
130 | 138 | */ |
131 | | - _onChangeSearchFocus({ value }) { |
| 139 | + _onChangeSearchFocus({value}) { |
132 | 140 | const state = !value || !this._$searchList.children().length; |
133 | 141 | this._$searchList.toggleClass('hidden', state); |
134 | 142 | } |
135 | 143 |
|
| 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 | + |
136 | 176 | /** |
137 | 177 | * @param value |
138 | 178 | * @private |
139 | 179 | */ |
140 | | - _onChangeSearch({ value }) { |
| 180 | + _onChangeSearch({value}) { |
141 | 181 | if (this._activeXHR) { |
142 | 182 | this._activeXHR.abort(); |
143 | 183 | this._activeXHR = null; |
|
168 | 208 | }); |
169 | 209 | this._$searchList.empty(); |
170 | 210 | this._$searchList.append($elements); |
171 | | - this._onChangeSearchFocus({ value: this._parent.focused }); |
| 211 | + this._onChangeSearchFocus({value: this._parent.focused}); |
172 | 212 | }, () => { |
173 | 213 | this._$searchList.empty(); |
174 | 214 | this._$searchList |
175 | 215 | .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}); |
177 | 217 | }); |
178 | 218 | }, 500); |
179 | 219 | } else { |
180 | 220 | this._$searchList.empty(); |
181 | | - this._onChangeSearchFocus({ value: this._parent.focused }); |
| 221 | + this._onChangeSearchFocus({value: this._parent.focused}); |
182 | 222 | } |
183 | 223 | } |
184 | 224 |
|
|
188 | 228 | * @param isWatched |
189 | 229 | * @private |
190 | 230 | */ |
191 | | - _clickSearchItem({ id }, isChangeBase, isWatched) { |
| 231 | + _clickSearchItem({id}, isChangeBase, isWatched) { |
192 | 232 | if (isChangeBase) { |
193 | 233 | this.baseAssetId = id; |
194 | 234 | if (this.activeRowId === id) { |
|
332 | 372 | return new DexWatchlist(); |
333 | 373 | }; |
334 | 374 |
|
335 | | - controller.$inject = ['Base', 'waves', 'utils', '$element', '$scope']; |
| 375 | + controller.$inject = ['Base', 'waves', 'utils', '$element', '$scope', '$state', '$location']; |
336 | 376 |
|
337 | 377 | angular.module('app.dex') |
338 | 378 | .component('wDexWatchlist', { |
|
0 commit comments