-
Notifications
You must be signed in to change notification settings - Fork 31
feat(efp): read-only EFP stats on address profiles #1913
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
24
commits into
drips-network:main
Choose a base branch
from
Quantumlyy:efp
base: main
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
d9cd9b4
feat(efp): add EFP API client and types
Quantumlyy aa592e9
feat(network): add EFP feature flag
Quantumlyy fa23012
feat(efp): implement EFP Svelte store for stats and common followers
Quantumlyy a110501
feat(efp): create `EfpStats` Svelte component
Quantumlyy b838a25
feat(efp): display EFP stats on `IdentityCard`
Quantumlyy ac88bf4
feat(efp): add 'Show supporters you follow' feature to `SupportersSec…
Quantumlyy 2f626d6
feat(efp): display EFP stats and common followers on profile page
Quantumlyy 8aef357
feat(efp): introduce async request guard to prevent race conditions
Quantumlyy 214b22d
build(deps): update zod dependency for web3-onboard packages in lockfile
Quantumlyy 7887855
feat(efp): Add hydrateStats to EFP store for SSR hydration
Quantumlyy fdc45ff
chore(efp): Export `commonFollowersKey` from EFP store
Quantumlyy ca3c66f
refactor(efp): Consolidate EFP store mocks
Quantumlyy d28c0e1
test(efp): Add stub components for `EfpStats` unit tests
Quantumlyy 0ca96da
refactor(efp): Improve `extractSupporterAddresses` utility and add tests
Quantumlyy f7a52ec
test(efp): Add unit test for `getSupportersYouFollow`
Quantumlyy a6526e5
feat(pages): Integrate EFP stats and common followers on account page
Quantumlyy aa502aa
chore(components): Remove redundant EFP check from IdentityCard
Quantumlyy efbc591
refactor: Remove unused async request guard utility
Quantumlyy 37c76a3
refactor(account-page): Remove async request guard usage
Quantumlyy 26a9da7
feat(efp): Improve mutualsRank parsing and add test
Quantumlyy fae5783
test(efp): Export commonFollowersKey from mock store
Quantumlyy 718903b
fix(efp-stats): URL encode address in profile link
Quantumlyy 4b2c2b5
feat(supporters): Add aria-pressed to filter toggle button
Quantumlyy 2b6b679
Merge branch 'main' into efp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <script lang="ts"> | ||
| import Pile from '$lib/components/pile/pile.svelte'; | ||
| import IdentityBadge from '$lib/components/identity-badge/identity-badge.svelte'; | ||
| import formatNumber from '$lib/utils/format-number'; | ||
| import type { EfpCommonFollower, EfpStats } from '$lib/utils/efp'; | ||
| import network from '$lib/stores/wallet/network'; | ||
|
|
||
| interface Props { | ||
| address: string; | ||
| stats?: EfpStats | null; | ||
| commonFollowers?: EfpCommonFollower[]; | ||
| showCommonFollowers?: boolean; | ||
| maxCommonFollowers?: number; | ||
| } | ||
|
|
||
| let { | ||
| address, | ||
| stats = null, | ||
| commonFollowers = [], | ||
| showCommonFollowers = false, | ||
| maxCommonFollowers = 5, | ||
| }: Props = $props(); | ||
|
|
||
| const profileUrl = $derived(`https://efp.app/${encodeURIComponent(address)}`); | ||
|
|
||
| const hasStats = $derived( | ||
| !!stats && (stats.followers > 0 || stats.following > 0), | ||
| ); | ||
|
|
||
| const visibleCommonFollowers = $derived( | ||
| showCommonFollowers ? commonFollowers.slice(0, maxCommonFollowers) : [], | ||
| ); | ||
|
|
||
| const showCommon = $derived(visibleCommonFollowers.length > 0); | ||
|
|
||
| const pileComponents = $derived( | ||
| visibleCommonFollowers.map((follower) => ({ | ||
| component: IdentityBadge, | ||
| props: { | ||
| address: follower.address, | ||
| disableLink: false, | ||
| disableTooltip: true, | ||
| size: 'small' as const, | ||
| }, | ||
| })), | ||
| ); | ||
| </script> | ||
|
|
||
| {#if network.enableEfp && (hasStats || showCommon)} | ||
| <div class="efp-stats typo-text-small"> | ||
| {#if hasStats && stats} | ||
| <a class="counts" href={profileUrl} target="_blank" rel="noopener noreferrer"> | ||
| {formatNumber(stats.followers)} {stats.followers === 1 ? 'follower' : 'followers'} · {formatNumber(stats.following)} following | ||
| </a> | ||
| {/if} | ||
| {#if showCommon} | ||
| <div class="common-followers"> | ||
| <span class="label typo-all-caps">Followers you know</span> | ||
| <Pile components={pileComponents} maxItems={maxCommonFollowers} countOverride={commonFollowers.length} /> | ||
| </div> | ||
| {/if} | ||
| </div> | ||
| {/if} | ||
|
|
||
| <style> | ||
| .efp-stats { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.5rem; | ||
| color: var(--color-foreground-level-5); | ||
| } | ||
|
|
||
| .counts { | ||
| color: var(--color-foreground-level-5); | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .counts:hover { | ||
| color: var(--color-primary); | ||
| text-decoration: underline; | ||
| } | ||
|
|
||
| .common-followers { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.375rem; | ||
| } | ||
|
|
||
| .label { | ||
| color: var(--color-foreground-level-4); | ||
| } | ||
| </style> |
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,62 @@ | ||
| import { render, screen } from '@testing-library/svelte'; | ||
| import EfpStats from './efp-stats.svelte'; | ||
|
|
||
| vi.mock('$lib/stores/wallet/network', () => ({ | ||
| default: { enableEfp: true }, | ||
| })); | ||
|
|
||
| vi.mock('$lib/components/identity-badge/identity-badge.svelte', async () => ({ | ||
| default: (await import('./identity-badge-stub.svelte')).default, | ||
| })); | ||
|
|
||
| vi.mock('$lib/components/pile/pile.svelte', async () => ({ | ||
| default: (await import('./pile-stub.svelte')).default, | ||
| })); | ||
|
|
||
| describe('efp-stats.svelte', () => { | ||
| it('renders follower and following counts when stats are present', () => { | ||
| render(EfpStats, { | ||
| props: { | ||
| address: '0x1234567890123456789012345678901234567890', | ||
| stats: { followers: 1200, following: 42 }, | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByText(/1,200 followers/)).toBeInTheDocument(); | ||
| expect(screen.getByText(/42 following/)).toBeInTheDocument(); | ||
| expect(screen.getByRole('link')).toHaveAttribute( | ||
| 'href', | ||
| 'https://efp.app/0x1234567890123456789012345678901234567890', | ||
| ); | ||
| }); | ||
|
|
||
| it('renders nothing when stats are absent', () => { | ||
| const { container } = render(EfpStats, { | ||
| props: { | ||
| address: '0x1234567890123456789012345678901234567890', | ||
| stats: null, | ||
| }, | ||
| }); | ||
|
|
||
| expect(container.querySelector('.efp-stats')).toBeNull(); | ||
| }); | ||
|
|
||
| it('truncates common followers to maxCommonFollowers', () => { | ||
| render(EfpStats, { | ||
| props: { | ||
| address: '0x1234567890123456789012345678901234567890', | ||
| stats: { followers: 3, following: 1 }, | ||
| showCommonFollowers: true, | ||
| maxCommonFollowers: 2, | ||
| commonFollowers: [ | ||
| { address: '0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }, | ||
| { address: '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' }, | ||
| { address: '0xcccccccccccccccccccccccccccccccccccccccc' }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| expect(screen.getByText('Followers you know')).toBeInTheDocument(); | ||
| expect(screen.getByText('+1')).toBeInTheDocument(); | ||
| }); | ||
| }); |
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,9 @@ | ||
| <script lang="ts"> | ||
| interface Props { | ||
| address?: string; | ||
| } | ||
|
|
||
| let { address }: Props = $props(); | ||
| </script> | ||
|
|
||
| <span data-testid="identity-badge-stub">{address}</span> |
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,13 @@ | ||
| <script lang="ts"> | ||
| interface Props { | ||
| maxItems?: number; | ||
| components?: unknown[]; | ||
| countOverride?: number; | ||
| } | ||
|
|
||
| let { maxItems = 4, components = [], countOverride }: Props = $props(); | ||
|
|
||
| const overflowAmount = $derived((countOverride ?? components.length) - maxItems); | ||
| </script> | ||
|
|
||
| {#if overflowAmount > 0}<span>+{overflowAmount}</span>{/if} |
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
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.