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

Replace connectAsync with connect and disconnectAsync with disconnect #1548

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion src/libs/modals/modals/WalletModal/ModalWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const ModalWallet: ModalFC<undefined> = ({ id }) => {
const onClickConnect = async (c: Connector) => {
setSelectedConnection(c);
try {
await connect(c);
connect(c);
closeModal(id);
} catch (e: any) {
setConnectionError(e.message || 'Unknown connection error.');
Expand Down
4 changes: 2 additions & 2 deletions src/libs/wagmi/WagmiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const defaultValue: CarbonWagmiProviderContext = {
chainId: currentChain.id,
accountChainId: undefined,
handleTenderlyRPC: () => {},
disconnect: async () => {},
connect: async () => {},
disconnect: () => {},
connect: () => {},
networkError: undefined,
isSupportedNetwork: true,
switchNetwork: () => {},
Expand Down
30 changes: 12 additions & 18 deletions src/libs/wagmi/useWagmiUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
useAccountEffect,
type Connector,
} from 'wagmi';
import { type ConnectErrorType, type DisconnectErrorType } from '@wagmi/core';
import { type DisconnectErrorType } from '@wagmi/core';
import { isAccountBlocked } from 'utils/restrictedAccounts';
import { lsService } from 'services/localeStorage';
import { useStore } from 'store';
Expand All @@ -34,8 +34,8 @@ export const useWagmiUser = ({
const [isUncheckedSigner, _setIsUncheckedSigner] = useState(
lsService.getItem('isUncheckedSigner') || false
);
const { connectAsync } = useConnect();
const { disconnectAsync } = useDisconnect();
const { connect: _connect } = useConnect();
const { disconnect: _disconnect } = useDisconnect();

const setIsUncheckedSigner = (value: boolean) => {
_setIsUncheckedSigner(value);
Expand Down Expand Up @@ -114,39 +114,33 @@ export const useWagmiUser = ({
* Asynchronously connects to the connector in the input
* @param {Connector} connector Connector to connect to
*/
async (connector: Connector) => {
(connector: Connector) => {
if (isCountryBlocked || isCountryBlocked === null) {
throw new Error('Your country is restricted from using this app.');
}
isManualConnection.current = true;
try {
await connectAsync(
{ connector, chainId },
{
onError: (error: ConnectErrorType) => {
isManualConnection.current = false;
console.error(`Error connecting ${connector.name}` + error);
},
}
);
_connect({ connector, chainId });
} catch (error: any) {
// Attempt to disconnect
await disconnectAsync({ connector });
isManualConnection.current = false;
console.error(`Error connecting ${connector.name}` + error);
_disconnect();
const codeErrorMessage = error?.code ? errorMessages[error?.code] : '';
throw new Error(codeErrorMessage || error.message);
}
},
[isCountryBlocked, connectAsync, chainId, disconnectAsync]
[isCountryBlocked, _connect, chainId, _disconnect]
);

const disconnect = useCallback(
/**
* Asynchronously disconnects from the last connected connector
*/
async () => {
() => {
isManualConnection.current = true;
try {
await disconnectAsync(
_disconnect(
{},
{
onError: (error: DisconnectErrorType) => {
Expand All @@ -163,7 +157,7 @@ export const useWagmiUser = ({
throw new Error(codeErrorMessage || error.message);
}
},
[disconnectAsync, setImposterAccount]
[_disconnect, setImposterAccount]
);

return {
Expand Down
4 changes: 2 additions & 2 deletions src/libs/wagmi/wagmi.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export interface CarbonWagmiProviderContext {
voucherAddress?: string
) => void;
setImposterAccount: (account?: string) => void;
disconnect: () => Promise<void>;
connect: (type: Connector) => Promise<void>;
disconnect: () => void;
connect: (type: Connector) => void;
isSupportedNetwork: boolean;
switchNetwork: () => void;
isUserBlocked: boolean;
Expand Down
Loading