feat(dataset): mock data fetching to v2 dataset and add codes

This commit is contained in:
Daniel Klein 2024-09-12 08:43:01 +02:00
parent e699a2acfe
commit 22d11fa9fa
9 changed files with 16331 additions and 4 deletions

View File

@ -1,7 +1,15 @@
import type { Category, Project, ProjectShallow } from '~/types'
import type { Asset } from '~/types/asset'
import type { Ecosystem } from '~/types/ecosystem'
import type { Feature } from '~/types/feature'
import type { Usecase } from '~/types/usecase'
export const useData = defineStore('data', () => {
const categories = useState<Category[]>('categories')
const usecases = useState<Usecase[]>('usecases')
const features = useState<Feature[]>('features')
const assets = useState<Asset[]>('assets')
const ecosystems = useState<Ecosystem[]>('ecosystems')
const projects = useState<Project[]>('projects')
const selectedCategoryId = useState(() => 'all')
const filter = reactive({
@ -25,14 +33,47 @@ export const useData = defineStore('data', () => {
const data = await $fetch<{
categories: Category[]
projects: Project[]
usecases: Usecase[]
ecosystems: Ecosystem[]
assets: Asset[]
features: Feature[]
}>('/api/data')
projects.value = data.projects.filter(p => p.name)
projects.value = data.projects.map(project => ({
...project,
ratings: {
openess: {
documentation: 'Link',
funding: 0,
github: 'Link',
socials: '',
team: 1,
whitepaper: '',
},
technology: {
mainnet: true,
opensource: true,
assets: false,
audits: 0,
no_pgradability: true,
},
privacy: {
no_kyc: true,
no_compliance: true,
default_privacy: false,
policy: 'Link',
},
},
})).filter(p => p.name)
categories.value = data.categories.map((c) => {
c.projectsCount = projects.value.filter(p =>
p.categories?.includes(c.id),
).length
return c
}).filter(c => c.projectsCount > 0)
usecases.value = data.usecases
ecosystems.value = data.ecosystems
assets.value = data.assets
features.value = data.features
}
catch (e) {
console.error(e)
@ -72,6 +113,30 @@ export const useData = defineStore('data', () => {
support: availableSupport(),
image: project.logos?.[0]?.url ?? '',
anonymity: true,
categories: project.categories,
ratings: {
openess: {
documentation: 'Link',
funding: 0,
github: 'Link',
socials: '',
team: 1,
whitepaper: '',
},
technology: {
mainnet: true,
opensource: true,
assets: false,
audits: 0,
no_pgradability: true,
},
privacy: {
no_kyc: true,
no_compliance: true,
default_privacy: false,
policy: 'Link',
},
},
}
}
const shallowProjects = computed(() => projects.value.map(project => projectToShallow(project)))
@ -114,10 +179,25 @@ export const useData = defineStore('data', () => {
else
return 0
})
return filteredShallowProjects
})
const groupedProjectsPerCategory = computed(() => {
const groupedProjects = categories.value.map((category) => {
// Find all projects that include this category
const projectsInCategory = filteredProjects.value.filter(project =>
project.categories.includes(category.id),
)
return {
title: category.name,
projects: projectsInCategory,
}
}).sort((a, b) => b.projects.length - a.projects.length)
return groupedProjects
})
const filteredProjectsCount = computed(() => filteredProjects.value.length)
return {
@ -125,8 +205,13 @@ export const useData = defineStore('data', () => {
filter,
switcher,
categories,
usecases,
features,
ecosystems,
assets,
projects,
shallowProjects,
groupedProjectsPerCategory,
filteredProjectsCount,
fetchData,
getProjectById,

View File

@ -1,3 +1,4 @@
export default defineEventHandler(() => {
return $fetch('https://explorer-data.web3privacy.info/')
export default defineEventHandler(async () => {
// return $fetch('https://explorer-data.web3privacy.info/')
return await useStorage('assets:server').getItem('data.json')
})

16189
server/assets/data.json Normal file

File diff suppressed because it is too large Load Diff

4
types/asset.ts Normal file
View File

@ -0,0 +1,4 @@
export interface Asset {
id: string
name: string
}

View File

@ -2,4 +2,5 @@ export interface Category {
id: string
name: string
projectsCount: number
usecases?: string[]
}

5
types/ecosystem.ts Normal file
View File

@ -0,0 +1,5 @@
export interface Ecosystem {
id: string
name: string
icon: string
}

4
types/feature.ts Normal file
View File

@ -0,0 +1,4 @@
export interface Feature {
id: string
name: string
}

View File

@ -121,6 +121,11 @@ export interface Project {
url?: string
[k: string]: unknown
}[]
ratings: {
openess: OpenessRating
technology: TechnologyRating
privacy: PrivacyRating
}
}
export interface ProjectShallow {
@ -129,6 +134,7 @@ export interface ProjectShallow {
title1: string
description: string
percentage: number
categories: string[]
forum?: string | undefined
github?: string | undefined
website?: string | undefined
@ -142,8 +148,36 @@ export interface ProjectShallow {
audits?: Audit[] | undefined
support?: number | undefined
anonymity?: boolean | undefined
ratings: {
openess: OpenessRating
technology: TechnologyRating
privacy: PrivacyRating
}
}
export interface ProjectIndexable extends Project {
[key: string]: unknown
}
export interface OpenessRating {
documentation: string
github: string
socials: string
whitepaper: string
team: number
funding: number
}
export interface TechnologyRating {
mainnet: boolean
opensource: boolean
assets: boolean
no_pgradability: boolean
audits: number
}
export interface PrivacyRating {
policy: string
no_kyc: boolean
no_compliance: boolean
default_privacy: boolean
}

4
types/usecase.ts Normal file
View File

@ -0,0 +1,4 @@
export interface Usecase {
id: string
name: string
}