Skip to content

Commit

Permalink
refactor(types): update type definitions (#118)
Browse files Browse the repository at this point in the history
* refactor(types): update type definitions

* refactor(types): update type definitions build fix

* refactor(types): update type definitions build fix

---------

Co-authored-by: Brandon Fernández <[email protected]>
  • Loading branch information
suhas-sensei and Bran18 authored Feb 3, 2025
1 parent e5461c6 commit a4a1342
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 53 deletions.
95 changes: 46 additions & 49 deletions apps/web/app/auth/callback/route.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { createClient } from '~/lib/supabase/server';
import type { NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { createClient } from '~/lib/supabase/server'

// List of allowed domains for redirection
const ALLOWED_DOMAINS = [
'kindfi.org',
'kindfi.vercel.app',
'kind-fi.com',
/^kindfi-[\w-]+\.vercel\.app$/, // Dynamic subdomains
];
'kindfi.org',
'kindfi.vercel.app',
'kind-fi.com',
/^kindfi-[\w-]+\.vercel\.app$/, // Dynamic subdomains
]

// Function to validate redirect URLs
function isValidRedirectUrl(url: string): boolean {
try {
const parsedUrl = new URL(url);
// Check if the hostname matches any allowed domain
return ALLOWED_DOMAINS.some((domain) =>
typeof domain === 'string'
? parsedUrl.hostname === domain
: domain.test(parsedUrl.hostname)
);
} catch (error) {
console.error(`Invalid URL format: ${url}`);
return false; // If the URL is invalid, return false
}
try {
const parsedUrl = new URL(url)
// Check if the hostname matches any allowed domain
return ALLOWED_DOMAINS.some((domain) =>
typeof domain === 'string'
? parsedUrl.hostname === domain
: domain.test(parsedUrl.hostname),
)
} catch (error) {
console.error(`Invalid URL format: ${url}`)
return false // If the URL is invalid, return false
}
}

export async function GET(request: NextRequest) {
const requestUrl = new URL(request.url);
const code = requestUrl.searchParams.get('code');
const redirectUrl = requestUrl.searchParams.get('redirect');
const requestUrl = new URL(request.url)
const code = requestUrl.searchParams.get('code')
const redirectUrl = requestUrl.searchParams.get('redirect')

console.log(`Incoming request URL: ${requestUrl}`);
console.log(`Redirect URL: ${redirectUrl}`);
console.log(`Incoming request URL: ${requestUrl}`)
console.log(`Redirect URL: ${redirectUrl}`)

// If redirect URL is missing or invalid, return a JSON error
if (!redirectUrl || !isValidRedirectUrl(redirectUrl)) {
console.warn(`Invalid or missing redirect URL: ${redirectUrl}`);
return NextResponse.json(
{ error: 'Invalid redirect URL' },
{ status: 400 }
);
}
// If redirect URL is missing or invalid, return a JSON error
if (!redirectUrl || !isValidRedirectUrl(redirectUrl)) {
console.warn(`Invalid or missing redirect URL: ${redirectUrl}`)
return NextResponse.json({ error: 'Invalid redirect URL' }, { status: 400 })
}

// Exchange the code for a Supabase session if provided
if (code) {
try {
const supabase = await createClient();
await supabase.auth.exchangeCodeForSession(code);
} catch (error) {
console.error(`Error exchanging code for session: ${error}`);
return NextResponse.json(
{ error: 'Failed to exchange code for session' },
{ status: 500 }
);
}
}
// Exchange the code for a Supabase session if provided
if (code) {
try {
const supabase = await createClient()
await supabase.auth.exchangeCodeForSession(code)
} catch (error) {
console.error(`Error exchanging code for session: ${error}`)
return NextResponse.json(
{ error: 'Failed to exchange code for session' },
{ status: 500 },
)
}
}

// Redirect to the validated URL
console.log(`Final Redirect URL: ${redirectUrl}`);
return NextResponse.redirect(redirectUrl);
// Redirect to the validated URL
console.log(`Final Redirect URL: ${redirectUrl}`)
return NextResponse.redirect(redirectUrl)
}
157 changes: 157 additions & 0 deletions apps/web/components/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import dynamic from 'next/dynamic'
import {
type Money,
type Percentage,
type Project,
createMoney,
createPercentage,
} from '~/lib/types'

const Hero = dynamic(
() => import('~/components/sections/home/hero').then((mod) => mod.Hero),
Expand Down Expand Up @@ -73,6 +80,156 @@ const FinalCTA = dynamic(
},
)

const projects: Project[] = [
{
id: 'healthy-kids-id',
image: '/images/kids.webp',
category: 'Child Welfare',
title: 'Healthy Kids Workshop',
description:
'Provide nourishing meals and support to children at risk of malnutrition in Costa Rica...',
currentAmount: { __brand: 'money', value: 22800 } as unknown as Money,
targetAmount: { __brand: 'money', value: 25000 } as unknown as Money,
investors: 18,
minInvestment: { __brand: 'money', value: 5 } as unknown as Money,
percentageComplete: {
__brand: 'percentage',
value: 90,
} as unknown as Percentage,
tags: [
{ id: 'ngo-tag-id', text: 'NGO' },
{ id: 'nutrition-tag-id', text: 'NUTRITION' },
{ id: 'children-tag-id', text: 'CHILDREN' },
],
},
{
id: 'forest-restoration-id',
image: '/images/bosques.webp',
category: 'Environmental Protection',
title: 'Forest Restoration Initiative',
description:
'Restore and reforest areas devastated by uncontrolled deforestation. Your support helps rebuild ecosystems and fight climate change.',
currentAmount: createMoney(54000),
targetAmount: createMoney(60000),
investors: 35,
minInvestment: createMoney(10),
percentageComplete: createPercentage(90),
tags: [
{ id: 'environment-tag-id', text: 'ENVIRONMENT' },
{ id: 'ecological-tag-id', text: 'ECOLOGICAL' },
{ id: 'sustainable-tag-id', text: 'SUSTAINABLE' },
],
},
{
id: 'rural-animal-shelter-id',
image: '/images/dogs.webp',
category: 'Animal Welfare',
title: 'Rural Animal Shelter',
description:
'Provide care and shelter to homeless animals in rural communities. Help us create safe havens for animals in need.',
currentAmount: createMoney(15500),
targetAmount: createMoney(20000),
investors: 22,
minInvestment: createMoney(8),
percentageComplete: createPercentage(77),
tags: [
{ id: 'animals-tag-id', text: 'ANIMALS' },
{ id: 'care-tag-id', text: 'CARE' },
{ id: 'community-tag-id', text: 'COMMUNITY' },
],
},
{
id: 'disaster-aid-id',
image: '/images/disaster-aid.webp',
category: 'Disaster Relief',
title: 'Natural Disasters Human Aid',
description:
'Provide critical support to communities affected by natural disasters. From emergency supplies to long-term rebuilding efforts, join us in bringing hope and recovery to those in need.',
currentAmount: createMoney(30000),
targetAmount: createMoney(50000),
investors: 28,
minInvestment: createMoney(20),
percentageComplete: createPercentage(60),
tags: [
{ id: 'humanitarian-tag-id', text: 'HUMANITARIAN' },
{ id: 'disaster-tag-id', text: 'DISASTER RELIEF' },
{ id: 'community-tag-id', text: 'COMMUNITY SUPPORT' },
],
},
{
id: 'indigenous-crafts-id',
image: '/images/artesania.webp',
category: 'Culture and Arts',
title: 'Preserving Indigenous Crafts',
description:
'Support the preservation of indigenous craftsmanship in Costa Rica. Your contributions protect traditional techniques and cultural heritage.',
currentAmount: createMoney(34000),
targetAmount: createMoney(50000),
investors: 29,
minInvestment: createMoney(15),
percentageComplete: createPercentage(68),
tags: [
{ id: 'culture-tag-id', text: 'CULTURE' },
{ id: 'indigenous-tag-id', text: 'INDIGENOUS' },
{ id: 'art-tag-id', text: 'ART' },
],
},
{
id: 'water-for-rural-communities-id',
image: '/images/water.webp',
category: 'Access to Clean Water',
title: 'Water for Rural Communities',
description:
'Provide access to safe drinking water in underserved rural areas. Help us install water purification systems to improve health and livelihoods.',
currentAmount: createMoney(18500),
targetAmount: createMoney(25000),
investors: 20,
minInvestment: createMoney(20),
percentageComplete: createPercentage(74),
tags: [
{ id: 'water-tag-id', text: 'WATER' },
{ id: 'health-tag-id', text: 'HEALTH' },
{ id: 'community-tag-id', text: 'COMMUNITY' },
],
},
{
id: 'empowering-education-id',
image: '/images/education.webp',
category: 'Education',
title: 'Empowering Education',
description:
'Support education programs for children in low-income areas. Together, we can bridge the education gap and create opportunities for the next generation.',
currentAmount: createMoney(40000),
targetAmount: createMoney(55000),
investors: 40,
minInvestment: createMoney(10),
percentageComplete: createPercentage(73),
tags: [
{ id: 'education-tag-id', text: 'EDUCATION' },
{ id: 'children-tag-id', text: 'CHILDREN' },
{ id: 'future-tag-id', text: 'FUTURE' },
],
},
{
id: 'mobile-clinics-id',
image: '/images/healthcare.webp',
category: 'Healthcare',
title: 'Mobile Clinics',
description:
'Bring essential healthcare services to remote areas through mobile clinics. Your support helps save lives and build healthier communities.',
currentAmount: createMoney(32000),
targetAmount: createMoney(45000),
investors: 30,
minInvestment: createMoney(20),
percentageComplete: createPercentage(71),
tags: [
{ id: 'healthcare-tag-id', text: 'HEALTHCARE' },
{ id: 'community-tag-id', text: 'COMMUNITY' },
{ id: 'impact-tag-id', text: 'IMPACT' },
],
},
]

export function HomeDashboard() {
return (
<>
Expand Down
5 changes: 3 additions & 2 deletions apps/web/components/shared/layout/header/navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client'
import type { NavigationItem } from '~/lib/types'

import Link from 'next/link'
import { usePathname } from 'next/navigation'
Expand All @@ -14,7 +15,7 @@ import {
} from '~/components/base/navigation-menu'
import { cn } from '~/lib/utils'

const projects = [
const projects: NavigationItem[] = [
{
title: 'Explore Projects',
href: '/projects',
Expand All @@ -32,7 +33,7 @@ const projects = [
},
]

const resources = [
const resources: NavigationItem[] = [
{
title: 'Learn Web3',
href: '/learn',
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/stellar/escrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function initializeEscrowContract(
// Generate unique IDs
const engagementId = generateUniqueId()
const contributionId = generateUniqueId()

// Initialize contract on Stellar
const payerAccount = new Account(
Keypair.fromSecret(params.parties.payer).publicKey(),
Expand Down
8 changes: 7 additions & 1 deletion apps/web/lib/types/home.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import type { ReactNode } from 'react'
/** Interface for category items in hero section */
export interface Category {
/** Unique identifier for the category */
id: string
icon: React.ReactNode
/** Icon component for the category */
icon: ReactNode
/** Display label for the category */
label: string
/** Tailwind CSS color classes for styling */
color: string
}

Expand Down
2 changes: 2 additions & 0 deletions apps/web/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export type ConditionalRequired<
> = Flag extends true ? Required<Pick<T, K>> : Partial<Pick<T, K>>

export * from './pages'
export * from './project'
export * from './stats'
17 changes: 17 additions & 0 deletions apps/web/lib/types/pages.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import type { ReactNode } from 'react'
import type { ConditionalRequired } from '~/lib/types'

export interface PagePropsBase {
params?: Promise<{ [key: string]: string }>
searchParams?: Promise<URLSearchParams>
}

export interface NavigationItem {
title: string
href: `/${string}` | `https://${string}` | `http://${string}`
description?: string
}

/**
* Represents a section of navigation items with a label.
* @property {NavigationItem[]} items - Array of navigation items in this section
* @property {string} label - Label for the navigation section
*/
export interface NavigationSection {
items: NavigationItem[]
label: string
}

export type PageProps<
ParamsRequired extends boolean = false,
SearchParamsRequired extends boolean = false,
Expand Down
Loading

0 comments on commit a4a1342

Please sign in to comment.