-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for top-level offers end-point with account, selling, and buying filter. #485
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,70 @@ | ||
import { Asset } from "stellar-base"; | ||
import { CallBuilder } from "./call_builder"; | ||
import { BadRequestError } from "./errors"; | ||
import { ServerApi } from "./server_api"; | ||
|
||
/** | ||
* Creates a new {@link OfferCallBuilder} pointed to server defined by serverUrl. | ||
* Do not create this object directly, use {@link Server#offers}. | ||
* | ||
* @see [Offers for Account](https://www.stellar.org/developers/horizon/reference/endpoints/offers-for-account.html) | ||
* @see [Offers](https://www.stellar.org/developers/horizon/reference/endpoints/offers.html) | ||
* @class OfferCallBuilder | ||
* @constructor | ||
* @extends CallBuilder | ||
* @param {string} serverUrl Horizon server URL. | ||
* @param {string} resource Resource to query offers | ||
* @param {...string} resourceParams Parameters for selected resource | ||
*/ | ||
export class OfferCallBuilder extends CallBuilder< | ||
ServerApi.CollectionPage<ServerApi.OfferRecord> | ||
> { | ||
constructor( | ||
serverUrl: uri.URI, | ||
resource: string, | ||
...resourceParams: string[] | ||
) { | ||
constructor(serverUrl: uri.URI) { | ||
super(serverUrl); | ||
if (resource === "accounts") { | ||
this.url.segment([resource, ...resourceParams, "offers"]); | ||
this.url.segment("offers"); | ||
} | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rice2000 can you check the copy on the functions? thanks! |
||
* Returns all offers where the given account is the seller. | ||
* | ||
* @see [Offers](https://www.stellar.org/developers/horizon/reference/endpoints/offers.html) | ||
* @param {string} id For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD` | ||
* @returns {OfferCallBuilder} current OfferCallBuilder instance | ||
*/ | ||
public forAccount(id: string): this { | ||
this.url.setQuery("seller", id); | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns all offers buying an asset. | ||
* @see [Offers](https://www.stellar.org/developers/horizon/reference/endpoints/offers.html) | ||
* @see Asset | ||
* @param {Asset} value For example: `new Asset('USD','GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD')` | ||
* @returns {OfferCallBuilder} current OfferCallBuilder instance | ||
*/ | ||
public buying(asset: Asset): this { | ||
if (!asset.isNative()) { | ||
this.url.setQuery("buying_asset_type", asset.getAssetType()); | ||
this.url.setQuery("buying_asset_code", asset.getCode()); | ||
this.url.setQuery("buying_asset_issuer", asset.getIssuer()); | ||
} else { | ||
this.url.setQuery("buying_asset_type", "native"); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Returns all offers selling an asset. | ||
* @see [Offers](https://www.stellar.org/developers/horizon/reference/endpoints/offers.html) | ||
* @see Asset | ||
* @param {Asset} value For example: `new Asset('EUR','GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD')` | ||
* @returns {OfferCallBuilder} current OfferCallBuilder instance | ||
*/ | ||
public selling(asset: Asset): this { | ||
if (!asset.isNative()) { | ||
this.url.setQuery("selling_asset_type", asset.getAssetType()); | ||
this.url.setQuery("selling_asset_code", asset.getCode()); | ||
this.url.setQuery("selling_asset_issuer", asset.getIssuer()); | ||
} else { | ||
throw new BadRequestError("Bad resource specified for offer:", resource); | ||
this.url.setQuery("selling_asset_type", "native"); | ||
} | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not related with the PR, but came because of prettier. @tyvdh do you have prettier locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like in my ide? I don’t think so.