|
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 | 14 | const controller = function (Base, waves, utils, $element, $scope, $state, $location) { |
|
104 | 106 | _activeWatchListId: 'dex.watchlist.activeWatchListId' |
105 | 107 | }); |
106 | 108 |
|
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); |
117 | 118 |
|
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(); |
121 | 122 | }); |
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(); |
130 | 123 | } |
131 | 124 |
|
132 | 125 | removeWatchedAsset(event, asset) { |
|
143 | 136 | * @param value |
144 | 137 | * @private |
145 | 138 | */ |
146 | | - _onChangeSearchFocus({ value }) { |
| 139 | + _onChangeSearchFocus({value}) { |
147 | 140 | const state = !value || !this._$searchList.children().length; |
148 | 141 | this._$searchList.toggleClass('hidden', state); |
149 | 142 | } |
150 | 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 | + |
151 | 176 | /** |
152 | 177 | * @param value |
153 | 178 | * @private |
154 | 179 | */ |
155 | | - _onChangeSearch({ value }) { |
| 180 | + _onChangeSearch({value}) { |
156 | 181 | if (this._activeXHR) { |
157 | 182 | this._activeXHR.abort(); |
158 | 183 | this._activeXHR = null; |
|
183 | 208 | }); |
184 | 209 | this._$searchList.empty(); |
185 | 210 | this._$searchList.append($elements); |
186 | | - this._onChangeSearchFocus({ value: this._parent.focused }); |
| 211 | + this._onChangeSearchFocus({value: this._parent.focused}); |
187 | 212 | }, () => { |
188 | 213 | this._$searchList.empty(); |
189 | 214 | this._$searchList |
190 | 215 | .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}); |
192 | 217 | }); |
193 | 218 | }, 500); |
194 | 219 | } else { |
195 | 220 | this._$searchList.empty(); |
196 | | - this._onChangeSearchFocus({ value: this._parent.focused }); |
| 221 | + this._onChangeSearchFocus({value: this._parent.focused}); |
197 | 222 | } |
198 | 223 | } |
199 | 224 |
|
|
203 | 228 | * @param isWatched |
204 | 229 | * @private |
205 | 230 | */ |
206 | | - _clickSearchItem({ id }, isChangeBase, isWatched) { |
| 231 | + _clickSearchItem({id}, isChangeBase, isWatched) { |
207 | 232 | if (isChangeBase) { |
208 | 233 | this.baseAssetId = id; |
209 | 234 | if (this.activeRowId === id) { |
|
0 commit comments