Skip to content

Commit

Permalink
Migrate to Lens v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Dec 9, 2024
1 parent af8fb77 commit 0d0ad14
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@hey/ui": "workspace:*",
"@lens-network/sdk": "canary",
"@lens-protocol/metadata": "next",
"@lens-protocol/storage-node-client": "^0.0.2",
"@livepeer/react": "^4.2.9",
"@next/bundle-analyzer": "^15.0.4",
"@radix-ui/react-hover-card": "^1.1.2",
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Composer/NewPublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AudioPostSchema } from "@components/Shared/Audio";
import Wrapper from "@components/Shared/Embed/Wrapper";
import errorToast from "@helpers/errorToast";
import uploadMetadata from "@helpers/uploadMetadata";
import { KNOWN_ATTRIBUTES, METADATA_ENDPOINT } from "@hey/data/constants";
import { KNOWN_ATTRIBUTES } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import collectModuleParams from "@hey/helpers/collectModuleParams";
import getAccount from "@hey/helpers/getAccount";
Expand Down Expand Up @@ -261,12 +261,12 @@ const NewPublication: FC<NewPublicationProps> = ({ className, post }) => {
};

const metadata = getMetadata({ baseMetadata });
const metadataId = await uploadMetadata(metadata);
const contentUri = await uploadMetadata(metadata);

return await createPost({
variables: {
request: {
contentUri: `${METADATA_ENDPOINT}/${metadataId}`,
contentUri,
...(isComment && { commentOn: { post: post?.id } }),
...(isQuote && { quoteOf: { post: quotedPost?.id } }),
...(collectModule.type && {
Expand Down
13 changes: 3 additions & 10 deletions apps/web/src/components/Settings/Profile/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import uploadCroppedImage, { readFile } from "@helpers/accountPictureUtils";
import errorToast from "@helpers/errorToast";
import uploadMetadata from "@helpers/uploadMetadata";
import { InformationCircleIcon } from "@heroicons/react/24/outline";
import {
AVATAR,
COVER,
METADATA_ENDPOINT,
STATIC_IMAGES_URL
} from "@hey/data/constants";
import { AVATAR, COVER, STATIC_IMAGES_URL } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { Regex } from "@hey/data/regex";
import getAccountAttribute from "@hey/helpers/getAccountAttribute";
Expand Down Expand Up @@ -233,12 +228,10 @@ const AccountSettingsForm: FC = () => {
return m.key !== "" && Boolean(trimify(m.value));
});
const metadata = accountMetadata(preparedAccountMetadata);
const metadataId = await uploadMetadata(metadata);
const metadataUri = await uploadMetadata(metadata);

return await setAccountMetadata({
variables: {
request: { metadataUri: `${METADATA_ENDPOINT}/${metadataId}` }
}
variables: { request: { metadataUri } }
});
} catch (error) {
onError(error);
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/Shared/Auth/Signup/ChooseUsername.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FaceFrownIcon,
FaceSmileIcon
} from "@heroicons/react/24/outline";
import { APP_NAME, METADATA_ENDPOINT } from "@hey/data/constants";
import { APP_NAME } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { Regex } from "@hey/data/regex";
import {
Expand Down Expand Up @@ -101,14 +101,14 @@ const ChooseUsername: FC = () => {
if (auth.data?.authenticate.__typename === "AuthenticationTokens") {
const accessToken = auth.data?.authenticate.accessToken;
const metadata = accountMetadata({ name: username });
const metadataId = await uploadMetadata(metadata);
const metadataUri = await uploadMetadata(metadata);

return await createAccountWithUsername({
context: { headers: { "X-Access-Token": accessToken } },
variables: {
request: {
username: { localName: username.toLowerCase() },
metadataUri: `${METADATA_ENDPOINT}/${metadataId}`
metadataUri
}
},
onCompleted: ({ createAccountWithUsername }) => {
Expand Down
13 changes: 7 additions & 6 deletions apps/web/src/helpers/uploadMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { HEY_API_URL } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import axios from "axios";
import toast from "react-hot-toast";
Expand All @@ -12,12 +11,14 @@ import toast from "react-hot-toast";
*/
const uploadMetadata = async (data: any): Promise<string> => {
try {
const response = await axios.post(`${HEY_API_URL}/metadata`, {
...data
});
const { id }: { id: string } = response.data;
const response = await axios.post(
"https://storage-api.testnet.lens.dev",
data
);

return id;
const { uri } = response.data[0];

return uri;
} catch {
toast.error(Errors.SomethingWentWrong);
throw new Error(Errors.SomethingWentWrong);
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0d0ad14

Please sign in to comment.