-
Notifications
You must be signed in to change notification settings - Fork 96
feat: implement Stellar Explorer Integration and Transaction Links #154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a5ba752
feat: implement Stellar Explorer Integration and Transaction Links
ekumamatthew fde6473
Merge branch 'boundlessfi:main' into steller_explorer
ekumamatthew 888ce1f
Merge branch 'main' of matthew:ekumamatthew/bounties into steller_exp…
ekumamatthew 005455c
fix: address feedback and complete Stellar Explorer integration
ekumamatthew 4328d4d
Merge branch 'steller_explorer' of matthew:ekumamatthew/bounties into…
ekumamatthew 0922279
Merge github.com:boundlessfi/bounties into steller_explorer
0xdevcollins a924fd2
feat: add comprehensive platform documentation and local configuratio…
0xdevcollins 245b635
feat: add platform documentation and local configuration while refini…
0xdevcollins 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
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,221 @@ | ||
| "use client"; | ||
|
|
||
| import React, { useState } from "react"; | ||
| import { Copy, ExternalLink, Check } from "lucide-react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipProvider, | ||
| TooltipTrigger, | ||
| } from "@/components/ui/tooltip"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { | ||
| getTransactionUrl, | ||
| getAccountUrl, | ||
| getContractUrl, | ||
| getStellarNetwork, | ||
| StellarNetwork, | ||
| isValidStellarAddress, | ||
| isValidStellarTxHash, | ||
| isValidStellarContractId, | ||
| } from "@/lib/utils/stellar-explorer"; | ||
|
|
||
| export type StellarLinkType = "transaction" | "account" | "contract"; | ||
|
|
||
| interface StellarLinkProps { | ||
| /** The value to link to (transaction hash, address, or contract ID) */ | ||
| value: string; | ||
| /** The type of link */ | ||
| type: StellarLinkType; | ||
| /** Optional network override */ | ||
| network?: StellarNetwork; | ||
| /** Optional explorer override */ | ||
| explorer?: string; | ||
| /** Maximum characters to display before truncating */ | ||
| maxLength?: number; | ||
| /** Whether to show the copy button */ | ||
| showCopy?: boolean; | ||
| /** Whether to show the external link icon */ | ||
| showExternalIcon?: boolean; | ||
| /** Custom CSS classes */ | ||
| className?: string; | ||
| /** Custom link text (overrides truncation) */ | ||
| linkText?: string; | ||
| /** Tooltip text prefix */ | ||
| tooltipPrefix?: string; | ||
| } | ||
|
|
||
| export function StellarLink({ | ||
| value, | ||
| type, | ||
| network, | ||
| explorer = "stellar.expert", | ||
| maxLength = 12, | ||
| showCopy = true, | ||
| showExternalIcon = true, | ||
| className, | ||
| linkText, | ||
| tooltipPrefix, | ||
| }: StellarLinkProps) { | ||
| const [copied, setCopied] = useState(false); | ||
| const [copyError, setCopyError] = useState(false); | ||
|
|
||
| // Validate the input | ||
| const isValid = React.useMemo(() => { | ||
| switch (type) { | ||
| case "transaction": | ||
| return isValidStellarTxHash(value); | ||
| case "account": | ||
| return isValidStellarAddress(value); | ||
| case "contract": | ||
| return isValidStellarContractId(value); | ||
| default: | ||
| return false; | ||
| } | ||
| }, [value, type]); | ||
|
|
||
| // Generate the appropriate URL | ||
| const url = React.useMemo(() => { | ||
| if (!isValid) return ""; | ||
|
|
||
| try { | ||
| const detectedNetwork = network || getStellarNetwork(); | ||
|
|
||
| switch (type) { | ||
| case "transaction": | ||
| return getTransactionUrl(value, detectedNetwork, explorer); | ||
| case "account": | ||
| return getAccountUrl(value, detectedNetwork, explorer); | ||
| case "contract": | ||
| return getContractUrl(value, detectedNetwork, explorer); | ||
| default: | ||
| return ""; | ||
| } | ||
| } catch (error) { | ||
| console.error("Error generating Stellar URL:", error); | ||
| return ""; | ||
| } | ||
| }, [value, type, network, explorer, isValid]); | ||
|
|
||
| // Truncate the display value | ||
| const displayValue = React.useMemo(() => { | ||
| if (linkText) return linkText; | ||
| if (!value) return ""; | ||
| if (value.length <= maxLength) return value; | ||
|
|
||
| const start = value.slice(0, Math.ceil(maxLength / 2)); | ||
| const end = value.slice(-Math.floor(maxLength / 2)); | ||
| return `${start}...${end}`; | ||
| }, [value, maxLength, linkText]); | ||
|
|
||
| // Copy to clipboard handler | ||
| const handleCopy = async (e: React.MouseEvent) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
|
|
||
| try { | ||
| await navigator.clipboard.writeText(value); | ||
| setCopied(true); | ||
| setCopyError(false); | ||
| setTimeout(() => setCopied(false), 2000); | ||
| } catch (error) { | ||
| console.error("Failed to copy:", error); | ||
| setCopyError(true); | ||
| setTimeout(() => setCopyError(false), 2000); | ||
| } | ||
| }; | ||
|
|
||
| // Generate tooltip text | ||
| const tooltipText = React.useMemo(() => { | ||
| if (!isValid) return `Invalid ${type}`; | ||
| const prefix = tooltipPrefix || `View ${type}`; | ||
| const networkText = network || getStellarNetwork(); | ||
| return `${prefix} on ${networkText} • ${explorer}`; | ||
| }, [type, network, explorer, isValid, tooltipPrefix, value]); | ||
|
|
||
| if (!value || !isValid) { | ||
| return ( | ||
| <span | ||
| className={cn("text-muted-foreground font-mono text-sm", className)} | ||
| > | ||
| {displayValue || "Invalid"} | ||
| </span> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <TooltipProvider> | ||
| <div className={cn("inline-flex items-center gap-1", className)}> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <a | ||
| href={url} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| className={cn( | ||
| "inline-flex items-center gap-1 text-primary hover:text-primary/80", | ||
| "transition-colors duration-200", | ||
| "font-mono text-sm", | ||
| "hover:underline", | ||
| "focus:outline-none focus:ring-2 focus:ring-primary/20 focus:ring-offset-1", | ||
| )} | ||
| > | ||
| <span>{displayValue}</span> | ||
| {showExternalIcon && ( | ||
| <ExternalLink className="h-3 w-3 shrink-0" /> | ||
| )} | ||
| </a> | ||
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| <p className="text-xs">{tooltipText}</p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
|
|
||
| {showCopy && ( | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <Button | ||
| variant="ghost" | ||
| size="icon-sm" | ||
| onClick={handleCopy} | ||
| className={cn( | ||
| "h-6 w-6 shrink-0", | ||
| copied && "text-green-600", | ||
| copyError && "text-red-600", | ||
| )} | ||
| aria-label={`Copy ${type} value`} | ||
| > | ||
| {copied ? ( | ||
| <Check className="h-3 w-3" /> | ||
| ) : copyError ? ( | ||
| <span className="text-xs">!</span> | ||
| ) : ( | ||
| <Copy className="h-3 w-3" /> | ||
| )} | ||
| </Button> | ||
| </TooltipTrigger> | ||
| <TooltipContent> | ||
| <p className="text-xs"> | ||
| {copied ? "Copied!" : copyError ? "Failed" : `Copy ${type}`} | ||
| </p> | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| )} | ||
| </div> | ||
| </TooltipProvider> | ||
| ); | ||
| } | ||
|
|
||
| // Convenience components for specific types | ||
| export function TransactionLink(props: Omit<StellarLinkProps, "type">) { | ||
| return <StellarLink {...props} type="transaction" />; | ||
| } | ||
|
|
||
| export function AccountLink(props: Omit<StellarLinkProps, "type">) { | ||
| return <StellarLink {...props} type="account" />; | ||
| } | ||
|
|
||
| export function ContractLink(props: Omit<StellarLinkProps, "type">) { | ||
| return <StellarLink {...props} type="contract" />; | ||
| } | ||
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.