From f2a4fb693ecee01fa3a6794dccafdf1e30bbd093 Mon Sep 17 00:00:00 2001 From: Alec Chen <93971719+0xAlec@users.noreply.github.com> Date: Thu, 8 Aug 2024 21:19:20 -0700 Subject: [PATCH] `WalletDropdownFundLink` component --- src/internal/svg/fundWallet.tsx | 17 +++++++ .../WalletDropdownFundLink.test.tsx | 47 +++++++++++++++++++ .../components/WalletDropdownFundLink.tsx | 44 +++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 src/internal/svg/fundWallet.tsx create mode 100644 src/wallet/components/WalletDropdownFundLink.test.tsx create mode 100644 src/wallet/components/WalletDropdownFundLink.tsx diff --git a/src/internal/svg/fundWallet.tsx b/src/internal/svg/fundWallet.tsx new file mode 100644 index 00000000000..91aa26df62c --- /dev/null +++ b/src/internal/svg/fundWallet.tsx @@ -0,0 +1,17 @@ +import { fill } from '../../styles/theme'; + +export const FundWalletSvg = ( + + + +); diff --git a/src/wallet/components/WalletDropdownFundLink.test.tsx b/src/wallet/components/WalletDropdownFundLink.test.tsx new file mode 100644 index 00000000000..f3bdb358541 --- /dev/null +++ b/src/wallet/components/WalletDropdownFundLink.test.tsx @@ -0,0 +1,47 @@ +import { render, screen } from '@testing-library/react'; +import { describe, expect, it } from 'vitest'; +import { WalletDropdownFundLink } from './WalletDropdownFundLink'; + +const FUNDING_URL = + 'http://keys.coinbase.com/funding?dappName=&dappUrl=http://localhost:3000/'; + +describe('WalletDropdownFundLink', () => { + it('renders correctly with default props', () => { + render(); + + const linkElement = screen.getByRole('link'); + expect(linkElement).toBeInTheDocument(); + expect(linkElement).toHaveAttribute('href', FUNDING_URL); + expect(screen.getByText('Deposit Funds')).toBeInTheDocument(); + }); + + it('renders correctly with custom icon element', () => { + const customIcon = ; + render( + + Link Text + + ); + + const linkElement = screen.getByRole('link'); + expect(linkElement).toBeInTheDocument(); + expect(linkElement).toHaveAttribute('href', FUNDING_URL); + expect(screen.getByText('Link Text')).toBeInTheDocument(); + expect(screen.getByLabelText('custom-icon')).toBeInTheDocument(); + }); + + it('renders correctly with target and rel attributes', () => { + render( + + Link Text + + ); + + const linkElement = screen.getByRole('link'); + expect(linkElement).toBeInTheDocument(); + expect(linkElement).toHaveAttribute('href', FUNDING_URL); + expect(linkElement).toHaveAttribute('target', '_blank'); + expect(linkElement).toHaveAttribute('rel', 'noopener noreferrer'); + expect(screen.getByText('Link Text')).toBeInTheDocument(); + }); +}); diff --git a/src/wallet/components/WalletDropdownFundLink.tsx b/src/wallet/components/WalletDropdownFundLink.tsx new file mode 100644 index 00000000000..01deaeb40c0 --- /dev/null +++ b/src/wallet/components/WalletDropdownFundLink.tsx @@ -0,0 +1,44 @@ +import { isValidElement, useMemo } from 'react'; +import { FundWalletSvg } from '../../internal/svg/fundWallet'; +import { cn, pressable, text } from '../../styles/theme'; +import type { WalletDropdownLinkReact } from '../types'; + +export function WalletDropdownFundLink({ + children, + className, + icon, + rel, + target, +}: WalletDropdownLinkReact) { + const iconSvg = useMemo(() => { + if (icon === undefined) { + return FundWalletSvg; + } + if (isValidElement(icon)) { + return icon; + } + }, [icon]); + + const currentURL = window.location.href; + const tabName = document.title; + + return ( + +
+ {iconSvg} +
+ + {children || 'Deposit Funds'} + +
+ ); +}