Skip to content

Commit

Permalink
feat: improve wallet/fallback/useErrorMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
alx-khramov committed Mar 5, 2024
1 parent 96f0c34 commit 46b4d61
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions shared/wallet/fallback/useErrorMessage.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import { useSupportedChains, useConnectorError } from 'reef-knot/web3-react';
import { CHAINS } from '@lido-sdk/constants';
import { useMemo } from 'react';
import {
useSupportedChains,
useConnectorError,
helpers,
} from 'reef-knot/web3-react';
import { useNetwork } from 'wagmi';

export const useErrorMessage = (): string | undefined => {
const error = useConnectorError();
const { isUnsupported, supportedChains } = useSupportedChains();

const chains = useMemo(() => {
const chains = supportedChains
.map(({ chainId, name }) => CHAINS[chainId] || name)
.filter((chain) => chain !== 'unknown');
const lastChain = chains.pop();

return [chains.join(', '), lastChain].filter((chain) => chain).join(' or ');
}, [supportedChains]);
const { isUnsupported } = useSupportedChains();
const { chains: supportedChains } = useNetwork();

// TODO: fix useConnectorError in reef-knot and remove this block
if (isUnsupported) {
return `Unsupported chain. Please switch to ${chains} in your wallet and restart the page.`;
return helpers.getUnsupportedChainError(supportedChains).message;
}

return error?.message;
Expand Down

0 comments on commit 46b4d61

Please sign in to comment.