@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 +1 -1
- package/src/index.d.ts +1 -1
- package/src/mediator.js +8 -5
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
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
|
|