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
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2db0d21
localstorage & urlencoding grants curation
ghostffcode d2401bd
Merge branch 'main' into localstorage-encoded-collections
ghostffcode 54435a6
Merge pull request #1 from supermodularxyz/localstorage-encoded-colle…
ghostffcode 1c3d4f7
remove lock file
ghostffcode 5e300e3
update indexer client
ghostffcode 2614cfd
fix updates
ghostffcode 2f952eb
remove collection owner
ghostffcode ce14c87
Localstorage encoded collections - Design & clean up updates (#2)
ghostffcode 992dc37
remove unused packages
ghostffcode 43ea48c
remove duplicate roundId prop
ghostffcode aab6c55
add hack for new collections update
ghostffcode 163af6e
add empty state and lists link copy to clipboard
ghostffcode File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
.DS_Store | ||
/lerna-debug.log | ||
.turbo | ||
.vercel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
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 | ||
projects: number[] | ||
} | ||
|
||
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, projects }: 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)))) | ||
|
||
document.dispatchEvent(new Event('collectionsUpdated')) | ||
} | ||
|
||
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)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.