From 14d7ce940f4330509312eaf7a59147bae84ebeb4 Mon Sep 17 00:00:00 2001 From: Davide Silva Date: Tue, 25 Jun 2024 18:37:30 +0100 Subject: [PATCH] fix: extra allocation --- packages/web-app/app/_lib/queries.tsx | 18 ++++++ .../web-app/app/_server/extra-allocation.ts | 20 ++++++ .../web-app/app/_ui/my-projects/my-tokens.tsx | 62 ++++++++++++++----- 3 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 packages/web-app/app/_server/extra-allocation.ts diff --git a/packages/web-app/app/_lib/queries.tsx b/packages/web-app/app/_lib/queries.tsx index 90e5cfc4..6523e929 100644 --- a/packages/web-app/app/_lib/queries.tsx +++ b/packages/web-app/app/_lib/queries.tsx @@ -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({ @@ -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], diff --git a/packages/web-app/app/_server/extra-allocation.ts b/packages/web-app/app/_server/extra-allocation.ts new file mode 100644 index 00000000..37741e3e --- /dev/null +++ b/packages/web-app/app/_server/extra-allocation.ts @@ -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; +}; diff --git a/packages/web-app/app/_ui/my-projects/my-tokens.tsx b/packages/web-app/app/_ui/my-projects/my-tokens.tsx index 6fc2ae7d..616d67be 100644 --- a/packages/web-app/app/_ui/my-projects/my-tokens.tsx +++ b/packages/web-app/app/_ui/my-projects/my-tokens.tsx @@ -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'; @@ -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: { @@ -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 ( <>
-

-
- Confirmed Allocation - {status === 'live' ? ( -
- Ongoing cap calculations +
+
+

+
+ Confirmed Allocation + {status === 'live' ? ( +
+ Ongoing cap calculations +
+ ) : null}
- ) : null} +

+
{confirmedAllocation} USDC
-

-
{confirmedAllocation} USDC
+ {extraAllocation ? ( +
+

Available for refund

+
{refundValue} USDC
+
+ ) : null} +

Current CTND PRICE (FDV)

@@ -73,10 +92,25 @@ export const MyTokens = () => {

CTND Available to Claim

{availableToClaim}
-
-

Available for refund

-
{refundValue} USDC
-
+ {extraAllocation ? ( +
+

Contribution bonus

+ + {bonusAllocation} CTND{' '} +
+ +
+
+
+ ) : ( +
+

Available for refund

+
{refundValue} USDC
+
+ )}