Skip to content

Commit

Permalink
refector: update ui code
Browse files Browse the repository at this point in the history
  • Loading branch information
Thammarong Glomjai committed Nov 14, 2024
1 parent 8f40860 commit 9b238b6
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 25 deletions.
15 changes: 15 additions & 0 deletions src/assets/bitcoin-btc-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions src/assets/icon_lightning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/assets/solana-sol-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions src/assets/sui-sui-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/Layout/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const Header = ({ rightWidget, menuItems }: Props) => {
return (
<header
className={
'sticky top-0 left-0 z-1003 w-full h-[var(--layout-header-height)] bg-[var(--color-background)]'
"sticky top-0 left-0 z-1003 w-full h-[var(--layout-header-height)] bg-white/20 shadow ring-1 ring-black/5"
}
>
<nav className="flex w-full items-center justify-between gap-3 pb-3 pl-4 pr-4 pt-3">
Expand Down
1 change: 0 additions & 1 deletion src/components/WalletStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const WalletStatus = () => {
return (
<>
<Heading mb="2">Wallet Status</Heading>

{account ? (
<Flex direction="column">
<Text>Wallet connected</Text>
Expand Down
6 changes: 4 additions & 2 deletions src/components/elements/Container/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Container as RadixContainer } from '@radix-ui/themes'
import type { ContainerProps } from '@radix-ui/themes/dist/esm/components/container'

export function Container(props: ContainerProps) {
const { className, ...other } = props
return <RadixContainer className={cn('w-11/12 pt-10', className)} {...other} />
const { className, ...other } = props;
return (
<RadixContainer className={cn("p-10", className)} {...other} />
);
}
1 change: 0 additions & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ createRoot(document.getElementById('root')!).render(
grayColor="gray"
panelBackground="solid"
scaling="100%"
radius="full"
>
<QueryClientProvider client={queryClient}>
<SuiClientProvider networks={networkConfig} defaultNetwork="devnet">
Expand Down
201 changes: 197 additions & 4 deletions src/pages/Swap.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,203 @@
import { WalletStatus } from '../components/WalletStatus'
import { Container } from '../components/elements/Container'
import { useCurrentAccount, ConnectButton } from "@mysten/dapp-kit";
import { Box, Card, TextField, Flex, Select } from "@radix-ui/themes";
import { Container } from "../components/elements/Container";
import { useState } from "react";
import BitcoinLogo from "./../assets/bitcoin-btc-logo.svg";
import LNBitcoinLogo from "./../assets/icon_lightning.svg";
import SuiLogo from "./../assets/sui-sui-logo.svg";
import SolLogo from "./../assets/solana-sol-logo.svg";
import { UpdateIcon } from "@radix-ui/react-icons";

interface CryptoAsset {
label: string;
icon: JSX.Element;
}

interface CryptoData {
[key: string]: CryptoAsset;
}

const sourceData: CryptoData = {
btc: {
label: "BTC",
icon: <img src={BitcoinLogo} alt="BTC" className="w-5 h-5" />,
},
ln_btc: {
label: "LN-BTC",
icon: <img src={LNBitcoinLogo} alt="LN-BTC" className="w-6 h-6" />,
},
};

const targetData: CryptoData = {
sui: {
label: "SUI",
icon: <img src={SuiLogo} alt="SUI" className="w-5 h-5" />,
},
sol: {
label: "SOL",
icon: <img src={SolLogo} alt="SOL" className="w-6 h-6" />,
},
};

type SourceCurrency = keyof typeof sourceData;
type TargetCurrency = keyof typeof targetData;

export const Swap = () => {
const account = useCurrentAccount();
const [targetValue, setTargetValue] = useState<TargetCurrency>("sui");
const [sourceValue, setSourceValue] = useState<SourceCurrency>("btc");

// Mock balances - replace with actual balance fetching logic
const balances = {
btc: "1.245",
ln_btc: "0.5",
sui: "1000",
sol: "25.5",
};

const renderWalletInfo = () => {
if (!account) return null;

return (
<div className="mb-6">
<div className="flex items-center justify-between mb-1">
<span className="text-sm text-gray-400">Connected Wallet</span>
<span className="text-sm text-gray-400">
Balance: {balances[sourceValue]} {sourceData[sourceValue].label}

Check failure on line 66 in src/pages/Swap.tsx

View workflow job for this annotation

GitHub Actions / build

Element implicitly has an 'any' type because expression of type 'string | number' can't be used to index type '{ btc: string; ln_btc: string; sui: string; sol: string; }'.
</span>
</div>
<div className="text-sm text-gray-500 font-medium">
{account.address.slice(0, 6)}...{account.address.slice(-4)}
</div>
</div>
);
};

const renderAmountInput = () => (
<Box className="w-7/12">
<TextField.Root
placeholder="0.00"
size="3"
className="h-14 bg-transparent focus:ring-0 border-none text-lg"
/>
</Box>
);

const renderCurrencySelect = (
value: string,
onChange: (value: string) => void,
data: CryptoData,
options: { value: string; label: string }[]
) => (
<Box className="w-5/12">
<Select.Root value={value} onValueChange={onChange} size="3">
<Select.Trigger className="w-full h-14 bg-white/5 border-none focus:ring-0 hover:bg-white/10 transition-colors">
<Flex align="center" gap="2" className="px-3">
{data[value].icon}
<span className="font-medium text-lg min-w-[80px]">
{data[value].label}
</span>
</Flex>
</Select.Trigger>
<Select.Content
position="popper"
className="bg-slate-800/90 backdrop-blur-md min-w-[140px]"
>
{options.map((option) => (
<Select.Item
key={option.value}
value={option.value}
className="text-gray-100 hover:bg-white/10 transition-colors focus:bg-white/10"
>
<Flex align="center" gap="2" className="px-2">
{data[option.value].icon}
<span className="font-medium">{option.label}</span>
</Flex>
</Select.Item>
))}
</Select.Content>
</Select.Root>
</Box>
);

const renderWalletBackdrop = () => (
<div className="absolute inset-0 bg-black/20 backdrop-blur-md rounded-xl flex items-center justify-center">
<div className="bg-slate-800/90 backdrop-blur-md rounded-xl p-8 shadow-lg max-w-sm w-full mx-4">
<div className="text-center mb-6">
<h3 className="text-xl font-semibold text-white">Connect Wallet</h3>
<p className="text-sm text-gray-400 mt-2">
Please connect your wallet to access the swap feature
</p>
</div>
<div className="flex justify-center">
<ConnectButton className="bg-white/10 text-white px-6 py-3 rounded-lg hover:bg-white/20 transition-colors font-medium" />
</div>
</div>
</div>
);

const sourceOptions = [
{ value: "btc", label: "BTC" },
{ value: "ln_btc", label: "LN-BTC" },
];

const targetOptions = [
{ value: "sui", label: "SUI" },
{ value: "sol", label: "SOL" },
];

return (
<Container data-testid="swap-page">
<WalletStatus />
<Container data-testid="swap-page" maxWidth="1" className="min-h-screen">
<div className="max-w-screen-xl mx-auto px-4">
<div className="py-8" />

<div className="flex justify-center">
<Box className="w-full max-w-[520px] relative">
<Card className="bg-slate-800/90 backdrop-blur-md text-white rounded-xl p-6">
<div className="space-y-6">
{renderWalletInfo()}

<div>
<p className="text-gray-400 mb-2">You pay</p>
<div className="rounded-xl bg-black/20 p-4 backdrop-blur-md">
<Flex gap="3" justify="between">
{renderAmountInput()}
{renderCurrencySelect(
sourceValue,

Check failure on line 166 in src/pages/Swap.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | number' is not assignable to parameter of type 'string'.
setSourceValue,
sourceData,
sourceOptions
)}
</Flex>
</div>
</div>

<div className="flex justify-center">
<div className="bg-white/5 hover:bg-white/10 p-3 rounded-xl cursor-pointer transition-colors">
<UpdateIcon className="w-6 h-6 text-white rotate-180" />
</div>
</div>

<div>
<p className="text-gray-400 mb-2">You receive</p>
<div className="rounded-xl bg-black/20 p-4 backdrop-blur-md">
<Flex gap="3" justify="between">
{renderAmountInput()}
{renderCurrencySelect(
targetValue,

Check failure on line 187 in src/pages/Swap.tsx

View workflow job for this annotation

GitHub Actions / build

Argument of type 'string | number' is not assignable to parameter of type 'string'.
setTargetValue,
targetData,
targetOptions
)}
</Flex>
</div>
</div>
</div>
</Card>
{!account && renderWalletBackdrop()}
</Box>
</div>
</div>
</Container>
)
}
17 changes: 1 addition & 16 deletions src/pages/Transaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,7 @@ import { Box, Text, Flex, Card, Avatar } from '@radix-ui/themes'
export const Transaction = () => (
<Box maxWidth="240px">
<Card>
<Flex gap="3" align="center">
<Avatar
size="3"
src="https://images.unsplash.com/photo-1607346256330-dee7af15f7c5?&w=64&h=64&dpr=2&q=70&crop=focalpoint&fp-x=0.67&fp-y=0.5&fp-z=1.4&fit=crop"
radius="full"
fallback="T"
/>
<Box>
<Text as="div" size="2" weight="bold">
Teodros Girmay
</Text>
<Text as="div" size="2" color="gray">
Engineering
</Text>
</Box>
</Flex>

</Card>
</Box>
)

0 comments on commit 9b238b6

Please sign in to comment.