-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Prompt to add BSC network to user wallet (#610)
- Loading branch information
1 parent
88d0485
commit 35e83a5
Showing
4 changed files
with
50 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 was deleted.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { nodes } from './getRpcUrl' | ||
|
||
export const setupNetwork = async () => { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const provider = window.ethereum | ||
if (provider) { | ||
const chainId = parseInt(process.env.REACT_APP_CHAIN_ID, 10) | ||
try { | ||
await provider.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: `0x${chainId.toString(16)}`, | ||
chainName: 'Binance Smart Chain', | ||
nativeCurrency: { | ||
name: 'BNB', | ||
symbol: 'BNB', | ||
decimals: 18, | ||
}, | ||
rpcUrls: nodes, | ||
blockExplorerUrls: ['https://bscscan.com/'], | ||
}, | ||
], | ||
}) | ||
return true | ||
} catch (error) { | ||
console.error(error) | ||
return false | ||
} | ||
} else { | ||
console.error("Can't setup the BSC network on metamask because window.ethereum is undefined") | ||
return false | ||
} | ||
} | ||
|
||
export default null |