1- import React , { useEffect , useMemo } from 'react'
1+ import React , { useState , useEffect , useMemo } from 'react'
22import { RouteComponentProps } from 'react-router-dom'
33import { useTranslation } from 'react-i18next'
44import {
5+ Stack ,
56 ShimmeredDetailsList ,
67 TextField ,
78 IColumn ,
89 CheckboxVisibility ,
10+ DefaultButton ,
911 IconButton ,
12+ Text ,
1013 getTheme ,
1114} from 'office-ui-fabric-react'
1215
1316import { contextMenu } from 'services/remote'
17+ import { ckbCore } from 'services/chain'
1418import { StateWithDispatch } from 'states/stateProvider/reducer'
1519
1620import { useLocalDescription } from 'utils/hooks'
@@ -27,6 +31,7 @@ const Addresses = ({
2731 history,
2832 dispatch,
2933} : React . PropsWithoutRef < StateWithDispatch & RouteComponentProps > ) => {
34+ const [ showMainnetAddress , setShowMainnetAddress ] = useState ( false )
3035 const [ t ] = useTranslation ( )
3136 useEffect ( ( ) => {
3237 if ( ! showAddressBook ) {
@@ -181,18 +186,44 @@ const Addresses = ({
181186 enableShimmer = { isLoading }
182187 checkboxVisibility = { CheckboxVisibility . hidden }
183188 columns = { addressColumns . map ( col => ( { ...col , name : t ( col . name ) } ) ) }
184- items = { addresses }
189+ items = { addresses . map ( addr => ( {
190+ ...addr ,
191+ address : showMainnetAddress
192+ ? ckbCore . utils . bech32Address ( addr . identifier , {
193+ prefix : ckbCore . utils . AddressPrefix . Mainnet ,
194+ type : ckbCore . utils . AddressType . HashIdx ,
195+ codeHashIndex : '0x00' ,
196+ } ) || ''
197+ : addr . address ,
198+ } ) ) }
185199 onItemContextMenu = { item => {
186- contextMenu ( { type : 'addressList' , id : item . identifier } )
200+ if ( ! showMainnetAddress ) {
201+ contextMenu ( { type : 'addressList' , id : item . identifier } )
202+ }
187203 } }
188204 className = "listWithDesc"
189205 onRenderRow = { onRenderRow }
190206 />
191207 ) ,
192- [ isLoading , addressColumns , addresses , t ]
208+ [ isLoading , addressColumns , addresses , showMainnetAddress , t ]
193209 )
194210
195- return List
211+ return (
212+ < >
213+ < Stack verticalAlign = "center" horizontalAlign = "start" tokens = { { childrenGap : 15 } } >
214+ < DefaultButton
215+ text = { t ( `addresses.display-${ showMainnetAddress ? 'testnet' : 'mainnet' } -addresses` ) }
216+ onClick = { ( ) => setShowMainnetAddress ( ! showMainnetAddress ) }
217+ />
218+ { showMainnetAddress ? (
219+ < Text variant = "medium" style = { { color : semanticColors . errorText } } >
220+ { t ( 'addresses.mainnet-address-caution' ) }
221+ </ Text >
222+ ) : null }
223+ </ Stack >
224+ { List }
225+ </ >
226+ )
196227}
197228
198229Addresses . displayName = 'Addresses'
0 commit comments