@stellar-broker/client 0.6.11 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/mediator.js +14 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-broker/client",
3
- "version": "0.6.11",
3
+ "version": "0.6.13",
4
4
  "description": "Client library for StellarBroker service",
5
5
  "author": "team@stellar.broker",
6
6
  "homepage": "https://stellar.broker",
package/src/mediator.js CHANGED
@@ -176,8 +176,6 @@ export class Mediator {
176
176
  const sellingTrustline = findTrustline(sourceAccount, this.sellingAsset)
177
177
  if (!sellingTrustline || toStroops(sellingTrustline.balance) < this.sellingAmount)
178
178
  throw new Error('Insufficient selling asset balance')
179
- if (!findTrustline(sourceAccount, this.buyingAsset))
180
- throw new Error('Source account doesn\'t have buying asset trustline')
181
179
  //TODO: check authorizations
182
180
  //create trustline for selling asset
183
181
  ops.push(Operation.changeTrust({
@@ -192,6 +190,20 @@ export class Mediator {
192
190
  amount: fromStroops(this.sellingAmount)
193
191
  }))
194
192
  }
193
+ //create trustline for buying asset
194
+ if (!buyingAsset.isNative()) {
195
+ ops.push(Operation.changeTrust({
196
+ source: this.mediatorAddress,
197
+ asset: buyingAsset
198
+ }))
199
+ //if source account itself doesn't have trustline for buying asset
200
+ if (!findTrustline(sourceAccount, buyingAsset)) {
201
+ ops.push(Operation.changeTrust({
202
+ source: this.source,
203
+ asset: buyingAsset
204
+ }))
205
+ }
206
+ }
195
207
 
196
208
  if (sourceAccount.signers.length > 1) { //multisig or delegated schema
197
209
  let {thresholds, signers} = sourceAccount
@@ -235,13 +247,6 @@ export class Mediator {
235
247
  }))
236
248
  }
237
249
 
238
- //create trustline for buying asset
239
- if (!buyingAsset.isNative()) {
240
- ops.push(Operation.changeTrust({
241
- source: this.mediatorAddress,
242
- asset: buyingAsset
243
- }))
244
- }
245
250
  //store the record in the localStorage
246
251
  localStorage.setItem(this.storagePrefix + this.mediatorAddress, this.source)
247
252
  //confirm tx