@stellar-broker/client 0.6.12 → 0.6.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-broker/client",
3
- "version": "0.6.12",
3
+ "version": "0.6.14",
4
4
  "description": "Client library for StellarBroker service",
5
5
  "author": "team@stellar.broker",
6
6
  "homepage": "https://stellar.broker",
package/src/index.d.ts CHANGED
@@ -273,5 +273,5 @@ export class Mediator {
273
273
  /**
274
274
  * Dispose mediator account
275
275
  */
276
- dispose(address: string): Promise<void>;
276
+ dispose(address?: string): Promise<void>;
277
277
  }
package/src/mediator.js CHANGED
@@ -1,4 +1,4 @@
1
- import {Asset, Keypair, Memo, Operation, TransactionBuilder, Horizon, Networks, StrKey, TimeoutInfinite} from '@stellar/stellar-sdk'
1
+ import {Asset, Keypair, Memo, Operation, TransactionBuilder, Horizon, Networks, StrKey, TimeoutInfinite, NotFoundError} from '@stellar/stellar-sdk'
2
2
  import {fromStroops, toStroops} from './stroops.js'
3
3
  import {convertToStellarAsset} from './asset.js'
4
4
  import {AuthorizationWrapper} from './authorization.js'
@@ -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({
@@ -269,7 +267,7 @@ export class Mediator {
269
267
  //load account
270
268
  let mediatorAccount = await this.loadAccount(address)
271
269
  if (!mediatorAccount) {
272
- //remove reference from local storage
270
+ //remove reference from local storage only if account doesn't exist on the ledger
273
271
  localStorage.removeItem(this.storagePrefix + address)
274
272
  throw new Error(`Mediator account ${address} doesn't exist on the ledger`)
275
273
  }
@@ -355,9 +353,14 @@ export class Mediator {
355
353
  */
356
354
  async loadAccount(address) {
357
355
  try {
358
- return this.constructor.createHorizon().loadAccount(address)
356
+ return await this.constructor.createHorizon().loadAccount(address)
359
357
  } catch (e) {
358
+ if (e instanceof NotFoundError) {
359
+ console.warn(`Account ${address} doesn't exist on the ledger`)
360
+ return null
361
+ }
360
362
  console.error(e)
363
+ throw e
361
364
  }
362
365
  }
363
366