Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

refactor: rely on Onboard for provider watching #3364

Merged
merged 30 commits into from
Feb 17, 2022
Merged

Conversation

iamacook
Copy link
Member

@iamacook iamacook commented Jan 24, 2022

Known bugs that resulted in reopening

  • Multiple GA event tracking: one is occuring per provider action and when switching network it sometimes tracks incorrectly.
  • ENS name is not resolving correctly, as explained here.
  • Disconnecting and refreshing reconnects the user automatically.
  • No network switch prompt when connecting.

May likely fix

What it solves

The removal of an unnecessary interval and, in turn, numerous requests. Also, a reduction of ENS errors in the console.

How this PR fixes it

In researching how to reduce ENS console errors from our provider watcher, it became apparent that we were relying on a legacy method of 'watching' the Onboard provider. Onboard, however, has built-in subscriptions that are a better alternative than the interval we were using. (One of which resolves ENS domains on wallet connection).

Instead of using an interval that polls every few seconds, this PR migrates to using the wallet, address, network and ens subscriptions from ENS, responsible for:

  • Wallet changes
  • Account changes
  • Network changes
  • ENS resolutions (when the above three change)

The legacy watcher interval has been removed, as well as the associated reducer/middleware adjusted. The reducer handles the subscriptions based on updates instead and wallet disconnection is now handled internally via Onboard, removing reliance on a provider removal method. Logic that was previously required in the middleware: instantiating contracts and saving the current provider for re-connection is now also handled by Onboard.

The notification system has been moved from provider 'fetching' (which was previously happening every time per interval) to the middleware, which is also subscription-based.

A few unnecessary utility functions have also be replaced or substituted for their Onboard counterparts.

How to test it

Nothing should change on a UI/UX level. Connection may seem a bit quicker. Areas to check are the following (cross-wallet):

  • Wallet connection should correctly update the providers store data correctly, i.e. EOA details, ENS domain, hardware/smart contract wallet flags, etc.
  • Disconnection should clear the providers store.
  • Provider-related notifications should work as before.

@github-actions
Copy link

CLA Assistant Lite All Contributors have signed the CLA.

@iamacook iamacook self-assigned this Jan 24, 2022
@iamacook iamacook changed the title feat: rely on Onboard for provider watching refactor: rely on Onboard for provider watching Jan 24, 2022
@github-actions
Copy link

github-actions bot commented Jan 24, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 1 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@github-actions
Copy link

Deployment links

🟠 Rinkeby Mainnet 🟣 Polygon 🟡 BSC Arbitrum 🟢 Gnosis Chain

@github-actions
Copy link

github-actions bot commented Jan 24, 2022

E2E Tests Failed
Check the results here: https://github.com/gnosis/safe-react-e2e-tests/actions/runs/1859214340

Failed tests:

  • ❌ Address book Address book
  • ❌ Read-only transaction creation and review Read-only transaction creation and review

@coveralls
Copy link

coveralls commented Jan 24, 2022

Pull Request Test Coverage Report for Build 1859171848

  • 69 of 152 (45.39%) changed or added relevant lines in 17 files are covered.
  • 4 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.03%) to 33.613%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/components/AppLayout/Header/index.tsx 0 1 0.0%
src/logic/wallets/getWeb3.ts 1 2 50.0%
src/logic/wallets/utils/network.ts 1 2 50.0%
src/logic/wallets/store/selectors/index.ts 10 14 71.43%
src/routes/CreateSafePage/steps/OwnersAndConfirmationsNewSafeStep.tsx 11 16 68.75%
src/logic/wallets/store/reducer/index.ts 4 11 36.36%
src/logic/wallets/utils/walletList.ts 3 14 21.43%
src/logic/wallets/store/middleware/index.ts 12 28 42.86%
src/logic/wallets/patchedWalletConnect.ts 4 21 19.05%
src/logic/wallets/onboard.ts 6 26 23.08%
Files with Coverage Reduction New Missed Lines %
src/components/AppLayout/Header/index.tsx 1 0%
src/logic/wallets/onboard.ts 1 12.07%
src/logic/wallets/utils/network.ts 1 76.32%
src/logic/wallets/utils/walletList.ts 1 13.64%
Totals Coverage Status
Change from base Build 1858621660: 0.03%
Covered Lines: 3238
Relevant Lines: 8625

💛 - Coveralls

Copy link
Member

@DiogoSoaress DiogoSoaress left a comment

Choose a reason for hiding this comment

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

The PR looks good to me and it is easier to follow the logic with the subscriptions. I am not sure I have enough understanding of all the underlying problems to say it's ready for QA.

@iamacook
Copy link
Member Author

I am not sure I have enough understanding of all the underlying problems to say it's ready for QA.

What problems did you find?

Copy link
Collaborator

@dasanra dasanra left a comment

Choose a reason for hiding this comment

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

Nice refactor!

@github-actions
Copy link

github-actions bot commented Feb 8, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

* fix: checksum address before ens validation

* fix: checksum `verifiedAddress`

* refactor: lookup ENS w/ form init
* fix: use field-level owner validation

* fix: test

* fix: forward compare previous owners

* fix: checksum address from Onboard

* fix: keep store logic in reducer
* fix: increase block polling interval

* fix: patch balance `stateSyncer` out of WC

* fix: upgrade `bnc-onboard` + patch `web3-provider-engine`

* fix: cleanup patch

* fix: cleanup patch

* fix: exchange patch for custom WC module instead
@liliya-soroka
Copy link
Member

Tested on Rinkeby with

  • Ledger nano X - works both signing and execution
  • Trezor T - only signing works. Execution is not available with trezor T
    image

@francovenica
Copy link
Contributor

Issue with WC connection. Tried in dev and prod and it doesn't happen there
#3528

@francovenica
Copy link
Contributor

The trezor causes 2 calls to GA when connecting it, one when the modal open to select an account from the dropdown and one when you actually confirm it. This also happens in dev, but given the 1st checkbox in the description of this ticket I wanted to know if this ticket is supposed to fix these repeated calls to GA or not.
image

@francovenica
Copy link
Contributor

Tested in Rinkeby so far. Signing tx with MM chrome extension, WC with MM phone app, trezor one and ledger nano S worked fine. Also safe creation
I'll give it a try to other networks tomorrow

@iamacook
Copy link
Member Author

Issue with WC connection. Tried in dev and prod and it doesn't happen there #3528

I'm a bit confused as you're following comment:

Tested in Rinkeby so far. Signing tx with MM chrome extension, WC with MM phone app, trezor one and ledger nano S worked fine.

suggests it works? Can you provide any more details?


I wanted to know if this ticket is supposed to fix these repeated calls to GA or not

Not here. I am working on the Analytics epic where it will be sorted.

@francovenica
Copy link
Contributor

Let me summarize my comments:

@github-actions
Copy link

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 2 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@iamacook
Copy link
Member Author

* 2 issues I found recently: [Onboard refactor: Safe not loading when WC is used to connect to the safe. #3528](https://github.com/gnosis/safe-react/issues/3528) and [Onboard refactor: Console warnings when opening the safe list on the sidebar #3529](https://github.com/gnosis/safe-react/issues/3529). The "dev" comment is that I always check dev (and sometimes prod) to see if the issue are happening there as well, but in this case both of those issues only happen in this PR.

Just confirmed with @francovenica that these were solved by merging dev into this branch (649cfd0)

* Lili seems to have issues with the "Trezor T" to sign txs

Awaiting confirmation on whether this is related to an older ticket.

Looks like we can merge this soon 👀

@iamacook iamacook merged commit 74e980f into dev Feb 17, 2022
@iamacook iamacook deleted the cleanup-provider-watcher branch February 17, 2022 16:07
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants