|
71 | 71 | */ |
72 | 72 | this.totalPrice = null; |
73 | 73 | /** |
74 | | - * @type {string} |
75 | | - * @private |
76 | | - */ |
77 | | - this._priceAssetId = null; |
78 | | - /** |
79 | | - * @type {string} |
| 74 | + * @type {{amount: string, price: string}} |
80 | 75 | * @private |
81 | 76 | */ |
82 | | - this._amountAssetId = null; |
| 77 | + this._assetIdPair = null; |
83 | 78 |
|
84 | 79 | Waves.Money.fromTokens('0.003', WavesApp.defaultAssets.WAVES).then((money) => { |
85 | 80 | this.fee = money; |
86 | 81 | }); |
87 | 82 |
|
88 | | - /** |
89 | | - * @type {Poll} |
90 | | - */ |
91 | | - const balancesPoll = createPoll(this, this._getBalances, this._setBalances, 1000); |
92 | | - |
93 | 83 | this.receive(dexDataService.chooseOrderBook, ({ type, price, amount }) => { |
94 | 84 | this.amount = new BigNumber(amount); |
95 | 85 | this.price = new BigNumber(price); |
96 | 86 | this.expand(type); |
97 | 87 | $scope.$apply(); |
98 | 88 | }); |
99 | 89 |
|
100 | | - this.observe(['_amountAssetId', '_priceAssetId'], () => { |
101 | | - |
102 | | - if (!this._priceAssetId || !this._amountAssetId) { |
103 | | - return null; |
104 | | - } |
| 90 | + this.syncSettings({ |
| 91 | + _assetIdPair: 'dex.assetIdPair' |
| 92 | + }); |
105 | 93 |
|
| 94 | + this.observe('_assetIdPair', () => { |
106 | 95 | this.amount = null; |
107 | 96 | this.price = null; |
108 | 97 | balancesPoll.restart(); |
109 | 98 | }); |
110 | 99 |
|
111 | | - this.syncSettings({ |
112 | | - _amountAssetId: 'dex.amountAssetId', |
113 | | - _priceAssetId: 'dex.priceAssetId' |
114 | | - }); |
| 100 | + /** |
| 101 | + * @type {Poll} |
| 102 | + */ |
| 103 | + const balancesPoll = createPoll(this, this._getBalances, this._setBalances, 1000); |
115 | 104 |
|
116 | 105 | this.observe(['amount', 'price', 'step', 'type'], this._currentTotal); |
117 | 106 |
|
|
174 | 163 | createOrder(form) { |
175 | 164 | user.getSeed() |
176 | 165 | .then((seed) => { |
177 | | - return Waves.AssetPair.get(this._amountAssetId, this._priceAssetId).then((pair) => { |
| 166 | + return Waves.AssetPair.get(this._assetIdPair.amount, this._assetIdPair.price).then((pair) => { |
178 | 167 | return Promise.all([ |
179 | 168 | Waves.Money.fromTokens(this.amount.toFixed(), this.amountBalance.asset.id), |
180 | 169 | Waves.OrderPrice.fromTokens(this.price.toFixed(), pair) |
|
212 | 201 | } |
213 | 202 |
|
214 | 203 | _getBalances() { |
215 | | - return Waves.AssetPair.get(this._amountAssetId, this._priceAssetId).then((pair) => { |
| 204 | + return Waves.AssetPair.get(this._assetIdPair.amount, this._assetIdPair.price).then((pair) => { |
216 | 205 | return utils.whenAll([ |
217 | 206 | waves.node.assets.balance(pair.amountAsset.id), |
218 | 207 | waves.node.assets.balance(pair.priceAsset.id) |
|
223 | 212 | }); |
224 | 213 | } |
225 | 214 |
|
226 | | - _setBalances({ amountBalance, priceBalance }) { |
227 | | - this.amountBalance = amountBalance; |
228 | | - this.priceBalance = priceBalance; |
| 215 | + _setBalances(data) { |
| 216 | + if (data) { |
| 217 | + this.amountBalance = data.amountBalance; |
| 218 | + this.priceBalance = data.priceBalance; |
| 219 | + } |
229 | 220 | } |
230 | 221 |
|
231 | 222 | /** |
|
253 | 244 | * @private |
254 | 245 | */ |
255 | 246 | _getData() { |
256 | | - return waves.matcher.getOrderBook(this._amountAssetId, this._priceAssetId) |
| 247 | + return waves.matcher.getOrderBook(this._assetIdPair.amount, this._assetIdPair.price) |
257 | 248 | .then(({ bids, asks, spread }) => { |
258 | 249 | const [lastAsk] = asks; |
259 | 250 | const [firstBid] = bids; |
|
0 commit comments