@stellar-broker/client 0.6.4 → 0.6.6
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/README.md +1 -1
- package/package.json +1 -1
- package/src/index.d.ts +3 -2
- package/src/mediator.js +12 -9
- package/jest.config.cjs +0 -4
package/README.md
CHANGED
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -249,7 +249,7 @@ export class Mediator {
|
|
|
249
249
|
* @param source - Initiator account that created a mediator
|
|
250
250
|
* @param [storagePrefix] - Local storage key prefix
|
|
251
251
|
*/
|
|
252
|
-
static hasObsoleteMediators(source: string, storagePrefix
|
|
252
|
+
static hasObsoleteMediators(source: string, storagePrefix?: string): boolean
|
|
253
253
|
|
|
254
254
|
/**
|
|
255
255
|
* Retrieve funds from mediator accounts that belong to lost swap sessions
|
|
@@ -259,9 +259,10 @@ export class Mediator {
|
|
|
259
259
|
/**
|
|
260
260
|
* Retrieve funds from mediator accounts that belong to lost swap sessions
|
|
261
261
|
* @param source - Initiator account that created a mediator
|
|
262
|
+
* @param authorization - Authorization callback or secret key
|
|
262
263
|
* @param [storagePrefix] - Local storage key prefix
|
|
263
264
|
*/
|
|
264
|
-
static disposeObsoleteMediators(source:string, storagePrefix?:string): Promise<void>;
|
|
265
|
+
static disposeObsoleteMediators(source: string, authorization: ClientAuthorizationParams, storagePrefix?: string): Promise<void>;
|
|
265
266
|
|
|
266
267
|
/**
|
|
267
268
|
* Create mediator account and deposit tokens to sell
|
package/src/mediator.js
CHANGED
|
@@ -14,7 +14,7 @@ export class Mediator {
|
|
|
14
14
|
* @param {string|Asset} sellingAsset - Identifier of the asset to sell
|
|
15
15
|
* @param {string|Asset} buyingAsset - Identifier of the asset to buy
|
|
16
16
|
* @param {string} sellingAmount - Asset amount to sell
|
|
17
|
-
* @param {ClientAuthorizationParams} authorization - Authorization
|
|
17
|
+
* @param {ClientAuthorizationParams} authorization - Authorization callback or secret key
|
|
18
18
|
*/
|
|
19
19
|
constructor(source, sellingAsset, buyingAsset, sellingAmount, authorization) {
|
|
20
20
|
if (!StrKey.isValidEd25519PublicKey(source))
|
|
@@ -38,9 +38,7 @@ export class Mediator {
|
|
|
38
38
|
console.error(e)
|
|
39
39
|
throw new Error('Invalid selling amount')
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
this.authorization = new AuthorizationWrapper(authorization)
|
|
43
|
-
}
|
|
41
|
+
this.authorization = new AuthorizationWrapper(authorization)
|
|
44
42
|
}
|
|
45
43
|
|
|
46
44
|
/**
|
|
@@ -120,11 +118,13 @@ export class Mediator {
|
|
|
120
118
|
/**
|
|
121
119
|
* Retrieve funds from mediator accounts that belong to lost swap sessions
|
|
122
120
|
* @param {string} source - Initiator account that created a mediator
|
|
121
|
+
* @param {ClientAuthorizationParams} authorization - Authorization callback or secret key
|
|
123
122
|
* @param {string} [storagePrefix] - Local storage key prefix
|
|
124
123
|
* @return {Promise}
|
|
125
124
|
*/
|
|
126
|
-
static async disposeObsoleteMediators(source, storagePrefix = defaultStoragePrefix) {
|
|
127
|
-
const wrapper = new Mediator(source, 'XLM', 'XLM', '0',
|
|
125
|
+
static async disposeObsoleteMediators(source, authorization, storagePrefix = defaultStoragePrefix) {
|
|
126
|
+
const wrapper = new Mediator(source, 'XLM', 'XLM', '0', authorization)
|
|
127
|
+
wrapper.storagePrefix = storagePrefix
|
|
128
128
|
await wrapper.disposeObsoleteMediators()
|
|
129
129
|
}
|
|
130
130
|
|
|
@@ -203,10 +203,10 @@ export class Mediator {
|
|
|
203
203
|
asset: buyingAsset
|
|
204
204
|
}))
|
|
205
205
|
}
|
|
206
|
-
//confirm tx
|
|
207
|
-
await this.buildAndSend(sourceAccount, ops)
|
|
208
206
|
//store the record in the localStorage
|
|
209
207
|
localStorage.setItem(this.storagePrefix + this.mediatorAddress, this.source)
|
|
208
|
+
//confirm tx
|
|
209
|
+
await this.buildAndSend(sourceAccount, ops)
|
|
210
210
|
//client will need mediator secret for trading
|
|
211
211
|
return this.mediator.secret()
|
|
212
212
|
}
|
|
@@ -222,8 +222,11 @@ export class Mediator {
|
|
|
222
222
|
}
|
|
223
223
|
//load account
|
|
224
224
|
let account = await this.loadAccount(address)
|
|
225
|
-
if (!account)
|
|
225
|
+
if (!account) {
|
|
226
|
+
//remove reference from local storage
|
|
227
|
+
localStorage.removeItem(this.storagePrefix + address)
|
|
226
228
|
throw new Error(`Mediator account ${address} doesn't exist on the ledger`)
|
|
229
|
+
}
|
|
227
230
|
|
|
228
231
|
if (!account.signers.find(s => s.key === this.source))
|
|
229
232
|
throw new Error(`${address} is not a mediator account for ${this.source}`)
|
package/jest.config.cjs
DELETED