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

Feature/lending project #228

Open
wants to merge 68 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
31b92e3
initial setup for web3onboard
gbonumore Jun 12, 2023
9c3078d
swap all chainIds
gbonumore Jun 12, 2023
aad9145
contracts rework
gbonumore Jun 13, 2023
918e7b4
put bestnet for testing purposes
gbonumore Jun 14, 2023
aacda4d
remove migration page
gbonumore Jun 14, 2023
b83c44c
use npx patch package
gbonumore Jun 14, 2023
1015155
trigger build
gbonumore Jun 14, 2023
4dca94c
change UI colors on web3onboard
gbonumore Jun 14, 2023
9b62ccb
put straight projectId
gbonumore Jun 14, 2023
def3111
fix zindex
gbonumore Jun 14, 2023
a0067f8
fix zindex
gbonumore Jun 14, 2023
2c2ebe4
move walletconnect id
gbonumore Jun 14, 2023
e5a7d24
fix all walletconnect wallets
gbonumore Jun 15, 2023
bcc57a9
restore add token to metamask
gbonumore Jun 15, 2023
d1099ea
put bestnet
gbonumore Jun 15, 2023
1140c0d
restore mainnet
gbonumore Jun 15, 2023
503b51e
prevent memory leak
gbonumore Jun 15, 2023
14b7ec0
add @ethersproject/hash dep
gbonumore Jun 15, 2023
3466b9a
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jun 20, 2023
824822b
lending project
gbonumore Jun 27, 2023
18c5286
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jun 27, 2023
53996e3
correct data on explore page
gbonumore Jun 28, 2023
65825ae
update card on page amounts
gbonumore Jun 28, 2023
b3ab70f
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jul 3, 2023
9deb9a0
restore thunks
gbonumore Jul 3, 2023
c846361
remove unused package
gbonumore Jul 3, 2023
da8e98d
check for approval on lending
gbonumore Jul 6, 2023
c821d01
erge branch 'main' of https://github.com/pie-dao/monorepo into featur…
gbonumore Jul 6, 2023
fd0b9e0
restore prv withdrawal
gbonumore Jul 6, 2023
08bfef0
add coinbase & trezor
gbonumore Jul 6, 2023
0d8e7f9
add balances for tokens
gbonumore Jul 6, 2023
0fcdbc8
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jul 10, 2023
a621579
lending project ready to test
gbonumore Jul 12, 2023
470e7da
remove unused imports
gbonumore Jul 12, 2023
1458a3a
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jul 12, 2023
9106b89
lending test rpc
gbonumore Jul 13, 2023
8da560c
correct rpc url
gbonumore Jul 13, 2023
0675597
remove unused file
gbonumore Jul 13, 2023
908be97
further updates to lending UI
gbonumore Jul 17, 2023
5a10557
Merge branch 'feature/enanche-wallets' of https://github.com/pie-dao/…
gbonumore Jul 17, 2023
3e20cd8
lending pools UI udpates
gbonumore Jul 18, 2023
c77414b
UI updates on testing
gbonumore Jul 19, 2023
10660d0
latest checks
gbonumore Jul 19, 2023
36708d2
update rpc
gbonumore Jul 20, 2023
9926f7b
change rpc
gbonumore Jul 20, 2023
d242dea
new rpc
gbonumore Jul 20, 2023
7077764
show always 6 decimals
gbonumore Jul 20, 2023
9125cb1
debug values
gbonumore Jul 20, 2023
81dd23f
new lend rpc & new abi
gbonumore Jul 20, 2023
72adf3f
new rpc
gbonumore Jul 20, 2023
1052220
filter out inactive pools on chain
gbonumore Jul 21, 2023
725b96c
better pick preference
gbonumore Jul 21, 2023
a86778e
localhost rpc
gbonumore Jul 21, 2023
e0356ec
new rpc
gbonumore Jul 21, 2023
4f21e8e
fix approval
gbonumore Jul 21, 2023
4ec6706
lending-demo-testing
gbonumore Jul 21, 2023
d0cb9ac
new rpc
gbonumore Jul 21, 2023
b492452
updated abi
gbonumore Jul 21, 2023
8a46155
new rpc
gbonumore Jul 21, 2023
7484832
updates from feedback
gbonumore Jul 24, 2023
c39139b
updates from feedback pt2
gbonumore Jul 24, 2023
4be7fde
Merge branch 'main' of https://github.com/pie-dao/monorepo into featu…
gbonumore Jul 25, 2023
9fb2096
update abi
gbonumore Jul 28, 2023
4f86cbf
update code according to ABI
gbonumore Jul 28, 2023
b3ef62e
update pool address
gbonumore Jul 28, 2023
80366d7
update with contract changes
gbonumore Aug 1, 2023
a01edf1
add messages
gbonumore Aug 2, 2023
9eaaa1a
preference UI update
gbonumore Aug 2, 2023
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
3 changes: 3 additions & 0 deletions apps/auxo/components/Alerts/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export function Alert({
open,
children,
style = 'warning',
className,
}: {
open?: boolean;
children: React.ReactNode;
style?: 'error' | 'warning';
className?: string;
}) {
return (
<AnimatePresence>
Expand All @@ -38,6 +40,7 @@ export function Alert({
'rounded-lg items-center py-1 justify-center',
style === 'warning' && 'bg-warning text-primary',
style === 'error' && 'bg-red text-white',
className,
)}
variants={variants}
initial="hidden"
Expand Down
128 changes: 128 additions & 0 deletions apps/auxo/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import classNames from '../../utils/classnames';

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={classNames(
'shadow-lg flex flex-col @[620px]/main:flex-row @[1224px]/grid:flex-row overflow-hidden rounded-lg',
className,
)}
{...props}
/>
));
Card.displayName = 'Card';

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={classNames('flex flex-col space-y-4 p-2', className)}
{...props}
/>
));
CardHeader.displayName = 'CardHeader';

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={classNames('text-lg text-primary font-semibold', className)}
{...props}
/>
));
CardTitle.displayName = 'CardTitle';

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={classNames('text-sm', className)} {...props} />
));
CardDescription.displayName = 'CardDescription';

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={classNames('p-2 pt-0', className)} {...props} />
));
CardContent.displayName = 'CardContent';

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={classNames('flex items-center p-2 pt-0', className)}
{...props}
/>
));
CardFooter.displayName = 'CardFooter';

const CardInfoList = React.forwardRef<
HTMLDivElement,
{ className?: string; infos: { title: string; value: JSX.Element }[] }
>(({ className, infos, ...props }, ref) => (
<div
ref={ref}
className={classNames(
'p-2 grid grid-cols-1 @lg:grid-cols-[minmax(100px,_150px)_minmax(100px,_150px)_minmax(100px,_1fr)] gap-x-5 text-sm justify-center flex-1',
className,
)}
{...props}
>
{infos.map(({ title, value }, index) => (
<dl key={index} className="font-medium flex gap-1 justify-between">
<dt>{title}</dt>
<dd className="font-medium text-right">{value}</dd>
</dl>
))}
</div>
));
CardInfoList.displayName = 'CardInfoList';

const CardDebug = React.forwardRef<
HTMLDivElement,
{ className?: string; infos: { title: string; value: JSX.Element }[] }
>(({ className, infos, ...props }, ref) => (
<div
ref={ref}
className={classNames(
'flex flex-col p-2 gap-y-2 text-sm justify-center flex-1',
)}
{...props}
>
{infos.map(({ title, value }, index) => (
<dl
key={index}
className="font-medium flex flex-col gap-1 justify-between"
>
<dt>{title}</dt>
<dd className="font-medium">{value}</dd>
</dl>
))}
</div>
));
CardDebug.displayName = 'CardDebug';

export default CardInfoList;

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
CardInfoList,
CardDebug,
};
123 changes: 123 additions & 0 deletions apps/auxo/components/Card/CardVariants/PoolCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import Image from 'next/image';
import { useAppSelector } from '../../../hooks';
import useTranslation from 'next-translate/useTranslation';
import classNames from '../../../utils/classnames';
import { formatBalance } from '../../../utils/formatBalance';
import CardInfoList, {
Card,
CardContent,
CardDescription,
CardFooter,
} from '../Card';
import { formatDate } from '../../../utils/dates';
import { userMergedPosition } from '../../../hooks/useEnanchedPools';
import { isEmpty } from 'lodash';
import { ParseMarkdown } from '../../ParseMarkdown/ParseMarkdown';

export const PoolCard = ({ pool }: { pool: userMergedPosition }) => {
const { t } = useTranslation();
const { defaultLocale } = useAppSelector((state) => state.preferences);
if (isEmpty(pool)) {
return null;
}
return (
<Card
className={classNames(
'bg-grsadient-primary flex-row',
!pool?.attributes?.is_active && 'opacity-50 pointer-events-none',
)}
>
<CardContent className="gap-4 flex-col lg:flex-row flex">
<div className="flex relative overflow-hidden rounded-md items-center justify-center flex-shrink-0 h-48 lg:h-auto lg:w-[380px]">
{pool?.attributes?.card_image?.data?.attributes?.url ? (
<Image
src={pool?.attributes?.card_image?.data?.attributes?.url}
alt="eth"
objectPosition={'top'}
objectFit={'cover'}
layout={'fill'}
priority
/>
) : null}
{pool?.attributes?.pool_token_image?.data?.attributes?.url ? (
<div className="absolute">
<Image
src={pool?.attributes?.pool_token_image?.data?.attributes?.url}
alt="eth"
width={200}
height={200}
/>
</div>
) : null}
</div>
<CardDescription>
<div className="text-primary bg-light-gray text-sm p-4 rounded-md relative">
{ParseMarkdown(pool?.attributes?.description)}
<div className="flex flex-wrap gap-2 mt-2">
{pool?.attributes?.tags?.map(({ tag }, i) => (
<span
key={i}
className="text-base text-white bg-gradient-major-secondary-predominant rounded-lg px-2 py-0.5"
>
{tag}
</span>
))}
</div>
</div>
<CardInfoList
className="text-primary bg-light-gray text-sm p-4 rounded-md"
infos={[
{
title: t('currentTotalSupply'),
value: (
<>
{formatBalance(
pool?.lastEpoch?.totalBorrow?.label,
defaultLocale,
2,
'standard',
)}{' '}
{pool?.attributes?.token?.data?.attributes?.symbol}
</>
),
},
{
title: t('rewardsGenerated'),
value: (
<>
{pool?.lastEpoch?.forClaims?.label !== 0
? `${formatBalance(
pool?.lastEpoch?.forClaims?.label,
defaultLocale,
2,
'standard',
)} ${pool?.attributes?.token?.data?.attributes?.symbol}`
: t('N/A')}
</>
),
},
{
title: t('withdrawIn'),
value: (
<>
{formatDate(
pool.attributes?.date_until_next_state,
defaultLocale,
)}
</>
),
},
{
title: t('startingDate'),
value: (
<>{formatDate('2021-09-01T00:00:00.000Z', defaultLocale)}</>
),
},
]}
/>
</CardDescription>
</CardContent>
<CardFooter></CardFooter>
</Card>
);
};
27 changes: 27 additions & 0 deletions apps/auxo/components/Card/Skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const CardSkeleton = () => {
return (
<div
role="status"
className="animate-pulse shadow-lg max-w-[800px] flex flex-col @[620px]/main:flex-row @[1224px]/grid:flex-row overflow-hidden bg-white border-gray-200 rounded-lg p-4"
>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="flex items-center justify-center h-48 mb-4 bg-gray-300 rounded dark:bg-gray-700">
<svg
className="w-12 h-12 text-gray-200 dark:text-gray-600"
xmlns="http://www.w3.org/2000/svg"
aria-hidden="true"
fill="currentColor"
viewBox="0 0 640 512"
>
<path d="M480 80C480 35.82 515.8 0 560 0C604.2 0 640 35.82 640 80C640 124.2 604.2 160 560 160C515.8 160 480 124.2 480 80zM0 456.1C0 445.6 2.964 435.3 8.551 426.4L225.3 81.01C231.9 70.42 243.5 64 256 64C268.5 64 280.1 70.42 286.8 81.01L412.7 281.7L460.9 202.7C464.1 196.1 472.2 192 480 192C487.8 192 495 196.1 499.1 202.7L631.1 419.1C636.9 428.6 640 439.7 640 450.9C640 484.6 612.6 512 578.9 512H55.91C25.03 512 .0006 486.1 .0006 456.1L0 456.1z" />
</svg>
</div>
<div className="h-2.5 bg-gray-200 rounded-full dark:bg-gray-700 w-48 mb-4"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700 mb-2.5"></div>
<div className="h-2 bg-gray-200 rounded-full dark:bg-gray-700"></div>

<span className="sr-only">Loading...</span>
</div>
);
};
70 changes: 70 additions & 0 deletions apps/auxo/components/ClaimablePoolRewards/ClaimablePoolRewards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import useTranslation from 'next-translate/useTranslation';
import { useAppDispatch, useAppSelector } from '../../hooks';
import { formatBalance } from '../../utils/formatBalance';
import { BanknotesIcon, WalletIcon } from '../Icons/Icons';
import { useEnanchedPools } from '../../hooks/useEnanchedPools';
import { isEqual } from 'lodash';
import { zeroBalance } from '../../utils/balances';
import { STEPS } from '../../store/lending/lending.types';
import {
setLendingFlowPool,
setLendingFlowOpen,
setLendingStep,
setDepositValue,
} from '../../store/lending/lending.slice';

export const ClaimablePoolRewards = ({
poolAddress,
}: {
poolAddress: string;
}) => {
const { defaultLocale } = useAppSelector((state) => state.preferences);

const { t } = useTranslation();
const { data } = useEnanchedPools(poolAddress);
const claimableAmount =
isEqual(data?.userData?.yield, zeroBalance) ||
data?.userData?.yield === undefined ||
data?.userData?.yield === null;

const dispatch = useAppDispatch();

const claimRewards = () => {
dispatch(setLendingFlowPool(poolAddress));
dispatch(setLendingFlowOpen(true));
dispatch(setDepositValue(data?.userData?.yield));
dispatch(setLendingStep(STEPS.LEND_REWARDS_CLAIM));
};

return (
<div className="flex gap-x-4 gap-y-2 flex-wrap items-center w-full bg-gradient-primary shadow-md rounded-lg px-3 py-2 justify-between">
<div className="flex gap-x-2 items-center">
<div className="flex flex-shrink-0 text-primary">
<WalletIcon />
</div>
<p className="text-lg text-primary font-medium">
{t('claimableRewards', {
amount: formatBalance(
data?.userData?.yield?.label,
defaultLocale,
6,
'standard',
),
})}{' '}
{data?.attributes?.token?.data?.attributes?.name}
</p>
</div>
<div className="flex gap-x-2 items-center ml-auto">
<button
type="button"
className="flex gap-x-2 items-center w-fit px-2 py-1 text-sm font-medium text-white bg-green rounded-full ring-inset ring-2 ring-green enabled:hover:bg-transparent enabled:hover:text-green disabled:opacity-30"
onClick={claimRewards}
disabled={claimableAmount}
>
<BanknotesIcon />
{t('claimRewards')}
</button>
</div>
</div>
);
};
24 changes: 24 additions & 0 deletions apps/auxo/components/Countdown/Countdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { useMemo } from 'react';
import useCountdown from '../../hooks/useCountdown';

interface CountdownProps {
date: string;
}

const Countdown: React.FC<CountdownProps> = ({ date }) => {
const dateUntilNextState = useMemo(() => {
const parsedDate = Date.parse(date);
return !isNaN(parsedDate) ? new Date(parsedDate) : null;
}, [date]);

// Use the countdown hook
const counter = useCountdown(dateUntilNextState);

return (
<div className=" text-primary font-semibold text-2xl">
{dateUntilNextState === null ? null : <p>{counter}</p>}
</div>
);
};

export default Countdown;
Loading