Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/components/ErrorBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Pressable, StyleSheet, Text, View } from "react-native";
import { colors, spacing } from "../theme";

interface ErrorBannerProps {
message: string;
onRetry: () => void;
}

export function ErrorBanner({ message, onRetry }: ErrorBannerProps) {
return (
<View style={styles.container}>
<Text style={styles.message}>{message}</Text>
<Pressable onPress={onRetry} style={styles.retryButton}>
<Text style={styles.retryText}>Retry</Text>
</Pressable>
</View>
);
}

const styles = StyleSheet.create({
container: {
borderRadius: 12,
borderWidth: 1,
borderColor: "#fecaca",
backgroundColor: "#fef2f2",
padding: spacing.md,
gap: spacing.sm,
},
message: {
color: colors.danger,
fontSize: 14,
},
retryButton: {
alignSelf: "flex-start",
borderRadius: 8,
backgroundColor: colors.danger,
paddingHorizontal: 12,
paddingVertical: 8,
minHeight: 44,
minWidth: 44,
justifyContent: "center",
alignItems: "center",
},
retryText: {
color: "#ffffff",
fontWeight: "600",
fontSize: 13,
},
});
17 changes: 8 additions & 9 deletions src/components/RegisterModal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState } from "react";
import {
ActivityIndicator,
Linking,
Modal,
Pressable,
ScrollView,
Expand All @@ -13,6 +12,7 @@ import {
import { prepareRegister, submitRegister } from "../api/resources";
import type { Resource } from "../types";
import { colors, shared, typography } from "../theme";
import { openExternalUrl, stellarExpertTxUrl } from "../utils/stellarExpert";

interface RegisterModalProps {
visible: boolean;
Expand Down Expand Up @@ -86,11 +86,8 @@ export function RegisterModal({

function handleOpenExplorer() {
if (!txHash) return;
// Stellar testnet explorer - update for mainnet if needed
const explorerUrl = `https://stellar.expert/explorer/testnet/tx/${txHash}`;
Linking.openURL(explorerUrl).catch(() => {
onError("Failed to open explorer");
});
const explorerUrl = stellarExpertTxUrl({ txHash });
openExternalUrl(explorerUrl).catch(() => onError("Failed to open explorer"));
}

function handleClose() {
Expand Down Expand Up @@ -148,9 +145,11 @@ export function RegisterModal({
<Text style={[typography.body, styles.successText]}>✓ Registration successful!</Text>
<View style={styles.txHashContainer}>
<Text style={typography.caption}>Transaction Hash:</Text>
<Text style={[typography.caption, styles.txHash]} numberOfLines={1}>
{txHash}
</Text>
<Pressable onPress={handleOpenExplorer}>
<Text style={[typography.caption, styles.txHash]} numberOfLines={1}>
{txHash}
</Text>
</Pressable>
</View>
</View>
<View style={styles.actions}>
Expand Down
17 changes: 14 additions & 3 deletions src/components/TransferOwnershipModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { colors, shared, spacing, typography } from "../theme";
import { useTransferOwnership } from "../hooks/useTransferOwnership";
import type { Resource } from "../types";
import { openExternalUrl, stellarExpertTxUrl } from "../utils/stellarExpert";

interface TransferOwnershipModalProps {
resource: Resource;
Expand Down Expand Up @@ -47,6 +48,14 @@ export function TransferOwnershipModal({
const isProcessing = ["preparing", "signing", "submitting"].includes(step);
const isDone = step === "done";

function handleOpenExplorer() {
if (!txHash) return;
const url = stellarExpertTxUrl({ txHash });
openExternalUrl(url).catch(() => {
// no-op; this modal doesn't have an error callback and should remain usable
});
}

function handleClose() {
reset();
onClose();
Expand Down Expand Up @@ -133,9 +142,11 @@ export function TransferOwnershipModal({
<View style={styles.successContainer}>
<Text style={styles.successText}>✓ {STEP_LABELS.done}</Text>
{txHash ? (
<Text style={styles.txHash} numberOfLines={1} ellipsizeMode="middle">
Tx: {txHash}
</Text>
<Pressable onPress={handleOpenExplorer}>
<Text style={styles.txHash} numberOfLines={1} ellipsizeMode="middle">
Tx: {txHash}
</Text>
</Pressable>
) : null}
<Pressable
onPress={handleSuccess}
Expand Down
32 changes: 2 additions & 30 deletions src/screens/CatalogScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { StatusBar } from "expo-status-bar";
import type { NativeStackNavigationProp } from "@react-navigation/native-stack";

import { fetchCatalog, fetchRegistryStatus, getApiBaseUrl } from "../api/resources";
import { ErrorBanner } from "../components/ErrorBanner";
import { ResourceCard } from "../components/ResourceCard";
import { SkeletonCard } from "../components/SkeletonCard";
import type { RootStackParamList } from "../navigation";
Expand Down Expand Up @@ -128,12 +129,7 @@ export function CatalogScreen({ navigation }: CatalogScreenProps) {
<Text style={styles.apiHint}>API: {getApiBaseUrl()}</Text>

{error ? (
<View style={styles.errorBanner}>
<Text style={styles.errorText}>{error}</Text>
<Pressable onPress={() => void loadData()} style={styles.retryButton}>
<Text style={styles.retryText}>Retry</Text>
</Pressable>
</View>
<ErrorBanner message={error} onRetry={() => void loadData()} />
) : null}

{loading ? (
Expand Down Expand Up @@ -198,30 +194,6 @@ const styles = StyleSheet.create({
fontSize: 11,
color: colors.textSubtle,
},
errorBanner: {
borderRadius: 12,
borderWidth: 1,
borderColor: "#fecaca",
backgroundColor: "#fef2f2",
padding: spacing.md,
gap: spacing.sm,
},
errorText: {
color: colors.danger,
fontSize: 14,
},
retryButton: {
alignSelf: "flex-start",
borderRadius: 8,
backgroundColor: colors.danger,
paddingHorizontal: 12,
paddingVertical: 8,
},
retryText: {
color: "#ffffff",
fontWeight: "600",
fontSize: 13,
},
skeletons: {
gap: 12,
},
Expand Down
44 changes: 41 additions & 3 deletions src/screens/ResourceDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { fetchResource } from "../api/resources";
import type { RootStackParamList } from "../navigation";
import type { Resource } from "../types";
import { colors, shared, spacing, typography } from "../theme";
import { openExternalUrl, stellarExpertAccountUrl, stellarExpertTxUrl } from "../utils/stellarExpert";

type Props = NativeStackScreenProps<RootStackParamList, "ResourceDetail">;

Expand Down Expand Up @@ -90,6 +91,18 @@ export function ResourceDetailScreen({ route, navigation }: Props) {
}
}

function handleOpenOwner() {
if (!resource) return;
const url = stellarExpertAccountUrl({ accountId: resource.walletAddress });
openExternalUrl(url).catch(() => setToast("Unable to open explorer"));
}

function handleOpenTx() {
if (!resource?.onchainTxHash) return;
const url = stellarExpertTxUrl({ txHash: resource.onchainTxHash });
openExternalUrl(url).catch(() => setToast("Unable to open explorer"));
}

if (loading) {
return (
<SafeAreaView style={shared.screen} edges={["bottom"]}>
Expand Down Expand Up @@ -152,11 +165,28 @@ export function ResourceDetailScreen({ route, navigation }: Props) {

<View style={styles.infoRow}>
<Text style={styles.label}>Owner</Text>
<Text style={typography.body}>
{shortenAddress(resource.walletAddress)}
</Text>
<Pressable onPress={handleOpenOwner}>
<Text style={[typography.body, styles.linkText]}>
{shortenAddress(resource.walletAddress)}
</Text>
</Pressable>
</View>

{resource.onchainTxHash ? (
<View style={styles.infoRow}>
<Text style={styles.label}>Tx</Text>
<Pressable onPress={handleOpenTx}>
<Text
style={[typography.body, styles.linkText, styles.mono]}
numberOfLines={1}
ellipsizeMode="middle"
>
{resource.onchainTxHash}
</Text>
</Pressable>
</View>
) : null}

<View style={styles.infoRow}>
<Text style={styles.label}>Type</Text>
<Text style={typography.body}>{resource.resourceType}</Text>
Expand Down Expand Up @@ -239,6 +269,14 @@ const styles = StyleSheet.create({
color: colors.textSubtle,
lineHeight: 18,
},
linkText: {
color: colors.primary,
},
mono: {
fontFamily: "monospace",
fontSize: 12,
maxWidth: 220,
},
toast: {
position: "absolute",
bottom: spacing.xl,
Expand Down
62 changes: 62 additions & 0 deletions src/utils/stellarExpert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Constants from "expo-constants";
import { Linking } from "react-native";

type StellarExpertNetworkSegment = "testnet" | "public";

const DEFAULT_NETWORK_PASSPHRASE =
(Constants.expoConfig?.extra?.networkPassphrase as string | undefined) ??
"Test SDF Network ; September 2015";

function normalizeNetwork(input?: string): string | null {
const value = input?.trim().toLowerCase();
return value && value.length > 0 ? value : null;
}

function networkSegmentFromNetworkName(network?: string): StellarExpertNetworkSegment | null {
const n = normalizeNetwork(network);
if (!n) return null;

if (n.includes("test")) return "testnet";
if (n.includes("public") || n.includes("mainnet") || n.includes("main")) return "public";

return null;
}

function networkSegmentFromPassphrase(passphrase?: string): StellarExpertNetworkSegment {
const p = normalizeNetwork(passphrase) ?? normalizeNetwork(DEFAULT_NETWORK_PASSPHRASE) ?? "";

if (p.includes("test sdf network")) return "testnet";
if (p.includes("public global stellar network")) return "public";

// Default to testnet to match current app defaults.
return "testnet";
}

export function stellarExpertTxUrl(opts: {
txHash: string;
network?: string;
networkPassphrase?: string;
}): string {
const segment =
networkSegmentFromNetworkName(opts.network) ??
networkSegmentFromPassphrase(opts.networkPassphrase);
return `https://stellar.expert/explorer/${segment}/tx/${encodeURIComponent(opts.txHash)}`;
}

export function stellarExpertAccountUrl(opts: {
accountId: string;
network?: string;
networkPassphrase?: string;
}): string {
const segment =
networkSegmentFromNetworkName(opts.network) ??
networkSegmentFromPassphrase(opts.networkPassphrase);
return `https://stellar.expert/explorer/${segment}/account/${encodeURIComponent(opts.accountId)}`;
}

export async function openExternalUrl(url: string): Promise<void> {
const canOpen = await Linking.canOpenURL(url);
if (!canOpen) throw new Error("Cannot open URL");
await Linking.openURL(url);
}

Loading