diff --git a/packages/contracts/test/contracts/token/Sale.d.sol b/packages/contracts/test/contracts/token/Sale.d.sol index 1290ebff..8273309c 100644 --- a/packages/contracts/test/contracts/token/Sale.d.sol +++ b/packages/contracts/test/contracts/token/Sale.d.sol @@ -65,8 +65,8 @@ contract SaleTest is Test { token = new Citizend(owner, end); paymentTokenMultiplier = 10 ** paymentToken.decimals(); - rate = (2 * paymentTokenMultiplier ) / 10; - minContribution = 2 * paymentTokenMultiplier / 10; + rate = (2 * paymentTokenMultiplier) / 10; + minContribution = (2 * paymentTokenMultiplier) / 10; sale = new Sale( address(paymentToken), @@ -114,8 +114,8 @@ contract SaleTest is Test { function testConstructor() public view { require(sale.paymentToken() == address(paymentToken)); require(sale.rate() == rate); - require(sale.minPrice() == 2 * paymentTokenMultiplier / 10); - require(sale.maxPrice() == 4 * paymentTokenMultiplier / 10); + require(sale.minPrice() == (2 * paymentTokenMultiplier) / 10); + require(sale.maxPrice() == (4 * paymentTokenMultiplier) / 10); require(sale.start() == start); require(sale.end() == end); require(sale.hasRole(sale.DEFAULT_ADMIN_ROLE(), owner)); @@ -441,7 +441,7 @@ contract SaleTest is Test { require(sale.allocation(alice) == 25 ether); require( sale.allocation(alice) == - (6 * 1e6 / sale.currentTokenPrice()) * 1 ether + ((6 * 1e6) / sale.currentTokenPrice()) * 1 ether ); } diff --git a/packages/web-app/app/_lib/queries.tsx b/packages/web-app/app/_lib/queries.tsx index 2e1e606a..34a65669 100644 --- a/packages/web-app/app/_lib/queries.tsx +++ b/packages/web-app/app/_lib/queries.tsx @@ -336,11 +336,18 @@ export const useFetchRisingTideCap = (enabled?: boolean) => { }); }; -export const useCanContribute = (project: string, address: string) => { +export const useCanContribute = (project?: string, address?: string) => { return useQuery({ queryKey: ['can-contribute', project, address], queryFn: async () => { - return await canContribute(project, address); + if (!project || !address) return false; + const result = await canContribute(project, address); + if (typeof result === 'object' && 'error' in result) { + appSignal.sendError(new Error(result.error)); + throw new Error(result.error); + } + + return result; }, enabled: !!project && !!address, }); diff --git a/packages/web-app/app/_providers/kyc/index.tsx b/packages/web-app/app/_providers/kyc/index.tsx index 1685173e..cfb9cdb8 100644 --- a/packages/web-app/app/_providers/kyc/index.tsx +++ b/packages/web-app/app/_providers/kyc/index.tsx @@ -3,7 +3,12 @@ import { PropsWithChildren, useMemo } from 'react'; import { KycContext, TKycContextValue, TWallet } from './context'; import { useKycCredential } from '@/app/_lib/hooks'; -import { useFetchCredentialContent, useFetchGrants } from '@/app/_lib/queries'; +import { + useCanContribute, + useFetchCredentialContent, + useFetchGrants, + usePublicInfo, +} from '@/app/_lib/queries'; import { useIdOS } from '../idos'; import { compareAddresses } from '@/app/_lib/utils'; import { blockedCountries } from '@/app/_server/blocked-countries'; @@ -58,6 +63,11 @@ export const KycProvider = ({ children }: PropsWithChildren) => { isSuccess: grantsSuccess, refetch: refetchGrants, } = useFetchGrants(); + const { data: citizendPublicInfo } = usePublicInfo(); + const { data: hasPlatformGrant } = useCanContribute( + citizendPublicInfo?.grantee, + address, + ); const wallet = useMemo(() => { return credentialContent?.credentialSubject?.wallets.find( @@ -86,10 +96,10 @@ export const KycProvider = ({ children }: PropsWithChildren) => { const state: TKycContextValue = useMemo(() => { return { id, - status: credentialContent?.status, + status: hasPlatformGrant ? 'approved' : credentialContent?.status, residentialCountry, idDocumentCountry, - isBlockedCountry, + isBlockedCountry: hasPlatformGrant ? false : isBlockedCountry, wallet, isLoading, error, @@ -101,6 +111,7 @@ export const KycProvider = ({ children }: PropsWithChildren) => { }; }, [ id, + hasPlatformGrant, credentialContent, residentialCountry, idDocumentCountry, diff --git a/packages/web-app/app/_server/can-contribute.ts b/packages/web-app/app/_server/can-contribute.ts index aa334155..2d555251 100644 --- a/packages/web-app/app/_server/can-contribute.ts +++ b/packages/web-app/app/_server/can-contribute.ts @@ -6,16 +6,16 @@ import { createClient } from './supabase/server'; export const canContribute = async (project: string, address: string) => { const supabase = createClient(); - const { error, count } = await supabase + const { error, data } = await supabase .from('applications') .select('*') .eq('project', project) - .eq('address', address); + .ilike('address', `%${address}%`); if (error) { console.error(error); return { error: error.message }; } - return count && count > 0 ? true : false; + return data?.length && data.length > 0 ? true : false; }; diff --git a/packages/web-app/app/_server/idos/index.ts b/packages/web-app/app/_server/idos/index.ts index 4770923a..5ee11ab1 100644 --- a/packages/web-app/app/_server/idos/index.ts +++ b/packages/web-app/app/_server/idos/index.ts @@ -9,6 +9,7 @@ import { evmGranteePublicKey, } from '../wallet'; import { createClient } from '../supabase/server'; +import { compareAddresses } from '@/app/_lib/utils'; export interface idOSGrant { content: string; @@ -143,20 +144,15 @@ export const updateAllowedProjectApplicants = async ( // remove already allowed addresses const addresses = parsedApplicants.filter( - (address) => !currentAllowedList.includes(address), + (address) => + !currentAllowedList.some((allowed) => + compareAddresses(allowed, address), + ), ); console.log('==>Current Applicants', parsedApplicants.length); - console.log( - '==>Allowed', - 'color: green; background: yellow; font-size: 20px', - currentAllowedList.length, - ); - console.log( - '==>To Process', - 'color: green; background: yellow; font-size: 20px', - addresses.length, - ); + console.log('==>Allowed', currentAllowedList.length); + console.log('==>To Process', addresses.length); const grantee = await idOSGrantee.init({ granteeSigner: evmGrantee, @@ -180,8 +176,7 @@ export const updateAllowedProjectApplicants = async ( console.log('==>', 'NOT ALLOWED:'); console.log(notAllowed); - const newlyAllowed = Array.from(allowed); - return [...currentAllowedList, ...newlyAllowed]; + return Array.from(allowed); } catch (error) { console.error(error); diff --git a/packages/web-app/app/_ui/components/wallet-button.tsx b/packages/web-app/app/_ui/components/wallet-button.tsx index 27cac0a2..e50c09b8 100644 --- a/packages/web-app/app/_ui/components/wallet-button.tsx +++ b/packages/web-app/app/_ui/components/wallet-button.tsx @@ -58,7 +58,7 @@ const SignedButton = () => { }; const ConnectedButton = () => { - const { hasSigner, setSigner } = useIdOS(); + // const { hasSigner, setSigner } = useIdOS(); const { data: balance } = usePaymentTokenBalance(); if (!balance) @@ -66,9 +66,10 @@ const ConnectedButton = () => {
); - if (!hasSigner) { - return Verify identity; - } + // TEMPORARY DISABLED + // if (!hasSigner) { + // return Verify identity; + // } return ; }; diff --git a/packages/web-app/app/_ui/project/project-content.tsx b/packages/web-app/app/_ui/project/project-content.tsx index 8d75b01f..4924d41c 100644 --- a/packages/web-app/app/_ui/project/project-content.tsx +++ b/packages/web-app/app/_ui/project/project-content.tsx @@ -6,7 +6,10 @@ import { CitizendProjectDescription } from './citizend-project-description'; import { HowToParticipate } from './how-to-participate'; import { SaleStatus } from './sale-status'; import { ApplyButton } from './apply-button'; -import { useFetchProjectsSaleDetails } from '@/app/_lib/queries'; +import { + useCanContribute, + useFetchProjectsSaleDetails, +} from '@/app/_lib/queries'; import { useProject } from '@/app/_providers/project/context'; import { ProjectContribution } from './project-contribution'; import { useHasCitizendGrant, useHasProjectGrant } from '@/app/_lib/hooks'; @@ -36,7 +39,8 @@ export const ProjectContent = () => { const project = data?.find( (project) => project.project.toLowerCase() === projectId, ); - const hasGrant = hasProjectGrant && hasCitizendGrant; + const { data: canContribute } = useCanContribute(project?.address, address); + const hasGrant = canContribute || (hasProjectGrant && hasCitizendGrant); const saleCompleted = project?.status === 'completed'; if (isLoading || isLoadingGrant || (!data && !isError)) { diff --git a/packages/web-app/app/api/process_applications/route.ts b/packages/web-app/app/api/process_applications/route.ts index 475b421e..6313e669 100644 --- a/packages/web-app/app/api/process_applications/route.ts +++ b/packages/web-app/app/api/process_applications/route.ts @@ -11,10 +11,7 @@ const persistData = async (data: string[]) => { return { project: projectsInfo.citizend.address, address }; }); - const { error, data: result } = await supabase - .from('applications') - .upsert(rows) - .select(); + const { error } = await supabase.from('applications').upsert(rows); if (error) { return new Response(`Insert applications list: ${error.message}`, { @@ -22,7 +19,7 @@ const persistData = async (data: string[]) => { }); } - return result?.length || 0; + return rows?.length || 0; }; export async function GET(_request: Request) {