connectkit icon indicating copy to clipboard operation
connectkit copied to clipboard

Fix: Prevent Family Wallet Connection Pop-up from Being Blocked

Open GianlucaMinoprio opened this issue 8 months ago β€’ 6 comments

This PR addresses an issue where the Family Wallet connection pop-up was being blocked by browsers due to it not being triggered by a direct user interaction.

Changes Made

  • Improved the connection flow to ensure pop-ups are triggered properly

πŸŽ₯ Demo

https://github.com/user-attachments/assets/331be9f4-489a-4dd8-aea9-f109fae3f079

A video has been created showing the difference between:

  • ❌ The old flow β€” where pop-ups could be blocked
  • βœ… The new flow β€” where the connection works seamlessly

πŸ” Testing

Tested across:

  • Chrome
  • Safari

GianlucaMinoprio avatar May 14 '25 03:05 GianlucaMinoprio

@GianlucaMinoprio is attempting to deploy a commit to the Avara Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 14 '25 03:05 vercel[bot]

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
connectkit-testbench βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 21, 2025 0:05am

vercel[bot] avatar May 21 '25 12:05 vercel[bot]

hey @GianlucaMinoprio, thanks for the PR! this looks to have some regression on desktop due to it calling connect() again once the route has changed. we would need an isMobile check wrapped around this for this logic to work

example:

if(isMobile) {
   connect({ connector });
} else {
  context.setRoute(routes.CONNECT);
} 

https://github.com/user-attachments/assets/2279a8bc-b9ec-4939-94d3-db634042eb96

lochie avatar May 21 '25 13:05 lochie

Because connect is being called twice in this case, I recommend moving the logic into a useEffectof ConnectWithInjector like this:

    if (wallet?.connector.id !== 'familyAccountsProvider') {
      connectTimeout = setTimeout(runConnect, 600);
    }

https://github.com/user-attachments/assets/9a4e89b1-1b67-44f9-a3e2-af15c284408a

For the familyAccountsProvider, I believe the connection should remain tied to the button click. This ensures consistent behavior across the Apple ecosystem and helps avoid the pop-up being blocked. On both iOS and desktop Safari, pop-ups triggered outside of a direct user interaction (like a button click) are blocked, resulting in a failed connection attempt. It’s frustrating UX when a smooth pop-up could have worked.

Right now, the only issue is that I’m unable to detect the error message that rejects the connection inside ConnectWithinjector. Other than that, everything is working well.

GianlucaMinoprio avatar May 21 '25 18:05 GianlucaMinoprio

Pushed the update @lochie, if you’re able to find a way to detect when the connection is canceled, that would be awesome. Let me know if I can help debug!

GianlucaMinoprio avatar May 21 '25 18:05 GianlucaMinoprio

I've added a small change so that the direct connect from the button only work for Family Account:

                if (connector.id === 'familyAccountsProvider') {
                  connect({ connector: connector });
                }

In the useConnect() of Connectors we should add the management of the User rejected request and sync with the UI using the context.

GianlucaMinoprio avatar May 21 '25 18:05 GianlucaMinoprio