mirror of
https://github.com/haveno-dex/haveno-ts.git
synced 2025-04-15 13:33:13 -04:00
can get the user's created offers
This commit is contained in:
parent
bea11ab1f4
commit
b48f329d97
@ -22,4 +22,4 @@ This application is a basic [create-react-app](https://github.com/facebook/creat
|
||||
|
||||
1. Copy grpc.proto and pb.proto from Haveno's [protobuf definitions](https://github.com/haveno-dex/haveno/tree/master/proto/src/main/proto) to ./config.
|
||||
2. Install protobuf for your system, e.g. on mac: `brew install protobuf`
|
||||
2. `./bin/build_protobuf.sh`
|
||||
3. `./bin/build_protobuf.sh`
|
@ -20,7 +20,14 @@ test("Can get the user's balances", async () => {
|
||||
});
|
||||
|
||||
test("Can get offers", async() => {
|
||||
let offers: HavenoOffer[] = await daemon.getOffers("SELL", "XMR");
|
||||
let offers: HavenoOffer[] = await daemon.getOffers("BUY");
|
||||
for (let offer of offers) {
|
||||
testOffer(offer);
|
||||
}
|
||||
});
|
||||
|
||||
test("Can get the user's created offers", async() => {
|
||||
let offers: HavenoOffer[] = await daemon.getMyOffers("SELL");
|
||||
for (let offer of offers) {
|
||||
testOffer(offer);
|
||||
}
|
||||
|
@ -68,51 +68,49 @@ class HavenoDaemon {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available offers.
|
||||
* Get available offers to buy or sell XMR.
|
||||
*
|
||||
* @param {string} direction - one of "BUY" or "SELL"
|
||||
* @param {string} currencyCode - the currency being bought or sold, e.g. "ETH"
|
||||
*
|
||||
* @return {HavenoOffer[]} available offers
|
||||
*/
|
||||
async getOffers(direction: string, currencyCode: string): Promise<HavenoOffer[]> {
|
||||
async getOffers(direction: string): Promise<HavenoOffer[]> {
|
||||
if (!this._offersClient) this._offersClient = new OffersClient(this._url);
|
||||
let request = new GetOffersRequest()
|
||||
.setDirection(direction)
|
||||
.setCurrencycode(currencyCode);
|
||||
.setCurrencycode("XMR");
|
||||
let that = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
that._offersClient.getOffers(request, {password: that._password}, function(err: any, response: any) {
|
||||
if (err) reject(err);
|
||||
else {
|
||||
let offers: HavenoOffer[] = [];
|
||||
for (let offer of response.getOffersList()) {
|
||||
offers.push(new HavenoOffer(
|
||||
offer.getId(),
|
||||
offer.getDirection(),
|
||||
offer.getPrice(),
|
||||
offer.getUsemarketbasedprice(),
|
||||
offer.getMarketpricemargin(),
|
||||
offer.getAmount(),
|
||||
offer.getMinamount(),
|
||||
offer.getVolume(),
|
||||
offer.getMinvolume(),
|
||||
offer.getBuyersecuritydeposit(),
|
||||
offer.getTriggerprice(),
|
||||
offer.getIscurrencyformakerfeebtc(),
|
||||
offer.getPaymentaccountid(),
|
||||
offer.getPaymentmethodid(),
|
||||
offer.getPaymentmethodshortname(),
|
||||
offer.getBasecurrencycode(),
|
||||
offer.getCountercurrencycode(),
|
||||
offer.getDate(),
|
||||
offer.getState(),
|
||||
offer.getSellersecuritydeposit(),
|
||||
offer.getOfferfeepaymenttxid(),
|
||||
offer.getTxfee(),
|
||||
offer.getMakerfee()
|
||||
));
|
||||
}
|
||||
for (let offer of response.getOffersList()) offers.push(grpcOfferToHavenoOffer(offer));
|
||||
resolve(offers);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user's created offers to buy or sell XMR.
|
||||
*
|
||||
* @param {string} direction - one of "BUY" or "SELL"
|
||||
*
|
||||
* @return {HavenoOffer[]} created offers
|
||||
*/
|
||||
async getMyOffers(direction: string): Promise<HavenoOffer[]> {
|
||||
if (!this._offersClient) this._offersClient = new OffersClient(this._url);
|
||||
let request = new GetOffersRequest()
|
||||
.setDirection(direction)
|
||||
.setCurrencycode("XMR");
|
||||
let that = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
that._offersClient.getMyOffers(request, {password: that._password}, function(err: any, response: any) {
|
||||
if (err) reject(err);
|
||||
else {
|
||||
let offers: HavenoOffer[] = [];
|
||||
for (let offer of response.getOffersList()) offers.push(grpcOfferToHavenoOffer(offer));
|
||||
resolve(offers);
|
||||
}
|
||||
});
|
||||
@ -209,4 +207,32 @@ class HavenoOffer {
|
||||
}
|
||||
}
|
||||
|
||||
function grpcOfferToHavenoOffer(offer: any) {
|
||||
return new HavenoOffer(
|
||||
offer.getId(),
|
||||
offer.getDirection(),
|
||||
offer.getPrice(),
|
||||
offer.getUsemarketbasedprice(),
|
||||
offer.getMarketpricemargin(),
|
||||
offer.getAmount(),
|
||||
offer.getMinamount(),
|
||||
offer.getVolume(),
|
||||
offer.getMinvolume(),
|
||||
offer.getBuyersecuritydeposit(),
|
||||
offer.getTriggerprice(),
|
||||
offer.getIscurrencyformakerfeebtc(),
|
||||
offer.getPaymentaccountid(),
|
||||
offer.getPaymentmethodid(),
|
||||
offer.getPaymentmethodshortname(),
|
||||
offer.getBasecurrencycode(),
|
||||
offer.getCountercurrencycode(),
|
||||
offer.getDate(),
|
||||
offer.getState(),
|
||||
offer.getSellersecuritydeposit(),
|
||||
offer.getOfferfeepaymenttxid(),
|
||||
offer.getTxfee(),
|
||||
offer.getMakerfee()
|
||||
);
|
||||
}
|
||||
|
||||
export {HavenoDaemon, HavenoBalances, HavenoOffer};
|
Loading…
x
Reference in New Issue
Block a user