-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1907 from cprussin/re-do-feedback
feat(staking): re do feedback
- Loading branch information
Showing
8 changed files
with
286 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ClipboardDocumentIcon, CheckIcon } from "@heroicons/react/24/outline"; | ||
import clsx from "clsx"; | ||
import { type ComponentProps, useCallback, useEffect, useState } from "react"; | ||
import { Button } from "react-aria-components"; | ||
|
||
import { useLogger } from "../../hooks/use-logger"; | ||
|
||
type CopyButtonProps = ComponentProps<typeof Button> & { | ||
text: string; | ||
}; | ||
|
||
export const CopyButton = ({ | ||
text, | ||
children, | ||
className, | ||
...props | ||
}: CopyButtonProps) => { | ||
const [isCopied, setIsCopied] = useState(false); | ||
const logger = useLogger(); | ||
const copy = useCallback(() => { | ||
// eslint-disable-next-line n/no-unsupported-features/node-builtins | ||
navigator.clipboard | ||
.writeText(text) | ||
.then(() => { | ||
setIsCopied(true); | ||
}) | ||
.catch((error: unknown) => { | ||
/* TODO do something here? */ | ||
logger.error(error); | ||
}); | ||
}, [text, logger]); | ||
|
||
useEffect(() => { | ||
setIsCopied(false); | ||
}, [text]); | ||
|
||
useEffect(() => { | ||
if (isCopied) { | ||
const timeout = setTimeout(() => { | ||
setIsCopied(false); | ||
}, 2000); | ||
return () => { | ||
clearTimeout(timeout); | ||
}; | ||
} else { | ||
return; | ||
} | ||
}, [isCopied]); | ||
|
||
return ( | ||
<Button | ||
onPress={copy} | ||
isDisabled={isCopied} | ||
className={clsx( | ||
"group -mt-0.5 rounded-md px-2 py-0.5 align-middle transition hover:bg-white/10 focus:outline-none focus-visible:ring-1 focus-visible:ring-pythpurple-400", | ||
className, | ||
)} | ||
{...(isCopied && { "data-is-copied": true })} | ||
{...props} | ||
> | ||
{(...args) => ( | ||
<> | ||
<span className="align-middle"> | ||
{typeof children === "function" ? children(...args) : children} | ||
</span> | ||
<span className="relative ml-[0.25em] inline-block align-middle"> | ||
<span className="opacity-50 transition-opacity duration-100 group-data-[is-copied]:opacity-0"> | ||
<ClipboardDocumentIcon className="size-[1em]" /> | ||
<div className="sr-only">Copy code to clipboaord</div> | ||
</span> | ||
<CheckIcon className="absolute inset-0 text-green-600 opacity-0 transition-opacity duration-100 group-data-[is-copied]:opacity-100" /> | ||
</span> | ||
</> | ||
)} | ||
</Button> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
apps/staking/src/components/Header/current-stake-account.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,30 @@ | ||
"use client"; | ||
|
||
import clsx from "clsx"; | ||
import { type HTMLProps } from "react"; | ||
|
||
import { StateType as ApiStateType, useApi } from "../../hooks/use-api"; | ||
import { CopyButton } from "../CopyButton"; | ||
import { TruncatedKey } from "../TruncatedKey"; | ||
|
||
export const CurrentStakeAccount = ({ | ||
className, | ||
...props | ||
}: HTMLProps<HTMLDivElement>) => { | ||
const api = useApi(); | ||
|
||
return api.type === ApiStateType.Loaded ? ( | ||
<div className={clsx("grid place-content-center", className)} {...props}> | ||
<div className="flex flex-col items-end text-xs md:flex-row md:items-baseline md:text-sm"> | ||
<div className="font-semibold">Stake account:</div> | ||
<CopyButton | ||
text={api.account.address.toBase58()} | ||
className="-mr-2 ml-2 text-pythpurple-400 md:mr-0" | ||
> | ||
<TruncatedKey>{api.account.address}</TruncatedKey> | ||
</CopyButton> | ||
</div> | ||
</div> | ||
) : // eslint-disable-next-line unicorn/no-null | ||
null; | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.