Compare commits
3 Commits
main
...
skip-loggi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91bedd9fec | ||
|
|
8818d64c3e | ||
|
|
949a1bfd6c |
@ -40,6 +40,7 @@ export enum WalletErrorType {
|
|||||||
// General
|
// General
|
||||||
ChainMismatch,
|
ChainMismatch,
|
||||||
UserCanceled,
|
UserCanceled,
|
||||||
|
SwitchChainMethodMissing,
|
||||||
|
|
||||||
// Non-Deterministic
|
// Non-Deterministic
|
||||||
NonDeterministicWallet,
|
NonDeterministicWallet,
|
||||||
|
|||||||
@ -163,17 +163,20 @@ export const useWalletConnection = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw Object.assign(
|
const { isErrorExpected } = parseWalletError({ error, stringGetter });
|
||||||
new Error([error.message, error.cause?.message].filter(Boolean).join('\n')),
|
if (!isErrorExpected) {
|
||||||
{
|
throw Object.assign(
|
||||||
walletConnectionType: walletConnection?.type,
|
new Error([error.message, error.cause?.message].filter(Boolean).join('\n')),
|
||||||
}
|
{
|
||||||
);
|
walletConnectionType: walletConnection?.type,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
walletType,
|
walletType,
|
||||||
walletConnectionType: walletConnection.type,
|
walletConnectionType: walletConnection?.type,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[isConnectedGraz, signerGraz, isConnectedWagmi, signerWagmi]
|
[isConnectedGraz, signerGraz, isConnectedWagmi, signerWagmi]
|
||||||
|
|||||||
@ -92,6 +92,10 @@ export const getWalletErrorType = ({ error }: { error: Error }) => {
|
|||||||
return WalletErrorType.ChainMismatch;
|
return WalletErrorType.ChainMismatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (messageLower.includes('Missing or invalid. request() method: wallet_switchEthereumChain')) {
|
||||||
|
return WalletErrorType.SwitchChainMethodMissing;
|
||||||
|
}
|
||||||
|
|
||||||
// ImToken - User canceled
|
// ImToken - User canceled
|
||||||
if (messageLower.includes('用户取消了操作')) {
|
if (messageLower.includes('用户取消了操作')) {
|
||||||
return WalletErrorType.UserCanceled;
|
return WalletErrorType.UserCanceled;
|
||||||
@ -113,13 +117,18 @@ export const parseWalletError = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const walletErrorType = getWalletErrorType({ error });
|
const walletErrorType = getWalletErrorType({ error });
|
||||||
let message;
|
let message;
|
||||||
|
let isErrorExpected;
|
||||||
|
|
||||||
switch (walletErrorType) {
|
switch (walletErrorType) {
|
||||||
case WalletErrorType.ChainMismatch:
|
case WalletErrorType.ChainMismatch:
|
||||||
case WalletErrorType.UserCanceled: {
|
case WalletErrorType.UserCanceled:
|
||||||
|
case WalletErrorType.SwitchChainMethodMissing: {
|
||||||
|
isErrorExpected = true;
|
||||||
|
message = error.message;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
isErrorExpected = false;
|
||||||
message = stringGetter({
|
message = stringGetter({
|
||||||
key: STRING_KEYS.SOMETHING_WENT_WRONG_WITH_MESSAGE,
|
key: STRING_KEYS.SOMETHING_WENT_WRONG_WITH_MESSAGE,
|
||||||
params: {
|
params: {
|
||||||
@ -132,5 +141,6 @@ export const parseWalletError = ({
|
|||||||
return {
|
return {
|
||||||
walletErrorType,
|
walletErrorType,
|
||||||
message,
|
message,
|
||||||
|
isErrorExpected,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -44,7 +44,6 @@ export const GenerateKeys = ({
|
|||||||
onKeysDerived = () => {},
|
onKeysDerived = () => {},
|
||||||
}: ElementProps) => {
|
}: ElementProps) => {
|
||||||
const stringGetter = useStringGetter();
|
const stringGetter = useStringGetter();
|
||||||
const { isMobile } = useBreakpoints();
|
|
||||||
|
|
||||||
const [shouldRememberMe, setShouldRememberMe] = useState(false);
|
const [shouldRememberMe, setShouldRememberMe] = useState(false);
|
||||||
|
|
||||||
@ -66,17 +65,30 @@ export const GenerateKeys = ({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await matchNetwork?.();
|
await matchNetwork?.();
|
||||||
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const { message, walletErrorType } = parseWalletError({ error, stringGetter });
|
const { message, walletErrorType, isErrorExpected } = parseWalletError({
|
||||||
|
error,
|
||||||
|
stringGetter,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isErrorExpected) {
|
||||||
|
log('GenerateKeys/switchNetwork', error, { walletErrorType });
|
||||||
|
}
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
log('GenerateKeys/switchNetwork', error, { walletErrorType });
|
|
||||||
setError(message);
|
setError(message);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const switchNetworkAndDeriveKeys = async () => {
|
||||||
|
const networkSwitched = await switchNetwork();
|
||||||
|
if (networkSwitched) await deriveKeys();
|
||||||
|
};
|
||||||
|
|
||||||
// 2. Derive keys from EVM account
|
// 2. Derive keys from EVM account
|
||||||
const { getWalletFromEvmSignature } = useDydxClient();
|
const { getWalletFromEvmSignature } = useDydxClient();
|
||||||
const { getSubaccounts } = useAccounts();
|
const { getSubaccounts } = useAccounts();
|
||||||
@ -154,11 +166,16 @@ export const GenerateKeys = ({
|
|||||||
setStatus(EvmDerivedAccountStatus.Derived);
|
setStatus(EvmDerivedAccountStatus.Derived);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setStatus(EvmDerivedAccountStatus.NotDerived);
|
setStatus(EvmDerivedAccountStatus.NotDerived);
|
||||||
const { message, walletErrorType } = parseWalletError({ error, stringGetter });
|
const { message, walletErrorType, isErrorExpected } = parseWalletError({
|
||||||
|
error,
|
||||||
|
stringGetter,
|
||||||
|
});
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
setError(message);
|
setError(message);
|
||||||
log('GenerateKeys/deriveKeys', error, { walletErrorType });
|
if (!isErrorExpected) {
|
||||||
|
log('GenerateKeys/deriveKeys', error, { walletErrorType });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -231,7 +248,7 @@ export const GenerateKeys = ({
|
|||||||
{!isMatchingNetwork ? (
|
{!isMatchingNetwork ? (
|
||||||
<Button
|
<Button
|
||||||
action={ButtonAction.Primary}
|
action={ButtonAction.Primary}
|
||||||
onClick={() => switchNetwork().then(deriveKeys).then(onKeysDerived)}
|
onClick={() => switchNetworkAndDeriveKeys().then(onKeysDerived)}
|
||||||
state={{ isLoading: isSwitchingNetwork }}
|
state={{ isLoading: isSwitchingNetwork }}
|
||||||
>
|
>
|
||||||
{stringGetter({ key: STRING_KEYS.SWITCH_NETWORK })}
|
{stringGetter({ key: STRING_KEYS.SWITCH_NETWORK })}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user