forked from sifiorg/sifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): add multi network support (sifiorg#233)
Co-authored-by: Norbert <[email protected]>
- Loading branch information
1 parent
5a9735b
commit c080d12
Showing
17 changed files
with
229 additions
and
93 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,35 @@ | ||
import { useCallback } from 'react'; | ||
import { Chain } from 'viem'; | ||
import { useWalletClient } from 'wagmi'; | ||
|
||
const useAddNetwork = () => { | ||
const { data: walletClient } = useWalletClient(); | ||
const addNetwork = useCallback(async (chain: Chain) => { | ||
if (walletClient) { | ||
await walletClient.request({ | ||
method: 'wallet_addEthereumChain', | ||
params: [ | ||
{ | ||
chainId: `0x${chain.id.toString(16)}`, | ||
chainName: chain.name, | ||
nativeCurrency: { | ||
name: chain.nativeCurrency.name, | ||
symbol: chain.nativeCurrency.symbol, | ||
decimals: chain.nativeCurrency.decimals, | ||
}, | ||
rpcUrls: chain.rpcUrls.default.http, | ||
blockExplorerUrls: chain.blockExplorers?.default.url | ||
? [chain.blockExplorers.default.url] | ||
: [], | ||
}, | ||
], | ||
}); | ||
} else { | ||
console.error('Ethereum object does not exist on window, or does not have a request method.'); | ||
} | ||
}, []); | ||
|
||
return { addNetwork }; | ||
}; | ||
|
||
export { useAddNetwork }; |
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
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
Oops, something went wrong.