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

Calling the getPKH function multiple times open multiples address selection modal #4

Open
felixdenoix opened this issue Feb 22, 2024 · 0 comments

Comments

@felixdenoix
Copy link

felixdenoix commented Feb 22, 2024

In the case where a user has multiples wallet registered in the app, if the UI invokes a function that triggers a wallet choice the webview will open as many times as the users invokes the said function.

Example: In the case where I'm trying to retrieve the user pkh in a react's useEffect function, the modal open's twice in developpement mode as the useEffect are called twice to test the cleanup function (see docs).

const [currentWalletAddress, setCurrentWalletAddress] = useState<string | undefined>()
const [isWalletConnected, setIsWalletConnected] = useState<boolean>(false)

const auWalletRef = useRef<AUWalletProviderClass | null>(null)
const tezosRef = useRef<TezosToolkit | null>(null)

useEffect(() => {
  if (typeof window !== 'undefined') {

    tezosRef.current = new TezosToolkit(process.env.NEXT_PUBLIC_APP_RPC_ADDRESS as string)

    auWalletRef.current = new AUWalletProvider({
      name: walletOptions.name,
      url: walletOptions.url,
      icons: [walletOptions.iconUrl],
    })

    tezos.current.setProvider({ wallet: auWalletRef.current })
    const walletAddress = await auWalletRef.current?.getPKH()

    if (walletAddress) {
      setCurrentWalletAddress(walletAddress)
      setIsWalletConnected(true)
    }

    return () => {
      // Effect cleanup
      // is there a method to cancel the previous request ?
    }
  }
}, [])
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

No branches or pull requests

1 participant