Skip to content

Commit

Permalink
Merge branch 'develop' into cell_data_support_decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Mar 27, 2024
2 parents d9951fc + 5d4d3bc commit e7a54c8
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/components/Capacity/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface CapacityProps {
capacity: string
type?: 'value' | 'diff'
layout?: 'responsive' | 'fixed'
unit?: 'CKB' | null
unit?: 'CKB' | string | null
display?: 'full' | 'short'
}

Expand Down
15 changes: 15 additions & 0 deletions src/components/TransactionItem/TransactionItemCell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,21 @@ const TransactionCellCapacity = ({ cell, cellType }: { cell: Cell; cellType: Cel
return <TransactionCellUDT cell={cell} />
}

if (cell.cellType === 'omiga_inscription') {
const info = cell.extraInfo
if (info?.amount && info.decimal && info.symbol) {
return (
<div className="transactionCellWithoutIcon">
<Capacity
capacity={parseUDTAmount(info.amount, info.decimal).replace(/,/g, '')}
unit={info.symbol}
display="short"
/>
</div>
)
}
}

return (
<div className="transactionCellWithoutIcon">
<Capacity capacity={shannonToCkb(cell.capacity)} />
Expand Down
8 changes: 7 additions & 1 deletion src/models/Address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +22,7 @@ export interface Address {
transactionsCount: number
lockScript: Script
pendingRewardBlocksCount: number
type: 'Address' | 'LockHash' | ''
type: AddressType
daoDeposit: number
interest: number
daoCompensation: number
Expand Down
15 changes: 14 additions & 1 deletion src/models/Cell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export interface Cell$NoExtra extends Cell$Base {
| 'spore_cluster'
| 'spore_cell'
| 'nrc_721_factory'
| 'omiga_inscription'
extraInfo?: never
}

Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/pages/Address/Cells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Address/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from '../../models/Address'
import { Address, AddressType } from '../../models/Address'

export const defaultAddressInfo: Address = {
addressHash: '',
Expand All @@ -15,7 +15,7 @@ export const defaultAddressInfo: Address = {
codeHash: '',
hashType: '',
},
type: '',
type: AddressType.Unknown,
lockInfo: {
status: 'unlocked',
epochNumber: '0',
Expand Down
12 changes: 12 additions & 0 deletions src/pages/Transaction/TransactionCell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -285,6 +291,12 @@ const TransactionCellCapacityAmount = ({ cell }: { cell: Cell }) => {
}
return <span>{`${t('udt.unknown_token')} #${udtInfo.typeHash.substring(udtInfo.typeHash.length - 4)}`}</span>
}
if (cell.cellType === 'omiga_inscription') {
const info = cell.extraInfo
if (info?.decimal && info?.amount && info?.symbol) {
return <span>{`${parseUDTAmount(info.amount, info.decimal)} ${info.symbol}`}</span>
}
}
return <Capacity capacity={shannonToCkb(cell.capacity)} layout="responsive" />
}

Expand Down
29 changes: 21 additions & 8 deletions src/services/ExplorerService/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -71,13 +71,26 @@ export const apiFetcher = {

fetchLatestBlocks: (size: number) => apiFetcher.fetchBlocks(1, size),

fetchAddressInfo: (address: string) =>
v1GetWrapped<Address>(`addresses/${address}`).then(
(wrapper): Address => ({
...wrapper.attributes,
type: wrapper.type === 'lock_hash' ? 'LockHash' : 'Address',
}),
),
fetchAddressInfo: async (address: string) => {
const res = await v1GetWrapped<Address[] | Address>(`addresses/${address}`).then(wrapper => {
let addr: Response.Wrapper<Address> | 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<Address>
}
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
Expand Down

0 comments on commit e7a54c8

Please sign in to comment.