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 4, 2024
1 parent d9ce9a2 commit ccdef32
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import IndexStatus from "@components/Shared/IndexStatus";
import errorToast from "@helpers/errorToast";
import { Leafwatch } from "@helpers/leafwatch";
import { LensHub } from "@hey/abis";
import { LENS_HUB } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { SETTINGS } from "@hey/data/tracking";
import { Button } from "@hey/ui";
import cn from "@hey/ui/cn";
import type { FC } from "react";
import { useState } from "react";
import toast from "react-hot-toast";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { useWriteContract } from "wagmi";

interface ToggleLensManagerProps {
buttonSize?: "sm";
Expand All @@ -25,37 +20,11 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
const { isSuspended } = useAccountStatus();
const [isLoading, setIsLoading] = useState(false);

const onCompleted = (__typename?: "RelayError" | "RelaySuccess") => {
if (__typename === "RelayError") {
return;
}

setIsLoading(false);
toast.success("Account updated");
Leafwatch.track(SETTINGS.MANAGER.TOGGLE);
};

const onError = (error: any) => {
setIsLoading(false);
errorToast(error);
};

const { data: writeHash, writeContractAsync } = useWriteContract({
mutation: {
onError,
onSuccess: () => onCompleted()
}
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
abi: LensHub,
address: LENS_HUB,
args,
functionName: "changeDelegatedExecutorsConfig"
});
};

const handleToggleDispatcher = async () => {
if (isSuspended) {
return toast.error(Errors.Suspended);
Expand Down
16 changes: 0 additions & 16 deletions apps/web/src/components/Settings/Profile/Account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import errorToast from "@helpers/errorToast";
import { Leafwatch } from "@helpers/leafwatch";
import uploadMetadata from "@helpers/uploadMetadata";
import { InformationCircleIcon } from "@heroicons/react/24/outline";
import { LensHub } from "@hey/abis";
import {
AVATAR,
COVER,
LENS_HUB,
METADATA_ENDPOINT,
STATIC_IMAGES_URL
} from "@hey/data/constants";
Expand Down Expand Up @@ -51,7 +49,6 @@ import { useState } from "react";
import toast from "react-hot-toast";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { useWriteContract } from "wagmi";
import type { z } from "zod";
import { object, string, union } from "zod";

Expand Down Expand Up @@ -126,19 +123,6 @@ const AccountSettingsForm: FC = () => {
errorToast(error);
};

const { error, writeContractAsync } = useWriteContract({
mutation: { onError, onSuccess: () => onCompleted() }
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
abi: LensHub,
address: LENS_HUB,
args,
functionName: "setProfileMetadataURI"
});
};

const [setAccountMetadata] = useSetAccountMetadataMutation({
onCompleted: ({ setAccountMetadata }) =>
onCompleted(setAccountMetadata.__typename),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import Loader from "@components/Shared/Loader";
import NoBalanceError from "@components/Shared/NoBalanceError";
import Slug from "@components/Shared/Slug";
import errorToast from "@helpers/errorToast";
import { Leafwatch } from "@helpers/leafwatch";
import { UserIcon } from "@heroicons/react/24/outline";
import { LensHub } from "@hey/abis";
import { LENS_HUB, POLYGONSCAN_URL } from "@hey/data/constants";
import { POLYGONSCAN_URL } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { ACCOUNT } from "@hey/data/tracking";
import formatAddress from "@hey/helpers/formatAddress";
import getAccount from "@hey/helpers/getAccount";
import getTokenImage from "@hey/helpers/getTokenImage";
Expand All @@ -24,7 +21,7 @@ import useHandleWrongNetwork from "src/hooks/useHandleWrongNetwork";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { formatUnits } from "viem";
import { useBalance, useWriteContract } from "wagmi";
import { useBalance } from "wagmi";

interface FollowModuleProps {
account: Account;
Expand Down Expand Up @@ -55,42 +52,11 @@ const FollowModule: FC<FollowModuleProps> = ({
});
};

const onCompleted = (__typename?: "RelayError" | "RelaySuccess") => {
if (__typename === "RelayError") {
return;
}

updateCache();
setIsLoading(false);
setShowFollowModal(false);
toast.success("Followed");
Leafwatch.track(ACCOUNT.SUPER_FOLLOW, {
path: pathname,
target: account?.id
});
};

const onError = (error: any) => {
setIsLoading(false);
errorToast(error);
};

const { writeContractAsync } = useWriteContract({
mutation: {
onError,
onSuccess: () => onCompleted()
}
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
abi: LensHub,
address: LENS_HUB,
args,
functionName: "follow"
});
};

const { data, loading } = useProfileQuery({
skip: !account?.id,
variables: { request: { forProfileId: account?.id } }
Expand Down
24 changes: 1 addition & 23 deletions apps/web/src/components/Shared/Account/Unfollow.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { useApolloClient } from "@apollo/client";
import errorToast from "@helpers/errorToast";
import { Leafwatch } from "@helpers/leafwatch";
import { LensHub } from "@hey/abis";
import { LENS_HUB } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { ACCOUNT } from "@hey/data/tracking";
import type { Account } from "@hey/indexer";
import { type Account, useUnfollowMutation } from "@hey/indexer";
import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import { Button } from "@hey/ui";
Expand All @@ -17,7 +15,6 @@ import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useGlobalModalStateStore } from "src/store/non-persisted/useGlobalModalStateStore";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { useTransactionStore } from "src/store/persisted/useTransactionStore";
import { useWriteContract } from "wagmi";

interface UnfollowProps {
buttonClassName: string;
Expand Down Expand Up @@ -85,25 +82,6 @@ const Unfollow: FC<UnfollowProps> = ({
errorToast(error);
};

const { writeContractAsync } = useWriteContract({
mutation: {
onError,
onSuccess: (hash: string) => {
addTransaction(generateOptimisticUnfollow({ txHash: hash }));
onCompleted();
}
}
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
abi: LensHub,
address: LENS_HUB,
args,
functionName: "unfollow"
});
};

const [unfollow] = useUnfollowMutation({
onCompleted: ({ unfollow }) => {
if (unfollow.__typename === "RelaySuccess") {
Expand Down
16 changes: 0 additions & 16 deletions apps/web/src/components/Shared/Alert/BlockOrUnBlockAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { ApolloCache } from "@apollo/client";
import errorToast from "@helpers/errorToast";
import { Leafwatch } from "@helpers/leafwatch";
import { LensHub } from "@hey/abis";
import { LENS_HUB } from "@hey/data/constants";
import { Errors } from "@hey/data/errors";
import { ACCOUNT } from "@hey/data/tracking";
import getAccount from "@hey/helpers/getAccount";
Expand All @@ -14,7 +12,6 @@ import { toast } from "react-hot-toast";
import { useAccountStatus } from "src/store/non-persisted/useAccountStatus";
import { useGlobalAlertStateStore } from "src/store/non-persisted/useGlobalAlertStateStore";
import { useAccountStore } from "src/store/persisted/useAccountStore";
import { useWriteContract } from "wagmi";

const BlockOrUnBlockAccount: FC = () => {
const { currentAccount } = useAccountStore();
Expand Down Expand Up @@ -65,19 +62,6 @@ const BlockOrUnBlockAccount: FC = () => {
errorToast(error);
};

const { writeContractAsync } = useWriteContract({
mutation: { onError, onSuccess: () => onCompleted() }
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
abi: LensHub,
address: LENS_HUB,
args,
functionName: "setBlockStatus"
});
};

const [blockProfile] = useBlockMutation({
onCompleted: ({ block }) => onCompleted(block.__typename),
onError,
Expand Down
23 changes: 0 additions & 23 deletions apps/web/src/hooks/useCreatePost.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { LensHub } from "@hey/abis";
import { LENS_HUB } from "@hey/data/constants";
import {
type CreatePostRequest,
type Post,
Expand All @@ -9,7 +7,6 @@ import { OptmisticPostType } from "@hey/types/enums";
import type { OptimisticTransaction } from "@hey/types/misc";
import { usePostStore } from "src/store/non-persisted/post/usePostStore";
import { useTransactionStore } from "src/store/persisted/useTransactionStore";
import { useWriteContract } from "wagmi";

interface CreatePostProps {
commentOn?: Post;
Expand Down Expand Up @@ -47,26 +44,6 @@ const useCreatePost = ({
};
};

const { error, writeContractAsync } = useWriteContract({
mutation: {
onError,
onSuccess: (hash: string) => {
addTransaction(generateOptimisticPublication({ txHash: hash }));
onCompleted();
}
}
});

const write = async ({ args }: { args: any[] }) => {
return await writeContractAsync({
__mode: "prepared",
abi: LensHub,
address: LENS_HUB,
args,
functionName: isComment ? "comment" : isQuote ? "quote" : "post"
});
};

// Onchain mutations
const [post] = useCreatePostMutation({
onCompleted: ({ post }) => {
Expand Down

0 comments on commit ccdef32

Please sign in to comment.