-
Notifications
You must be signed in to change notification settings - Fork 51
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
#245: Add Network Check for Sepolia #291
#245: Add Network Check for Sepolia #291
Conversation
Someone is attempting to deploy a commit to the keep-starknet-strange Team on Vercel. A member of the Team first needs to authorize it. |
eb625d1
to
a95aa75
Compare
a95aa75
to
2f850a3
Compare
JM! This is ready for review! |
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.
Hi, thanks for the work. I've just requested 2 changes
useEffect(() => { | ||
const handleChainIdChange = () => { | ||
const chainId = account.chainId; | ||
const currentChainId = NETWORK_NAME === 'SN_MAIN' ? mainnet.id : sepolia.id; | ||
|
||
if (chainId === currentChainId) { | ||
hideDialog(); | ||
} else if (chainId) { | ||
showDialog({ | ||
title: 'Wrong Network', | ||
description: | ||
'Joyboy currently only supports the Starknet Sepolia network. Please switch to the Sepolia network to continue.', | ||
buttons: [], | ||
}); | ||
} | ||
}; | ||
|
||
handleChainIdChange(); | ||
}, [account.chainId, hideDialog, showDialog]); |
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.
This check should be at the App, instead of TipModal
const chainId = account.chainId; | ||
const currentChainId = NETWORK_NAME === 'SN_MAIN' ? mainnet.id : sepolia.id; |
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.
You can use useNetwork hook
with starknetChainId
to get the chain id and check against CHAIN_ID.
import { starknetChainId, useNetwork } from '@starknet-react/core';
const { chain } = useNetwork();
useEffect(() => {
const chainId = chain.id ? starknetChainId(chain.id) : undefined;
if (chainId) {
if (chainId !== CHAIN_ID) {
// show dialog
} else {
// hide dialog
}
}
}, [chain.id])
JoyboyCommunity/src/app/App.tsx
Outdated
@@ -18,6 +20,28 @@ export default function App() { | |||
const tips = useTips(); | |||
const {showToast} = useToast(); | |||
|
|||
const {showDialog, hideDialog} = useDialog(); | |||
|
|||
const {chain} = useNetwork(); |
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.
Hi @ugur-eren,
I’ve applied the recent changes, but I’m encountering an issue where the hook always returns Sepolia, even when I’m on Mainnet. Is this expected behavior?
I’ve looked through the documentation and the Starknet React documentation, and it seems like it should be working. I’m not sure if this is an issue with the library or if something in our setup might be incorrect.
I also tried adding the commented-out code in JoyboyCommunity/src/app/StarknetProvider.tsx for argentMobileConnector, but I’m missing the WALLET_CONNECT_ID.
Do you have any ideas on what might be causing this issue?
Thanks!
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.. my mistake. Seems like useNetwork returns the provided network in the StarknetConfig, instead of the account's currently connected one. I've fixed it myself, sorry for inconvenience
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.
Hey no prob 😊
f6d1115
to
118a46e
Compare
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.
Thanks for the work! LGTM
Description
This PR solves issue #245
There should be a check for connect account's chain id. If the chain is not Starknet Sepolia, app should show a uncloseable dialog.
Implementation
useEffect
-Where handleChainIdChange`` checks if the user is on the correct network when the component mounts or the chain ID changes, showing or hiding the dialog accordingly.
Screenshots
Using mainnet
Using sepolia