From 9e8c64795ba974c71b70b55064da6255a69f1c19 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 25 Mar 2024 23:53:13 +0900 Subject: [PATCH 1/4] feat: add nervos dao withdrawing type in live cells --- src/pages/Address/Cells.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/Address/Cells.tsx b/src/pages/Address/Cells.tsx index 2561d1575b..4b68a512ee 100644 --- a/src/pages/Address/Cells.tsx +++ b/src/pages/Address/Cells.tsx @@ -104,9 +104,10 @@ const Cell: FC<{ cell: LiveCell }> = ({ cell }) => { detailInfo = BigNumber(cell.capacity).toFormat({ groupSeparator: '' }) break } - case 'nervos_dao_deposit': { + case 'nervos_dao_deposit': + case 'nervos_dao_withdrawing': { icon = CKBTokenIcon - assetName = 'Nervos DAO' + assetName = assetType === 'nervos_dao_deposit' ? 'Nervos DAO' : 'Nervos DAO Withdrawing' attribute = ckb detailInfo = BigNumber(cell.capacity).toFormat({ groupSeparator: '' }) break From a110bde7f62fd98b09e97a16d508222209444705 Mon Sep 17 00:00:00 2001 From: Keith Date: Tue, 26 Mar 2024 18:32:53 +0900 Subject: [PATCH 2/4] feat: optimize display of inscription --- src/components/Capacity/index.tsx | 2 +- .../TransactionItem/TransactionItemCell/index.tsx | 11 +++++++++++ src/models/Cell/index.ts | 15 ++++++++++++++- src/pages/Transaction/TransactionCell/index.tsx | 12 ++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/components/Capacity/index.tsx b/src/components/Capacity/index.tsx index a523982751..38e01fc363 100644 --- a/src/components/Capacity/index.tsx +++ b/src/components/Capacity/index.tsx @@ -6,7 +6,7 @@ interface CapacityProps { capacity: string type?: 'value' | 'diff' layout?: 'responsive' | 'fixed' - unit?: 'CKB' | null + unit?: 'CKB' | string | null display?: 'full' | 'short' } diff --git a/src/components/TransactionItem/TransactionItemCell/index.tsx b/src/components/TransactionItem/TransactionItemCell/index.tsx index aada2f8a16..fd4d35a9cc 100644 --- a/src/components/TransactionItem/TransactionItemCell/index.tsx +++ b/src/components/TransactionItem/TransactionItemCell/index.tsx @@ -218,6 +218,17 @@ const TransactionCellCapacity = ({ cell, cellType }: { cell: Cell; cellType: Cel return } + if (cell.cellType === 'omiga_inscription') { + const info = cell.extraInfo + if (info?.amount && info.decimal && info.symbol) { + return ( +
+ +
+ ) + } + } + return (
diff --git a/src/models/Cell/index.ts b/src/models/Cell/index.ts index 0f2961d1ae..f6249c6491 100644 --- a/src/models/Cell/index.ts +++ b/src/models/Cell/index.ts @@ -81,6 +81,7 @@ export interface Cell$NoExtra extends Cell$Base { | 'spore_cluster' | 'spore_cell' | 'nrc_721_factory' + | 'omiga_inscription' extraInfo?: never } @@ -109,4 +110,16 @@ export interface Cell$Nrc721Token extends Cell$Base { extraInfo: Nrc721TokenInfo } -export type Cell = Cell$NoExtra | Cell$UDT | Cell$NftIssuer | Cell$NftClass | Cell$NftToken | Cell$Nrc721Token +export interface Omiga$XUDT extends Cell$Base { + cellType: 'omiga_inscription' + extraInfo: Record<'amount' | 'decimal' | 'name' | 'symbol', string> +} + +export type Cell = + | Cell$NoExtra + | Cell$UDT + | Cell$NftIssuer + | Cell$NftClass + | Cell$NftToken + | Cell$Nrc721Token + | Omiga$XUDT diff --git a/src/pages/Transaction/TransactionCell/index.tsx b/src/pages/Transaction/TransactionCell/index.tsx index 398cbc1203..bb94e13939 100644 --- a/src/pages/Transaction/TransactionCell/index.tsx +++ b/src/pages/Transaction/TransactionCell/index.tsx @@ -235,6 +235,12 @@ const TransactionCellDetail = ({ cell }: { cell: Cell }) => { tooltip = t('transaction.spore') break } + case 'omiga_inscription': { + detailTitle = 'xUDT' + detailIcon = UDTTokenIcon + tooltip = detailTitle + break + } default: break } @@ -285,6 +291,12 @@ const TransactionCellCapacityAmount = ({ cell }: { cell: Cell }) => { } return {`${t('udt.unknown_token')} #${udtInfo.typeHash.substring(udtInfo.typeHash.length - 4)}`} } + if (cell.cellType === 'omiga_inscription') { + const info = cell.extraInfo + if (info?.decimal && info?.amount && info?.symbol) { + return {`${parseUDTAmount(info.amount, info.decimal)} ${info.symbol}`} + } + } return } From 56af3629323b5ac2c338b68e8d09e2875c125d47 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 27 Mar 2024 04:27:34 +0900 Subject: [PATCH 3/4] fix: fix number format of xudt --- .../TransactionItem/TransactionItemCell/index.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/TransactionItem/TransactionItemCell/index.tsx b/src/components/TransactionItem/TransactionItemCell/index.tsx index fd4d35a9cc..813f525807 100644 --- a/src/components/TransactionItem/TransactionItemCell/index.tsx +++ b/src/components/TransactionItem/TransactionItemCell/index.tsx @@ -223,7 +223,11 @@ const TransactionCellCapacity = ({ cell, cellType }: { cell: Cell; cellType: Cel if (info?.amount && info.decimal && info.symbol) { return (
- +
) } From 5d4d3bcf3cc5aaf7ff708e866d6f336c932b6f10 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 28 Mar 2024 00:46:19 +0900 Subject: [PATCH 4/4] feat: update address api for compatibility with rgbpp api --- src/models/Address/index.ts | 8 ++++++- src/pages/Address/state.ts | 4 ++-- src/services/ExplorerService/fetcher.ts | 29 ++++++++++++++++++------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/models/Address/index.ts b/src/models/Address/index.ts index 4551798bb7..cec76d930c 100644 --- a/src/models/Address/index.ts +++ b/src/models/Address/index.ts @@ -8,6 +8,12 @@ export interface LockInfo { estimatedUnlockTime: string } +export enum AddressType { + Address = 'Address', + LockHash = 'LockHash', + Unknown = 'Unknown', +} + export interface Address { addressHash: string lockHash: string @@ -16,7 +22,7 @@ export interface Address { transactionsCount: number lockScript: Script pendingRewardBlocksCount: number - type: 'Address' | 'LockHash' | '' + type: AddressType daoDeposit: number interest: number daoCompensation: number diff --git a/src/pages/Address/state.ts b/src/pages/Address/state.ts index 0e3d164b2d..73388a3162 100644 --- a/src/pages/Address/state.ts +++ b/src/pages/Address/state.ts @@ -1,4 +1,4 @@ -import { Address } from '../../models/Address' +import { Address, AddressType } from '../../models/Address' export const defaultAddressInfo: Address = { addressHash: '', @@ -15,7 +15,7 @@ export const defaultAddressInfo: Address = { codeHash: '', hashType: '', }, - type: '', + type: AddressType.Unknown, lockInfo: { status: 'unlocked', epochNumber: '0', diff --git a/src/services/ExplorerService/fetcher.ts b/src/services/ExplorerService/fetcher.ts index e1dd08860e..c49e2e99a5 100644 --- a/src/services/ExplorerService/fetcher.ts +++ b/src/services/ExplorerService/fetcher.ts @@ -18,7 +18,7 @@ import { Cell } from '../../models/Cell' import { Script } from '../../models/Script' import { Block } from '../../models/Block' import { Transaction } from '../../models/Transaction' -import { Address } from '../../models/Address' +import { Address, AddressType } from '../../models/Address' import { OmigaInscriptionCollection, UDT } from '../../models/UDT' import { HashType } from '../../constants/common' @@ -71,13 +71,26 @@ export const apiFetcher = { fetchLatestBlocks: (size: number) => apiFetcher.fetchBlocks(1, size), - fetchAddressInfo: (address: string) => - v1GetWrapped
(`addresses/${address}`).then( - (wrapper): Address => ({ - ...wrapper.attributes, - type: wrapper.type === 'lock_hash' ? 'LockHash' : 'Address', - }), - ), + fetchAddressInfo: async (address: string) => { + const res = await v1GetWrapped(`addresses/${address}`).then(wrapper => { + let addr: Response.Wrapper
| null = null + // This transform is for compatibility with the rgbpp API which may return an array of addresses + + if (Array.isArray(wrapper)) { + addr = wrapper.find(addr => addr.attributes.addressHash === address) + } else { + addr = wrapper as Response.Wrapper
+ } + if (!addr) { + throw new Error('Address not found') + } + return { + ...addr.attributes, + type: addr.type === 'lock_hash' ? AddressType.LockHash : AddressType.Address, + } + }) + return res + }, // sort field, block_timestamp, capacity // sort type, asc, desc