Skip to content

Commit

Permalink
feat: add garden swap functionality and ui components
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Dec 23, 2024
1 parent ee2bc04 commit be7d9e2
Show file tree
Hide file tree
Showing 29 changed files with 5,596 additions and 328 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"@fontsource/inter": "^5.0.18",
"@fontsource/onest": "^5.0.3",
"@fontsource/poppins": "^5.0.8",
"@gardenfi/core": "0.3.0-beta.14",
"@gardenfi/orderbook": "0.2.0-beta.41",
"@gardenfi/react-hooks": "0.0.1-beta.135",
"@gemwallet/api": "^3.8.0",
"@ledgerhq/hw-app-xrp": "^6.29.4",
"@ledgerhq/hw-transport-webusb": "^6.28.6",
Expand All @@ -41,12 +44,13 @@
"@types/chrome": "^0.0.248",
"@types/d3": "^7.4.3",
"@types/ramda": "^0.30.1",
"@wagmi/core": "^2.16.1",
"apexcharts": "^3.49.1",
"buffer": "^6.0.3",
"concurrently": "^8.2.2",
"d3": "^7.9.0",
"decimal.js": "^10.4.3",
"dlc-btc-lib": "2.5.1",
"dlc-btc-lib": "2.5.3",
"dotenv": "^16.3.1",
"ethers": "5.7.2",
"formik": "^2.4.5",
Expand All @@ -66,7 +70,7 @@
"redux-persist-expire": "^1.1.1",
"viem": "2.x",
"vite-plugin-toml": "^0.7.0",
"wagmi": "^2.12.2",
"wagmi": "2.14.4",
"xrpl": "^4.0.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions public/images/gear-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/images/swap-arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 46 additions & 33 deletions src/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Route } from 'react-router-dom';

import { AppLayout } from '@components/app.layout';
import { MerchantDetails } from '@components/proof-of-reserve/components/merchant-details/merchant-details';
import { SwapPage } from '@components/swap/pages/swap-page';
import { getWagmiConfiguration } from '@functions/configuration.functions';
import { GardenProvider, environment } from '@gardenfi/react-hooks';
import { AttestorDetailsPage } from '@pages/attestor-details/attestor-details-page';
import { AttestorDetailsSelectPage } from '@pages/attestor-details/attestor-details-select-page';
import { MyVaults } from '@pages/my-vaults/my-vaults';
Expand Down Expand Up @@ -31,39 +33,50 @@ export function App(): React.JSX.Element {
return (
<WagmiProvider config={wagmiConfiguration}>
<QueryClientProvider client={queryClient}>
<NetworkConfigurationContextProvider>
<RippleNetworkConfigurationContextProvider>
<EthereumNetworkConfigurationContextProvider>
<XRPWalletContextProvider>
<BitcoinWalletContextProvider>
<NetworkConnectionContextProvider>
<VaultContextProvider>
<BitcoinTransactionConfirmationsProvider>
<BalanceContextProvider>
<ProofOfReserveContextProvider>
<AppLayout>
<Route path="/" element={<PointsPage />} />
<Route path="/my-vaults" element={<MyVaults />} />
{/* <Route path="/how-it-works" element={<About />} /> */}
<Route path="/proof-of-reserve" element={<ProofOfReservePage />} />
<Route path="/attestor-details" element={<AttestorDetailsPage />} />
<Route
path="/attestor-details-select"
element={<AttestorDetailsSelectPage />}
/>
<Route path="/merchant-details/:name" element={<MerchantDetails />} />
<Route path="/mint-withdraw" element={<Dashboard />} />
</AppLayout>
</ProofOfReserveContextProvider>
</BalanceContextProvider>
</BitcoinTransactionConfirmationsProvider>
</VaultContextProvider>
</NetworkConnectionContextProvider>
</BitcoinWalletContextProvider>
</XRPWalletContextProvider>
</EthereumNetworkConfigurationContextProvider>
</RippleNetworkConfigurationContextProvider>
</NetworkConfigurationContextProvider>
<GardenProvider
config={{
store: localStorage,
environment: environment.testnet,
}}
>
<NetworkConfigurationContextProvider>
<RippleNetworkConfigurationContextProvider>
<EthereumNetworkConfigurationContextProvider>
<XRPWalletContextProvider>
<BitcoinWalletContextProvider>
<NetworkConnectionContextProvider>
<VaultContextProvider>
<BitcoinTransactionConfirmationsProvider>
<BalanceContextProvider>
<ProofOfReserveContextProvider>
<AppLayout>
<Route path="/" element={<PointsPage />} />
<Route path="/my-vaults" element={<MyVaults />} />
{/* <Route path="/how-it-works" element={<About />} /> */}
<Route path="/proof-of-reserve" element={<ProofOfReservePage />} />
<Route path="/attestor-details" element={<AttestorDetailsPage />} />
<Route
path="/attestor-details-select"
element={<AttestorDetailsSelectPage />}
/>
<Route
path="/merchant-details/:name"
element={<MerchantDetails />}
/>
<Route path="/mint-withdraw" element={<Dashboard />} />
<Route path="/swap" element={<SwapPage />} />
</AppLayout>
</ProofOfReserveContextProvider>
</BalanceContextProvider>
</BitcoinTransactionConfirmationsProvider>
</VaultContextProvider>
</NetworkConnectionContextProvider>
</BitcoinWalletContextProvider>
</XRPWalletContextProvider>
</EthereumNetworkConfigurationContextProvider>
</RippleNetworkConfigurationContextProvider>
</NetworkConfigurationContextProvider>
</GardenProvider>
</QueryClientProvider>
</WagmiProvider>
);
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/header/components/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ export function NavigationTabs({
isActive={activeTab === '/how-it-works'}
handleClick={() => handleTabClick('/how-it-works')}
/> */}
<TabButton
title={'Swap'}
isActive={activeTab === '/swap'}
handleClick={() => handleTabClick('/swap')}
/>

{isActiveTabs && (
<>
Expand Down
96 changes: 96 additions & 0 deletions src/app/components/swap/components/swap-amount-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { HStack, Input, Text, VStack } from '@chakra-ui/react';
import { Asset } from '@gardenfi/orderbook';

import { SwapTokenLabel } from './swap-token-label';

interface SwapAmountCardProps {
direction: string;
asset: Asset;
amount?: string;
amountInUSD?: string;
setAmount?: (amount: string) => void;
balance?: number;
transactionGasFee?: number;
}

const assetDetails = {
iBTC: {
assetColor: 'purple.01',
assetSymbol: 'iBTC',
assetLogo: '/images/logos/ibtc-logo.svg',
},
BTC: {
assetColor: 'orange.01',
assetSymbol: 'BTC',
assetLogo: '/images/logos/bitcoin-logo.svg',
},
};

export function SwapAmountCard({
direction,
amount,
asset,
amountInUSD,
setAmount,
}: SwapAmountCardProps): React.JSX.Element | null {
const isBTC = asset.symbol === 'BTC';
const { assetColor, assetSymbol, assetLogo } = assetDetails[isBTC ? 'BTC' : 'iBTC'];

return (
<VStack
p={'15px'}
w={'100%'}
bg={'background.container.02'}
borderRadius={'md'}
border={'1px solid'}
spacing={'15px'}
borderColor={assetColor}
alignItems={'flex-start'}
boxShadow={'2px 2px 4px rgba(0, 0, 0, 0.5)'}
>
<Text color={'white'} fontWeight={'600'}>
{direction}
</Text>
<VStack
p={'15px'}
w={'100%'}
bg={'background.content.02'}
borderRadius={'md'}
border={'1px solid'}
spacing={'15px'}
borderColor={'white.03'}
alignItems={'flex-start'}
boxShadow={'2px 2px 4px rgba(0, 0, 0, 0.5)'}
>
<HStack w={'100%'} justifyContent={'space-between'}>
{direction === 'From' ? (
<Input
autoFocus
w={'175px'}
value={amount}
onChange={e => setAmount?.(e.target.value)}
borderColor={'white.01'}
color={'white.01'}
focusBorderColor={'rgba(50, 201, 247, 1)'} // accent.lightBlue.01
/>
) : (
<Text
color={'white'}
fontWeight={'800'}
fontSize={'x-large'}
textShadow={'2px 2px 4px rgba(0, 0, 0, 0.5)'}
>
{amount}
</Text>
)}
<SwapTokenLabel tokenImage={assetLogo} tokenDisplay={assetSymbol} />
</HStack>
<HStack justifyContent={'space-between'} width={'100%'}>
<Text color={'white.03'} fontSize={'sm'}>
{amountInUSD} USD
</Text>
</HStack>
</VStack>
</VStack>
);
}
21 changes: 21 additions & 0 deletions src/app/components/swap/components/swap-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';

import { Button } from '@chakra-ui/react';

interface SwapButtonProps {
isDisabled?: boolean;
onClick: () => void;
}

export function SwapButton({ onClick, isDisabled }: SwapButtonProps): React.JSX.Element {
return (
<Button
isDisabled={isDisabled}
onClick={onClick}
w={'100%'}
boxShadow={'2px 2px 4px rgba(0, 0, 0, 0.5)'}
>
Swap
</Button>
);
}
47 changes: 47 additions & 0 deletions src/app/components/swap/components/swap-extra-details-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// import { HStack, Text, VStack } from '@chakra-ui/react';

// interface SwapExtraDetailsCardProps {
// gasFee: number;
// }

// export function SwapExtraDetailsCard({ gasFee }: SwapExtraDetailsCardProps): React.JSX.Element {
// return (
// <VStack
// p={'15px'}
// w={'100%'}
// bg={'background.container.02'}
// borderRadius={'md'}
// border={'1px dashed'}
// spacing={'15px'}
// borderColor={'white.02'}
// alignItems={'flex-start'}
// >
// <HStack w={'100%'} justifyContent={'space-between'}>
// <Text color={'white.02'} fontSize={'sm'}>
// Gas Fee
// </Text>
// <Text color={'white.02'} fontSize={'sm'} fontWeight={600}>
// {gasFee}
// </Text>
// </HStack>
// <HStack w={'100%'} justifyContent={'space-between'}>
// <Text color={'white.02'} fontSize={'sm'}>
// Rate
// </Text>
// <Text color={'white.02'} fontSize={'sm'} fontWeight={600}>
// 1 BTC = 1 dlcBTC
// </Text>
// </HStack>
// <HStack w={'100%'} justifyContent={'space-between'}>
// <Text color={'white.02'} fontSize={'sm'}>
// Slippage Tolerance
// </Text>
// <Text color={'white.02'} fontSize={'sm'} fontWeight={600}>
// Auto
// </Text>
// </HStack>
// </VStack>
// );
// }

// TODO: Add back this component
17 changes: 17 additions & 0 deletions src/app/components/swap/components/swap-header.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HStack, Text } from '@chakra-ui/react';

// import { SwapNetworksMenu } from './swap-networks-menu';

export function SwapHeader(): React.JSX.Element {
return (
<HStack w={'100%'} justifyContent={'space-between'}>
<Text color={'white'} fontSize={'xx-large'} fontWeight={'600'}>
Swap
</Text>
<HStack>
{/* <SwapNetworksMenu isMenuOpen={false} setIsMenuOpen={() => {}} /> */}
{/* <SwapSettingsMenu isMenuOpen={false} setIsMenuOpen={() => {}} /> */}
</HStack>
</HStack>
);
}
Loading

0 comments on commit be7d9e2

Please sign in to comment.