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

fix: campaign fixes #616

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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