Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/alissa.crane/swap-lite-component…
Browse files Browse the repository at this point in the history
…' into alissa.crane/buy-playground-2
  • Loading branch information
alissacrane-cb committed Dec 17, 2024
2 parents 265e646 + 27320d9 commit 6767f99
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/buy/components/Buy.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useOutsideClick } from '@/ui-react/internal/hooks/useOutsideClick';
import { useRef } from 'react';
import { useTheme } from '../../core-react/internal/hooks/useTheme';
import { cn } from '../../styles/theme';
import { FALLBACK_DEFAULT_MAX_SLIPPAGE } from '../../swap/constants';
import type { BuyReact } from '../types';
Expand All @@ -10,6 +11,7 @@ import { BuyMessage } from './BuyMessage';
import { BuyProvider, useBuyContext } from './BuyProvider';

function BuyContent({ className }: { className?: string }) {
const componentTheme = useTheme();
const { isDropdownOpen, setIsDropdownOpen } = useBuyContext();
const buyContainerRef = useRef<HTMLDivElement>(null);

Expand All @@ -22,7 +24,7 @@ function BuyContent({ className }: { className?: string }) {
return (
<div
ref={buyContainerRef}
className={cn('relative flex flex-col gap-2', className)}
className={cn('relative flex flex-col gap-2', componentTheme, className)}
>
<div className={cn('flex items-center gap-4', className)}>
<BuyAmountInput />
Expand Down
13 changes: 10 additions & 3 deletions src/buy/components/BuyAmountInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isValidAmount } from '../../core/utils/isValidAmount';
import { TextInput } from '../../internal/components/TextInput';
import { cn, color } from '../../styles/theme';
import { background, cn, color } from '../../styles/theme';
import { formatAmount } from '../../swap/utils/formatAmount';
import { TokenChip } from '../../token';
import { useBuyContext } from './BuyProvider';
Expand All @@ -13,11 +13,18 @@ export function BuyAmountInput() {
}

return (
<div className="flex h-full items-center rounded-lg border px-4">
<div
className={cn(
'flex h-full items-center rounded-lg border px-4',
background.default,
)}
>
<TextInput
className={cn(
'mr-2 w-full border-[none] bg-transparent font-display',
'mr-2 w-full border-[none] font-display',
'leading-none outline-none',
background.default,
color.foreground,
)}
placeholder="0.0"
delayMs={1000}
Expand Down
15 changes: 12 additions & 3 deletions src/buy/components/BuyButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useMemo } from 'react';
import { Spinner } from '../../internal/components/Spinner';
import { checkmarkSvg } from '../../internal/svg/checkmarkSvg';
import { closeSvg } from '../../internal/svg/closeSvg';
import {
background,
border,
Expand All @@ -16,6 +17,7 @@ export function BuyButton() {
const {
address,
setIsDropdownOpen,
isDropdownOpen,
from,
fromETH,
fromUSDC,
Expand All @@ -33,15 +35,22 @@ export function BuyButton() {
const isDisabled = !to?.amount || !to?.token || isLoading;

const handleSubmit = useCallback(() => {
setIsDropdownOpen(true);
}, [setIsDropdownOpen]);
if (isDropdownOpen) {
setIsDropdownOpen(false);
} else {
setIsDropdownOpen(true);
}
}, [setIsDropdownOpen, isDropdownOpen]);

const buttonContent = useMemo(() => {
if (statusName === 'success') {
return checkmarkSvg;
}
if (isDropdownOpen) {
return closeSvg;
}
return 'Buy';
}, [statusName]);
}, [statusName, isDropdownOpen]);

if (!isDisabled && !address) {
return <ConnectWallet text="Buy" className="h-12 w-24 min-w-24" />;
Expand Down
4 changes: 2 additions & 2 deletions src/buy/components/BuyDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export function BuyDropdown() {
<div
className={cn(
color.foreground,
background.alternate,
background.default,
'absolute right-0 bottom-0 flex translate-y-[105%] flex-col gap-2',
'min-w-80 rounded p-2',
'border min-w-80 rounded p-2 rounded-lg',
)}
>
<div className="px-2 pt-2">Buy with</div>
Expand Down

0 comments on commit 6767f99

Please sign in to comment.