diff --git a/apps/api/src/public-trace/public-mint-view.spec.ts b/apps/api/src/public-trace/public-mint-view.spec.ts new file mode 100644 index 0000000..1a8308c --- /dev/null +++ b/apps/api/src/public-trace/public-mint-view.spec.ts @@ -0,0 +1,26 @@ +import { readMintView } from './public-mint-view'; + +describe('readMintView', () => { + it('uses the frozen mint fields and ignores the rest of the raw response', () => { + const view = readMintView({ + product: { productId: '154109005352', author: '黄志伟', feature: 'https://art.qclh.xyz/uploads/a.png' }, + confirmation: { appKey: 'secret' }, + }, '154109005352', '后来改名', '0xae3ecbac36b5874b0372686e5b88894c22be4296'); + expect(view).toEqual({ + author: '黄志伟', + productId: '154109005352', + feature: 'https://art.qclh.xyz/uploads/a.png', + mintTo: '0xae3ecbac36b5874b0372686e5b88894c22be4296', + }); + expect(JSON.stringify(view)).not.toContain('secret'); + }); + + it('falls back to the artwork artist and short code when the snapshot is missing', () => { + expect(readMintView(null, '734648008702', '黄志伟', 'not-an-address')).toEqual({ + author: '黄志伟', + productId: '734648008702', + feature: null, + mintTo: null, + }); + }); +}); \ No newline at end of file diff --git a/apps/api/src/public-trace/public-mint-view.ts b/apps/api/src/public-trace/public-mint-view.ts new file mode 100644 index 0000000..6340f5e --- /dev/null +++ b/apps/api/src/public-trace/public-mint-view.ts @@ -0,0 +1,23 @@ +export interface PublicMintView { + author: string | null; + productId: string; + feature: string | null; + mintTo: string | null; +} + +function text(row: Record, key: string): string | null { + const value = row[key]; + return typeof value === 'string' && value.trim() ? value.trim() : null; +} + +/** 只取出发行时保存的产品字段,不把原始响应里的其他内容交给浏览器。 */ +export function readMintView(raw: unknown, shortCode: string, artist: string | null, wallet: string | null): PublicMintView { + const product = raw && typeof raw === 'object' ? (raw as { product?: unknown }).product : null; + const row = product && typeof product === 'object' ? product as Record : {}; + return { + author: text(row, 'author') || artist?.trim() || null, + productId: text(row, 'productId') || shortCode, + feature: text(row, 'feature'), + mintTo: wallet && /^0x[0-9a-fA-F]{40}$/.test(wallet) ? wallet : null, + }; +} diff --git a/apps/api/src/public-trace/public-trace.service.spec.ts b/apps/api/src/public-trace/public-trace.service.spec.ts index 008b67a..541b81d 100644 --- a/apps/api/src/public-trace/public-trace.service.spec.ts +++ b/apps/api/src/public-trace/public-trace.service.spec.ts @@ -96,7 +96,8 @@ function createHarness(options: { set: jest.fn().mockResolvedValue('OK'), }; const storage = { getUrl: jest.fn((key: string) => `/uploads/${key}`) }; - const service = new PublicTraceService(prisma as any, storage as any, redis as any); + const settings = { get: jest.fn().mockResolvedValue(null) }; + const service = new PublicTraceService(prisma as any, storage as any, redis as any, settings as any); return { service, prisma }; } diff --git a/apps/api/src/public-trace/public-trace.service.ts b/apps/api/src/public-trace/public-trace.service.ts index 83886c4..1d49773 100644 --- a/apps/api/src/public-trace/public-trace.service.ts +++ b/apps/api/src/public-trace/public-trace.service.ts @@ -15,8 +15,10 @@ import { } from '@artveris/shared'; import { PrismaService } from '../prisma/prisma.service'; import { StorageService } from '../storage/storage.service'; +import { SettingsService } from '../settings/settings.service'; import { REDIS_CLIENT } from '../redis/redis.module'; import { parseUserAgent } from '../common/utils/ua.util'; +import { readMintView } from './public-mint-view'; type TraceCodeWithRel = Prisma.TraceCodeGetPayload<{ include: { batch: true; artwork: true } }>; type ArtworkWithRel = Prisma.ArtworkGetPayload<{ @@ -44,6 +46,7 @@ export class PublicTraceService { private readonly prisma: PrismaService, private readonly storage: StorageService, @Inject(REDIS_CLIENT) private readonly redis: Redis, + private readonly settings: SettingsService, ) {} private mapMedia( @@ -265,6 +268,7 @@ export class PublicTraceService { const updated = await this.prisma.traceCode.findUniqueOrThrow({ where: { id } }); const proof = await this.prisma.blockchainProof.findUnique({ where: { traceCodeId: id } }); + const mintTo = await this.mintRecipient(proof); const result = firstActivate ? QueryResult.FIRST_ACTIVATE : QueryResult.REPEAT; await this.writeLog(id, artwork.id, shortCode, result, ctx, { ...code, ...updated }); @@ -276,7 +280,7 @@ export class PublicTraceService { queryCount: updated.queryCount, firstActivatedAt: updated.firstActivatedAt, }, - ...this.buildArtworkPayload(artwork, code, proof), + ...this.buildArtworkPayload(artwork, code, proof, mintTo), }; } @@ -321,6 +325,7 @@ export class PublicTraceService { } const proof = await this.prisma.blockchainProof.findUnique({ where: { traceCodeId: id } }); + const mintTo = await this.mintRecipient(proof); const now = new Date(); const firstQuery = state === 'inactive'; @@ -335,7 +340,7 @@ export class PublicTraceService { queryCount: code.queryCount > 0 ? code.queryCount : 2, firstActivatedAt: code.firstActivatedAt ?? now, }, - ...this.buildArtworkPayload(artwork, code, proof), + ...this.buildArtworkPayload(artwork, code, proof, mintTo), }; } @@ -343,6 +348,7 @@ export class PublicTraceService { private buildArtworkPayload( artwork: ArtworkWithRel, code: { + shortCode: string; outbound?: { outTime: Date; remark: string | null; @@ -357,11 +363,15 @@ export class PublicTraceService { chainName: string | null; onchainAt: Date | null; contractAddress: string | null; + tokenId: bigint | null; + rawResponse: unknown; status: string; failureReason: string | null; submittedAt: Date | null; } | null, + mintTo: string | null, ) { + const mint = proof ? readMintView(proof.rawResponse, code.shortCode, artwork.artist, mintTo) : null; return { artwork: { title: artwork.title, @@ -407,6 +417,11 @@ export class PublicTraceService { chainName: proof.chainName, onchainAt: proof.onchainAt, contractAddress: proof.contractAddress, + tokenId: proof.tokenId === null || proof.tokenId === undefined ? null : proof.tokenId.toString(), + author: mint?.author ?? null, + productId: mint?.productId ?? code.shortCode, + feature: mint?.feature ?? null, + mintTo: mint?.mintTo ?? null, submittedAt: proof.submittedAt, failureReason: this.publicFailureReason(proof.status, proof.failureReason), } @@ -414,6 +429,12 @@ export class PublicTraceService { }; } + private async mintRecipient(proof: { chainName: string | null } | null): Promise { + if (proof?.chainName !== '天河链') return null; + const value = await this.settings.get('tianheWalletAddress'); + return typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value) ? value : null; + } + private publicFailureReason(status: string, reason: string | null): string | null { if (status === ProofStatus.UNKNOWN) return '链上结果暂时无法确认,请稍后重试或联系平台管理员'; if (status === ProofStatus.FAILED) return reason ? '上链处理失败,请联系平台管理员' : '上链处理失败'; diff --git a/apps/client/src/components/trace/TraceBlockchainModule.vue b/apps/client/src/components/trace/TraceBlockchainModule.vue index 4a56d6c..b164393 100644 --- a/apps/client/src/components/trace/TraceBlockchainModule.vue +++ b/apps/client/src/components/trace/TraceBlockchainModule.vue @@ -68,21 +68,23 @@
{{ t('chain.notOnchain') }}
- - -

{{ t('chain.proofTitle') }}

-
-
- {{ row.label }} - {{ row.value }} - -
-
+ +

{{ t('chain.proofTitle') }}

+
@@ -114,6 +116,7 @@ import { computed, onUnmounted, ref, watch } from 'vue'; import { fetchTraceCertificate, requestTraceCertificate, type TraceCertificateRecord, type TraceCertificateResult } from '@/api'; import { downloadCertificatePng } from '@/utils/certificateImage'; +import TraceTxDetail from './TraceTxDetail.vue'; import { useI18n } from 'vue-i18n'; import dayjs from 'dayjs'; @@ -139,6 +142,11 @@ const props = defineProps<{ blockHeight?: string | number | null; onchainAt?: string | null; blockHash?: string | null; + tokenId?: string | number | null; + author?: string | null; + productId?: string | null; + feature?: string | null; + mintTo?: string | null; failureReason?: string | null; chainName?: string | null; } | null; @@ -228,17 +236,6 @@ const status = computed(() => { const value = props.blockchain?.status as ProofStatus | undefined; return value && STATUSES.has(value) ? value : 'ONCHAIN'; }); -const proofRows = computed(() => { - const chain = props.blockchain; - if (!chain) return []; - return [ - { label: t('chain.hash'), value: chain.txHash || '-', copy: chain.txHash || '' }, - { label: t('chain.contract'), value: chain.contractAddress || '-', copy: chain.contractAddress || '' }, - { label: t('chain.blockHeight'), value: chain.blockHeight == null ? '-' : String(chain.blockHeight), copy: '' }, - { label: t('chain.blockHash'), value: chain.blockHash || '-', copy: chain.blockHash || '' }, - { label: t('chain.onchainAt'), value: chain.onchainAt ? formatTime(chain.onchainAt) : '-', copy: '' }, - ]; -}); const certificateRows = computed(() => { const record = certificateRecord.value; if (!record) return []; @@ -374,6 +371,9 @@ function formatTime(value?: string | null) { .chain-actions { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; } .certificate-link { margin-left: auto; padding: 0; border: 0; background: none; cursor: pointer; font-family: inherit; } .certificate-link:disabled { opacity: .55; cursor: default; } +.tx-dialog { width: min(960px, calc(100vw - 16px)); max-height: calc(100vh - 16px); padding: 0; border: 0; background: transparent; box-shadow: none; overflow: auto; } +.tx-dialog::backdrop { background: #0007; } +.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; } .certificate-dialog { width: min(420px, calc(100vw - 40px)); max-height: min(640px, calc(100vh - 48px)); box-sizing: border-box; padding: 28px; border: 1px solid var(--border); border-radius: 16px; background: var(--card-bg); color: var(--text); box-shadow: 0 16px 60px #0003; } .certificate-dialog[open] { display: flex; flex-direction: column; } .sheet-body { overflow: auto; min-height: 0; } diff --git a/apps/client/src/components/trace/TraceTxDetail.vue b/apps/client/src/components/trace/TraceTxDetail.vue new file mode 100644 index 0000000..b815db9 --- /dev/null +++ b/apps/client/src/components/trace/TraceTxDetail.vue @@ -0,0 +1,235 @@ + + + + + diff --git a/apps/client/src/locales/en-US.json b/apps/client/src/locales/en-US.json index 81989d3..12f1d0e 100644 --- a/apps/client/src/locales/en-US.json +++ b/apps/client/src/locales/en-US.json @@ -60,7 +60,24 @@ "blockHeight": "Block Height", "onchainAt": "On-chain Time", "blockHash": "Block Hash", - "proofTitle": "Attestation", + "proofTitle": "Transaction", + "txTitle": "Transaction", + "txInfo": "Details", + "txLogs": "Logs", + "txHash": "Tx Hash", + "txStatus": "Status", + "txSuccess": "Success", + "txAction": "Action", + "txIssue": "Mint NFR ID", + "txFromNull": "from Null Address:", + "txToward": "to", + "txReceiver": "Receiver", + "txTime": "Created", + "txInput": "Input", + "txName": "Name", + "txType": "Type", + "txData": "Data", + "txBack": "Back", "explorer": "View Proof", "copy": "Copy", "copied": "Copied", diff --git a/apps/client/src/locales/zh-CN.json b/apps/client/src/locales/zh-CN.json index ab9ef41..07c6ba3 100644 --- a/apps/client/src/locales/zh-CN.json +++ b/apps/client/src/locales/zh-CN.json @@ -60,7 +60,24 @@ "blockHeight": "区块高度", "onchainAt": "上链时间", "blockHash": "区块哈希", - "proofTitle": "存证详情", + "proofTitle": "交易详情", + "txTitle": "交易详情", + "txInfo": "交易信息", + "txLogs": "日志", + "txHash": "交易哈希", + "txStatus": "状态", + "txSuccess": "成功", + "txAction": "交易动作", + "txIssue": "发行 NFR ID", + "txFromNull": "从 Null Address:", + "txToward": "到", + "txReceiver": "接收方", + "txTime": "交易生成时间", + "txInput": "输入信息", + "txName": "名称", + "txType": "类型", + "txData": "数据", + "txBack": "返回", "explorer": "查看存证", "copy": "复制", "copied": "已复制",