Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Algosigner not injected again after refreshing page in React #396

@kashishkhullar

Description

@kashishkhullar

I am building a project using Algosigner and React and I followed the code given in the article Integrate AlgoSigner to JavaScript Application on Algorand

Code snippet:

    useEffect(() => {
        if (typeof window.AlgoSigner !== "undefined") {
            // connects to the browser AlgoSigner instance
            window.AlgoSigner.connect()
                // finds the TestNet accounts currently in AlgoSigner
                .then(() =>
                    window.AlgoSigner.accounts({
                        ledger: "TestNet",
                    })
                )
                .then((accountData) => {
                    // the accountData object should contain the Algorand addresses from TestNet that AlgoSigner currently knows about
                    console.log(accountData);
                })
                .catch((e) => {
                    // handle errors and perform error cleanup here
                    console.error(e);
                });
        } else {
            console.log(window.AlgoSigner);
        }
    }, []);

On opening the application for the first time, everything works fine. The accounts addresses get logged on the console.
However, on refreshing the page, the useEffect runs again and window.Algosigner is undefined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions