-
Notifications
You must be signed in to change notification settings - Fork 38
feat: implement wallet connection for health credentials [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] #173
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
waterWang
wants to merge
1
commit into
GuardZero144:main
Choose a base branch
from
waterWang:feat/wallet-connection-health-credentials
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
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,162 @@ | ||
| import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
| import { WalletConnect } from '../src/components/wallet-connect'; | ||
| import { AccessibilityProvider } from '../src/contexts/AccessibilityContext'; | ||
|
|
||
| jest.mock('framer-motion', () => { | ||
| const React = require('react'); | ||
| return { | ||
| ...jest.requireActual('framer-motion'), | ||
| motion: new Proxy( | ||
| {}, | ||
| { | ||
| get: (_, tag) => | ||
| React.forwardRef(function MotionComponent(props: any, ref: any) { | ||
| const { initial, animate, exit, transition, whileHover, whileTap, layout, ...rest } = props; | ||
| return React.createElement(tag, { ...rest, ref }); | ||
| }), | ||
| }, | ||
| ), | ||
| AnimatePresence: ({ children }: { children: React.ReactNode }) => children, | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('@stellar/freighter-api', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| isConnected: jest.fn(), | ||
| getPublicKey: jest.fn(), | ||
| }, | ||
| })); | ||
|
|
||
| function renderWithProviders(ui: React.ReactElement) { | ||
| return render(<AccessibilityProvider>{ui}</AccessibilityProvider>); | ||
| } | ||
|
|
||
| // Reset the mocked freighter module state between tests | ||
| const mockFreighter = require('@stellar/freighter-api').default as { | ||
| isConnected: jest.Mock; | ||
| getPublicKey: jest.Mock; | ||
| }; | ||
|
|
||
| describe('WalletConnect', () => { | ||
| beforeEach(() => { | ||
| mockFreighter.isConnected.mockReset(); | ||
| mockFreighter.getPublicKey.mockReset(); | ||
| (global as any).window.freighter = { getPublicKey: jest.fn() }; | ||
| (global as any).window.albedo = undefined; | ||
| (global as any).window.lobstr = undefined; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| delete (global as any).window.freighter; | ||
| delete (global as any).window.albedo; | ||
| delete (global as any).window.lobstr; | ||
| }); | ||
|
|
||
| it('renders the connect button', () => { | ||
| renderWithProviders(<WalletConnect onConnect={() => {}} />); | ||
| expect(screen.getByLabelText('Connect wallet')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('connects via Freighter and calls onConnect with the address', async () => { | ||
| mockFreighter.isConnected.mockResolvedValue(true); | ||
| mockFreighter.getPublicKey.mockResolvedValue('GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U'); | ||
| const onConnect = jest.fn(); | ||
|
|
||
| renderWithProviders(<WalletConnect onConnect={onConnect} />); | ||
| fireEvent.click(screen.getByLabelText('Connect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mockFreighter.getPublicKey).toHaveBeenCalled(); | ||
| }); | ||
| await waitFor(() => { | ||
| expect(onConnect).toHaveBeenCalledWith('GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U'); | ||
| }); | ||
| }); | ||
|
|
||
| it('displays a truncated wallet address after connecting', async () => { | ||
| mockFreighter.isConnected.mockResolvedValue(true); | ||
| mockFreighter.getPublicKey.mockResolvedValue('GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U'); | ||
| const onConnect = jest.fn(); | ||
|
|
||
| renderWithProviders(<WalletConnect onConnect={onConnect} />); | ||
| fireEvent.click(screen.getByLabelText('Connect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByLabelText('Disconnect wallet')).toBeInTheDocument(); | ||
| }); | ||
| // Truncated address should be present (GC4CQ...U7U7U7U) | ||
| expect(screen.getByText(/GC4CQ/)).toBeInTheDocument(); | ||
| const mono = screen.getByText(/U7U7U7U/); | ||
| expect(mono).toBeInTheDocument(); | ||
| expect(mono.textContent).toBe('GC4CQ...U7U7U7U'); | ||
| }); | ||
|
|
||
| it('calls onDisconnect when the disconnect button is clicked', async () => { | ||
| mockFreighter.isConnected.mockResolvedValue(true); | ||
| mockFreighter.getPublicKey.mockResolvedValue('GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U'); | ||
| const onDisconnect = jest.fn(); | ||
|
|
||
| renderWithProviders( | ||
| <WalletConnect onConnect={() => {}} onDisconnect={onDisconnect} />, | ||
| ); | ||
| fireEvent.click(screen.getByLabelText('Connect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByLabelText('Disconnect wallet')).toBeInTheDocument(); | ||
| }); | ||
| fireEvent.click(screen.getByLabelText('Disconnect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(onDisconnect).toHaveBeenCalled(); | ||
| }); | ||
| // Should return to connect state | ||
| expect(screen.getByLabelText('Connect wallet')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows an error message when Freighter is not installed', async () => { | ||
| mockFreighter.isConnected.mockRejectedValue(new Error('Freighter not found')); | ||
| (global as any).window.freighter = undefined; | ||
|
|
||
| renderWithProviders(<WalletConnect onConnect={() => {}} />); | ||
| fireEvent.click(screen.getByLabelText('Connect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| const alert = screen.getByRole('alert'); | ||
| expect(alert).toBeInTheDocument(); | ||
| expect(alert.textContent).toMatch(/Freighter/); | ||
| }); | ||
| }); | ||
|
|
||
| it('opens the wallet selector when multiple wallets are available', () => { | ||
| (global as any).window.freighter = { getPublicKey: jest.fn() }; | ||
| (global as any).window.albedo = { publicKey: jest.fn() }; | ||
|
|
||
| renderWithProviders(<WalletConnect onConnect={() => {}} />); | ||
| // Button should indicate a selector | ||
| const button = screen.getByLabelText('Select wallet to connect'); | ||
| fireEvent.click(button); | ||
|
|
||
| expect(screen.getByRole('listbox')).toBeInTheDocument(); | ||
| expect(screen.getByText('Freighter')).toBeInTheDocument(); | ||
| expect(screen.getByText('Albedo')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('shows copy button and Stellar Expert link when connected', async () => { | ||
| mockFreighter.isConnected.mockResolvedValue(true); | ||
| mockFreighter.getPublicKey.mockResolvedValue('GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U'); | ||
|
|
||
| renderWithProviders(<WalletConnect onConnect={() => {}} />); | ||
| fireEvent.click(screen.getByLabelText('Connect wallet')); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByLabelText('Copy wallet address')).toBeInTheDocument(); | ||
| expect(screen.getByLabelText('View on Stellar Expert')).toBeInTheDocument(); | ||
| }); | ||
| const link = screen.getByLabelText('View on Stellar Expert'); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| 'https://stellar.expert/explorer/public/account/GC4CQK3WXU7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U7U', | ||
| ); | ||
| }); | ||
| }); | ||
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.
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: GuardZero144/ValidFi
Length of output: 11489
🏁 Script executed:
Repository: GuardZero144/ValidFi
Length of output: 8871
🏁 Script executed:
Repository: GuardZero144/ValidFi
Length of output: 15741
Replace all explicit
anyannotations and casts in the test with typed test doubles.Define typed motion props and a forwarded ref. Extend
Windowwith optionalfreighter,albedo, andlobstrproperties. Usewindowdirectly for setup and cleanup at lines 45-53, 119, and 132-133.🤖 Prompt for AI Agents
Source: Path instructions