-
Notifications
You must be signed in to change notification settings - Fork 5.4k
chore: updates web3-react, adds key for changing connector order #4085
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d34d5cf
fix connectors changing
vm 230860f
update package
vm 386816c
add connection name
vm b81bf2d
rename file
vm 5f8127c
de-dupe
vm d3dd1bf
cb wallet fix
vm b0eb028
fix
vm 3bd224c
yarn change
vm 659895c
Merge branch 'main' into w3r-connectors
vm 3f80992
log the key
vm 8ad7c95
re-order connections
vm 5489d33
memoize the key
vm c350c02
some updates
vm 6e81dba
rm console
vm a293818
prevent memory leak
NoahZinsmeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,21 @@ | ||
| import { Web3ReactProvider } from '@web3-react/core' | ||
| import useConnectors from 'hooks/useConnectors' | ||
| import { Web3ReactHooks, Web3ReactProvider } from '@web3-react/core' | ||
| import { Connector } from '@web3-react/types' | ||
| import { Connection } from 'connection' | ||
| import { getConnectionName } from 'connection/utils' | ||
| import useEagerlyConnect from 'hooks/useEagerlyConnect' | ||
| import { ReactNode } from 'react' | ||
| import useOrderedConnections from 'hooks/useOrderedConnections' | ||
| import { ReactNode, useMemo } from 'react' | ||
|
|
||
| export default function Web3Provider({ children }: { children: ReactNode }) { | ||
| useEagerlyConnect() | ||
| const connectors = useConnectors() | ||
| const connections = useOrderedConnections() | ||
| const connectors: [Connector, Web3ReactHooks][] = connections.map(({ hooks, connector }) => [connector, hooks]) | ||
|
|
||
| return <Web3ReactProvider connectors={connectors}>{children}</Web3ReactProvider> | ||
| const key = useMemo(() => connections.map(({ type }: Connection) => getConnectionName(type)).join('-'), [connections]) | ||
|
|
||
| return ( | ||
| <Web3ReactProvider connectors={connectors} key={key}> | ||
| {children} | ||
| </Web3ReactProvider> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { ConnectionType } from 'connection' | ||
|
|
||
| export const BACKFILLABLE_WALLETS = [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't really matter but i just re-ordered based on the order in the wallet modal |
||
| ConnectionType.INJECTED, | ||
| ConnectionType.COINBASE_WALLET, | ||
| ConnectionType.WALLET_CONNECT, | ||
| ConnectionType.INJECTED, | ||
| ] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need a
key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i should have surfaced the change in web3-react that requires this more broadly - i introduced it here: Uniswap/web3-react@a792857
the root of the issue is was that in the widget codebase, we started dynamically adding a provider to the
connectorsprop, which in turn is passed togetPriorityConnector, and finally threaded through togetSelectedConnector, which mounts hooks for each array element. so, if the length of the array changes, we change the number of hooks rendered mid-flight, which breaks the rules of hooks and was causing serious issues in the widget (hooks were returning invalid data)so, there 100% needs to be a
keyat least onconnectors.length. what i'm less sure about is whether changing the ordering of connectors without changing the length would also cause issues - admittedly i haven't dug into this enough to be sure, but i figured it was better to be safe than sorry, so i started enforcing referential equality forconnectorsto be safe, hence the need for a key