Browse Source

ts: Add optional `prepend` parameter to `preInstructions` method (#2863)

Taylor Johnson 1 year ago
parent
commit
4393d73d3d
2 changed files with 7 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 2
      ts/packages/anchor/src/program/namespace/methods.ts

+ 1 - 0
CHANGELOG.md

@@ -37,6 +37,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - ts: Make `opts` parameter of `AnchorProvider` constructor optional ([#2843](https://github.com/coral-xyz/anchor/pull/2843)).
 - cli: Add `--no-idl` flag to the `build` command ([#2847](https://github.com/coral-xyz/anchor/pull/2847)).
 - cli: Add priority fees to idl commands ([#2845](https://github.com/coral-xyz/anchor/pull/2845)).
+- ts: Add `prepend` option to MethodBuilder `preInstructions` method ([#2863](https://github.com/coral-xyz/anchor/pull/2863)).
 
 ### Fixes
 

+ 6 - 2
ts/packages/anchor/src/program/namespace/methods.ts

@@ -247,8 +247,12 @@ export class MethodsBuilder<
     return this;
   }
 
-  public preInstructions(ixs: Array<TransactionInstruction>) {
-    this._preInstructions = this._preInstructions.concat(ixs);
+  public preInstructions(ixs: Array<TransactionInstruction>, prepend = false) {
+    if (prepend) {
+      this._preInstructions = ixs.concat(this._preInstructions);
+    } else {
+      this._preInstructions = this._preInstructions.concat(ixs);
+    }
     return this;
   }