-
Notifications
You must be signed in to change notification settings - Fork 175
Verification Badge + filter #475
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
Draft
rsproule
wants to merge
7
commits into
main
Choose a base branch
from
rfs/verified
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.
Draft
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
94081b8
verified filter works
rsproule 314bc86
verified on all the tables + mobile friendly
rsproule 5c8e256
global wrapper. fix docs link
rsproule f0d5ffe
add index for verified
rsproule 43d3905
rm the shake logic
rsproule 22e6892
fmt
rsproule 2d8bb9d
build
rsproule 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
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
24 changes: 24 additions & 0 deletions
24
apps/scan/src/app/(home)/(overview)/_components/sellers/known-sellers/container.tsx
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,24 @@ | ||
| 'use client'; | ||
|
|
||
| import { Section } from '@/app/_components/layout/page-utils'; | ||
| import { RangeSelector } from '@/app/_contexts/time-range/component'; | ||
|
|
||
| export const TopServersContainer = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <Section | ||
| title="Top Servers" | ||
| description="Top addresses that have received x402 transfers and are listed in the Bazaar" | ||
| actions={ | ||
| <div className="flex items-center gap-2"> | ||
| <RangeSelector /> | ||
| </div> | ||
| } | ||
| > | ||
| {children} | ||
| </Section> | ||
| ); | ||
| }; |
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
217 changes: 217 additions & 0 deletions
217
apps/scan/src/app/(home)/(overview)/_components/verified-filter-wrapper.tsx
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,217 @@ | ||
| 'use client'; | ||
|
|
||
| import { useEffect, useState } from 'react'; | ||
| import { VerifiedFilterProvider } from '@/app/_contexts/verified-filter/provider'; | ||
| import { useVerifiedFilter } from '@/app/_contexts/verified-filter/hook'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog'; | ||
| import { Label } from '@/components/ui/label'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { CheckCircle, Smartphone } from 'lucide-react'; | ||
|
|
||
| const MOTION_PERMISSION_KEY = 'motion-permission-requested'; | ||
|
|
||
| export const VerifiedFilterWrapper = ({ | ||
| children, | ||
| }: { | ||
| children: React.ReactNode; | ||
| }) => { | ||
| return ( | ||
| <VerifiedFilterProvider> | ||
| <MotionPermissionPrompt /> | ||
| <VerifiedFilterDialog /> | ||
| {children} | ||
| </VerifiedFilterProvider> | ||
| ); | ||
| }; | ||
|
|
||
| // Prompt for motion permission on iOS | ||
| const MotionPermissionPrompt = () => { | ||
| const [showPrompt, setShowPrompt] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| // Check if permission was already requested | ||
| const requested = localStorage.getItem(MOTION_PERMISSION_KEY); | ||
| if (requested) return; | ||
|
|
||
| // Check if device supports motion events and requires permission | ||
| if ( | ||
| typeof DeviceMotionEvent !== 'undefined' && | ||
| typeof (DeviceMotionEvent as any).requestPermission === 'function' | ||
| ) { | ||
| // Show prompt after a short delay | ||
| setTimeout(() => setShowPrompt(true), 2000); | ||
| } else { | ||
| // No permission needed, mark as completed | ||
| localStorage.setItem(MOTION_PERMISSION_KEY, 'true'); | ||
| } | ||
| }, []); | ||
|
|
||
| const handleRequestPermission = async () => { | ||
| try { | ||
| const permission = await (DeviceMotionEvent as any).requestPermission(); | ||
| localStorage.setItem(MOTION_PERMISSION_KEY, 'true'); | ||
| setShowPrompt(false); | ||
| } catch (error) { | ||
| console.error('Error requesting motion permission:', error); | ||
| localStorage.setItem(MOTION_PERMISSION_KEY, 'true'); // Don't show again | ||
| setShowPrompt(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleDismiss = () => { | ||
| localStorage.setItem(MOTION_PERMISSION_KEY, 'true'); | ||
| setShowPrompt(false); | ||
| }; | ||
|
|
||
| if (!showPrompt) return null; | ||
|
|
||
| return ( | ||
| <Dialog open={showPrompt} onOpenChange={handleDismiss}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle className="flex items-center gap-2"> | ||
| <Smartphone className="size-4" /> | ||
| Enable Shake Gesture | ||
| </DialogTitle> | ||
| <DialogDescription> | ||
| Allow motion access to use shake gesture for opening the verified | ||
| filter. This is an optional feature for mobile devices. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="flex gap-2 justify-end"> | ||
| <Button variant="outline" onClick={handleDismiss}> | ||
| Skip | ||
| </Button> | ||
| <Button onClick={handleRequestPermission}>Enable</Button> | ||
| </div> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| // Reusable toggle switch component | ||
| const VerifiedToggleSwitch = () => { | ||
| const { verifiedOnly, setVerifiedOnly } = useVerifiedFilter(); | ||
|
|
||
| const handleToggle = () => { | ||
| setVerifiedOnly(!verifiedOnly); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex items-center justify-between py-4"> | ||
| <Label htmlFor="verified-toggle" className="text-sm font-medium"> | ||
| Show only verified servers | ||
| </Label> | ||
| <button | ||
| id="verified-toggle" | ||
| type="button" | ||
| role="switch" | ||
| aria-checked={verifiedOnly} | ||
| onClick={handleToggle} | ||
| className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 ${ | ||
| verifiedOnly ? 'bg-green-500' : 'bg-gray-200' | ||
| }`} | ||
| > | ||
| <span | ||
| className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${ | ||
| verifiedOnly ? 'translate-x-6' : 'translate-x-1' | ||
| }`} | ||
| /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| // Dialog with keyboard shortcut (desktop) and shake detection (mobile) | ||
| const VerifiedFilterDialog = () => { | ||
| const [showModal, setShowModal] = useState(false); | ||
|
|
||
| // Keyboard shortcut for desktop (triple tap 'v') | ||
| useEffect(() => { | ||
| let tapCount = 0; | ||
| let tapTimeout: NodeJS.Timeout; | ||
|
|
||
| const handleKeyDown = (e: KeyboardEvent) => { | ||
| if (e.key === 'v' || e.key === 'V') { | ||
| tapCount++; | ||
|
|
||
| // Clear existing timeout | ||
| if (tapTimeout) { | ||
| clearTimeout(tapTimeout); | ||
| } | ||
|
|
||
| // Open modal on third tap | ||
| if (tapCount === 3) { | ||
| e.preventDefault(); | ||
| setShowModal(true); | ||
| tapCount = 0; | ||
| } else { | ||
| // Reset counter after 500ms of no taps | ||
| tapTimeout = setTimeout(() => { | ||
| tapCount = 0; | ||
| }, 500); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| document.addEventListener('keydown', handleKeyDown); | ||
| return () => { | ||
| document.removeEventListener('keydown', handleKeyDown); | ||
| if (tapTimeout) { | ||
| clearTimeout(tapTimeout); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| // Shake detection for mobile | ||
| useEffect(() => { | ||
| // Only set up if permission was granted | ||
| const permissionGranted = localStorage.getItem(MOTION_PERMISSION_KEY); | ||
| if (!permissionGranted) return; | ||
|
|
||
| // Use shake.js library | ||
| const Shake = require('shake.js'); | ||
| const myShakeEvent = new Shake({ | ||
| threshold: 15, // Sensitivity of shake detection | ||
| timeout: 1000, // Time between shakes | ||
| }); | ||
|
|
||
| myShakeEvent.start(); | ||
|
|
||
| const handleShake = () => { | ||
| setShowModal(true); | ||
| }; | ||
|
|
||
| window.addEventListener('shake', handleShake, false); | ||
|
|
||
| return () => { | ||
| window.removeEventListener('shake', handleShake, false); | ||
| myShakeEvent.stop(); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <Dialog open={showModal} onOpenChange={setShowModal}> | ||
| <DialogContent> | ||
| <DialogHeader> | ||
| <DialogTitle className="flex items-center gap-2"> | ||
| <CheckCircle className="size-4 text-green-500" /> | ||
| Verified Servers Filter | ||
| </DialogTitle> | ||
| <DialogDescription> | ||
| Filter servers to only show those with verified accepts. Volume and | ||
| metrics are recalculated to only include transactions to verified | ||
| addresses. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <VerifiedToggleSwitch /> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The shake detection effect runs once on mount with empty dependencies. If the user grants motion permission after page load, the shake detector won't be initialized because the effect won't re-run.
View Details
📝 Patch Details
Analysis
Shake detector not initialized when motion permission granted after page load
What fails:
VerifiedFilterDialogcomponent does not initialize the shake detector if the user grants motion permission after the initial page load. The shake detection effect has an empty dependency array but depends on localStorage state that can change.How to reproduce:
VerifiedFilterDialogmounts and its useEffect runs with empty dependenciesMOTION_PERMISSION_KEYis not in localStorage yet, so the effect exits earlyMotionPermissionPromptto appearMotionPermissionPromptsets the localStorage flagRoot cause: The shake detection effect had an empty dependency array
[]but checkedlocalStorage.getItem(MOTION_PERMISSION_KEY)inside. This meant the effect only ran once on mount, before permission was granted. When the user later granted permission by setting the localStorage flag, the effect had no mechanism to re-run.Fix applied:
permissionGrantedstate variable that tracks whether the motion permission has been grantedpermissionGranted, so it runs whenever the permission status changesThe fix properly handles the async nature of the permission flow while maintaining clean React patterns with appropriate dependency arrays.