Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Buy component #1729

Merged
merged 65 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3b1985f
initial commit
alissacrane-cb Dec 13, 2024
38b978d
fix typo
alissacrane-cb Dec 13, 2024
4d2accf
lint
alissacrane-cb Dec 13, 2024
b3474a8
fix lint
alissacrane-cb Dec 13, 2024
75a16d4
fix imports
alissacrane-cb Dec 13, 2024
ee0f7bc
adjust swap quote functionality
alissacrane-cb Dec 13, 2024
de3805d
fix swap test
alissacrane-cb Dec 13, 2024
9e98425
adjust svgs
alissacrane-cb Dec 13, 2024
fd8241f
adjust imports
alissacrane-cb Dec 13, 2024
1672671
adjust hook behavior
alissacrane-cb Dec 13, 2024
7f8cdc4
add popup monitor
alissacrane-cb Dec 16, 2024
9570480
fix optional params - revisit
alissacrane-cb Dec 16, 2024
2303671
remove unused file
alissacrane-cb Dec 16, 2024
1f5d208
add leading 0
alissacrane-cb Dec 16, 2024
ddf3654
fix swap error
alissacrane-cb Dec 16, 2024
6b34326
remove SwapLite components
alissacrane-cb Dec 16, 2024
62f9586
add buy components
alissacrane-cb Dec 16, 2024
63f4717
add test coverage
alissacrane-cb Dec 16, 2024
eb0d0ac
remove unused code
alissacrane-cb Dec 16, 2024
64decc8
remove exit handler
alissacrane-cb Dec 16, 2024
66545a6
adjust imports
alissacrane-cb Dec 16, 2024
1e65878
add test coverage
alissacrane-cb Dec 16, 2024
8194392
add test coverage
alissacrane-cb Dec 16, 2024
e792579
fix imports and lint
alissacrane-cb Dec 16, 2024
0cee0d3
fix import
alissacrane-cb Dec 16, 2024
40e8074
update import
alissacrane-cb Dec 16, 2024
24c5d01
throw error if no project id
alissacrane-cb Dec 16, 2024
12c5ae7
fix import
alissacrane-cb Dec 16, 2024
676fed9
fix imports
alissacrane-cb Dec 16, 2024
a30f64e
remove console log
alissacrane-cb Dec 16, 2024
e2837e7
add comments
alissacrane-cb Dec 16, 2024
d60b789
add test coverage
alissacrane-cb Dec 17, 2024
404a730
add test coverage
alissacrane-cb Dec 17, 2024
42d3a11
add test coverage
alissacrane-cb Dec 17, 2024
fe9c92b
remove uneccesary error
alissacrane-cb Dec 17, 2024
215761b
remove project id
alissacrane-cb Dec 17, 2024
c7b0e8c
address pr comments
alissacrane-cb Dec 17, 2024
a43a105
fix lint
alissacrane-cb Dec 17, 2024
c9daec4
fix tests
alissacrane-cb Dec 17, 2024
322db40
refactor useOnrampeventlistener
alissacrane-cb Dec 17, 2024
ad8be9d
add test coverage
alissacrane-cb Dec 17, 2024
ebf9200
add test coverage
alissacrane-cb Dec 17, 2024
81e7ae4
add test coverage
alissacrane-cb Dec 17, 2024
ddd20db
add test coverage
alissacrane-cb Dec 17, 2024
e8672f6
re require transactionReceipt
alissacrane-cb Dec 17, 2024
0b88800
fix test
alissacrane-cb Dec 17, 2024
ec56e5a
update buy button
alissacrane-cb Dec 17, 2024
0e306b5
add quote validation
alissacrane-cb Dec 17, 2024
727e826
validate quote
alissacrane-cb Dec 17, 2024
27320d9
adjust styling
alissacrane-cb Dec 17, 2024
a082d8e
fix lint
alissacrane-cb Dec 17, 2024
8117757
add test coverage
alissacrane-cb Dec 17, 2024
8c13dd2
add test coverage
alissacrane-cb Dec 17, 2024
ede2e92
add test coverage
alissacrane-cb Dec 17, 2024
96de464
fix lint
alissacrane-cb Dec 17, 2024
727bb99
add changelog
alissacrane-cb Dec 18, 2024
1090562
address qa comments
alissacrane-cb Dec 18, 2024
bbda91a
fix test
alissacrane-cb Dec 18, 2024
dc415b8
add z index
alissacrane-cb Dec 18, 2024
4843432
fix lint
alissacrane-cb Dec 18, 2024
5b3afb3
add missing required fields message and address pr comments
alissacrane-cb Dec 18, 2024
7c63536
add test coverage
alissacrane-cb Dec 18, 2024
19512c4
fix lint
alissacrane-cb Dec 18, 2024
1cf2f1a
fix test and build
alissacrane-cb Dec 18, 2024
d527a6b
remove unsued code
alissacrane-cb Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions site/docs/pages/token/types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type TokenChipReact = {
token: Token; // Rendered token
onClick?: (token: Token) => void;
className?: string;
isPressable?: boolean; // Default: true
};
```

Expand Down
7 changes: 3 additions & 4 deletions src/buy/components/BuyAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ export function BuyAmountInput() {
return (
<div
className={cn(
'flex h-full items-center rounded-lg border px-4',
'flex h-full items-center rounded-lg border pl-4 px-2',
background.default,
)}
>
<TextInput
className={cn(
'mr-2 w-full border-[none] font-display',
'leading-none outline-none',
'disabled:cursor-not-allowed',
'mr-2 w-full border-none font-display',
'leading-none outline-none disabled:cursor-not-allowed',
background.default,
color.foreground,
)}
Expand Down
27 changes: 24 additions & 3 deletions src/buy/components/BuyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function BuyButton() {
fromUSDC,
to,
lifecycleStatus: { statusName },
updateLifecycleStatus,
} = useBuyContext();

const isLoading =
to?.loading ||
from?.loading ||
Expand All @@ -32,15 +34,34 @@ export function BuyButton() {
statusName === 'transactionPending' ||
statusName === 'transactionApproved';

const isDisabled = !to?.amount || !to?.token || isLoading;
const isMissingRequiredField = !to?.amount || !to?.token;
const isDisabled = isLoading;

const handleSubmit = useCallback(() => {
if (isMissingRequiredField) {
updateLifecycleStatus({
statusName: 'error',
statusData: {
code: 'TmBPc05',
error: 'Missing required fields',
message: 'Complete the field to continue',
},
});
return;
}
if (isDropdownOpen) {
setIsDropdownOpen(false);
} else {
return;
}
if (!isDropdownOpen) {
setIsDropdownOpen(true);
}
}, [setIsDropdownOpen, isDropdownOpen]);
}, [
isMissingRequiredField,
setIsDropdownOpen,
isDropdownOpen,
updateLifecycleStatus,
]);

const buttonContent = useMemo(() => {
if (statusName === 'success') {
Expand Down
25 changes: 17 additions & 8 deletions src/buy/components/BuyMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

export function BuyMessage() {
const {
lifecycleStatus: { statusName },
lifecycleStatus: { statusName, statusData },
} = useBuyContext();

if (statusName !== 'error') {
return null;
// Missing required fields
if (statusName === 'error' && statusData.code === 'TmBPc05') {

Check failure on line 10 in src/buy/components/BuyMessage.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

src/buy/components/BuyMessage.test.tsx > BuyMessage > renders error message when statusName is "error"

TypeError: Cannot read properties of undefined (reading 'code') ❯ BuyMessage src/buy/components/BuyMessage.tsx:10:44 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performConcurrentWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:25789:22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to not just always show the error.message on errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in other components we only show Something went wrong... so i'm keeping consistent for now and will investigate better errors in follow up but it might be something we want to change for all our components.

return (
<div className={cn('text-sm', color.foregroundMuted)}>
Complete the field to continue
</div>
);
}

return (
<div className={cn(color.error, 'text-sm')}>
Something went wrong. Please try again.
</div>
);
if (statusName === 'error') {
return (
<div className={cn(color.error, 'text-sm')}>
Something went wrong. Please try again.
</div>
);
}

return null;
}
2 changes: 1 addition & 1 deletion src/buy/components/BuyTokenItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function BuyTokenItem({ swapUnit }: { swapUnit?: SwapUnit }) {
<button
className={cn(
'flex items-center gap-2 rounded-lg p-2',
!hasInsufficientBalance && 'hover:bg-[var(--ock-bg-inverse)]',
!hasInsufficientBalance,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this doing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nothing removing

)}
onClick={handleClick}
type="button"
Expand Down
Loading