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

Commit

Permalink
Merge pull request #9 from darwinia-network/feature
Browse files Browse the repository at this point in the history
Update Account Disconnect and Staking Addresses for Crab/Darwinia
  • Loading branch information
snoopy1412 authored Mar 13, 2024
2 parents 0572251 + 866127d commit 40d86da
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/claim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const Claim = ({ onTransactionActiveChange }: ClaimProps) => {
</Tooltip>
</TooltipProvider>
)}
<span className=" text-[1.5rem] font-bold leading-normal text-white">RING</span>
<span className=" text-[1.5rem] font-bold leading-normal text-white">
{activeChain?.nativeToken.symbol}
</span>
</div>
<Button
disabled={isButtonDisabled}
Expand Down
43 changes: 39 additions & 4 deletions src/components/connect-button/account.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
'use client';
import { useRef } from 'react';
import { useDisconnect } from 'wagmi';
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon';
import { useCopyToClipboard } from 'react-use';
import { toast } from 'sonner';

import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger
} from '@/components/ui/dropdown-menu';
import Button from '@/components/ui/ghost-button';
import { toShortAddress } from '@/utils';

Expand All @@ -15,20 +22,48 @@ const styles = {
};
const Account = ({ address }: AccountProps) => {
const toastRef = useRef<string | number | null>(null);
const disconnectTimerRef: React.MutableRefObject<NodeJS.Timeout | null> = useRef(null);
const [, copyToClipboard] = useCopyToClipboard();

const { disconnect } = useDisconnect();

const handleCopy = () => {
copyToClipboard(address);
toastRef.current = toast('✅ Address successfully copied to clipboard.', {
duration: 2000
});
};
const handleDisconnect = () => {
disconnectTimerRef?.current && clearTimeout(disconnectTimerRef?.current);
disconnectTimerRef.current = setTimeout(() => {
disconnect();
}, 500);
};

return address ? (
<Button title="Click to copy the address to your clipboard" onClick={handleCopy}>
<Jazzicon diameter={24} seed={jsNumberForAddress(address)} svgStyles={styles} />
<span>{toShortAddress(address)?.toUpperCase()}</span>
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button>
<Jazzicon diameter={24} seed={jsNumberForAddress(address)} svgStyles={styles} />
<span>{toShortAddress(address)?.toUpperCase()}</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-[10rem] gap-[0.625rem] rounded-[0.3125rem] border border-primary p-[0.625rem]">
<DropdownMenuItem
title="Click to copy the address to your clipboard"
className=" cursor-pointer p-[0.625rem] focus:bg-[rgba(94,214,42,.1)] "
onClick={handleCopy}
>
Copy Address
</DropdownMenuItem>
<DropdownMenuItem
className=" cursor-pointer p-[0.625rem] focus:bg-[rgba(94,214,42,.1)] "
onClick={handleDisconnect}
>
Disconnect
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
) : null;
};
export default Account;
2 changes: 1 addition & 1 deletion src/components/connect-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ConnectButton = () => {
<Button onClick={openConnectModal}>Connect Wallet</Button>
) : null}
{isConnected ? <SwitchChain /> : null}
{address ? <Account address={address} /> : null}
{isConnected && address ? <Account address={address} /> : null}
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/config/chains/crab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ export const crab: ChainConfig = {
decimals: 18,
logoPath: '/images/token/ckton.svg'
},
stakingContractAddress: '0x'
stakingContractAddress: '0x000000000419683a1a03abc21fc9da25fd2b4dd7'
} as const satisfies ChainConfig;
2 changes: 1 addition & 1 deletion src/config/chains/darwinia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ export const darwinia: ChainConfig = {
decimals: 18,
logoPath: '/images/token/kton.svg'
},
stakingContractAddress: '0x'
stakingContractAddress: '0x000000000419683a1a03abc21fc9da25fd2b4dd7'
} as const satisfies ChainConfig;

0 comments on commit 40d86da

Please sign in to comment.