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

Override idOS for allowed addresses #260

Merged
merged 8 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
11 changes: 9 additions & 2 deletions packages/web-app/app/_lib/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
17 changes: 14 additions & 3 deletions packages/web-app/app/_providers/kyc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -101,6 +111,7 @@ export const KycProvider = ({ children }: PropsWithChildren) => {
};
}, [
id,
hasPlatformGrant,
credentialContent,
residentialCountry,
idDocumentCountry,
Expand Down
3 changes: 2 additions & 1 deletion packages/web-app/app/_providers/persist-query-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { hashFn } from 'wagmi/query';

const oneMinute = 1_000 * 60;
const oneHour = oneMinute * 60;
const tenMinutes = oneMinute * 10;

const queryClient = new QueryClient({
defaultOptions: {
queries: {
queryKeyHashFn: hashFn,
retry: 0,
staleTime: oneMinute,
staleTime: tenMinutes,
gcTime: oneHour,
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/web-app/app/_server/can-contribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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)
Expand All @@ -17,5 +17,5 @@ export const canContribute = async (project: string, address: string) => {
return { error: error.message };
}

return count && count > 0 ? true : false;
return data?.length && data.length > 0 ? true : false;
};
15 changes: 3 additions & 12 deletions packages/web-app/app/_server/idos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,8 @@ export const updateAllowedProjectApplicants = async (
);

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,
Expand All @@ -180,8 +172,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);

Expand Down
9 changes: 5 additions & 4 deletions packages/web-app/app/_ui/components/wallet-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,18 @@ const SignedButton = () => {
};

const ConnectedButton = () => {
const { hasSigner, setSigner } = useIdOS();
// const { hasSigner, setSigner } = useIdOS();
const { data: balance } = usePaymentTokenBalance();

if (!balance)
return (
<div className="h-14 w-44 animate-pulse rounded-md bg-gradient-to-br from-mono-800 to-mono-900" />
);

if (!hasSigner) {
return <EdgeButton onClick={setSigner}>Verify identity</EdgeButton>;
}
// TEMPORARY DISABLED
// if (!hasSigner) {
// return <EdgeButton onClick={setSigner}>Verify identity</EdgeButton>;
// }

return <SignedButton />;
};
Expand Down
8 changes: 6 additions & 2 deletions packages/web-app/app/_ui/project/project-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)) {
Expand Down
7 changes: 2 additions & 5 deletions packages/web-app/app/api/process_applications/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ 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}`, {
status: 500,
});
}

return result?.length || 0;
return rows?.length || 0;
};

export async function GET(_request: Request) {
Expand Down
Loading