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

feat: you can now abort transaction confirmations in web3.js #29057

Merged
merged 4 commits into from Dec 3, 2022
Merged

feat: you can now abort transaction confirmations in web3.js #29057

merged 4 commits into from Dec 3, 2022

Conversation

steveluscher
Copy link
Contributor

Problem

Now that we have long-running transaction confirmation strategies, like #25839, one might like to cancel outstanding transaction confirmations that they no longer care about. For instance, if a user takes an action, but then visits a different page on your site before the transaction has confirmed, you might like to dispose of it.

Summary of Changes

  • Add abortSignal as an input to confirmTransaction()

Now, callers can do this:

const abortController = new AbortController();
try {
  await connection.confirmTransaction({
    abortSignal: abortController.signal,
    /* ... usual transaction confirmation strategy properties */
  });
} catch (e) {
  if (e.name === 'AbortError') {
    // Handle aborted confirmation.
  }
}

// ...then some time later:
abortController.abort();

Fixes #25304.

@github-actions github-actions bot added the web3.js Related to the JavaScript client label Dec 2, 2022
@steveluscher steveluscher changed the title Cancelable transaction confirmation web3 feat: you can now abort transaction confirmations in web3.js Dec 2, 2022
@@ -1167,6 +1167,44 @@ describe('Connection', function () {
});

describe('block height strategy', () => {
it('rejects if called with an already-aborted `abortSignal`', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: I would have written more test coverage here, to assert that when cancelled, the subscription gets disposed and the nonce account no longer gets pinged. Our test framework, however, just doesn't work. I tried setting up sinon spies, and they never fired. I tested other spies in previous tests and – surprise – they don't work either.

I, for one, can't wait to return to Jest as we rewrite web3.js.

@codecov
Copy link

codecov bot commented Dec 3, 2022

Codecov Report

Merging #29057 (fa6e0fe) into master (9725a45) will decrease coverage by 0.0%.
The diff coverage is 64.7%.

@@            Coverage Diff            @@
##           master   #29057     +/-   ##
=========================================
- Coverage    76.8%    76.8%   -0.1%     
=========================================
  Files          55       55             
  Lines        3112     3127     +15     
  Branches      460      466      +6     
=========================================
+ Hits         2393     2402      +9     
- Misses        556      561      +5     
- Partials      163      164      +1     

@steveluscher steveluscher added the automerge Merge this Pull Request automatically once CI passes label Dec 3, 2022
@mergify
Copy link
Contributor

mergify bot commented Dec 3, 2022

automerge label removed due to a CI failure

@mergify mergify bot removed the automerge Merge this Pull Request automatically once CI passes label Dec 3, 2022
@steveluscher steveluscher merged commit 35f3c18 into solana-labs:master Dec 3, 2022
@steveluscher steveluscher deleted the cancelable-transaction-confirmation-web3 branch December 3, 2022 00:36
gnapoli23 pushed a commit to gnapoli23/solana that referenced this pull request Dec 16, 2022
…labs#29057)

* Upgrade Typescript, `@types/node`, and `typedoc` to versions that play well together

In this instance it means they:

* understand `AbortSignal`
* don't cause build errors

* You can now abort transaction confirmation using an `AbortSignal`

* Pipe an `AbortSignal` down through `sendAndConfirmTransaction()`

* Add `AbortController` polyfill to test so that test works in Node 14
nickfrosty pushed a commit to nickfrosty/solana that referenced this pull request Jan 4, 2023
…labs#29057)

* Upgrade Typescript, `@types/node`, and `typedoc` to versions that play well together

In this instance it means they:

* understand `AbortSignal`
* don't cause build errors

* You can now abort transaction confirmation using an `AbortSignal`

* Pipe an `AbortSignal` down through `sendAndConfirmTransaction()`

* Add `AbortController` polyfill to test so that test works in Node 14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
web3.js Related to the JavaScript client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

web3.js: Make confirmTransaction cancellable
1 participant