-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseErrorMessage.ts
More file actions
42 lines (33 loc) · 1.13 KB
/
useErrorMessage.ts
File metadata and controls
42 lines (33 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useDappStatus } from 'modules/web3';
import { useConnectorInfo } from 'reef-knot/core-react';
// TODO: to remove the 'reef-knot/web3-react' after it will be deprecated
import { helpers } from 'reef-knot/web3-react';
import { joinWithOr } from 'utils/join-with-or';
import { useAccount, useConnect } from 'wagmi';
export const useErrorMessage = (): string | undefined => {
const { isLedger } = useConnectorInfo();
const {
isSupportedChain,
isChainTypeMatched,
isAccountActive,
supportedChainLabels,
} = useDappStatus();
const { error } = useConnect();
const { chainId } = useAccount();
// Errors from chain state
if (isAccountActive && !isChainTypeMatched) {
return `Wrong network. Please switch to ${supportedChainLabels[chainId || 1]} in your wallet to wrap/unwrap.`;
}
if (!isSupportedChain) {
const switchTo = joinWithOr(supportedChainLabels);
return `Unsupported chain. Please switch to ${switchTo} in your wallet.`;
}
// errors from connection state
if (!error) {
return;
}
if (isLedger) {
return helpers.interceptLedgerError(error).message;
}
return error?.message;
};