-
Notifications
You must be signed in to change notification settings - Fork 6
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 rp--open-payments-sdk
- Loading branch information
Showing
31 changed files
with
536 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { fireEvent, render } from '@testing-library/react' | ||
import React from 'react' | ||
|
||
import { Code } from '../code' | ||
|
||
describe('Code', () => { | ||
it('should render the code component', () => { | ||
const { queryByRole, container } = render(<Code value="test" />) | ||
const code = container.querySelector('code') | ||
|
||
expect(code).toBeInTheDocument() | ||
expect(code).toHaveTextContent('test') | ||
expect(queryByRole('button')).toHaveAttribute('aria-label', 'copy') | ||
}) | ||
|
||
it('calls clipboard.writeText with the correct value', () => { | ||
Object.assign(navigator, { | ||
clipboard: { | ||
writeText: jest.fn(), | ||
}, | ||
}) | ||
|
||
const { getByRole } = render(<Code value="test" />) | ||
const copyButton = getByRole('button') | ||
expect(copyButton).toBeInTheDocument() | ||
|
||
fireEvent.click(copyButton) | ||
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('test') | ||
}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
|
||
import { cn } from '@/utils/cn' | ||
|
||
import { Button } from './button' | ||
import { CheckIcon, ClipboardIcon } from './icons' | ||
|
||
interface CodeProps extends React.HTMLAttributes<HTMLDivElement> { | ||
value: string | ||
} | ||
|
||
export const Code = ({ value, className, ...props }: CodeProps) => { | ||
return ( | ||
<div | ||
className={cn( | ||
'flex items-center justify-between gap-x-2 rounded-xl bg-nav-active p-4 text-medium break-all', | ||
className, | ||
)} | ||
{...props}> | ||
<code>{value}</code> | ||
<CopyButton value={value} /> | ||
</div> | ||
) | ||
} | ||
|
||
interface CopyButtonProps extends React.HTMLAttributes<HTMLButtonElement> { | ||
value: string | ||
} | ||
|
||
const CopyButton = ({ value, ...props }: CopyButtonProps) => { | ||
const [hasCopied, setHasCopied] = React.useState(false) | ||
|
||
React.useEffect(() => { | ||
if (hasCopied === true) { | ||
setTimeout(() => { | ||
setHasCopied(false) | ||
}, 2000) | ||
} | ||
}, [hasCopied]) | ||
|
||
return ( | ||
<Button | ||
{...props} | ||
aria-label="copy" | ||
variant="ghost" | ||
size="icon" | ||
className="text-primary rounded-sm" | ||
onClick={() => { | ||
navigator.clipboard.writeText(value) | ||
setHasCopied(true) | ||
}}> | ||
{hasCopied ? <CheckIcon className="h-6 w-6" /> : <ClipboardIcon className="h-6 w-6" />} | ||
</Button> | ||
) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { runtime } from 'webextension-polyfill' | ||
|
||
import { initMonetizationTagManager } from '@/utils/monetizationTagManager' | ||
|
||
import { loadObserver } from './linksObserver' | ||
import MessageListener from './messageListener' | ||
|
||
runtime.onMessage.addListener(MessageListener) | ||
|
||
// DEBUG PURPOSE | ||
loadObserver() | ||
|
||
// TBD - check logic | ||
initMonetizationTagManager() |
This file was deleted.
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
Oops, something went wrong.