-
-
Notifications
You must be signed in to change notification settings - Fork 368
feat: add network picker #414
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
Conversation
| const openButton = document.getElementById('openNetworkPicker'); | ||
| const closeButton = modal.querySelector('.network-modal-close'); | ||
|
|
||
| // Populate network lists |
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.
Method name is pretty self descriptive 👍🏾
so I'd prefer we remove this comment to avoid redundancy
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.
great point, I've removed all of them 🙏
| } | ||
| }); | ||
|
|
||
| // Initial update |
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.
Same for this one, and even the above comment for the event listeners I would remove, it's all pretty straight forward to follow
| if ( | ||
| globalContext.chainIdInt !== undefined && | ||
| globalContext.chainIdInt !== null | ||
| ) { | ||
| const network = NETWORKS.find((n) => { | ||
| const networkChainId = parseInt(n.chainId, 16); | ||
| return networkChainId === globalContext.chainIdInt; | ||
| }); | ||
|
|
||
| if (network) { | ||
| currentNetworkName.textContent = `Current Network: ${network.name}`; | ||
| } else { | ||
| // Fallback to chain ID if network not found | ||
| currentNetworkName.textContent = `Current Network: Chain ID 0x${globalContext.chainIdInt.toString( | ||
| 16, | ||
| )}`; | ||
| } | ||
| } else { | ||
| currentNetworkName.textContent = 'Current Network: Not Connected'; | ||
| } |
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.
| if ( | |
| globalContext.chainIdInt !== undefined && | |
| globalContext.chainIdInt !== null | |
| ) { | |
| const network = NETWORKS.find((n) => { | |
| const networkChainId = parseInt(n.chainId, 16); | |
| return networkChainId === globalContext.chainIdInt; | |
| }); | |
| if (network) { | |
| currentNetworkName.textContent = `Current Network: ${network.name}`; | |
| } else { | |
| // Fallback to chain ID if network not found | |
| currentNetworkName.textContent = `Current Network: Chain ID 0x${globalContext.chainIdInt.toString( | |
| 16, | |
| )}`; | |
| } | |
| } else { | |
| currentNetworkName.textContent = 'Current Network: Not Connected'; | |
| } | |
| if (!globalContext.chainIdInt) { | |
| currentNetworkName.textContent = 'Current Network: Not Connected'; | |
| return; | |
| } | |
| const network = NETWORKS.find((n) => { | |
| const networkChainId = parseInt(n.chainId, 16); | |
| return networkChainId === globalContext.chainIdInt; | |
| }); | |
| // Fallback to chain ID if network not found | |
| currentNetworkName.textContent = network | |
| ? `Current Network: ${network.name}` | |
| : `Current Network: Chain ID 0x${globalContext.chainIdInt.toString(16)}`; |
I believe the cognitive complexity of this function is reduced if we use an early return, instead of having nested if..else clauses, what do you think ?
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.
whoa much better 😍 Added the changes 🙏 thank you vmuch!
ffmcgee725
left a comment
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.
LGTM! 🚀
Thatguysdino
left a comment
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.
|
We the people, thank you |
Description
This PR adds a network picker to be able to switch networks from the dapp.
Future work:
Screenshots
Main networks
Test networks
Happy Path
net-picker.mp4
Error Handling
network-picker-test-dapp.mp4
Manual Testing Steps
Flow 1: Connected + Permissions
Flow 2: Connected without Permissions
Flow 3: Connected without Network in the Wallet