Skip to content

Commit

Permalink
🎨: improve Starknet network handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Dec 13, 2023
1 parent ad85cca commit 8d77d2e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
3 changes: 2 additions & 1 deletion frontend/.env.development
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
REACT_APP_INFURA_KEY=42
REACT_APP_TOKEN_CLASS_HASH=0x0278da3cbbc2105fc3ac1206a630357c5a4666020f15fed02c892ac5d856d8ef
REACT_APP_TOKEN_CLASS_HASH=0x0278da3cbbc2105fc3ac1206a630357c5a4666020f15fed02c892ac5d856d8ef
REACT_APP_NETWORK=goerli
9 changes: 9 additions & 0 deletions frontend/src/components/Layout/App/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useAccount, useNetwork } from '@starknet-react/core'
import NavBar from 'src/components/NavBar'
import NavBarMobile from 'src/components/NavBar/Mobile'
import Box from 'src/theme/components/Box'
Expand All @@ -9,8 +10,16 @@ interface AppLayoutProps {
}

export default function AppLayout({ children }: AppLayoutProps) {
const { chainId: walletChainId } = useAccount()
const { chain } = useNetwork()

return (
<>
{walletChainId !== undefined && walletChainId !== chain.id && (
<Box className={styles.chainWarning}>
The selected wallet is connected to the wrong network. Please switch to the {chain.name} network.
</Box>
)}
<NavBar />
<NavBarMobile />
<Box as="span" className={styles.radial} />
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/components/Layout/App/style.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ export const radial = style([
background: 'appGradient',
}),
])

export const chainWarning = sprinkles({
width: 'full',
paddingY: '8',
textAlign: 'center',
backgroundColor: 'accent',
color: 'text1',
})
6 changes: 4 additions & 2 deletions frontend/src/components/Web3Provider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { sepolia } from '@starknet-react/chains'
import { goerli, mainnet } from '@starknet-react/chains'
import { argent, braavos, publicProvider, StarknetConfig, starkscan, useInjectedConnectors } from '@starknet-react/core'

const network = process.env.REACT_APP_NETWORK ?? 'goerli'

// STARKNET

interface StarknetProviderProps {
Expand All @@ -17,7 +19,7 @@ export function StarknetProvider({ children }: StarknetProviderProps) {
return (
<StarknetConfig
connectors={connectors}
chains={[sepolia]}
chains={[network === 'mainnet' ? mainnet : goerli]}
provider={publicProvider()}
explorer={starkscan}
autoConnect
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/constants/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@ import { constants } from 'starknet'

export const UDC = constants.UDC

export const TOKEN_CLASS_HASH = process.env.REACT_APP_TOKEN_CLASS_HASH ?? ''
if (TOKEN_CLASS_HASH === '') {
throw new Error(`REACT_APP_TOKEN_CLASS_HASH must be a defined environment variable`)
}
export const TOKEN_CLASS_HASH =
process.env.REACT_APP_TOKEN_CLASS_HASH ?? '0x0278da3cbbc2105fc3ac1206a630357c5a4666020f15fed02c892ac5d856d8ef'

0 comments on commit 8d77d2e

Please sign in to comment.