|
| 1 | +import { ActivityEntry } from '@/stores/activityStore'; |
| 2 | +import { stellarTxUrl, horizenTxUrl, solanaTxUrl, ckbTxUrl } from '@/lib/explorer'; |
| 3 | +import { StellarLink } from '@/components/StellarLink'; |
| 4 | + |
| 5 | +interface ActivityRowProps { |
| 6 | + entry: ActivityEntry; |
| 7 | +} |
| 8 | + |
| 9 | +export function ActivityRow({ entry }: ActivityRowProps) { |
| 10 | + const isStellarAccount = |
| 11 | + entry.chain === 'stellar' && !!entry.recipient && /^[GM][A-Z2-7]+$/.test(entry.recipient); |
| 12 | + const getExplorerUrl = () => { |
| 13 | + switch (entry.chain) { |
| 14 | + case 'stellar': |
| 15 | + return stellarTxUrl(entry.id); |
| 16 | + case 'horizen': |
| 17 | + return horizenTxUrl(entry.id); |
| 18 | + case 'solana': |
| 19 | + return solanaTxUrl(entry.id); |
| 20 | + case 'ckb': |
| 21 | + return ckbTxUrl(entry.id); |
| 22 | + default: |
| 23 | + return '#'; |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + const getChainIcon = () => { |
| 28 | + switch (entry.chain) { |
| 29 | + case 'stellar': |
| 30 | + return ( |
| 31 | + <svg className="h-4 w-4" viewBox="0 0 16 16" fill="currentColor"> |
| 32 | + <circle cx="8" cy="8" r="7" fill="currentColor" opacity="0.2" /> |
| 33 | + <path d="M8 2L9.5 6.5L14 8L9.5 9.5L8 14L6.5 9.5L2 8L6.5 6.5L8 2Z" fill="currentColor" /> |
| 34 | + </svg> |
| 35 | + ); |
| 36 | + case 'horizen': |
| 37 | + return ( |
| 38 | + <svg className="h-4 w-4" viewBox="0 0 16 16" fill="currentColor"> |
| 39 | + <circle cx="8" cy="8" r="7" fill="currentColor" opacity="0.2" /> |
| 40 | + <path |
| 41 | + d="M8 3V13M5 6L8 3L11 6M5 10L8 13L11 10" |
| 42 | + stroke="currentColor" |
| 43 | + strokeWidth="1.5" |
| 44 | + strokeLinecap="round" |
| 45 | + /> |
| 46 | + </svg> |
| 47 | + ); |
| 48 | + case 'solana': |
| 49 | + return ( |
| 50 | + <svg className="h-4 w-4" viewBox="0 0 16 16" fill="currentColor"> |
| 51 | + <circle cx="8" cy="8" r="7" fill="currentColor" opacity="0.2" /> |
| 52 | + <path |
| 53 | + d="M3 8H13M8 3V13" |
| 54 | + stroke="currentColor" |
| 55 | + strokeWidth="1.5" |
| 56 | + strokeLinecap="round" |
| 57 | + /> |
| 58 | + </svg> |
| 59 | + ); |
| 60 | + case 'ckb': |
| 61 | + return ( |
| 62 | + <svg className="h-4 w-4" viewBox="0 0 16 16" fill="currentColor"> |
| 63 | + <circle cx="8" cy="8" r="7" fill="currentColor" opacity="0.2" /> |
| 64 | + <rect x="5" y="5" width="6" height="6" rx="1" fill="currentColor" /> |
| 65 | + </svg> |
| 66 | + ); |
| 67 | + default: |
| 68 | + return null; |
| 69 | + } |
| 70 | + }; |
| 71 | + |
| 72 | + return ( |
| 73 | + <div className="group flex flex-col gap-3 rounded-xl border border-outline-variant bg-surface-container p-4 transition-colors hover:border-outline"> |
| 74 | + <div className="flex items-center justify-between gap-4"> |
| 75 | + <div className="flex items-center gap-2"> |
| 76 | + {getChainIcon()} |
| 77 | + <span |
| 78 | + className={`h-2 w-2 rounded-full ${ |
| 79 | + entry.status === 'confirmed' |
| 80 | + ? 'bg-secondary' |
| 81 | + : entry.status === 'pending' |
| 82 | + ? 'bg-tertiary animate-pulse' |
| 83 | + : 'bg-error' |
| 84 | + }`} |
| 85 | + /> |
| 86 | + <span className="font-mono text-[10px] uppercase tracking-widest text-on-surface"> |
| 87 | + {entry.status} • {entry.kind.replace('-', ' ')} |
| 88 | + </span> |
| 89 | + </div> |
| 90 | + <span className="font-mono text-[10px] text-outline"> |
| 91 | + {new Date(entry.timestamp).toLocaleString()} |
| 92 | + </span> |
| 93 | + </div> |
| 94 | + |
| 95 | + <div className="flex flex-col gap-1"> |
| 96 | + <div className="flex items-center justify-between gap-4"> |
| 97 | + <span className="font-mono text-[10px] uppercase tracking-widest text-outline"> |
| 98 | + Direction |
| 99 | + </span> |
| 100 | + <span className="font-mono text-[10px] text-on-surface"> |
| 101 | + {entry.direction === 'in' ? 'Incoming (Received)' : 'Outgoing (Sent)'} |
| 102 | + </span> |
| 103 | + </div> |
| 104 | + |
| 105 | + {entry.amount && ( |
| 106 | + <div className="flex items-center justify-between gap-4"> |
| 107 | + <span className="font-mono text-[10px] uppercase tracking-widest text-outline"> |
| 108 | + Amount |
| 109 | + </span> |
| 110 | + <span className="font-mono text-[10px] text-on-surface"> |
| 111 | + {entry.amount} {entry.token || 'XLM'} |
| 112 | + </span> |
| 113 | + </div> |
| 114 | + )} |
| 115 | + |
| 116 | + {entry.recipient && ( |
| 117 | + <div className="flex items-center justify-between gap-4"> |
| 118 | + <span className="font-mono text-[10px] uppercase tracking-widest text-outline"> |
| 119 | + Recipient / Address |
| 120 | + </span> |
| 121 | + {isStellarAccount ? ( |
| 122 | + <StellarLink |
| 123 | + value={entry.recipient!} |
| 124 | + type="account" |
| 125 | + className="max-w-[240px]" |
| 126 | + linkClassName="text-[10px]" |
| 127 | + /> |
| 128 | + ) : ( |
| 129 | + <span |
| 130 | + className="max-w-[200px] truncate font-mono text-[10px] text-on-surface" |
| 131 | + title={entry.recipient} |
| 132 | + > |
| 133 | + {entry.recipient.length > 30 |
| 134 | + ? `${entry.recipient.slice(0, 12)}...${entry.recipient.slice(-12)}` |
| 135 | + : entry.recipient} |
| 136 | + </span> |
| 137 | + )} |
| 138 | + </div> |
| 139 | + )} |
| 140 | + |
| 141 | + {entry.kind !== 'stealth-receive' && ( |
| 142 | + <div className="flex items-center justify-between gap-4"> |
| 143 | + <span className="font-mono text-[10px] uppercase tracking-widest text-outline"> |
| 144 | + Hash |
| 145 | + </span> |
| 146 | + {entry.chain === 'stellar' ? ( |
| 147 | + <StellarLink value={entry.id} type="tx" linkClassName="text-[10px]" /> |
| 148 | + ) : ( |
| 149 | + <a |
| 150 | + href={getExplorerUrl()} |
| 151 | + target="_blank" |
| 152 | + rel="noopener noreferrer" |
| 153 | + className="font-mono text-[10px] text-tertiary hover:underline" |
| 154 | + > |
| 155 | + {entry.id.slice(0, 12)}...{entry.id.slice(-12)} |
| 156 | + </a> |
| 157 | + )} |
| 158 | + </div> |
| 159 | + )} |
| 160 | + </div> |
| 161 | + </div> |
| 162 | + ); |
| 163 | +} |
0 commit comments