11import React , { useState , useCallback } from 'react'
22import { useNavigate , useLocation } from 'react-router-dom'
3- import { Trans , useTranslation } from 'react-i18next'
3+ import { useTranslation } from 'react-i18next'
44import Pagination from 'widgets/Pagination'
55import SUDTAvatar from 'widgets/SUDTAvatar'
66import Button from 'widgets/Button'
@@ -11,27 +11,16 @@ import { Download, Search, ArrowNext } from 'widgets/Icons/icon'
1111import PageContainer from 'components/PageContainer'
1212import TransactionStatusWrap from 'components/TransactionStatusWrap'
1313import FormattedTokenAmount from 'components/FormattedTokenAmount'
14- import { UANTokenName , isTonkenInfoStandardUAN } from 'components/UANDisplay'
1514import { useState as useGlobalState , useDispatch } from 'states'
1615import { exportTransactions } from 'services/remote'
1716
1817import { ReactComponent as CKBAvatar } from 'widgets/Icons/Nervos.svg'
19- import { ReactComponent as Success } from 'widgets/Icons/Success.svg'
20- import { ReactComponent as Pending } from 'widgets/Icons/Pending.svg'
21- import { ReactComponent as Failure } from 'widgets/Icons/Failure.svg'
2218
23- import {
24- RoutePath ,
25- isMainnet as isMainnetUtil ,
26- uniformTimeFormatter ,
27- nftFormatter ,
28- sUDTAmountFormatter ,
29- sudtValueToAmount ,
30- shannonToCKBFormatter ,
31- } from 'utils'
19+ import { RoutePath , isMainnet as isMainnetUtil , uniformTimeFormatter } from 'utils'
3220import { onEnter } from 'utils/inputDevice'
3321import { CONFIRMATION_THRESHOLD , DEFAULT_SUDT_FIELDS } from 'utils/const'
3422import Tooltip from 'widgets/Tooltip'
23+ import TransactionType from 'components/TransactionType'
3524import RowExtend from './RowExtend'
3625
3726import { useSearch } from './hooks'
@@ -73,79 +62,12 @@ const History = () => {
7362
7463 const bestBlockNumber = Math . max ( cacheTipBlockNumber , bestKnownBlockNumber )
7564
76- const handleTransactionInfo = ( tx : State . Transaction ) => {
77- let name = '--'
78- let amount = '--'
79- let typeLabel : React . ReactNode = '--'
80- let sudtAmount = ''
81- let showWithUANFormatter = false
82-
83- if ( tx . nftInfo ) {
84- // NFT
85- name = walletName
86- const { type, data } = tx . nftInfo
87- typeLabel = `${ t ( `history.${ type } ` ) } m-NFT`
88- amount = `${ type === 'receive' ? '+' : '-' } ${ nftFormatter ( data ) } `
89- } else if ( tx . sudtInfo ?. sUDT ) {
65+ const getTxName = ( tx : State . Transaction ) => {
66+ if ( ! tx . nftInfo && tx . sudtInfo ?. sUDT ) {
9067 // Asset Account
91- name = tx . sudtInfo . sUDT . tokenName || DEFAULT_SUDT_FIELDS . tokenName
92- if ( [ 'create' , 'destroy' ] . includes ( tx . type ) ) {
93- // create/destroy an account
94- showWithUANFormatter = isTonkenInfoStandardUAN ( tx . sudtInfo . sUDT . tokenName , tx . sudtInfo . sUDT . symbol )
95- typeLabel = (
96- < Trans
97- i18nKey = { `history.${ tx . type } SUDT` }
98- components = { [ < UANTokenName name = { tx . sudtInfo . sUDT . tokenName } symbol = { tx . sudtInfo . sUDT . symbol } /> ] }
99- />
100- )
101- } else {
102- // send/receive to/from an account
103- const type = + tx . sudtInfo . amount <= 0 ? 'send' : 'receive'
104- typeLabel = `UDT ${ t ( `history.${ type } ` ) } `
105- }
106-
107- if ( tx . sudtInfo . sUDT . decimal ) {
108- sudtAmount = sudtValueToAmount ( tx . sudtInfo . amount , tx . sudtInfo . sUDT . decimal , true )
109- amount = `${ sUDTAmountFormatter ( sudtAmount ) } ${ tx . sudtInfo . sUDT . symbol } `
110- }
111- } else {
112- // normal tx
113- name = walletName
114- amount = `${ shannonToCKBFormatter ( tx . value , true ) } CKB`
115- if ( tx . type === 'create' || tx . type === 'destroy' ) {
116- if ( tx . assetAccountType === 'CKB' ) {
117- typeLabel = `${ t ( `history.${ tx . type } ` , { name : 'CKB' } ) } `
118- } else {
119- typeLabel = `${ t ( `overview.${ tx . type } ` , { name : 'Unknown' } ) } `
120- }
121- } else {
122- typeLabel = tx . nervosDao ? 'Nervos DAO' : t ( `history.${ tx . type } ` )
123- }
124- }
125-
126- let indicator = < Pending />
127- switch ( tx . status ) {
128- case 'success' : {
129- indicator = < Success />
130- break
131- }
132- case 'failed' : {
133- indicator = < Failure />
134- break
135- }
136- default : {
137- // ignore
138- }
139- }
140-
141- return {
142- name,
143- amount,
144- typeLabel,
145- sudtAmount,
146- showWithUANFormatter,
147- indicator,
68+ return tx . sudtInfo . sUDT . tokenName || DEFAULT_SUDT_FIELDS . tokenName
14869 }
70+ return walletName ?? '--'
14971 }
15072
15173 const handleExpandClick = ( idx : number | null ) => {
@@ -158,7 +80,7 @@ const History = () => {
15880 dataIndex : 'name' ,
15981 minWidth : '110px' ,
16082 render ( _ , __ , item ) {
161- const { name } = handleTransactionInfo ( item )
83+ const name = getTxName ( item )
16284 return name . length > 8 ? (
16385 < Tooltip tip = { < > { name } </ > } isTriggerNextToChild showTriangle >
16486 < div className = { styles . avatarBox } >
@@ -186,20 +108,26 @@ const History = () => {
186108 title : t ( 'history.table.type' ) ,
187109 dataIndex : 'type' ,
188110 align : 'left' ,
189- minWidth : '100px ' ,
111+ minWidth : '120px ' ,
190112 render : ( _ , __ , item ) => {
191- const { typeLabel } = handleTransactionInfo ( item )
192- return typeLabel
113+ return (
114+ < TransactionType
115+ item = { item }
116+ cacheTipBlockNumber = { cacheTipBlockNumber }
117+ bestKnownBlockNumber = { bestKnownBlockNumber }
118+ tokenNameClassName = { styles . tokenName }
119+ />
120+ )
193121 } ,
194122 } ,
195123 {
196124 title : t ( 'history.table.amount' ) ,
197125 dataIndex : 'amount' ,
198126 align : 'left' ,
199127 isBalance : true ,
200- minWidth : '220px ' ,
128+ minWidth : '200px ' ,
201129 render ( _ , __ , item , show ) {
202- return < FormattedTokenAmount item = { item } show = { show } />
130+ return < FormattedTokenAmount item = { item } show = { show } symbolClassName = { styles . symbol } />
203131 } ,
204132 } ,
205133 {
0 commit comments