mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
* feat: metamask switch network support + fixed dependancy cycle * feat: moved landing to index * feat: updated favicon * fix: fixed landing page issues + scrollSnap * feat: join button * fix: fixed seed script with new prod schema * feat: join button redirects based on user creation date * fix: minor ui bug fixes * feat: connect to mainnet to continue with switch network on metamask * fix: uniform setup screens * fix: fixed XP on dashboard * feat: added start page * fix: fixed issues on landing page * fix: fixed minor issues on dashboard * fix: update idx profile in auth webhook for new players * fix: minor fixes in seed page * fix: player avatar & type * fix: incorporated review comments from @dysbulic & @vidvidvid * fix: more review comments
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { MetaButton, MetaMaskIcon, Text } from '@metafam/ds';
|
|
import { useWeb3 } from 'lib/hooks';
|
|
import { useCallback, useState } from 'react';
|
|
import { switchChainOnMetaMask } from 'utils/metamask';
|
|
import { NETWORK_INFO } from 'utils/networks';
|
|
|
|
export const SwitchNetworkButton: React.FC<{ chainId?: string }> = ({
|
|
chainId = '0x1',
|
|
}) => {
|
|
const { connected, isMetaMask } = useWeb3();
|
|
const networkInfo = NETWORK_INFO[chainId];
|
|
|
|
const [isLoading, setLoading] = useState(false);
|
|
|
|
const onClick = useCallback(async () => {
|
|
if (connected) {
|
|
setLoading(true);
|
|
await switchChainOnMetaMask(chainId);
|
|
setLoading(false);
|
|
}
|
|
}, [connected, chainId]);
|
|
|
|
if (!connected || !networkInfo) return null;
|
|
|
|
const { name } = networkInfo;
|
|
|
|
return isMetaMask ? (
|
|
<MetaButton
|
|
size="sm"
|
|
fontSize="md"
|
|
px={2}
|
|
textTransform="initial"
|
|
leftIcon={<MetaMaskIcon />}
|
|
{...{ isLoading, onClick }}
|
|
>
|
|
{name}
|
|
</MetaButton>
|
|
) : (
|
|
<Text as="span">{name}</Text>
|
|
);
|
|
};
|