Skip to content

Commit

Permalink
fix: campaign fixes (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 authored Apr 8, 2024
1 parent c606a35 commit 541ad5b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
12 changes: 7 additions & 5 deletions packages/dapp/src/app/api/campaigns/issue/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)')
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dapp/src/utils/supabase/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit 541ad5b

Please sign in to comment.