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

#245: Add Network Check for Sepolia #291

Conversation

lauchaves
Copy link
Contributor

@lauchaves lauchaves commented Jul 25, 2024

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

  • added a 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
image
image

Using sepolia
image
image

Copy link

vercel bot commented Jul 25, 2024

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.

@lauchaves lauchaves force-pushed the feat-network-check-starknet-sepolia branch from eb625d1 to a95aa75 Compare July 25, 2024 07:42
@lauchaves
Copy link
Contributor Author

JM! This is ready for review!

@ugur-eren ugur-eren self-requested a review July 25, 2024 08:19
@ugur-eren ugur-eren linked an issue Jul 25, 2024 that may be closed by this pull request
Copy link
Collaborator

@ugur-eren ugur-eren left a 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

Comment on lines 49 to 67
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]);
Copy link
Collaborator

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

Comment on lines 51 to 52
const chainId = account.chainId;
const currentChainId = NETWORK_NAME === 'SN_MAIN' ? mainnet.id : sepolia.id;
Copy link
Collaborator

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])

@@ -18,6 +20,28 @@ export default function App() {
const tips = useTips();
const {showToast} = useToast();

const {showDialog, hideDialog} = useDialog();

const {chain} = useNetwork();
Copy link
Contributor Author

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!

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey no prob 😊

@lauchaves lauchaves force-pushed the feat-network-check-starknet-sepolia branch from f6d1115 to 118a46e Compare July 25, 2024 17:34
Copy link
Collaborator

@ugur-eren ugur-eren left a 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

@ugur-eren ugur-eren merged commit dd3bcb9 into keep-starknet-strange:main Jul 25, 2024
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Transaction Failure Issue When Tipping Using ArgentX Desktop
2 participants