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

Feat/user metadata upload endpoint #13

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1abb814
Endpoint created, testing pending
eduairet Dec 6, 2022
ff0b0d8
Test profile successfully uploaded to IPFS
eduairet Dec 8, 2022
b584390
Merge branch 'master' into feat/user-metadata-upload-endpoint
eduairet Dec 8, 2022
ba00710
Merge branch 'master' into feat/user-metadata-upload-endpoint
eduairet Dec 8, 2022
d00ae68
Create User form started
eduairet Dec 8, 2022
864ed2c
Form now uploads data to IPFS
eduairet Dec 10, 2022
49f6a52
Update usertest.js
eduairet Dec 11, 2022
6db4767
Update usertest.js
eduairet Dec 12, 2022
0f7739e
Update usertest.js
eduairet Dec 12, 2022
1641bd5
Update usertest.js
eduairet Dec 12, 2022
567e329
Update usertest.js
eduairet Dec 12, 2022
4e2a883
Create Lens user with username
eduairet Dec 12, 2022
ede53b4
Links input handled
eduairet Dec 15, 2022
c1bf936
Page name changed
eduairet Dec 15, 2022
3c386d9
Merge branch 'master' into feat/user-metadata-upload-endpoint
eduairet Dec 16, 2022
5249db2
Upload metadata endpoint secured
eduairet Dec 17, 2022
5f5d1ff
Input as a class
eduairet Dec 17, 2022
c204c27
Formik user form started
eduairet Dec 17, 2022
424ce38
Create profile
eduairet Dec 17, 2022
09f178c
Formik implemented
eduairet Dec 18, 2022
a258db0
Logs cleaned, input name changed
eduairet Dec 18, 2022
4d5af03
Metadata structure
eduairet Dec 18, 2022
7b3c931
Form values are get from Lense
eduairet Dec 19, 2022
3c29566
Edit user contract interaction added
eduairet Dec 19, 2022
8d28919
Merge branch 'master' into feat/user-metadata-upload-endpoint
eduairet Dec 19, 2022
327c0e3
Update pnpm-lock.yaml
eduairet Dec 19, 2022
15992bf
Update create-edit-user.js
eduairet Dec 21, 2022
c895ff4
First try IPFS
eduairet Jan 4, 2023
e0c53ec
Infura upload
eduairet Jan 4, 2023
a932478
IPFS url to Lens
eduairet Jan 4, 2023
35d37fa
Update create-edit-user.js
eduairet Jan 4, 2023
dfc8d39
Update create-edit-user.js
eduairet Jan 4, 2023
182d85b
Merge branch 'master' into feat/user-metadata-upload-endpoint
eduairet Jan 25, 2023
3d95f7b
Merged main into my branch
eduairet Jan 25, 2023
a9550a6
Delete FontProjectV2.json
eduairet Jan 25, 2023
7ed9f64
Delete test-user-profile-data.js
eduairet Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/clientApi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ export const client = new ApolloClient({
export * from "./lens/authenticate";
export * from "./lens/challenge";
export * from "./lens/createProfile";
export * from "./lens/createSetDefaultProfile";
export * from "./lens/exploreProfiles";
export * from "./lens/getDefaultProfile";
export * from "./lens/getProfileByHandle";
export * from "./lens/getProfileByAddress";
export * from "./lens/getPublications";
export * from "./lens/mirror";
export * from "./lens/refresh";
export * from "./lens/createSetProfileWithMetadata";

export * from "./ipfonts/createIPFontsUser";
export * from "./ipfonts/createIPFontProject";
11 changes: 2 additions & 9 deletions frontend/clientApi/lens/createProfile.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { gql } from "@apollo/client";

export const createProfile = gql`
mutation CreateProfile {
createProfile(
request: {
handle: "jptestdev"
profilePictureUri: null
followNFTURI: null
followModule: null
}
) {
mutation CreateProfile($request: CreateProfileRequest!) {
createProfile(request: $request) {
... on RelayerResult {
txHash
}
Expand Down
32 changes: 32 additions & 0 deletions frontend/clientApi/lens/createSetDefaultProfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { gql } from "@apollo/client";

export const createSetDefaultProfile = gql`
mutation CreateSetDefaultProfileTypedData(
$request: CreateSetDefaultProfileRequest!
) {
createSetDefaultProfileTypedData(request: $request) {
id
expiresAt
typedData {
types {
SetDefaultProfileWithSig {
name
type
}
}
domain {
name
chainId
version
verifyingContract
}
value {
nonce
deadline
wallet
profileId
}
}
}
}
`;
32 changes: 32 additions & 0 deletions frontend/clientApi/lens/createSetProfileWithMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { gql } from "@apollo/client";

export const createSetProfileWithMetadata = gql`
mutation CreateSetProfileMetadataTypedData(
$request: CreatePublicSetProfileMetadataURIRequest!
) {
createSetProfileMetadataTypedData(request: $request) {
id
expiresAt
typedData {
types {
SetProfileMetadataURIWithSig {
name
type
}
}
domain {
name
chainId
version
verifyingContract
}
value {
nonce
deadline
profileId
metadata
}
}
}
}
`;
25 changes: 25 additions & 0 deletions frontend/clientApi/lens/getDefaultProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ export const getDefaultProfile = gql`
defaultProfile(request: $request) {
id
handle
name
bio
attributes {
key
value
}
coverPicture {
... on MediaSet {
original {
url
}
}
}
picture {
... on MediaSet {
original {
url
}
}
... on NftImage {
uri
tokenId
contractAddress
}
}
}
}
`;
5 changes: 4 additions & 1 deletion frontend/components/Profile/ProfileCard/ProfileData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Link from "next/link";
import classes from "../../../styles/CardData.module.css";

export default function ProfileData(props) {
Expand Down Expand Up @@ -29,7 +30,9 @@ export default function ProfileData(props) {
{(props.user?.website ?? "").replace(/https?:\/\//, "")}
</a>
{props.connected && (
<button className={classes.edit}>Edit Profile</button>
<Link className={classes.edit} href="/create-edit-user">
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice job using Link from next here 🙌

Edit Profile
</Link>
)}
<div className={classes.about}>
<h6>About</h6>
Expand Down
9 changes: 9 additions & 0 deletions frontend/components/UI/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import classes from "../../styles/Form.module.css";
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR but when refactoring/cleaning up the code, what do you think about colocating the css module files with the components, example...

- frontend
   - components
      - UI
         - Form.js
         - Form.module.css

This will make it easier to navigate to the css module files to make changes

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes sense, at the beginning it was simpler to manage the styles that way but as they increased everything got more complex haha


export default function Form(props) {
return (
<form onSubmit={props.onSubmit} className={classes.form}>
{props.children}
</form>
);
}
31 changes: 31 additions & 0 deletions frontend/components/UI/Input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import classes from "../../styles/Form.module.css";

export default function Input(props) {
return (
<div className={classes.field}>
<label className={classes.label} htmlFor={props.id}>
{props.label}
</label>
{props.type !== "text-area" ? (
<input
className={classes.input}
id={props.id}
name={props.name}
type={props.type}
onChange={props.onChange}
onBlur={props.onBlur}
value={props.value || ""}
/>
) : (
<textarea
className={classes.input}
id={props.id}
name={props.name}
onChange={props.onChange}
onBlur={props.onBlur}
value={props.value || ""}
></textarea>
)}
</div>
);
}
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"siwe": "^1.1.6",
"typescript": "^4.8.3",
"utf8": "^3.0.0",
"uuid": "^9.0.0",
"wagmi": "^0.10.14",
"web3.storage": "^4.4.0",
"yup": "^0.32.11"
Expand Down
35 changes: 35 additions & 0 deletions frontend/pages/api/user-profile-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { withIronSessionApiRoute } from "iron-session/next";
import ironOptions from "../../config/ironOptions";
import { storeMetadataFileIPFS } from "../../utils/storeMetadataFileIPFS";

async function handler(req, res) {
if (req.method === "POST") {
return await storeUserMetadata(req, res);
} else {
return res
.status(405)
.json({ message: "Method not allowed", success: false });
}
}

async function storeUserMetadata(req, res) {
const body = req.body;

try {
const file = {
path: "/tmp/data.json",
content: Buffer.from(body),
};

const cid = await storeMetadataFileIPFS(file);

return res.status(200).json({ ok: true, cid: cid });
} catch (err) {
console.log(err);
return res
.status(500)
.json({ error: "Error creating/editing user", ok: false });
}
}

export default withIronSessionApiRoute(handler, ironOptions);
Loading