getMyOffers() does not require asset code

This commit is contained in:
woodser 2023-02-23 09:21:22 -05:00
parent ffb77bdb15
commit 30dd997810
2 changed files with 16 additions and 5 deletions

View File

@ -967,9 +967,18 @@ test("Can get offers (CI)", async () => {
}); });
test("Can get my offers (CI)", async () => { test("Can get my offers (CI)", async () => {
// get all offers
const offers: OfferInfo[] = await user1.getMyOffers();
for (const offer of offers) testOffer(offer);
// get offers by asset code
for (const assetCode of TestConfig.assetCodes) { for (const assetCode of TestConfig.assetCodes) {
const offers: OfferInfo[] = await user1.getMyOffers(assetCode); const offers: OfferInfo[] = await user1.getMyOffers(assetCode);
for (const offer of offers) testOffer(offer); for (const offer of offers) {
testOffer(offer);
expect(assetCode).toEqual(isCrypto(assetCode) ? offer.getBaseCurrencyCode() : offer.getCounterCurrencyCode()); // crypto asset codes are base
}
} }
}); });

View File

@ -958,14 +958,16 @@ export default class HavenoClient {
/** /**
* Get the user's posted offers to buy or sell XMR. * Get the user's posted offers to buy or sell XMR.
* *
* @param {string} assetCode - traded asset code * @param {string|undefined} assetCode - traded asset code
* @param {string|undefined} direction - "buy" or "sell" XMR (default all) * @param {string|undefined} direction - "buy" or "sell" XMR (default all)
* @return {OfferInfo[]} the user's created offers * @return {OfferInfo[]} the user's created offers
*/ */
async getMyOffers(assetCode: string, direction?: string): Promise<OfferInfo[]> { async getMyOffers(assetCode?: string, direction?: string): Promise<OfferInfo[]> {
try { try {
if (!direction) return (await this.getMyOffers(assetCode, "buy")).concat(await this.getMyOffers(assetCode, "sell")); // TODO: implement in backend const req = new GetOffersRequest();
return (await this._offersClient.getMyOffers(new GetOffersRequest().setDirection(direction).setCurrencyCode(assetCode), {password: this._password})).getOffersList(); if (assetCode) req.setCurrencyCode(assetCode);
if (direction) req.setDirection(direction);
return (await this._offersClient.getMyOffers(req, {password: this._password})).getOffersList();
} catch (e: any) { } catch (e: any) {
throw new HavenoError(e.message, e.code); throw new HavenoError(e.message, e.code);
} }