Support amount alias for manageBuyOffer#973
Conversation
Comment: Adds a manageBuyOffer amount alias while preserving buyAmount compatibility.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds amount as an alias for buyAmount in manageBuyOffer, updating runtime behavior, TypeScript typings, and tests to support the alias.
Changes:
- Accept
opts.amountas an alias ofopts.buyAmountwhen buildingmanageBuyOfferoperations. - Update TypeScript definitions to allow
amountorbuyAmountinManageBuyOfferoptions. - Extend unit tests and XDR decoding output to expose
amountalongsidebuyAmount.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| types/test.ts | Adds a TS usage example calling manageBuyOffer with the new amount alias. |
| types/index.d.ts | Updates TS types for ManageBuyOffer options and decoded operation shape. |
| test/unit/operations/classic_ops_test.js | Adds tests for the amount alias and invalid alias type. |
| src/operations/manage_buy_offer.js | Implements amount alias resolution and error attribution. |
| src/operation.js | Adds amount alias on decoded manageBuyOffer operation objects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const buyAmount = opts.buyAmount !== undefined ? opts.buyAmount : opts.amount; | ||
| const amountArg = opts.buyAmount !== undefined ? 'buyAmount' : 'amount'; | ||
| if (!this.isValidAmount(buyAmount, true)) { | ||
| throw new TypeError(this.constructAmountRequirementsError(amountArg)); | ||
| } | ||
| attributes.buyAmount = this._toXDRAmount(opts.buyAmount); | ||
| attributes.buyAmount = this._toXDRAmount(buyAmount); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 57389d5670
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| attributes.buying = opts.buying.toXDRObject(); | ||
| if (!this.isValidAmount(opts.buyAmount, true)) { | ||
| throw new TypeError(this.constructAmountRequirementsError('buyAmount')); | ||
| const buyAmount = opts.buyAmount !== undefined ? opts.buyAmount : opts.amount; |
There was a problem hiding this comment.
Respect amount when both aliases are present
When callers start from Operation.fromXDRObject() (which now always returns both buyAmount and amount) and then update the new amount alias before rebuilding a manage-buy-offer, this selection still prefers the stale buyAmount, so the rebuilt XDR silently keeps the old amount. That makes the alias unreliable for the parsed-operation objects this change exposes; either reject conflicting aliases or ensure the alias being edited cannot be shadowed by the legacy field.
Useful? React with 👍 / 👎.
|
Closing with the reasoning listed in the issue this PR was addressing |
Summary
Fixes #200.
Verification