Skip to content

sapphire-wagmi-v2: Add EIP-6963 support #550

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

Merged
merged 5 commits into from
Apr 3, 2025
Merged

sapphire-wagmi-v2: Add EIP-6963 support #550

merged 5 commits into from
Apr 3, 2025

Conversation

lubej
Copy link
Contributor

@lubej lubej commented Mar 26, 2025

Closes #499

Copy link

netlify bot commented Mar 26, 2025

Deploy Preview for oasisprotocol-sapphire-paratime canceled.

Name Link
🔨 Latest commit 29c1a51
🔍 Latest deploy log https://app.netlify.com/sites/oasisprotocol-sapphire-paratime/deploys/67ee12179e04d70008486c64

@lubej lubej force-pushed the ml/wagmi-eip-6963 branch 5 times, most recently from 183085f to 401322a Compare March 27, 2025 13:00
@lubej lubej marked this pull request as ready for review March 27, 2025 13:15
@lubej lubej requested review from aefhm, rube-de, matevz and buberdds March 27, 2025 13:15
@lubej lubej force-pushed the ml/wagmi-eip-6963 branch 3 times, most recently from 720f252 to 2cd6377 Compare March 31, 2025 07:10
@lubej lubej requested a review from aefhm March 31, 2025 07:16
@lubej
Copy link
Contributor Author

lubej commented Apr 1, 2025

Playwright test seems to be failing, but I could only reproduce it once. Needs investigation, seems there is an alert that need to be dismissed upon deploying the contract.

@matevz
Copy link
Member

matevz commented Apr 1, 2025

Playwright test seems to be failing, but I could only reproduce it once. Needs investigation, seems there is an alert that need to be dismissed upon deploying the contract.

Playwright seems flaky. Also failed on @ZigaMr PR https://github.com/oasisprotocol/sapphire-paratime/actions/runs/14178490717/job/39718975456?pr=552

Copy link
Contributor

@aefhm aefhm left a comment

Choose a reason for hiding this comment

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

Interface seems reasonable to me.

Not introduced in this PR, but I find it weird that sapphire-wagmi-v2 whitespace is so different from sapphire-paratime, and prefer the denser/smaller one.

@lubej lubej force-pushed the ml/wagmi-eip-6963 branch from 2cd6377 to 9224e17 Compare April 1, 2025 18:37
@lubej
Copy link
Contributor Author

lubej commented Apr 1, 2025

Interface seems reasonable to me.

Not introduced in this PR, but I find it weird that sapphire-wagmi-v2 whitespace is so different from sapphire-paratime, and prefer the denser/smaller one.

The issue here is that biome uses tabs as default ident style. And it just looks horrible on GitHub, I agree.

@lubej lubej force-pushed the ml/wagmi-eip-6963 branch from f392bf4 to 29c1a51 Compare April 3, 2025 04:44
@lubej lubej merged commit a84f1cb into main Apr 3, 2025
15 of 16 checks passed
@lubej lubej deleted the ml/wagmi-eip-6963 branch April 3, 2025 07:04
Comment on lines +138 to +150
const _addEventListener = EventTarget.prototype.addEventListener;
Object.defineProperty(EventTarget.prototype, "addEventListener", {
value: function (
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: AddEventListenerOptions | boolean,
): void {
if (type === EIP6963_ANNOUNCE_PROVIDER_EVENT_NAME) {
_addEventListener.call(
this,
type,
(event: Event) => {
let patchCustomEvent = null;
Copy link
Member

@lukaw3d lukaw3d Apr 8, 2025

Choose a reason for hiding this comment

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

This looks like it breaks removeEventListener(EIP6963_ANNOUNCE_PROVIDER_EVENT_NAME, callback, options) because callback function won't match inline patch function

Copy link
Member

Choose a reason for hiding this comment

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

If removing EIP6963_ANNOUNCE_PROVIDER_EVENT_NAME listeners isn't common then I would just add a headsup comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't seen a codebase, that would try to remove the event. But yeah, I see the potential issue. Thats why I didn't add "restore" to original _addEventListener, which could cause memory leaks, because I did not expect that someone would try to remove the event listener.

Either way, I added the comment here: #565. I hope that is enough for now, and if there is an use-case for it. I am happy to implement more robust solution, that would "reverse" event patching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sapphire-wagmi-v2: Add EIP-6963 support
5 participants