Skip to content

Commit

Permalink
fix: extra allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideSilva committed Jun 25, 2024
1 parent bd0dba3 commit 14d7ce9
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
18 changes: 18 additions & 0 deletions packages/web-app/app/_lib/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { appSignal } from '../app-signal';
import { useEffect } from 'react';
import { canContribute } from '../_server/can-contribute';
import { userProjects } from '../_server/user-projects';
import { extraAllocation } from '../_server/extra-allocation';

export const usePublicInfo = () => {
return useQuery({
Expand Down Expand Up @@ -333,6 +334,23 @@ export const useFetchRisingTideCap = (enabled?: boolean) => {
});
};

export const useExtraAllocation = (address?: string) => {
return useQuery({
queryKey: ['extra-allocation', address],
queryFn: async () => {
if (!address) return false;
const result = await extraAllocation(address);
if (typeof result === 'object' && 'error' in result) {
appSignal.sendError(new Error(result.error));
throw new Error(result.error);
}

return result;
},
enabled: !!address,
});
};

export const useCanContribute = (project?: string, address?: string) => {
return useQuery({
queryKey: ['can-contribute', project, address],
Expand Down
20 changes: 20 additions & 0 deletions packages/web-app/app/_server/extra-allocation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use server';

import { createClient } from './supabase/server';

// get wallets that participated in the first community sale
export const extraAllocation = async (address: string) => {
const supabase = createClient();

const { error, data } = await supabase
.from('extra_allocation')
.select('address')
.ilike('address', `%${address}%`);

if (error) {
console.error(error);
return { error: error.message };
}

return data?.length && data.length > 0 ? true : false;
};
62 changes: 48 additions & 14 deletions packages/web-app/app/_ui/my-projects/my-tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useCtzndSaleCapStatus, useCtzndSaleStatus } from '@/app/_lib/hooks';
import {
useCtzndRisingTideCap,
useCtzndSaleCapStatus,
useCtzndSaleStatus,
} from '@/app/_lib/hooks';
import {
useExtraAllocation,
useTotalInvestedUsdcCtznd,
useUserTotalInvestedUsdcCtznd,
} from '@/app/_lib/queries';
Expand All @@ -12,10 +17,12 @@ import { useAccount } from 'wagmi';
import { calculateTokenPrice } from '../utils/calculateTokenPrice';
import { number } from '../utils/intl-formaters/number';
import { usdValue } from '../utils/intl-formaters/usd-value';
import { Tooltip } from '../components/tooltip';

const useAvailableToClaim = () => {
const { address } = useAccount();
const capStatus = useCtzndSaleCapStatus();
const cap = useCtzndRisingTideCap();
const { data: availableToClaim } = useReadCtzndSaleAllocation({
args: [address!],
query: {
Expand Down Expand Up @@ -47,21 +54,33 @@ export const MyTokens = () => {
const totalContributions = useTotalInvestedUsdcCtznd();
const currentTokenPrice = calculateTokenPrice(Number(totalContributions));
const availableToClaim = useAvailableToClaim();
const bonusAllocation = 0 * 1.25;
const extraAllocation = useExtraAllocation(address).data;

return (
<>
<div className="flex flex-col gap-2 rounded-md bg-mono-50 px-6 py-8 text-mono-950">
<h3 className="flex text-sm text-mono-800">
<div className="relative">
Confirmed Allocation
{status === 'live' ? (
<div className="absolute right-0 top-0 w-48 -translate-y-1/2 translate-x-full rounded-full bg-mono-900 px-2 pb-0.5 pt-1 text-xs uppercase leading-3 text-mono-50">
Ongoing cap calculations
<div className="grid grid-cols-1 gap-6 pt-6 md:grid-cols-3">
<div className="col-span-2 flex flex-col gap-2">
<h3 className="flex flex-col text-sm text-mono-800">
<div className="relative">
Confirmed Allocation
{status === 'live' ? (
<div className="absolute left-0 top-0 w-48 -translate-y-1/2 translate-x-full rounded-full bg-mono-900 px-2 pb-0.5 pt-1 text-xs uppercase leading-3 text-mono-50">
Ongoing cap calculations
</div>
) : null}
</div>
) : null}
</h3>
<div className="text-3.5xl">{confirmedAllocation} USDC</div>
</div>
</h3>
<div className="text-3.5xl">{confirmedAllocation} USDC</div>
{extraAllocation ? (
<div className="flex flex-col gap-2">
<h3 className="text-sm text-mono-800">Available for refund</h3>
<div>{refundValue} USDC</div>
</div>
) : null}
</div>
<div className="grid grid-cols-1 gap-6 pt-6 md:grid-cols-3">
<div className="flex flex-col gap-2">
<h3 className="text-sm text-mono-800">Current CTND PRICE (FDV)</h3>
Expand All @@ -73,10 +92,25 @@ export const MyTokens = () => {
<h3 className="text-sm text-mono-800">CTND Available to Claim</h3>
<div>{availableToClaim}</div>
</div>
<div className="flex flex-col gap-2">
<h3 className="text-sm text-mono-800">Available for refund</h3>
<div>{refundValue} USDC</div>
</div>
{extraAllocation ? (
<div className="flex flex-col gap-2">
<h3 className="text-sm text-mono-800">Contribution bonus</h3>
<span className="relative flex">
{bonusAllocation} CTND{' '}
<div className="absolute -top-2 left-32">
<Tooltip
text="25% bonus for previous Community Sale participants"
className="-translate-x-3/4 -translate-y-full"
/>
</div>
</span>
</div>
) : (
<div className="flex flex-col gap-2">
<h3 className="text-sm text-mono-800">Available for refund</h3>
<div>{refundValue} USDC</div>
</div>
)}
</div>
</div>
</>
Expand Down

0 comments on commit 14d7ce9

Please sign in to comment.