Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix unsupported chain message issue
Browse files Browse the repository at this point in the history
  • Loading branch information
subject026 committed Oct 6, 2023
1 parent c85c93d commit 40e68a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
29 changes: 14 additions & 15 deletions src/hooks/useConnectedUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ import {
import { useAccount, useNetwork } from 'wagmi';
import config, { ChainConfiguration } from '../config';

export type TConnectedUserState = null | {
address: `0x${string}`;
config: ChainConfiguration;
isActiveChainSupported: boolean;
};
export type TConnectedUserState =
| null
| {
address: `0x${string}`;
config: ChainConfiguration | null;
isActiveChainSupported: boolean;
}
| {
address: `0x${string}`;
config: ChainConfiguration | null;
isActiveChainSupported: boolean;
};

const ConnectedUserContext = createContext<{
user: TConnectedUserState | null;
Expand All @@ -35,17 +42,9 @@ function ConnectedUserProvider({ children }: IConnectedUserProviderProps) {

useEffect(() => {
const configuration =
activeChain?.id && config[activeChain.id]
? config[activeChain.id]
: undefined;
activeChain?.id && config[activeChain.id] ? config[activeChain.id] : null;

if (
activeConnector &&
activeChain &&
accountAddress &&
isConnected &&
configuration
) {
if (activeConnector && activeChain && accountAddress && isConnected) {
setUser({
address: accountAddress,
config: configuration,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dashboard/components/Yield/ClaimYield.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default function ClaimYield({ amount }: IProps) {

return (
<section className="m-auto flex w-2/3 items-center justify-between p-6">
{user ? (
{user && user.config ? (
<>
<span>Claim Yield</span>
<ClaimYieldButton amount={amount} config={user.config} />
Expand Down
4 changes: 1 addition & 3 deletions src/routes/bake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ export function Bake() {
);
}

if (!user.isActiveChainSupported)
if (!user.config)
return (
<BakeLayout>
<UnsupportedNetwork />
</BakeLayout>
);

if (!user.config) throw new Error(`Missing chain config!`);

return (
<BakeLayout>
<Suspense
Expand Down

0 comments on commit 40e68a0

Please sign in to comment.