Skip to content
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 typings for manage_buy_offer. #230

Merged
merged 1 commit into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/@types/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ export namespace Operation {
offerId: string;
}

function manageBuyOffer(
options: OperationOptions.ManageBuyOffer
): xdr.Operation<ManageBuyOffer>;

export interface PathPayment extends BaseOperation<OperationType.PathPayment> {
sendAsset: Asset;
sendMax: string;
Expand Down
1 change: 0 additions & 1 deletion src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ export class Operation extends BaseOperation {
// TS-TODO: move this to BaseOperation
Operation.manageData = ops.manageData;
Operation.manageSellOffer = ops.manageSellOffer;
Operation.manageBuyOffer = ops.manageBuyOffer;
Operation.pathPayment = ops.pathPayment;
Operation.payment = ops.payment;
Operation.setOptions = ops.setOptions;
Expand Down
46 changes: 46 additions & 0 deletions src/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,50 @@ export abstract class BaseOperation {
this.setSourceAccount(opAttributes, opts);
return new xdr.Operation(opAttributes);
}

/**
* Returns a XDR ManageBuyOfferOp. A "manage buy offer" operation creates, updates, or
* deletes a buy offer.
* @function
* @alias Operation.manageBuyOffer
* @param {object} opts Options object
* @param {Asset} opts.selling - What you're selling.
* @param {Asset} opts.buying - What you're buying.
* @param {string} opts.buyAmount - The total amount you're buying. If 0, deletes the offer.
* @param {number|string|BigNumber|Object} opts.price - Price of 1 unit of `selling` in terms of `buying`.
* @param {number} opts.price.n - If `opts.price` is an object: the price numerator
* @param {number} opts.price.d - If `opts.price` is an object: the price denominator
* @param {number|string} [opts.offerId ] - If `0`, will create a new offer (default). Otherwise, edits an exisiting offer.
* @param {string} [opts.source] - The source account (defaults to transaction source).
* @throws {Error} Throws `Error` when the best rational approximation of `price` cannot be found.
* @returns {xdr.ManageBuyOfferOp} Manage Buy Offer operation
*/
static manageBuyOffer(opts: OperationOptions.ManageBuyOffer): xdrDef.Operation<Operation.ManageBuyOffer> {
const attributes = {};
attributes.selling = opts.selling.toXDRObject();
attributes.buying = opts.buying.toXDRObject();
if (!this.isValidAmount(opts.buyAmount, true)) {
throw new TypeError(this.constructAmountRequirementsError('buyAmount'));
}
attributes.buyAmount = this._toXDRAmount(opts.buyAmount);
if (isUndefined(opts.price)) {
throw new TypeError('price argument is required');
}
attributes.price = this._toXDRPrice(opts.price);

if (!isUndefined(opts.offerId)) {
opts.offerId = opts.offerId.toString();
} else {
opts.offerId = '0';
}

attributes.offerId = Hyper.fromString(opts.offerId);
const manageBuyOfferOp = new xdr.ManageBuyOfferOp(attributes);

const opAttributes = {};
opAttributes.body = xdr.OperationBody.manageBuyOffer(manageBuyOfferOp);
this.setSourceAccount(opAttributes, opts);

return new xdr.Operation(opAttributes);
}
}
48 changes: 0 additions & 48 deletions src/operations/manage_buy_offer.ts

This file was deleted.