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

URL encoded collection data for grant rounds #1786

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.DS_Store
/lerna-debug.log
.turbo
.vercel
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"api-build": "turbo run build --filter=api",
"api-test": "turbo run test --filter=api",
"api-start": "pnpm --filter api run start",
"api-gen": "pnpm --filter api run prisma:generate",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API folder is not used anymore so this might be just a leftover from git.

"lint-staged": "lint-staged",
"lint:builder": "pnpm --filter=builder run lint"
},
Expand Down
12 changes: 11 additions & 1 deletion packages/grant-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.0.1",
"@testing-library/user-event": "^14.1.1",
"@types/crypto-js": "^4.1.1",
"@types/uuid": "^9.0.1",
"@wagmi/core": "0.5.4",
"allo-indexer-client": "github:gitcoinco/allo-indexer-client#48490969985125e89bf1d65725ef9e510c97256a",
"allo-indexer-client": "github:gitcoinco/allo-indexer-client#9e713f46db8a13e19c923a983bc5956b79da7c56",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional updated . If not let's stick to the version that is on main

"babel-loader": "^8.3.0",
"buffer": "^6.0.3",
"classnames": "^2.3.2",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed, we have a util function which does this already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Located in the common package to be clear.

"common": "workspace:*",
"crypto-browserify": "^3.12.0",
"crypto-js": "^4.1.1",
"date-fns": "^2.29.3",
"eslint": ">=8.1.0 <9.0.0",
"ethers": "^5.6.5",
Expand All @@ -78,6 +82,7 @@
"ipfs-core": "^0.14.3",
"ipfs-core-types": "^0.14.0",
"jest-fetch-mock": "^3.0.3",
"lodash": "^4.17.21",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this anywhere ? If not let's remove it.

"moment": "^2.29.3",
"msw": "^0.47.4",
"node-fetch": "^3.3.1",
Expand All @@ -88,10 +93,12 @@
"react-dom": "^18.1.0",
"react-gtm-module": "^2.0.11",
"react-hook-form": "^7.31.3",
"react-loading-spin": "^2.1.9",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've got a spinner used across the app. Would recommend using that . Spinner.tsx is the file you are looking for

"react-redux": "^8.0.1",
"react-router": "^6",
"react-router-dom": "6",
"react-scripts": "5.0.1",
"react-select": "5.7.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would recommend using what we already have multiselect. Checkout the cart page

"react-tooltip": "^4.5.0",
"redux": "latest",
"redux-thunk": "latest",
Expand All @@ -101,6 +108,7 @@
"typescript": "^4.6.0",
"url": "^0.11.0",
"util": "^0.12.4",
"uuid": "^9.0.0",
"wagmi": "0.6.8",
"web-vitals": "^2.1.0",
"webpack": ">=2"
Expand All @@ -117,12 +125,14 @@
"@testing-library/dom": ">=7.21.4 ",
"@types/dompurify": "^2.4.0",
"@types/jest": "^27.4.1",
"@types/markdown-it": "^12.2.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ?

"@types/node": "^17.0.25",
"@types/react": "^18.0.6",
"@types/react-dom": "^18.0.2",
"@types/react-gtm-module": "^2.0.1",
"@types/testing-library__jest-dom": "^5.14.5",
"autoprefixer": "^10.4.7",
"craco-esbuild": "0.5.2",
vacekj marked this conversation as resolved.
Show resolved Hide resolved
"eslint-config-gitcoin": "workspace:*",
"jest-localstorage-mock": "^2.4.22",
"postcss": "^8.4.14",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/grant-explorer/src/assets/icons/bookmark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/grant-explorer/src/assets/icons/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/grant-explorer/src/assets/icons/minus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/grant-explorer/src/assets/icons/plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions packages/grant-explorer/src/features/api/collections.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { v4 as uuid } from 'uuid'
import CryptoJS from 'crypto-js'

export type Collection = {
title: string
id: string
enc?: string
owner: `0x${string}`
round: string
projects: number[]
}

type CreateCollectionParams = {
title: string
owner: `0x${string}`
round: string
}

const secretKey = 'grantProjects'

const parseCollections = (): string[] => {
return JSON.parse(localStorage.getItem(`collections`) || '[]')
}

export const encodeCollection = (collection: string) => {
return CryptoJS.AES.encrypt(collection, secretKey).toString()
}

export const createCollection = async ({ title, owner, round }: CreateCollectionParams): Promise<void> => {
const id = `collections_${round}_${uuid()}`

localStorage.setItem(
id,
JSON.stringify({
id,
title,
owner,
round,
projects: [],
})
)

localStorage.setItem('collections', JSON.stringify(Array.from(new Set(parseCollections()).add(id))))
}

export const getCollectionById = async (id: string): Promise<Collection> => {
// decrypt data
console.log(id)
const collection = JSON.parse(CryptoJS.AES.decrypt(id, secretKey).toString(CryptoJS.enc.Utf8))
console.log(collection)
// load collection data from id

return collection as Collection
}

export const getAllCollectionsForRound = (round: string): string[] => {
return parseCollections().filter((i) => {
const [, roundId] = i.split('_')
return roundId === round
})
}

export const getAllCollections = async (round: string): Promise<Collection[]> => {
return parseCollections()
.filter((i) => {
const [, roundId] = i.split('_')
return roundId === round
})
.map((collectionKey) => JSON.parse(localStorage.getItem(collectionKey) || '[]'))
.reverse()
}

export const getMyCollections = async (round: string): Promise<Collection[]> => {
return getAllCollections(round)
}

export type AddProjectData = {
collection: string
project: number
}

export const addProjectToCollection = async ({ collection, project }: AddProjectData) => {
const collectionData = JSON.parse(localStorage.getItem(collection) || '[]')
collectionData.projects = Array.from(new Set(collectionData.projects).add(project))

localStorage.setItem(collection, JSON.stringify(collectionData))
}
Loading