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

Flip updated dApp connections flag #3492

Merged
merged 13 commits into from
Jul 8, 2023
Merged

Flip updated dApp connections flag #3492

merged 13 commits into from
Jul 8, 2023

Conversation

Shadowfiend
Copy link
Contributor

@Shadowfiend Shadowfiend commented Jun 21, 2023

cc @VladUXUI for design QA

e2e test was also added for the initial display of the Connect to Taho hint popover.

Testing

  • With Taho as default set to on, the first time:
    • Ensure the toggle in the Taho popup is pointed at Taho.
    • Trying to connect to Uniswap, ensure the dApp connection popup displays the informational hint, and that the toggle in the popup is pointed at Taho.
    • Click the Taho as default toggle and ensure Taho auto-closes and MetaMask immediately appears, and allows connections normally.
    • Ensure the toggle in the Taho popup is pointed at MetaMask.
    • Switch the default toggle back to Taho and reload the page.
    • Ensure you can connect normally with Taho.
  • Check that coinmarketcap.com allows connections (with Taho set as default).
  • Check that https://wallet-beta.polygon.technology/ allows connections as Taho with Taho set as default and not.
  • Check that https://app.eigenlayer.xyz allows connections (with Taho set as default).

Fixes #3430.
Fixes #2500. (Sort of—Taho is now directly an option, but if we hack window.tally.isTally = false and try with Taho set as default, Taho works correctly. Only important insofar as the bug is no longer relevant.)
Fixes #3453.

Latest build: extension-builds-3492 (as of Sat, 08 Jul 2023 07:08:43 GMT).

@VladUXUI
Copy link
Contributor

VladUXUI commented Jun 22, 2023

Couple of non blocking small bits. Happy to have these as a ticket for next sprint.

  • Dapp connection box is still using the old image. For consistency let's use the one that we are using in sign tx information box.
image image

It doesn't need to be clickable

  • Couple of copy updates for this box

  • Dap Connection = Website connections (title)

  • How to connect to dapps = How to connect to websites

  • Set Taho as default = Connect using Taho

  • Click “connect to wallet” in a dapp = Click “connect” on a website

The verbiage is updated to refer to websites instead of dApps
regardless, while the default toggle is updated only if the feature flag
is enabled.
@Shadowfiend
Copy link
Contributor Author

This fellow should be ready.

@Shadowfiend
Copy link
Contributor Author

Trying to fix the failing e2e tests here led me to an issue that @hyphenized caught @ #3462 (comment) . Need to fix that one as it will trigger anytime the user tries to connect to Taho as Taho (rather than as default) if they have Taho-as-default turned off (by auto-closing the dApp connection popup whoops).

This runs a path that hides the default-displayed dApp default
connection popover that would otherwise block normal dApp connection
flow automation.
Also fix the regular dApp Connection test by dismissing the popover for
that flow.

The first-time dApp Connect test ensures that the popover is displayed
the first time, and is not after it is dismissed the first time.
Previously we were auto-dismissing if isDefaultWallet was ever false.
This meant if the user toggled the wallet to being not-default, then
tried to connect to a dApp, it would immediately dismiss—for example
when Taho-as-default is disabled and the user tries to connect to Taho
as Injected or as Taho on a website.

Now, the initial value when the popup was rendered is also checked, so
that the auto-dismissal only occurs if the popup was rendered when the
Taho-as-default was true, and then switched to false. This makes the
auto-dismissal work when the user changes the default setting in the
popup.
In certain cases width in e2e test-triggered popups can be oddly wide,
and width/height get out of sync with internal elements,
which ultimately leads to test failures.
@Shadowfiend
Copy link
Contributor Author

Ok, this should be ready again.

@michalinacienciala
Copy link
Contributor

@Shadowfiend, what about that removal of the connection banner from the swap screen? Are we leaving this at it is?

@Shadowfiend
Copy link
Contributor Author

Yep, remaining for now and left for future cleanup.

@VladUXUI
Copy link
Contributor

@hyphenized since you are feature buddy here, can you please review this PR?

Copy link
Contributor

@hyphenized hyphenized left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well! Found a small issue: when the wallet is not set as default, using the default wallet toggler twice in the connection popup opens a duplicate connect page.

await page.locator('text="Settings"').click()
await page.locator("text=Connected websites").click()
// Clear the popover.
const bgLocator = popupPage.locator(".bg")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we target the "void space" button instead? Something like this should work:

        popupPage
        .getByRole("button", { name: "Background close" })
        .click()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was my original approach and then I ran into issues that I thought were related but ultimately weren't, and then never changed it back. I'll poke at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await walletPageHelper.hideDappConnectPopup()

const dappPage = await context.newPage()
await dappPage.goto("https://swap.cow.fi/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth running one small dApp along hardhat for some standard tests of this kind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would really love to avoid more stuff we have to maintain tbh, but agree this is a pretty kludgey way to do it.

@Shadowfiend
Copy link
Contributor Author

Updated the last bullet to reference app.eigenlayer.xyz instead of .com.

Previously toggling default to off with only Taho installed would try
to route to the previous provider, which was also Taho. This would lead
to a second popup from Taho appearing.

We now check that the new provider is not the same as the Taho provider
and, if it is, then we skip rerouting and error out.
When the wallet started as non-default and was toggled to default, the
fact that the wallet was now default wasn't tracked. This meant that the
auto-close behavior if default was toggled back off was not triggering.

This is a fairly niche edge case, but should now work correctly.
This instead of clicking on the background element itself, which is
supported for user convenience but isn't really semantic.
@Shadowfiend
Copy link
Contributor Author

when the wallet is not set as default, using the default wallet toggler twice in the connection popup opens a duplicate connect page

This is fixed. I also made it so the wallet will correctly auto-close in this scenario.

The remaining edge case here is:

  • If Taho is the only installed wallet.
  • And Taho starts as non-default.
  • And the user sets Taho as default in the dApp Connection popup.
  • And the user then switches Taho back to non-default.
  • Then Taho will auto-close and automatically reject the connection request, instead of continuing to wait for the user to hit Connect or Reject.

This seems vanishingly unlikely, and I suggest we don't spend any time trying to fix it unless we get a lot of user confusion, even though my engineering brain wants to solve it.

@hyphenized hyphenized enabled auto-merge July 8, 2023 06:57
@hyphenized hyphenized merged commit a39b9b4 into main Jul 8, 2023
4 of 5 checks passed
@hyphenized hyphenized deleted the dapp-connection-flip branch July 8, 2023 06:59
kkosiorowska pushed a commit that referenced this pull request Jul 13, 2023
…cases (#3546)

## Background

Up until now, Taho's approach to being marked as default was meant to
be roughly:

- If Taho is marked as default, and the dApp supports showing a
non-MetaMask
  provider at `window.ethereum`, make Taho that provider.
- If Taho is marked as default, and the dApp *doesn't* support showing a
non
MetaMask provider, have Taho impersonate MetaMask so that users can
still
  connect using Taho.
- If Taho is marked as not-default, leave everything untouched, and only
show Taho for dApps that specifically look for it (typically at
`window.tally`,
  but sometimes in `window.ethereum.providers`).

For this to work, the window provider was tracking an allowlist of sites
to
impersonate MetaMask on, and it was *also* tracking an allowlist of
sites to
do additional tricks on (e.g. returning a blank `providers` array for
sites
that detect MetaMask and don't look for any other wallet). There were
other
tricks also being done to try to discern between scenarios, etc.

Other wallets just throw their hands up and attempt to impersonate
MetaMask
most/all the time, leading to escalating wars with dApp frameworks to
detect
these behaviors.

## Revised Approach

This PR throws all of that away. It was confusing for users (do you
click on
MetaMask? Browser/Injected? What happens if Taho isn't default? What
about
the times when MetaMask impersonation isn't hardcoded for a site?), and
it
was difficult to maintain (allowlists of specific sites are not
realistically
a scalable long-term approach).

Instead, having Taho set as default (a reminder that as of #3492, this
is
represented in the UI as a toggle between “connect with MetaMask” and
“connect
with Taho”) should mean two things:

- Trying to connect to MetaMask will *always* use Taho.
- For dApps that also specifically detect Taho, they may *also* allow
connecting
with Taho. If Taho is set as default, attempting to connect with
MetaMask will
  still connect with Taho.

On the flip side, if Taho is not set as default, it should mean two
things:

- Trying to connect to MetaMask will *always* use whatever was
presenting
  as MetaMask before Taho got involved.
- For dApps that also specifically detect Taho, they will allow
connecting
  with Taho still.

### Technical Details

How we do this is straightforward: any provider on the `providers` array
that presents as MetaMask (our heuristic: `isMetaMask` returns `true`
AND
there are no other `is*` methods on the provider) is wrapped in a
one-time
proxy. That proxy passes everything through to the wrapped provider,
*unless*
Taho has been set to present as MetaMask by the user (an explicit
choice).
In this case, a subset of functions are always redirected to Taho,
including
account and RPC requests. Additionally, any calls to `isMetaMask` on
`window.ethereum` return `true` if Taho is set to default, even though
the
provider presented on `window.ethereum` is the Taho provider.

We do two more small things:
- When Taho is set as default, it is set as the first provider in the
providers
array. When it is not, it is removed from the front of the providers
list. This
allows MetaMask or other wallet usage for dApps that use a framework
like wagmi,
which especially in older versions only used the first wallet in the
providers
array for connections. Examples of dApps that show this behavior include
Lens
and Vela (e.g. see [this bug report in
Discord](https://discord.com/channels/808358975287722045/888500174685614090/1127318749746311258)).
- When Taho is set as default by the user and MetaMask is not installed,
a mock
MetaMask is presented to the dApp that reroutes calls to Taho. If Taho
is
switched back to not default, the mock is removed. This allows dApps
like
bitcoinbridge.network that only allow connecting via MetaMask to work
with
  Taho even if MetaMask is not installed.

The net result is that the “act as MetaMask”/“Taho as default” toggle
should
behave consistently across all dApps. Famous last words :)

Finally, we fix a small issue with eth_requestAccounts handling on
certain dApps.
Not related to MetaMask impersonation really, but knockin' bugs out.

## Testing

- This is going to require doing some relatively extensive testing in
our
release QA dApps to make sure that MetaMask is replaced when Taho is set
  as default and not when
  it is not.
- All these should also be replicated with Taho as default and not and
MetaMask
disabled (to ensure the dApp registers MetaMask as uninstalled when Taho
is
  not default, and allows interaction as MetaMask when Taho is default).
- We should also check Lens (https://claim.lens.xyz/) to make sure the
Browser
  connection uses Taho when default, and MetaMask when not.
- Finally, the dApps in the issues below should be tested to make sure
they're
  all working!

Fixes #3433, fixes #3412, fixes #3368, fixes #3242, fixes #3231, fixes
#2506, fixes #2706, fixes #2818.

Latest build:
[extension-builds-3546](https://github.com/tahowallet/extension/suites/14241880950/artifacts/799754754)
(as of Wed, 12 Jul 2023 12:06:52 GMT).
@kkosiorowska kkosiorowska mentioned this pull request Jul 13, 2023
kkosiorowska pushed a commit that referenced this pull request Jul 14, 2023
## What's Changed
* Add private key onboarding flow by @jagodarybacka in
#3119
* Private key JSON import by @jagodarybacka in
#3177
* Allow export of private keys and mnemonics by @jagodarybacka in
#3248
* Export private key form by @jagodarybacka in
#3255
* Unlock screen for the account backup by @kkosiorowska in
#3257
* Show mnemonic menu by @jagodarybacka in
#3259
* Fix background blur issue by @jagodarybacka in
#3265
* Account backup UI fixes by @jagodarybacka in
#3270
* Fix unhiding removed accounts by @jagodarybacka in
#3282
* New error for incorrectly decrypted JSON file by @jagodarybacka in
#3293
* Export private keys from HD wallet addresses by @jagodarybacka in
#3253
* Refactor keyring redux slice to remove `importing` field by
@jagodarybacka in #3309
* 📚 Accounts backup by @kkosiorowska in
#3252
* Catch Enter keypress on Unlock screen by @jagodarybacka in
#3355
* Rename `keyring` to `internal signer` and other improvements by
@jagodarybacka in #3331
* 🗝 QA - Accounts backup and private key import by @jagodarybacka in
#3266
* Remove private key signers if they are replaced by accounts from HD
wallet by @jagodarybacka in
#3377
* RFB 4: One-Off Keyring Design by @Shadowfiend in
#3372
* Copy to clipboard warning by @kkosiorowska in
#3488
* Allow setting custom auto-lock timer by @hyphenized in
#3477
* Use Argon2 for encrypted vaults by @jagodarybacka in
#3502
* 👑 Private keys import and accounts backup by @jagodarybacka in
#3089
* Untrusted assets should not block the addition of custom tokens by
@kkosiorowska in #3491
* Flip updated dApp connections flag by @Shadowfiend in
#3492
* v0.41.0 by @Shadowfiend in
#3531
* Switch to a given network if adding a network that is already added.
by @0xDaedalus in #3154
* Remove waiting for Loading Doggo component in E2E tests by
@jagodarybacka in #3541
* Squeeze content to better fit on Swaps page by @jagodarybacka in
#3542
* Refactor of terms for verified/unverified assets by @kkosiorowska in
#3528
* Fix ChainList styling by @fulldecent in
#3547
* Update release checklist by @jagodarybacka in
#3548
* Fix custom asset price fetching by @hyphenized in
#3508
* Sticky Defaults: Make Taho-as-default replace MetaMask in almost all
cases by @Shadowfiend in
#3546

## New Contributors
* @fulldecent made their first contribution in
#3547

**Full Changelog**:
v0.41.0...v0.42.0

Latest build:
[extension-builds-3549](https://github.com/tahowallet/extension/suites/14268975651/artifacts/801826435)
(as of Thu, 13 Jul 2023 09:51:56 GMT).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants