Skip to content

Commit

Permalink
Override idOS for allowed addresses (#260)
Browse files Browse the repository at this point in the history
Why:
- We want to avoid blocking users due to idos issues
  • Loading branch information
luistorres authored May 21, 2024
1 parent 7eb3dac commit 0130db0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 37 deletions.
10 changes: 5 additions & 5 deletions packages/contracts/test/contracts/token/Sale.d.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
);
}

Expand Down
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
6 changes: 3 additions & 3 deletions packages/web-app/app/_server/can-contribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
21 changes: 8 additions & 13 deletions packages/web-app/app/_server/idos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
evmGranteePublicKey,
} from '../wallet';
import { createClient } from '../supabase/server';
import { compareAddresses } from '@/app/_lib/utils';

export interface idOSGrant {
content: string;
Expand Down Expand Up @@ -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,
Expand All @@ -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);

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

0 comments on commit 0130db0

Please sign in to comment.