Skip to content

Commit

Permalink
fix: Copy to clipboard format (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
RabbitDoge authored Feb 8, 2021
1 parent 2ff467a commit a77199c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/__tests__/widgets/walletModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@ it("renders ConnectModal correctly", () => {
});

it("renders AccountModal correctly", () => {
const { asFragment } = renderWithTheme(<AccountModal logout={noop} />);
const { asFragment } = renderWithTheme(
<AccountModal account="0xb218C5D6aF1F979aC42BC68d98A5A0D796C6aB01" logout={noop} />
);
expect(asFragment()).toMatchInlineSnapshot(`
<DocumentFragment>
<div
Expand Down Expand Up @@ -466,14 +468,16 @@ it("renders AccountModal correctly", () => {
color="text"
font-size="20px"
style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 8px;"
/>
>
0xb218C5D6aF1F979aC42BC68d98A5A0D796C6aB01
</div>
<div
class="sc-eCssSg gZPLzm"
>
<a
class="sc-bdfBwQ sc-gsTCUz kgxXAa djpNeP"
color="primary"
href="https://bscscan.com/address/undefined"
href="https://bscscan.com/address/0xb218C5D6aF1F979aC42BC68d98A5A0D796C6aB01"
rel="noreferrer noopener"
target="_blank"
>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/WalletModal/AccountModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CopyToClipboard from "./CopyToClipboard";
import { localStorageKey } from "./config";

interface Props {
account?: string;
account: string;
logout: () => void;
onDismiss?: () => void;
}
Expand Down
14 changes: 8 additions & 6 deletions src/widgets/WalletModal/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Text from "../../components/Text/Text";
import { CopyIcon } from "../../components/Svg";

interface Props {
toCopy?: string | number;
toCopy: string;
}

const StyleButton = styled(Text).attrs({ role: "button" })`
Expand Down Expand Up @@ -35,11 +35,13 @@ const CopyToClipboard: React.FC<Props> = ({ toCopy, children, ...props }) => {
small
bold
onClick={() => {
navigator.clipboard.writeText(JSON.stringify(toCopy));
setIsTooltipDisplayed(true);
setTimeout(() => {
setIsTooltipDisplayed(false);
}, 1000);
if (navigator.clipboard) {
navigator.clipboard.writeText(toCopy);
setIsTooltipDisplayed(true);
setTimeout(() => {
setIsTooltipDisplayed(false);
}, 1000);
}
}}
{...props}
>
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/WalletModal/useWalletModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface ReturnType {

const useWalletModal = (login: Login, logout: () => void, account?: string): ReturnType => {
const [onPresentConnectModal] = useModal(<ConnectModal login={login} />);
const [onPresentAccountModal] = useModal(<AccountModal account={account} logout={logout} />);
const [onPresentAccountModal] = useModal(<AccountModal account={account || ""} logout={logout} />);
return { onPresentConnectModal, onPresentAccountModal };
};

Expand Down

0 comments on commit a77199c

Please sign in to comment.