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

Clear backpack.#publicKey on disconnect #3585

Merged
merged 1 commit into from
Apr 4, 2023

Conversation

mcintyre94
Copy link
Contributor

This fixes a bug where the connect function is not called properly on a reconnect, as #publicKey is already defined

Specifically this is because of this condition in the wallet-standard wrapper (https://github.com/coral-xyz/backpack/blob/master/packages/wallet-standard/src/wallet.ts#L149):

    #connect: ConnectMethod = async ({ silent } = {}) => {
        if (!silent && !this.#backpack.publicKey) {
            await this.#backpack.connect();
        }

        this.#connected();

        return { accounts: this.accounts };
    };

On the first connect, this.#backpack.publicKey is undefined and this.#backpack.connect() is called correctly

However, on the second connect this.#backpack.publicKey was already set and so this.#backpack.connect() was not called. this.#connected() was called, and since this uses this.#backpack.publicKey it was able to emit an event that made it look to the wallet adapter UI like a connection was successfully performed. But the internal code in this.#backpack.connect() hadn't been called, and so signing didn't actually work.

The fix is to set backpack.#publicKey to undefined on disconnect, so that this.#backpack.connect() is called correctly on the reconnect.

Closes #3555

This fixes a bug where the connect function is not called properly on a reconnect, as #publicKey is already defined
@vercel
Copy link

vercel bot commented Apr 4, 2023

@mcintyre94 is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@armaniferrante armaniferrante merged commit b8420fc into coral-xyz:master Apr 4, 2023
@armaniferrante
Copy link
Member

Thank you!

@mcintyre94 mcintyre94 deleted the cm-fix-reconnect branch April 4, 2023 14:57
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.

Not an approved origin error when signing after reconnecting
2 participants