mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* Tweak `Add {Network}` button to enable network details update in MetaMask
Fixes #2591
* add NFTs tokens to MM wallet
30 lines
718 B
TypeScript
30 lines
718 B
TypeScript
import React from 'react';
|
|
|
|
import config from 'configs/app';
|
|
|
|
import useProvider from './useProvider';
|
|
import { getHexadecimalChainId } from './utils';
|
|
|
|
function getParams(): { chainId: string } {
|
|
if (!config.chain.id) {
|
|
throw new Error('Missing required chain config');
|
|
}
|
|
|
|
return { chainId: getHexadecimalChainId(Number(config.chain.id)) };
|
|
}
|
|
|
|
export default function useSwitchChain() {
|
|
const { wallet, provider } = useProvider();
|
|
|
|
return React.useCallback(() => {
|
|
if (!wallet || !provider) {
|
|
throw new Error('Wallet or provider not found');
|
|
}
|
|
|
|
return provider.request({
|
|
method: 'wallet_switchEthereumChain',
|
|
params: [ getParams() ],
|
|
});
|
|
}, [ wallet, provider ]);
|
|
}
|