-
Notifications
You must be signed in to change notification settings - Fork 149
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
Changes from 7 commits
2db0d21
d2401bd
54435a6
1c3d4f7
5e300e3
2614cfd
2f952eb
ce14c87
992dc37
43ea48c
aab6c55
163af6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
.DS_Store | ||
/lerna-debug.log | ||
.turbo | ||
.vercel |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be removed, we have a util function which does this already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Located in the |
||
"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", | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
@@ -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" | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
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)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
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.