diff --git a/packages/neuron-ui/src/components/FormattedTokenAmount/index.tsx b/packages/neuron-ui/src/components/FormattedTokenAmount/index.tsx index 4a180ba15f..b31da32d3c 100644 --- a/packages/neuron-ui/src/components/FormattedTokenAmount/index.tsx +++ b/packages/neuron-ui/src/components/FormattedTokenAmount/index.tsx @@ -12,7 +12,7 @@ type FormattedTokenAmountProps = { item: State.Transaction; show: boolean; symbo type AmountProps = Omit & { sudtAmount?: string isReceive: boolean - amount: string + amount?: string symbolClassName?: string } @@ -30,18 +30,18 @@ const Amount = ({ sudtAmount, show, item, isReceive, amount, symbolClassName, sy ) : (
- - {amount} + + {amount ?? '--'} -  {symbol} +  {amount ? symbol : ''}
) } export const FormattedTokenAmount = ({ item, show, symbolClassName }: FormattedTokenAmountProps) => { - let amount = '--' + let amount: string | undefined let sudtAmount = '' - let copyText = amount + let copyText: string | undefined = amount let isReceive = false let symbol = '' @@ -61,16 +61,22 @@ export const FormattedTokenAmount = ({ item, show, symbolClassName }: FormattedT isReceive = !sudtAmount.includes('-') } } else { - amount = show ? `${shannonToCKBFormatter(item.value, true)}` : `${HIDE_BALANCE}` - isReceive = !amount.includes('-') + amount = show + ? `${shannonToCKBFormatter(item.nervosDao ? item.daoCapacity ?? '--' : item.value, true)}` + : `${HIDE_BALANCE}` + isReceive = !amount?.includes('-') copyText = `${amount} CKB` symbol = 'CKB' + if (item.nervosDao && item.daoCapacity === undefined) { + amount = undefined + copyText = undefined + } } } const props = { sudtAmount, show, item, isReceive, amount, symbolClassName, symbol } - return show ? ( + return show && copyText ? ( diff --git a/packages/neuron-ui/src/components/History/index.tsx b/packages/neuron-ui/src/components/History/index.tsx index 6e1f19c2d3..f012415c87 100644 --- a/packages/neuron-ui/src/components/History/index.tsx +++ b/packages/neuron-ui/src/components/History/index.tsx @@ -126,7 +126,7 @@ const History = () => { sortable: true, }, { - title: t('history.table.amount'), + title: t('history.table.asset'), dataIndex: 'amount', align: 'left', isBalance: true, diff --git a/packages/neuron-ui/src/components/Overview/index.tsx b/packages/neuron-ui/src/components/Overview/index.tsx index 9ce1a0a94b..2aaf350574 100644 --- a/packages/neuron-ui/src/components/Overview/index.tsx +++ b/packages/neuron-ui/src/components/Overview/index.tsx @@ -268,7 +268,7 @@ const Overview = () => { }, }, { - title: t('overview.amount'), + title: t('overview.asset'), dataIndex: 'amount', align: 'left', isBalance: true, diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 2a90be36e6..1842c982ef 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -142,7 +142,7 @@ "activity": "Activity", "datetime": "Date & Time", "status": "Status", - "amount": "Amount", + "asset": "Asset", "address": "Address", "sent": "Sent", "sending": "Sending", @@ -313,7 +313,7 @@ "name": "Wallet Name", "type": "Type", "balance": "Balance", - "amount": "Amount", + "asset": "Asset", "timestamp": "Time", "status": "Status", "operation": "Operation" diff --git a/packages/neuron-ui/src/locales/es.json b/packages/neuron-ui/src/locales/es.json index 8c35cae3c0..3ac8e1f57f 100644 --- a/packages/neuron-ui/src/locales/es.json +++ b/packages/neuron-ui/src/locales/es.json @@ -135,7 +135,7 @@ "activity": "Actividad", "datetime": "Fecha y Hora", "status": "Estado", - "amount": "Cantidad", + "asset": "Activos", "address": "Dirección", "sent": "Enviado", "sending": "Enviando", @@ -305,7 +305,7 @@ "name": "Nombre de la Billetera", "type": "Tipo", "balance": "Saldo", - "amount": "Cantidad", + "asset": "activos", "timestamp": "Tiempo", "status": "Estado", "operation": "Operación" diff --git a/packages/neuron-ui/src/locales/fr.json b/packages/neuron-ui/src/locales/fr.json index ae9db42555..a609830ca1 100644 --- a/packages/neuron-ui/src/locales/fr.json +++ b/packages/neuron-ui/src/locales/fr.json @@ -142,7 +142,7 @@ "activity": "Activité", "datetime": "Date et heure", "status": "Statut", - "amount": "Montant", + "asset": "actifs", "address": "Adresse", "sent": "Envoyé", "sending": "Envoi", @@ -312,7 +312,7 @@ "name": "Nom du Wallet", "type": "Type", "balance": "Solde", - "amount": "Montant", + "asset": "actifs", "timestamp": "Heure", "status": "Statut", "operation": "Opération" diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index 76946f85f3..8e61fb1c5d 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -136,7 +136,7 @@ "activity": "收支活動", "datetime": "時間", "status": "狀態", - "amount": "金額", + "asset": "資產", "address": "地址", "sent": "已發送", "sending": "正在發送", @@ -308,7 +308,7 @@ "name": "錢包名稱", "type": "類型", "balance": "余額", - "amount": "金額", + "asset": "資產", "timestamp": "時間", "status": "狀態", "operation": "操作" diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 55109b76e9..d0ad40e458 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -135,7 +135,7 @@ "activity": "收支活动", "datetime": "时间", "status": "状态", - "amount": "金额", + "asset": "资产", "address": "地址", "sent": "已发送", "sending": "正在发送", @@ -306,7 +306,7 @@ "name": "钱包名称", "type": "类型", "balance": "余额", - "amount": "金额", + "asset": "资产", "timestamp": "时间", "status": "状态", "operation": "操作" diff --git a/packages/neuron-ui/src/types/App/index.d.ts b/packages/neuron-ui/src/types/App/index.d.ts index 76ce82827b..e9902f710c 100644 --- a/packages/neuron-ui/src/types/App/index.d.ts +++ b/packages/neuron-ui/src/types/App/index.d.ts @@ -19,6 +19,7 @@ declare namespace State { data: string } assetAccountType?: 'CKB' | 'sUDT' | string + daoCapacity?: string } interface DetailedInput { diff --git a/packages/neuron-wallet/src/models/chain/transaction.ts b/packages/neuron-wallet/src/models/chain/transaction.ts index 1f4a0d1223..a8942bb43c 100644 --- a/packages/neuron-wallet/src/models/chain/transaction.ts +++ b/packages/neuron-wallet/src/models/chain/transaction.ts @@ -82,6 +82,8 @@ export default class Transaction { public signatures: Signatures = {} public assetAccountType?: AssetAccountType + public daoCapacity?: string + constructor( version: string, cellDeps: CellDep[] = [], @@ -106,7 +108,8 @@ export default class Transaction { sudtInfo?: SudtInfo, nftType?: NFTInfo, signatures: Signatures = {}, - assetAccountType?: AssetAccountType + assetAccountType?: AssetAccountType, + daoCapacity?: string ) { this.cellDeps = cellDeps this.headerDeps = headerDeps @@ -133,6 +136,7 @@ export default class Transaction { this.sudtInfo = sudtInfo this.nftInfo = nftType this.signatures = signatures + this.daoCapacity = daoCapacity TypeCheckerUtils.hashChecker(...this.headerDeps, this.blockHash) TypeCheckerUtils.numberChecker( this.version, @@ -171,6 +175,7 @@ export default class Transaction { nftInfo, signatures = {}, assetAccountType, + daoCapacity, }: { version: string cellDeps?: CellDep[] @@ -196,6 +201,7 @@ export default class Transaction { nftInfo?: NFTInfo signatures?: Signatures assetAccountType?: AssetAccountType + daoCapacity?: string }): Transaction { return new Transaction( version, @@ -226,7 +232,8 @@ export default class Transaction { sudtInfo, nftInfo, signatures, - assetAccountType + assetAccountType, + daoCapacity ) } diff --git a/packages/neuron-wallet/src/services/tx/transaction-service.ts b/packages/neuron-wallet/src/services/tx/transaction-service.ts index eb5cf93dd3..8b43057ed9 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-service.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-service.ts @@ -256,6 +256,7 @@ export class TransactionsService { .addSelect('input.transactionHash', 'transactionHash') .addSelect('input.outPointTxHash', 'outPointTxHash') .addSelect('input.outPointIndex', 'outPointIndex') + .addSelect('input.data', 'data') .where( ` input.transactionHash IN (:...txHashes) AND @@ -266,7 +267,13 @@ export class TransactionsService { walletId: params.walletID, } ) - .getRawMany() + .getRawMany<{ + capacity: string + transactionHash: string + outPointTxHash: string + outPointIndex: string + data: string + }>() const outputs = await connection .getRepository(OutputEntity) @@ -284,7 +291,7 @@ export class TransactionsService { walletId: params.walletID, } ) - .getRawMany() + .getRawMany<{ capacity: string; transactionHash: string; daoData: string }>() const assetAccountInputs = await connection .getRepository(InputEntity) @@ -373,13 +380,17 @@ export class TransactionsService { ).filter(o => inputPreviousTxHashes.includes(o.txHash)) const sums = new Map() - const daoFlag = new Map() + const daoInfo = new Map() outputs.map(o => { const s = sums.get(o.transactionHash) || BigInt(0) sums.set(o.transactionHash, s + BigInt(o.capacity)) if (o.daoData) { - daoFlag.set(o.transactionHash, true) + if (daoInfo.has(o.transactionHash)) { + daoInfo.get(o.transactionHash)!.outputs.push(o) + } else { + daoInfo.set(o.transactionHash, { inputs: [], outputs: [o] }) + } } }) @@ -391,7 +402,11 @@ export class TransactionsService { return dc.txHash === i.outPointTxHash && dc.index === i.outPointIndex }) if (result) { - daoFlag.set(i.transactionHash, true) + if (daoInfo.has(i.transactionHash)) { + daoInfo.get(i.transactionHash)!.inputs.push(i) + } else { + daoInfo.set(i.transactionHash, { inputs: [i], outputs: [] }) + } } }) @@ -477,6 +492,16 @@ export class TransactionsService { nftInfo = { type: NFTType.Receive, data: receiveNFTCell.typeArgs! } } + const txDaoInfo = daoInfo.get(tx.hash) + let daoCapacity: string | undefined + if (txDaoInfo) { + if (txDaoInfo.inputs.length && !txDaoInfo.outputs.length) { + daoCapacity = txDaoInfo.inputs.reduce((pre, cur) => BigInt(cur.capacity) + pre, BigInt(value)).toString() + } else if (!txDaoInfo.inputs.length && txDaoInfo.outputs.length) { + daoCapacity = `-${txDaoInfo.outputs.reduce((pre, cur) => BigInt(cur.capacity) + pre, BigInt(0)).toString()}` + } + } + return Transaction.fromObject({ timestamp: tx.timestamp, value: value.toString(), @@ -484,7 +509,7 @@ export class TransactionsService { version: tx.version, type: txType, assetAccountType: assetAccountType, - nervosDao: daoFlag.get(tx.hash!), + nervosDao: !!txDaoInfo, status: tx.status, description: tx.description, createdAt: tx.createdAt, @@ -492,6 +517,7 @@ export class TransactionsService { blockNumber: tx.blockNumber, sudtInfo: sudtInfo, nftInfo: nftInfo, + daoCapacity, }) }) )