diff --git a/packages/dapp/src/app/api/campaigns/issue/route.ts b/packages/dapp/src/app/api/campaigns/issue/route.ts index d504c5f0c..e07cd7f60 100644 --- a/packages/dapp/src/app/api/campaigns/issue/route.ts +++ b/packages/dapp/src/app/api/campaigns/issue/route.ts @@ -58,7 +58,9 @@ export async function POST(request: NextRequest) { }, }); } + const supabase = supabaseServiceRoleClient(); + const { data: campaign, error: campaignError } = await supabase .from('campaigns') .select('*, requirements(id, *)') @@ -100,11 +102,11 @@ export async function POST(request: NextRequest) { if (!alreadyClaimed) { const now = new Date(); - const startDateValid = + const notYetStarted = campaign.start_date && new Date(campaign.start_date) > now; - const endDateValid = + const alreadyFinished = campaign.end_date && new Date(campaign.end_date) < now; - const isCampaignInactive = startDateValid || endDateValid; + const isCampaignInactive = notYetStarted || alreadyFinished; const isCampaignFullyClaimed = campaign.total && campaign.claimed >= campaign.total; @@ -124,8 +126,8 @@ export async function POST(request: NextRequest) { const { data: completedRequirements, error: completedRequirementsError } = await supabase.rpc('get_num_of_users_requirements_by_campaign', { - campaign_id: campaignId, - user_id: user.sub, + input_campaign_id: campaignId, + input_user_id: user.sub, }); if (completedRequirementsError) { diff --git a/packages/dapp/src/components/CampaignsDisplay/RequirementDisplay.tsx b/packages/dapp/src/components/CampaignsDisplay/RequirementDisplay.tsx index c24a79250..ca68e307b 100644 --- a/packages/dapp/src/components/CampaignsDisplay/RequirementDisplay.tsx +++ b/packages/dapp/src/components/CampaignsDisplay/RequirementDisplay.tsx @@ -12,7 +12,6 @@ import { useSwitchChain, useVerifyRequirement } from '@/hooks'; import { useAuthStore, useMascaStore, useToastStore } from '@/stores'; import { isError } from '@blockchain-lab-um/masca-connector'; import { shallow } from 'zustand/shallow'; -import { VerifiableCredential } from 'did-jwt-vc'; import type { W3CVerifiableCredential } from '@veramo/core'; type RequirementProps = { @@ -93,9 +92,22 @@ export const RequirementDisplay = ({ const createPresentationResult = await api.createPresentation({ vcs: queryCredentialsResult.data.reduce((acc, queryResult) => { const credential = queryResult.data; + + let issuer = null; + + if (!credential.issuer) return acc; + + if (typeof credential.issuer === 'string') { + issuer = credential.issuer; + } else if (credential.issuer.id) { + issuer = credential.issuer.id; + } + + if (!issuer) return acc; + if ( - !credential.issuer.includes('did:poylgonid') && - !credential.issuer.includes('did:iden3') + !issuer.includes('did:poylgonid') && + !issuer.includes('did:iden3') ) { acc.push(credential); } diff --git a/packages/dapp/src/utils/supabase/database.types.ts b/packages/dapp/src/utils/supabase/database.types.ts index 5549880df..22fcd9777 100644 --- a/packages/dapp/src/utils/supabase/database.types.ts +++ b/packages/dapp/src/utils/supabase/database.types.ts @@ -343,8 +343,8 @@ export type Database = { Functions: { get_num_of_users_requirements_by_campaign: { Args: { - campaign_id: string; - user_id: string; + input_campaign_id: string; + input_user_id: string; }; Returns: number; };