-
Notifications
You must be signed in to change notification settings - Fork 316
feat(efp): add Ethereum Follow Protocol plugin #12377
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
Open
Quantumlyy
wants to merge
23
commits into
DimensionDev:develop
Choose a base branch
from
Quantumlyy:ethfollow-twitter-embeds
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
787a881
feat(efp): recognize profile links
Quantumlyy 05d30d5
feat(efp): render twitter embeds
Quantumlyy abf12fe
fix(efp): hide native twitter preview
Quantumlyy 5d9b7bb
fix(efp): scope native twitter card hiding to post root
Quantumlyy 1aab157
fix(efp): query card.wrapper from the tweet, not from rootNode
Quantumlyy e22513a
fix(efp): detect via aria-label and hide card container
Quantumlyy e973299
fix(efp): widen search root to article parent
Quantumlyy 925c106
fix(efp): use card.contains(rootNode) to skip own injection target
Quantumlyy e92dd63
fix(efp): scope to article in timeline view
Quantumlyy 713fb82
fix(efp): clear lint errors in native twitter card hook
Quantumlyy 0b2e129
fix(efp): hide native card on link-only tweets
Quantumlyy 76c40aa
chore(efp): polish for review — i18n, dedup, drop completed TODOs
Quantumlyy a8db34a
feat(efp): add dedicated EFP icon
Quantumlyy 28edcb4
refactor(efp): route data API calls through background RPC
Quantumlyy edef341
fix(efp): match protocol-less EFP links in PostInspector
Quantumlyy 1ea8916
chore: whitelist efprpc in cspell.json
Quantumlyy 43d5b53
Merge branch 'develop' into ethfollow-twitter-embeds
Quantumlyy 80ca3e8
Potential fix for pull request finding
Quantumlyy 798a756
Merge branch 'develop' into ethfollow-twitter-embeds
Quantumlyy 528824f
fix(efp): restore native Twitter card when the plugin unmounts
Quantumlyy 4c6fe36
fix(efp): match cards by parsed link, not substring
Quantumlyy 47958d7
refactor(efp): use useQuery for profile data fetching
Quantumlyy e957433
Potential fix for pull request finding
Quantumlyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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,15 @@ | ||
| # Ethereum Follow Protocol plugin | ||
|
|
||
| ## Referenced resources | ||
|
|
||
| - https://efp.app | ||
| - https://docs.efp.app | ||
| - https://data.ethfollow.xyz/api/v1 | ||
| - https://github.com/ethereumfollowprotocol/app | ||
| - https://github.com/ethereumfollowprotocol/api-v2 | ||
|
|
||
| ## Known issues / Caveats | ||
|
|
||
| - The card intentionally accepts only direct one-segment profile/list URLs with an optional `topEight=true` query. | ||
| - Reserved EFP app routes such as `/api`, `/og`, `/assets`, `/leaderboard`, `/integrations`, `/team`, and `/swipe` are ignored. | ||
| - The embed uses EFP-generated preview images instead of arbitrary ENS avatar or header records to keep CSP changes narrow. |
This file contains hidden or 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,25 @@ | ||
| { | ||
| "name": "@masknet/plugin-efp", | ||
| "private": true, | ||
| "sideEffects": [ | ||
| "./src/register.ts" | ||
| ], | ||
| "type": "module", | ||
| "exports": { | ||
| ".": { | ||
| "mask-src": "./src/index.ts", | ||
| "default": "./dist/index.js" | ||
| }, | ||
| "./register": { | ||
| "mask-src": "./src/register.ts", | ||
| "default": "./dist/register.js" | ||
| } | ||
| }, | ||
| "dependencies": { | ||
| "@masknet/icons": "workspace:^", | ||
| "@masknet/plugin-infra": "workspace:^", | ||
| "@masknet/shared-base": "workspace:^", | ||
| "@masknet/theme": "workspace:^", | ||
| "@masknet/typed-message": "workspace:^" | ||
| } | ||
| } |
This file contains hidden or 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,271 @@ | ||
| import { Icons } from '@masknet/icons' | ||
| import { Trans } from '@lingui/react/macro' | ||
| import { makeStyles } from '@masknet/theme' | ||
| import { Box, Link, Stack, Typography } from '@mui/material' | ||
| import { useEffect, useMemo, useReducer, useState, type ReactNode } from 'react' | ||
| import { EFP_FALLBACK_IMAGE_URL } from '../constants.js' | ||
| import type { EFPProfileLink } from '../helpers/url.js' | ||
| import { PluginEFPRPC } from '../messages.js' | ||
| import type { EFPProfileResponse } from '../Worker/apis/index.js' | ||
|
|
||
| interface ProfileCardProps { | ||
| profileLink: EFPProfileLink | ||
| } | ||
|
|
||
| interface EFPProfileState { | ||
| data: EFPProfileResponse | null | ||
| loading: boolean | ||
| } | ||
|
|
||
| type EFPProfileAction = | ||
| | { type: 'loading' } | ||
| | { type: 'success'; data: EFPProfileResponse | null } | ||
| | { type: 'error' } | ||
|
|
||
| const formatter = new Intl.NumberFormat('en', { | ||
| notation: 'compact', | ||
| maximumFractionDigits: 1, | ||
| }) | ||
|
|
||
| const useStyles = makeStyles()((theme) => ({ | ||
| root: { | ||
| padding: theme.spacing(1.5), | ||
| paddingTop: 0, | ||
| }, | ||
| card: { | ||
| overflow: 'hidden', | ||
| borderRadius: 8, | ||
| border: `1px solid ${theme.palette.maskColor.line}`, | ||
| color: theme.palette.maskColor.main, | ||
| background: theme.palette.maskColor.bottom, | ||
| }, | ||
| image: { | ||
| display: 'block', | ||
| width: '100%', | ||
| aspectRatio: '1.91 / 1', | ||
| objectFit: 'cover', | ||
| background: theme.palette.maskColor.bg, | ||
| }, | ||
| imageFallback: { | ||
| display: 'flex', | ||
| width: '100%', | ||
| aspectRatio: '1.91 / 1', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| background: 'linear-gradient(135deg, #f1f3fe 0%, #dff2fb 45%, #ecfffd 100%)', | ||
| color: '#333333', | ||
| }, | ||
| body: { | ||
| padding: theme.spacing(1.5), | ||
| gap: theme.spacing(1), | ||
| }, | ||
| eyebrow: { | ||
| color: theme.palette.maskColor.second, | ||
| fontWeight: 700, | ||
| lineHeight: 1, | ||
| }, | ||
| title: { | ||
| fontWeight: 700, | ||
| wordBreak: 'break-word', | ||
| lineHeight: 1.25, | ||
| }, | ||
| description: { | ||
| color: theme.palette.maskColor.second, | ||
| display: '-webkit-box', | ||
| overflow: 'hidden', | ||
| WebkitBoxOrient: 'vertical', | ||
| WebkitLineClamp: 2, | ||
| }, | ||
| metrics: { | ||
| display: 'flex', | ||
| flexWrap: 'wrap', | ||
| gap: theme.spacing(1), | ||
| }, | ||
| metric: { | ||
| minWidth: 86, | ||
| borderRadius: 8, | ||
| padding: theme.spacing(0.75, 1), | ||
| background: theme.palette.maskColor.bg, | ||
| }, | ||
| metricValue: { | ||
| fontWeight: 700, | ||
| lineHeight: 1.2, | ||
| }, | ||
| metricLabel: { | ||
| color: theme.palette.maskColor.second, | ||
| lineHeight: 1.2, | ||
| }, | ||
| footer: { | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| gap: theme.spacing(1), | ||
| }, | ||
| link: { | ||
| display: 'inline-flex', | ||
| alignItems: 'center', | ||
| gap: theme.spacing(0.5), | ||
| fontWeight: 700, | ||
| textDecoration: 'none', | ||
| }, | ||
| })) | ||
|
|
||
| export function ProfileCard({ profileLink }: ProfileCardProps) { | ||
| const { classes } = useStyles() | ||
| const { data, loading } = useEFPProfile(profileLink) | ||
| const displayName = useMemo(() => getDisplayName(profileLink, data), [profileLink, data]) | ||
| const description = data?.ens?.records?.description | ||
| const primaryList = data?.primary_list | ||
|
|
||
| return ( | ||
| <Stack className={classes.root}> | ||
| <Box className={classes.card}> | ||
| <ProfileImage key={profileLink.imageUrl} profileLink={profileLink} /> | ||
| <Stack className={classes.body}> | ||
| <Typography className={classes.eyebrow} variant="caption"> | ||
| {profileLink.topEight ? | ||
| <Trans>EFP Top 8</Trans> | ||
| : <Trans>Ethereum Follow Protocol</Trans>} | ||
| </Typography> | ||
| <Typography className={classes.title} variant="h6"> | ||
| {displayName} | ||
| </Typography> | ||
| {description ? | ||
| <Typography className={classes.description} variant="body2"> | ||
| {description} | ||
| </Typography> | ||
| : null} | ||
| <Box className={classes.metrics}> | ||
| <Metric | ||
| label={<Trans>Followers</Trans>} | ||
| value={loading ? '--' : formatCount(data?.followers_count)} | ||
| /> | ||
| <Metric | ||
| label={<Trans>Following</Trans>} | ||
| value={loading ? '--' : formatCount(data?.following_count)} | ||
| /> | ||
| {primaryList ? | ||
| <Metric label={<Trans>Primary List</Trans>} value={`#${primaryList}`} /> | ||
| : profileLink.type === 'list' ? | ||
| <Metric label={<Trans>List</Trans>} value={`#${profileLink.user}`} /> | ||
| : null} | ||
| </Box> | ||
| <Box className={classes.footer}> | ||
| <Typography variant="caption" color="textSecondary"> | ||
| {profileLink.type === 'list' ? | ||
| <Trans>EFP list</Trans> | ||
| : <Trans>EFP profile</Trans>} | ||
| </Typography> | ||
| <Link | ||
| className={classes.link} | ||
| href={profileLink.profileUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer"> | ||
| <Trans>View on EFP</Trans> | ||
| <Icons.LinkOut size={14} /> | ||
| </Link> | ||
| </Box> | ||
| </Stack> | ||
| </Box> | ||
| </Stack> | ||
| ) | ||
| } | ||
|
|
||
| function ProfileImage({ profileLink }: ProfileCardProps) { | ||
| const { classes } = useStyles() | ||
| const [imageUrl, setImageUrl] = useState(profileLink.imageUrl) | ||
| const [failed, setFailed] = useState(false) | ||
|
|
||
| if (failed) { | ||
| return ( | ||
| <Box className={classes.imageFallback}> | ||
| <Icons.EFP size={64} /> | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <img | ||
| className={classes.image} | ||
| src={imageUrl} | ||
| alt="" | ||
| onError={() => { | ||
| if (imageUrl === EFP_FALLBACK_IMAGE_URL) { | ||
| setFailed(true) | ||
| return | ||
| } | ||
| setImageUrl(EFP_FALLBACK_IMAGE_URL) | ||
| }} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| function Metric({ label, value }: { label: ReactNode; value: string }) { | ||
| const { classes } = useStyles() | ||
| return ( | ||
| <Box className={classes.metric}> | ||
| <Typography className={classes.metricValue} variant="body2"> | ||
| {value} | ||
| </Typography> | ||
| <Typography className={classes.metricLabel} variant="caption"> | ||
| {label} | ||
| </Typography> | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| function useEFPProfile(profileLink: EFPProfileLink) { | ||
| const [state, dispatch] = useReducer(reduceEFPProfileState, { | ||
| data: null, | ||
| loading: true, | ||
| }) | ||
|
|
||
| useEffect(() => { | ||
| let cancelled = false | ||
| dispatch({ type: 'loading' }) | ||
|
|
||
| PluginEFPRPC.fetchEFPProfile(profileLink.apiPath) | ||
| .then((data) => { | ||
| if (cancelled) return | ||
| dispatch({ type: 'success', data: isProfileResponse(data) ? data : null }) | ||
| }) | ||
| .catch(() => { | ||
| if (cancelled) return | ||
| dispatch({ type: 'error' }) | ||
| }) | ||
|
|
||
| return () => { | ||
| cancelled = true | ||
| } | ||
| }, [profileLink.apiPath]) | ||
|
|
||
| return state | ||
| } | ||
|
|
||
| function reduceEFPProfileState(_: EFPProfileState, action: EFPProfileAction): EFPProfileState { | ||
| if (action.type === 'loading') return { data: null, loading: true } | ||
| if (action.type === 'success') return { data: action.data, loading: false } | ||
| return { data: null, loading: false } | ||
| } | ||
|
|
||
| function isProfileResponse(value: EFPProfileResponse | null): value is EFPProfileResponse { | ||
| return !!value && (typeof value.address === 'string' || typeof value.primary_list === 'string') | ||
|
Quantumlyy marked this conversation as resolved.
|
||
| } | ||
|
|
||
| function getDisplayName(profileLink: EFPProfileLink, data: EFPProfileResponse | null) { | ||
| const ensName = data?.ens?.name | ||
| if (ensName) return ensName | ||
| if (profileLink.type === 'list') return `List #${profileLink.user}` | ||
| return truncateAddress(profileLink.user) | ||
| } | ||
|
|
||
| function truncateAddress(value: string) { | ||
| if (!/^0x[\dA-Fa-f]{40}$/u.test(value)) return value | ||
| return `${value.slice(0, 6)}...${value.slice(-4)}` | ||
| } | ||
|
|
||
| function formatCount(value: string | number | undefined) { | ||
| const count = Number(value) | ||
| if (!Number.isFinite(count)) return '--' | ||
| return formatter.format(count) | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.