Skip to content

Commit

Permalink
fix: evaluator and changeAddress overriding on preCompleteHook
Browse files Browse the repository at this point in the history
  • Loading branch information
joacohoyos committed Sep 17, 2024
1 parent 1993902 commit 05c6661
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/pretty-rocks-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@blaze-cardano/sdk": patch
"@blaze-cardano/tx": patch
---

avoid preCompleteHook overriding user selections
5 changes: 3 additions & 2 deletions packages/blaze-sdk/src/blaze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ export class Blaze<ProviderType extends Provider, WalletType extends Wallet> {
const changeAddress = await this.wallet.getChangeAddress();
tx.setNetworkId(await this.wallet.getNetworkId())
.addUnspentOutputs(myUtxos)
.setChangeAddress(changeAddress)
.useEvaluator((x, y) => this.provider.evaluateTransaction(x, y));
// We do not want to override the change address if it was already set
.setChangeAddress(changeAddress, false)
.useEvaluator((x, y) => this.provider.evaluateTransaction(x, y), false);
});
}

Expand Down
14 changes: 10 additions & 4 deletions packages/blaze-tx/src/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ export class TxBuilder {
* This address will receive any remaining funds not allocated to outputs or fees.
*
* @param {Address} address - The address to receive the change.
* @param {boolean} [override=true] - Whether to override the change address if one is already set.
* @returns {TxBuilder} The same transaction builder
*/
setChangeAddress(address: Address): TxBuilder {
this.changeAddress = address;
setChangeAddress(address: Address, override = true): TxBuilder {
if (override || !this.changeAddress) {
this.changeAddress = address;
}
return this;
}

Expand All @@ -189,10 +192,13 @@ export class TxBuilder {
* The evaluator is used to execute Plutus scripts during transaction building.
*
* @param {Evaluator} evaluator - The evaluator to be used for script execution.
* @param {boolean} [override=true] - Whether to override the evaluator if one is already set.
* @returns {TxBuilder} The same transaction builder
*/
useEvaluator(evaluator: Evaluator): TxBuilder {
this.evaluator = evaluator;
useEvaluator(evaluator: Evaluator, override = true): TxBuilder {
if (override || !this.evaluator) {
this.evaluator = evaluator;
}
return this;
}

Expand Down

0 comments on commit 05c6661

Please sign in to comment.