Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: web3modal opening delay #1008

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions ui/address/contract/ContractConnectWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import AddressIcon from 'ui/shared/address/AddressIcon';
import AddressLink from 'ui/shared/address/AddressLink';

const ContractConnectWallet = () => {
const { open } = useWeb3Modal();
const { open, isOpen } = useWeb3Modal();
const { address, isDisconnected } = useAccount();
const { disconnect } = useDisconnect();
const isMobile = useIsMobile();
const [ isModalOpening, setIsModalOpening ] = React.useState(false);

const handleConnect = React.useCallback(() => {
open();
const handleConnect = React.useCallback(async() => {
setIsModalOpening(true);
await open();
setIsModalOpening(false);
}, [ open ]);

const handleDisconnect = React.useCallback(() => {
Expand All @@ -26,7 +29,16 @@ const ContractConnectWallet = () => {
return (
<>
<span>Disconnected</span>
<Button ml={ 3 } onClick={ handleConnect } size="sm" variant="outline">Connect wallet</Button>
<Button
ml={ 3 }
onClick={ handleConnect }
size="sm"
variant="outline"
isLoading={ isModalOpening || isOpen }
loadingText="Connect wallet"
>
Connect wallet
</Button>
</>
);
}
Expand Down
9 changes: 7 additions & 2 deletions ui/shared/Web3ModalProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useColorModeValue, useToken } from '@chakra-ui/react';
import { EthereumClient, w3mConnectors, w3mProvider } from '@web3modal/ethereum';
import { jsonRpcProvider } from '@wagmi/core/providers/jsonRpc';
import { EthereumClient, w3mConnectors } from '@web3modal/ethereum';
import { Web3Modal } from '@web3modal/react';
import React from 'react';
import type { Chain } from 'wagmi';
Expand Down Expand Up @@ -41,7 +42,11 @@ const getConfig = () => {
const chains = [ currentChain ];

const { publicClient } = configureChains(chains, [
w3mProvider({ projectId: appConfig.walletConnect.projectId || '' }),
jsonRpcProvider({
rpc: () => ({
http: appConfig.network.rpcUrl || '',
}),
}),
]);
const wagmiConfig = createConfig({
autoConnect: true,
Expand Down