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

v2 - silent-connect ("neverAsk") regression #166

Open
avimak opened this issue Dec 1, 2022 · 3 comments
Open

v2 - silent-connect ("neverAsk") regression #166

avimak opened this issue Dec 1, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@avimak
Copy link
Collaborator

avimak commented Dec 1, 2022

v2 introduces a regression in the silent-connect (now "neverAsk") flow.

    // silently attempt to connect with a pre-authorized wallet
    useEffect(() => {
        // match the dapp with a wallet instance
        connect({ modalMode: "neverAsk" }).then(wallet => {
            // connect the dapp with the chosen wallet instance
            wallet?.enable().then(() => {
                const isConnected = !!wallet?.isConnected;
                setIsConnected(isConnected);
            });
        });
    }, []);

the code above works 100% of the time using v1.5, and it fails on v2.

I suspect a race because adding a timeout with delay=0 helps, i.e. -

    // silently attempt to connect with a pre-authorized wallet
    useEffect(() => {
        setTimeout(() => {
            // match the dapp with a wallet instance
            connect({ modalMode: "neverAsk" }).then(wallet => {
                // connect the dapp with the chosen wallet instance
                wallet?.enable().then(() => {
                    const isConnected = !!wallet?.isConnected;
                    setIsConnected(isConnected);
                });
            });
        }, 0); // <-- no real delay, just skip a cycle
    }, []);

to reproduce, simply use the first version (without a timeout), choose a wallet, approve the connection (aka "pre-authorize"), then refresh the page. do it with a visible browser-inspect-application tab displayed, you'll see the id being removed (ptobably because getAvailableWallets returns empty array).

one more thing - if you adding a timeout, the code works, but you'll see multiple storage ids, meaning there are more races in there.

@avimak avimak added the bug Something isn't working label Dec 1, 2022
@janek26
Copy link
Member

janek26 commented Dec 5, 2022

bug.mp4

I was not able to reproduce this, using nextjs default boilerplate and the code you provided above
Am I missing anything?

@avimak
Copy link
Collaborator Author

avimak commented Dec 5, 2022

it reproduces also on the new example app (though not 100%).
btw, another bug - I'm getting another wallet while having a last-wallet set (and pre-authorized/"enabled" in the wallet itself) in storage.
see both mentioned issues in these 2 videos -

Screen.Recording.2022-12-05.at.21.38.53_1080p.mov
Screen.Recording.2022-12-05.at.21.43.06_1080p.mov

@lazarmitic
Copy link

I'm also seeing something similar, after I connect the wallet and refresh the page and call connect with neverAsk option, function:

const availableWallets = scanObjectForWallets(
    windowObject,
    isWalletObject,
)

fails to find starknet object on window object. Should I add some kind of wait, so that starknet object is injected in window object before get-starknet tries to read it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants