diff --git a/apps/u3/src/components/profile/lens/LensFollowProfileCard.tsx b/apps/u3/src/components/profile/lens/LensFollowProfileCard.tsx index af642f02..0d5f4f51 100644 --- a/apps/u3/src/components/profile/lens/LensFollowProfileCard.tsx +++ b/apps/u3/src/components/profile/lens/LensFollowProfileCard.tsx @@ -30,7 +30,7 @@ export default function LensFollowProfileCard({ () => ({ handle: getHandle(profile), address: getOwnedByAddress(profile), - name: getName(profile), + name: getName(profile) || profile?.id, avatar: getAvatar(profile), bio: getBio(profile), isFollowed: diff --git a/apps/u3/src/components/social/SocialWhoToFollow.tsx b/apps/u3/src/components/social/SocialWhoToFollow.tsx index 7ad25214..a27f2516 100644 --- a/apps/u3/src/components/social/SocialWhoToFollow.tsx +++ b/apps/u3/src/components/social/SocialWhoToFollow.tsx @@ -33,10 +33,7 @@ export default function SocialWhoToFollow() { const lensRecommendedProfiles: Profile[] = useMemo( () => lensProfiles - ?.filter( - (profile) => - profile.metadata.displayName && profile.metadata.displayName !== '' - ) + ?.filter((profile) => getName(profile) && getName(profile) !== '') .slice(0, SUGGEST_NUM), [lensProfiles, isLoginLens] ); diff --git a/apps/u3/src/components/social/lens/LensPostCard.tsx b/apps/u3/src/components/social/lens/LensPostCard.tsx index 298bb6d7..a4a09558 100644 --- a/apps/u3/src/components/social/lens/LensPostCard.tsx +++ b/apps/u3/src/components/social/lens/LensPostCard.tsx @@ -49,13 +49,17 @@ export default function LensPostCard({ isPending: isPendingReactionUpvote, } = useReactionLensUpvote({ publication, - onReactionSuccess: ({ originPublication }) => { + onReactionSuccess: ({ originPublication, hasUpvoted: upvoted }) => { if (originPublication?.id !== updatedPublication.id) return; setUpdatedPublication((prev) => { if (!prev) return prev; - const { stats } = prev; + const { stats, operations } = prev; return { ...prev, + operations: { + ...operations, + hasUpvoted: upvoted, + }, stats: { ...stats, upvotes: Number(stats.upvotes) + 1, diff --git a/apps/u3/src/components/social/lens/v1/LensPostCard.tsx b/apps/u3/src/components/social/lens/v1/LensPostCard.tsx index 82172db8..4ab25d3a 100644 --- a/apps/u3/src/components/social/lens/v1/LensPostCard.tsx +++ b/apps/u3/src/components/social/lens/v1/LensPostCard.tsx @@ -34,6 +34,7 @@ export default function LensPostCardV1({ navigate(`/social/post-detail/lens/${data.id}`); }} data={cardData} + likeDisabled replyDisabled={replyDisabled} repostDisabled={repostDisabled} shareLink={getSocialDetailShareUrlWithLens(data.id)} diff --git a/apps/u3/src/container/social/Social.tsx b/apps/u3/src/container/social/Social.tsx index 2cbacd63..8b19b238 100644 --- a/apps/u3/src/container/social/Social.tsx +++ b/apps/u3/src/container/social/Social.tsx @@ -24,6 +24,7 @@ import { PostList, } from './CommonStyles'; import { useLensCtx } from '../../contexts/social/AppLensCtx'; +import { getOwnedByAddress } from '../../utils/social/lens/profile'; export default function SocialAll() { // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -31,8 +32,8 @@ export default function SocialAll() { const { isLogin } = useLogin(); const { sessionProfile: lensSessionProfile } = useLensCtx(); const fid = useFarcasterCurrFid(); - const { ownedBy: lensProfileOwnedByAddress, id: lensSessionProfileId } = - lensSessionProfile || {}; + const { id: lensSessionProfileId } = lensSessionProfile || {}; + const lensProfileOwnedByAddress = getOwnedByAddress(lensSessionProfile); const { socialPlatform, diff --git a/apps/u3/src/container/social/SocialLayout.tsx b/apps/u3/src/container/social/SocialLayout.tsx index 1be6a15f..1e577559 100644 --- a/apps/u3/src/container/social/SocialLayout.tsx +++ b/apps/u3/src/container/social/SocialLayout.tsx @@ -25,14 +25,14 @@ import SearchInput from '../../components/common/input/SearchInput'; import { useFarcasterCtx } from '../../contexts/social/FarcasterCtx'; import TrendChannel from '../../components/social/farcaster/TrendChannel'; import { useLensCtx } from '../../contexts/social/AppLensCtx'; +import { getOwnedByAddress } from '../../utils/social/lens/profile'; export default function SocialLayout() { const location = useLocation(); const { isConnected: isConnectedFarcaster } = useFarcasterCtx(); const { sessionProfile: lensSessionProfile } = useLensCtx(); const { loading: lensSessionLoading } = useSession(); - const { ownedBy: lensProfileOwnedBy } = lensSessionProfile || {}; - const { address: lensProfileOwnedByAddress } = lensProfileOwnedBy || {}; + const lensProfileOwnedByAddress = getOwnedByAddress(lensSessionProfile); const [postScroll, setPostScroll] = useState({ currentParent: '', diff --git a/apps/u3/src/container/social/SocialLens.tsx b/apps/u3/src/container/social/SocialLens.tsx index 2e8b6e02..39374004 100644 --- a/apps/u3/src/container/social/SocialLens.tsx +++ b/apps/u3/src/container/social/SocialLens.tsx @@ -22,6 +22,7 @@ import { PostList, } from './CommonStyles'; import { useLensCtx } from '../../contexts/social/AppLensCtx'; +import { getOwnedByAddress } from '../../utils/social/lens/profile'; export default function SocialFarcaster() { const [parentId] = useState('social-lens'); @@ -52,8 +53,8 @@ export default function SocialFarcaster() { const { feeds, firstLoading, pageInfo, moreLoading } = useListFeeds(parentId); const { sessionProfile } = useLensCtx(); - const { ownedBy: lensProfileOwnedByAddress, id: lensSessionProfileId } = - sessionProfile || {}; + const { id: lensSessionProfileId } = sessionProfile || {}; + const lensProfileOwnedByAddress = getOwnedByAddress(sessionProfile); const loadFirstFeeds = useCallback(async () => { setFirstLoadingDone(false); diff --git a/apps/u3/src/contexts/social/AppLensCtx.tsx b/apps/u3/src/contexts/social/AppLensCtx.tsx index f1216c62..8dd7ce7c 100644 --- a/apps/u3/src/contexts/social/AppLensCtx.tsx +++ b/apps/u3/src/contexts/social/AppLensCtx.tsx @@ -20,6 +20,8 @@ import { useUpdateProfileManagers, Profile, PrimaryPublication, + useProfiles, + ProfileId, } from '@lens-protocol/react-web'; import { bindings as wagmiBindings } from '@lens-protocol/wagmi'; import { Connector, useAccount } from 'wagmi'; @@ -68,6 +70,20 @@ const lensConfig: LensConfig = { environment: LENS_ENV === 'production' ? production : development, }; +// TODO : 兼容v2登录,为了在登录前获取钱包对应的profileID + +let walletProfileId = ''; +const getWalletProfileId = (): Promise => { + return new Promise((resolve) => { + const intervalId = setInterval(() => { + if (walletProfileId) { + clearInterval(intervalId); + resolve(walletProfileId as ProfileId); + } + }, 100); + }); +}; + export function AppLensProvider({ children }: PropsWithChildren) { return ( @@ -113,6 +129,22 @@ export function LensAuthProvider({ children }: PropsWithChildren) { }); }, [sessionProfile, updateProfileManagers]); + // TODO : 兼容v2登录,为了在登录前获取钱包对应的profileID + const [walletAddress, setWalletAddress] = useState(null); + const profilesWhere = {}; + if (walletAddress) { + Object.assign(profilesWhere, { ownedBy: [walletAddress] }); + } + const { data: profiles } = useProfiles({ + where: profilesWhere, + }); + const firstProfile = profiles?.[0] || { id: '' }; + const { id: firstProfileId } = firstProfile; + useEffect(() => { + walletProfileId = firstProfileId; + }, [firstProfileId]); + + // const { execute: fetchProfile } = useLazyProfile(); const lensLoginStartRef = useRef(false); const lensLoginAdpater = async (connector: Connector) => { const chainId = await connector.getChainId(); @@ -123,7 +155,11 @@ export function LensAuthProvider({ children }: PropsWithChildren) { } const walletClient = await connector.getWalletClient(); const { address } = walletClient.account; - await login({ address }); + walletProfileId = ''; + setWalletAddress(address); + const profileId = await getWalletProfileId(); + + await login({ address, profileId }); }; const { connector: activeConnector, isConnected } = useAccount({ diff --git a/apps/u3/src/hooks/social/lens/useCreateLensComment.ts b/apps/u3/src/hooks/social/lens/useCreateLensComment.ts index 579fa402..9ecd67cf 100644 --- a/apps/u3/src/hooks/social/lens/useCreateLensComment.ts +++ b/apps/u3/src/hooks/social/lens/useCreateLensComment.ts @@ -50,7 +50,9 @@ export function useCreateLensComment(props?: { commentOn: { id: publicationId, }, - metadata, + metadata: { + ...(metadata?.lens || {}), + }, }); toast.success('Comment successfully!'); } catch (err) { diff --git a/apps/u3/src/hooks/social/lens/useCreateLensPost.ts b/apps/u3/src/hooks/social/lens/useCreateLensPost.ts index 778f6d26..de013249 100644 --- a/apps/u3/src/hooks/social/lens/useCreateLensPost.ts +++ b/apps/u3/src/hooks/social/lens/useCreateLensPost.ts @@ -31,10 +31,13 @@ export function useCreateLensPost() { const createPost = useCallback( async (content: string, attachments?: MediaImage[]) => { - const metadata = article({ + const metadataAttrs = { content, - attachments, - }); + }; + if (attachments && attachments.length > 0) { + Object.assign(metadataAttrs, { attachments }); + } + const metadata = article(metadataAttrs); const uri = await lensUploadToArweave(metadata); const result = await execute({ metadata: uri, diff --git a/apps/u3/src/utils/profile/biolink.ts b/apps/u3/src/utils/profile/biolink.ts index 942fe64c..e85ada77 100644 --- a/apps/u3/src/utils/profile/biolink.ts +++ b/apps/u3/src/utils/profile/biolink.ts @@ -21,7 +21,9 @@ export const isFarcasterHandle = (handle: string) => { }; export const lensHandleToBioLinkHandle = (handle: string) => { return handle - ? `${handle.replace(/\.[^.]+$/, '')}.${BIOLINK_LENS_SUFFIX}` + ? `${handle + .replace('test/', '') + .replace(/\.[^.]+$/, '')}.${BIOLINK_LENS_SUFFIX}` : ''; }; export const farcasterHandleToBioLinkHandle = (handle: string) => { diff --git a/apps/u3/src/utils/social/lens/lens-ui-utils.ts b/apps/u3/src/utils/social/lens/lens-ui-utils.ts index 1f47415a..e080641c 100644 --- a/apps/u3/src/utils/social/lens/lens-ui-utils.ts +++ b/apps/u3/src/utils/social/lens/lens-ui-utils.ts @@ -12,8 +12,8 @@ export const lensPublicationToPostCardData = ( return { platform: SocialPlatform.Lens, avatar: getAvatar(publication?.by), - name: getName(publication?.by), - handle: getHandle(publication?.by), + name: getName(publication?.by) || publication?.by?.id, + handle: getHandle(publication?.by) || publication?.by?.id, createdAt: publication?.createdAt || '', content: getContent(publication?.metadata), totalLikes: publication?.stats?.upvotes || 0, @@ -29,8 +29,8 @@ export const lensPublicationToReplyCardData = ( return { platform: SocialPlatform.Lens, avatar: getAvatar(publication?.by), - name: getName(publication?.by), - handle: getHandle(publication?.by), + name: getName(publication?.by) || publication?.by?.id, + handle: getHandle(publication?.by) || publication?.by?.id, createdAt: publication?.createdAt || '', content: getContent(publication?.metadata), totalLikes: publication?.stats?.upvotes || 0,