From e6f3d2bcf8009d317180c4d3aa5ee5854c5899e2 Mon Sep 17 00:00:00 2001 From: vsecoder Date: Sat, 18 Apr 2026 23:49:33 +0300 Subject: [PATCH] =?UTF-8?q?feat(client):=20transaction=20detail=20screen?= =?UTF-8?q?=20(wallet=20history=20=E2=86=92=20tap=20to=20inspect)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Users can now tap any row in the wallet history and see the full transaction detail, matching what the block explorer shows for the same tx. Covers every visible activity — transfers, contact requests, likes, posts, follows, relay proofs, contract calls. Components lib/api.ts - New TxDetail interface mirroring node/api_explorer.go's txDetail JSON (id, type, from/to + their DC addresses, µT amount + display string, fee, block coords, gas, payload, signature hex). - getTxDetail(txID) with 404→null handling. app/(app)/tx/[id].tsx — new screen - Hero row: icon + type label + local-time timestamp - Big amount pill (only for txs that move tokens) — signed by the viewer's perspective (+ when you received, − when you paid, neutral when it's someone else's tx or a non-transfer) - Info card rows with tap-to-copy on hashes and addresses: Tx ID, From (highlighted "you" when it's the signed-in user), To (same), Block, Fee, Gas used (when > 0), Memo (when set) - Collapsible Payload section — renders JSON with 2-space indent if the node could decode it, otherwise the raw hex - Signature copy row at the bottom (useful for debugging / audits) - txMeta() covers all EventTypes from blockchain/types.go (TRANSFER, CONTACT_REQUEST/ACCEPT/BLOCK, REGISTER_KEY/RELAY, BIND_WALLET, RELAY_PROOF, BLOCK_REWARD, HEARTBEAT, CREATE_POST, DELETE_POST, LIKE_POST/UNLIKE_POST, FOLLOW/UNFOLLOW, CALL_CONTRACT, DEPLOY_CONTRACT, STAKE/UNSTAKE) with distinct icons + in/out/neutral tone. - Nested Stack layout so router.back() pops to the caller; safeBack() fallback when entered via deep link. app/(app)/wallet.tsx - TxTile's outer Pressable was a no-op onPress handler; now router.push(`/(app)/tx/${tx.hash}`). Entire row is the touch target (icon + type + addr + time + amount). app/(app)/_layout.tsx - /tx/* added to hideNav regex so the detail screen is full-screen without the 5-icon bar at the bottom. Translation quirk The screen is English to match the rest of the UI (what the user just asked for in the previous commit). Handles copying via expo-clipboard — tapping an address/hash shows "Copied" for 1.5s with a green check, then reverts. Co-Authored-By: Claude Opus 4.7 (1M context) --- client-app/app/(app)/_layout.tsx | 4 +- client-app/app/(app)/tx/[id].tsx | 427 ++++++++++++++++++++++++++++ client-app/app/(app)/tx/_layout.tsx | 19 ++ client-app/app/(app)/wallet.tsx | 3 +- client-app/lib/api.ts | 37 +++ 5 files changed, 488 insertions(+), 2 deletions(-) create mode 100644 client-app/app/(app)/tx/[id].tsx create mode 100644 client-app/app/(app)/tx/_layout.tsx diff --git a/client-app/app/(app)/_layout.tsx b/client-app/app/(app)/_layout.tsx index 037004e..bda7cd5 100644 --- a/client-app/app/(app)/_layout.tsx +++ b/client-app/app/(app)/_layout.tsx @@ -36,10 +36,12 @@ export default function AppLayout() { // - chat detail // - compose (new post modal) // - feed sub-routes (post detail, hashtag search) + // - tx detail const hideNav = /^\/chats\/[^/]+/.test(pathname) || pathname === '/compose' || - /^\/feed\/.+/.test(pathname); + /^\/feed\/.+/.test(pathname) || + /^\/tx\/.+/.test(pathname); useBalance(); useContacts(); diff --git a/client-app/app/(app)/tx/[id].tsx b/client-app/app/(app)/tx/[id].tsx new file mode 100644 index 0000000..018e494 --- /dev/null +++ b/client-app/app/(app)/tx/[id].tsx @@ -0,0 +1,427 @@ +/** + * Transaction detail screen — shows everything the block explorer + * does for a single tx, so the user can audit any action they took + * (transfer, post, like, contact request) without leaving the app. + * + * Route: /(app)/tx/[id] + * + * Triggered from: wallet history (TxTile tap). Will also be reachable + * from post detail / profile timestamp once we wire those up (Phase + * v2.1 idea). + * + * Layout matches the style of the profile info card: + * [back] Transaction + * + * [ICON] + * · + * + * [amount pill, big, signed ± + tone colour] (for TRANSFER-ish) + * + * Info card rows: + * ID (tap → copy) + * From (tap → copy) + * To (tap → copy) + * Block #N + * Time + * Fee 0.001 T + * Gas 1234 (if CALL_CONTRACT) + * Memo (if set) + * + * [payload section, collapsible — raw JSON or hex] + */ +import React, { useCallback, useEffect, useState } from 'react'; +import { + View, Text, ScrollView, ActivityIndicator, Pressable, +} from 'react-native'; +import * as Clipboard from 'expo-clipboard'; +import { Ionicons } from '@expo/vector-icons'; +import { useLocalSearchParams } from 'expo-router'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; + +import { Header } from '@/components/Header'; +import { IconButton } from '@/components/IconButton'; +import { getTxDetail, type TxDetail } from '@/lib/api'; +import { useStore } from '@/lib/store'; +import { safeBack, formatAmount } from '@/lib/utils'; + +function shortAddr(a: string, n = 8): string { + if (!a) return '—'; + return a.length <= n * 2 + 1 ? a : `${a.slice(0, n)}…${a.slice(-n)}`; +} + +// Copy of the tx-type metadata used by wallet.tsx — keeps the icon + +// label consistent whichever screen surfaces the tx. +function txMeta(type: string): { + icon: React.ComponentProps['name']; + label: string; + tone: 'in' | 'out' | 'neutral'; +} { + switch (type) { + case 'TRANSFER': return { icon: 'swap-horizontal', label: 'Transfer', tone: 'neutral' }; + case 'CONTACT_REQUEST': return { icon: 'person-add', label: 'Contact request', tone: 'out' }; + case 'ACCEPT_CONTACT': return { icon: 'checkmark-circle', label: 'Accepted contact', tone: 'neutral' }; + case 'BLOCK_CONTACT': return { icon: 'ban', label: 'Blocked contact', tone: 'neutral' }; + case 'REGISTER_KEY': return { icon: 'key', label: 'Identity registered', tone: 'neutral' }; + case 'REGISTER_RELAY': return { icon: 'globe', label: 'Relay registered', tone: 'neutral' }; + case 'BIND_WALLET': return { icon: 'wallet', label: 'Wallet bound', tone: 'neutral' }; + case 'RELAY_PROOF': return { icon: 'receipt', label: 'Relay proof', tone: 'in' }; + case 'BLOCK_REWARD': return { icon: 'trophy', label: 'Block reward', tone: 'in' }; + case 'HEARTBEAT': return { icon: 'pulse', label: 'Heartbeat', tone: 'neutral' }; + case 'CREATE_POST': return { icon: 'newspaper', label: 'Post published', tone: 'out' }; + case 'DELETE_POST': return { icon: 'trash', label: 'Post deleted', tone: 'neutral' }; + case 'LIKE_POST': return { icon: 'heart', label: 'Like', tone: 'neutral' }; + case 'UNLIKE_POST': return { icon: 'heart-dislike', label: 'Unlike', tone: 'neutral' }; + case 'FOLLOW': return { icon: 'person-add', label: 'Follow', tone: 'neutral' }; + case 'UNFOLLOW': return { icon: 'person-remove', label: 'Unfollow', tone: 'neutral' }; + case 'CALL_CONTRACT': return { icon: 'terminal', label: 'Contract call', tone: 'neutral' }; + case 'DEPLOY_CONTRACT': return { icon: 'cube', label: 'Contract deployed', tone: 'neutral' }; + case 'STAKE': return { icon: 'lock-closed', label: 'Stake', tone: 'out' }; + case 'UNSTAKE': return { icon: 'lock-open', label: 'Unstake', tone: 'in' }; + default: return { icon: 'document', label: type || 'Transaction', tone: 'neutral' }; + } +} + +function toneColor(tone: 'in' | 'out' | 'neutral'): string { + if (tone === 'in') return '#3ba55d'; + if (tone === 'out') return '#f4212e'; + return '#ffffff'; +} + +export default function TxDetailScreen() { + const insets = useSafeAreaInsets(); + const { id } = useLocalSearchParams<{ id: string }>(); + const keyFile = useStore(s => s.keyFile); + + const [tx, setTx] = useState(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const [copied, setCopied] = useState(null); + const [payloadOpen, setPayloadOpen] = useState(false); + + useEffect(() => { + if (!id) return; + let cancelled = false; + setLoading(true); + setError(null); + getTxDetail(id) + .then(res => { if (!cancelled) setTx(res); }) + .catch(e => { if (!cancelled) setError(String(e?.message ?? e)); }) + .finally(() => { if (!cancelled) setLoading(false); }); + return () => { cancelled = true; }; + }, [id]); + + const copy = useCallback(async (field: string, value: string) => { + await Clipboard.setStringAsync(value); + setCopied(field); + setTimeout(() => setCopied(f => (f === field ? null : f)), 1500); + }, []); + + const meta = tx ? txMeta(tx.type) : null; + const mine = keyFile?.pub_key ?? ''; + const isMineOut = tx ? tx.from === mine && tx.to !== mine : false; + const isMineIn = tx ? tx.to === mine && tx.from !== mine : false; + const showAmount = tx ? tx.amount_ut > 0 : false; + // Sign based on perspective: money leaving my wallet → minus, coming in → plus. + const sign = isMineOut ? '−' : isMineIn ? '+' : ''; + const amountColor = + isMineOut ? '#f4212e' + : isMineIn ? '#3ba55d' + : '#ffffff'; + + return ( + +
safeBack()} />} + /> + + {loading ? ( + + + + ) : error ? ( + + {error} + + ) : !tx ? ( + + + + Not found + + + No transaction with this ID on this chain. + + + ) : ( + + {/* ── Hero row: icon + type + time ───────────────────────── */} + + + + + + + {meta!.label} + + + {new Date(tx.time).toLocaleString()} + + + + + {/* ── Amount big number — only for txs that move tokens ── */} + {showAmount && ( + + + {sign}{formatAmount(tx.amount_ut)} + + + {tx.amount} + + + )} + + {/* ── Info card ───────────────────────────────────────────── */} + + + + + {tx.to && ( + <> + + + + )} + + + + + {tx.gas_used ? ( + <> + + + + ) : null} + {tx.memo ? ( + <> + + + + ) : null} + + + {/* ── Payload expand ─────────────────────────────────────── */} + {(tx.payload || tx.payload_hex) && ( + + setPayloadOpen(o => !o)} + style={({ pressed }) => ({ + flexDirection: 'row', + alignItems: 'center', + paddingVertical: 10, + paddingHorizontal: 14, + backgroundColor: pressed ? '#0f0f0f' : '#0a0a0a', + borderWidth: 1, borderColor: '#1f1f1f', + borderRadius: 14, + })} + > + + + Payload + + + + {payloadOpen && ( + + + {tx.payload + ? JSON.stringify(tx.payload, null, 2) + : `hex: ${tx.payload_hex}`} + + + )} + + )} + + {/* Signature as a final copyable row, small */} + {tx.signature_hex && ( + + + + )} + + )} + + ); +} + +// ── Rows ────────────────────────────────────────────────────────────── + +function Divider() { + return ; +} + +function InfoRow({ label, value }: { label: string; value: string }) { + return ( + + {label} + + {value} + + + ); +} + +function CopyRow({ + label, value, rawValue, field, copied, onCopy, mono, highlight, +}: { + label: string; + value: string; + rawValue: string; + field: string; + copied: string | null; + onCopy: (field: string, value: string) => void; + mono?: boolean; + highlight?: 'you'; +}) { + const isCopied = copied === field; + return ( + onCopy(field, rawValue)} + style={({ pressed }) => ({ + flexDirection: 'row', + alignItems: 'center', + paddingHorizontal: 14, + paddingVertical: 12, + backgroundColor: pressed ? '#0f0f0f' : 'transparent', + })} + > + {label} + + {isCopied + ? 'Copied' + : highlight === 'you' + ? `${value} (you)` + : value} + + + + ); +} diff --git a/client-app/app/(app)/tx/_layout.tsx b/client-app/app/(app)/tx/_layout.tsx new file mode 100644 index 0000000..ee15a2d --- /dev/null +++ b/client-app/app/(app)/tx/_layout.tsx @@ -0,0 +1,19 @@ +/** + * Tx detail layout — native Stack so router.back() pops back to the + * screen that pushed us (wallet history, chat tx link, etc.) instead + * of falling through to the outer Slot-level root. + */ +import React from 'react'; +import { Stack } from 'expo-router'; + +export default function TxLayout() { + return ( + + ); +} diff --git a/client-app/app/(app)/wallet.tsx b/client-app/app/(app)/wallet.tsx index 33c5393..1e45f52 100644 --- a/client-app/app/(app)/wallet.tsx +++ b/client-app/app/(app)/wallet.tsx @@ -17,6 +17,7 @@ import { View, Text, ScrollView, Modal, Alert, RefreshControl, Pressable, TextInput, ActivityIndicator, } from 'react-native'; import * as Clipboard from 'expo-clipboard'; +import { router } from 'expo-router'; import { Ionicons } from '@expo/vector-icons'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; @@ -346,7 +347,7 @@ function TxTile({ const color = toneColor(m.tone); return ( - + router.push(`/(app)/tx/${tx.hash}` as never)}> { + try { + return await get(`/api/tx/${txID}`); + } catch (e: any) { + if (/→\s*404\b/.test(String(e?.message))) return null; + throw e; + } +} + export async function getTxHistory(pubkey: string, limit = 50): Promise { const data = await get(`/api/address/${pubkey}?limit=${limit}`); return (data.transactions ?? []).map(tx => ({