This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into kien/INFRA-303
- Loading branch information
Showing
112 changed files
with
1,089 additions
and
630 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/app/(dashboard)/(chain)/[chain_id]/components/client/add-chain-to-wallet.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { useAddress, useChainId, useSwitchChain } from "@thirdweb-dev/react"; | ||
import { ToolTipLabel } from "@/components/ui/tooltip"; | ||
import { useMutation } from "@tanstack/react-query"; | ||
import { Spinner } from "@/components/ui/Spinner/Spinner"; | ||
import { useDebounce } from "use-debounce"; | ||
|
||
type AddChainToWalletProps = { | ||
chainId: number; | ||
}; | ||
|
||
export const AddChainToWallet: React.FC<AddChainToWalletProps> = (props) => { | ||
const address = useAddress(); | ||
const switchChain = useSwitchChain(); | ||
const activeWalletChainId = useChainId(); | ||
|
||
const switchChainMutation = useMutation({ | ||
mutationFn: async () => { | ||
await switchChain(props.chainId); | ||
}, | ||
}); | ||
|
||
// debounce the loading state to prevent flickering | ||
const [debouncedLoading] = useDebounce(switchChainMutation.isLoading, 50); | ||
|
||
const buttonContent = ( | ||
<Button | ||
disabled={ | ||
!address || debouncedLoading || activeWalletChainId === props.chainId | ||
} | ||
className="w-full md:min-w-40" | ||
onClick={() => switchChainMutation.mutate()} | ||
> | ||
{debouncedLoading && <Spinner />} | ||
<span>Add to wallet</span> | ||
</Button> | ||
); | ||
|
||
if (address && activeWalletChainId !== props.chainId) { | ||
return buttonContent; | ||
} | ||
|
||
return ( | ||
<ToolTipLabel | ||
label={ | ||
activeWalletChainId === props.chainId | ||
? "You are already connected to this chain" | ||
: "Connect your wallet first" | ||
} | ||
> | ||
<div className="cursor-not-allowed">{buttonContent}</div> | ||
</ToolTipLabel> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.