-
Notifications
You must be signed in to change notification settings - Fork 42
feat(frontend): add reusable ExplorerLink component (Closes #130) #291
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
Stellar-VaultLink:main
Choose a base branch
from
waterWang:feat/reusable-explorer-link-130
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.
+129
−44
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
54 changes: 54 additions & 0 deletions
54
invofi/apps/frontend/src/components/common/ExplorerLink.test.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,54 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { ExplorerLink } from './ExplorerLink'; | ||
|
|
||
| describe('ExplorerLink', () => { | ||
| it('renders a contract link with the correct href', () => { | ||
| render(<ExplorerLink type="contract" value="abc123" />); | ||
| const link = screen.getByRole('link'); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| 'https://stellar.expert/explorer/testnet/contract/abc123', | ||
| ); | ||
| expect(link).toHaveAttribute('target', '_blank'); | ||
| expect(link).toHaveAttribute('rel', 'noreferrer noopener'); | ||
| }); | ||
|
|
||
| it('renders an account link', () => { | ||
| render(<ExplorerLink type="account" value="GABCDEF123456" />); | ||
| const link = screen.getByRole('link'); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| 'https://stellar.expert/explorer/testnet/account/GABCDEF123456', | ||
| ); | ||
| }); | ||
|
|
||
| it('renders a transaction link', () => { | ||
| render(<ExplorerLink type="tx" value="txhash" />); | ||
| const link = screen.getByRole('link'); | ||
| expect(link).toHaveAttribute( | ||
| 'href', | ||
| 'https://stellar.expert/explorer/testnet/tx/txhash', | ||
| ); | ||
| }); | ||
|
|
||
| it('renders children instead of the raw value', () => { | ||
| render(<ExplorerLink type="contract" value="abc123">View</ExplorerLink>); | ||
| expect(screen.getByRole('link')).toHaveTextContent('View'); | ||
| }); | ||
|
|
||
| it('applies a custom className', () => { | ||
| render(<ExplorerLink type="contract" value="abc123" className="font-mono" />); | ||
| expect(screen.getByRole('link')).toHaveClass('font-mono'); | ||
| }); | ||
|
|
||
| it('defaults title to "View on Stellar Expert"', () => { | ||
| render(<ExplorerLink type="contract" value="abc123" />); | ||
| expect(screen.getByRole('link')).toHaveAttribute('title', 'View on Stellar Expert'); | ||
| }); | ||
|
|
||
| it('accepts a custom title', () => { | ||
| render(<ExplorerLink type="contract" value="abc123" title="Check it out" />); | ||
| expect(screen.getByRole('link')).toHaveAttribute('title', 'Check it out'); | ||
| }); | ||
| }); |
41 changes: 41 additions & 0 deletions
41
invofi/apps/frontend/src/components/common/ExplorerLink.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,41 @@ | ||
| import { explorerContractUrl, explorerAccountUrl, explorerTxUrl } from '@/lib/constants'; | ||
|
|
||
| interface ExplorerLinkProps { | ||
| type: 'contract' | 'account' | 'tx'; | ||
| value: string; | ||
| children?: React.ReactNode; | ||
| className?: string; | ||
| title?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Reusable Stellar Expert explorer link. | ||
| * Uses the network-aware helpers from `@/lib/constants` so testnet vs mainnet | ||
| * is handled in one place — no inline `STELLAR_EXPERT` constants in call sites. | ||
| */ | ||
| export function ExplorerLink({ | ||
| type, | ||
| value, | ||
| children, | ||
| className = '', | ||
| title, | ||
| }: ExplorerLinkProps) { | ||
| const url = | ||
| type === 'contract' | ||
| ? explorerContractUrl(value) | ||
| : type === 'account' | ||
| ? explorerAccountUrl(value) | ||
| : explorerTxUrl(value); | ||
|
|
||
| return ( | ||
| <a | ||
| href={url} | ||
| target="_blank" | ||
| rel="noreferrer noopener" | ||
| className={className} | ||
| title={title ?? 'View on Stellar Expert'} | ||
| > | ||
| {children ?? value} | ||
| </a> | ||
| ); | ||
| } |
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
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the invoice contract identifier for contract links.
invoice.originatoris also passed totype="account"in both cards. The current contract links produce a/contract/<account-address>URL. Stellar Expert cannot resolve that as an invoice contract.invofi/apps/frontend/src/components/marketplace/MarketplaceCard.tsx#L49-L56: pass the invoice contract identifier instead ofinvoice.originator.invofi/apps/frontend/src/components/marketplace/SuggestedMatches.tsx#L142-L149: pass the invoice contract identifier instead ofinvoice.originator.📍 Affects 2 files
invofi/apps/frontend/src/components/marketplace/MarketplaceCard.tsx#L49-L56(this comment)invofi/apps/frontend/src/components/marketplace/SuggestedMatches.tsx#L142-L149🤖 Prompt for AI Agents