@@ -2,7 +2,14 @@ import React, { useEffect, useState, useMemo, useCallback } from 'react'
22import { useTranslation } from 'react-i18next'
33import { Stack , DetailsList , Text , CheckboxVisibility , IColumn , Icon } from 'office-ui-fabric-react'
44import { currentWallet as currentWalletCache } from 'services/localCache'
5- import { getTransaction , showErrorMessage , getAllNetworks , getCurrentNetworkID , openExternal } from 'services/remote'
5+ import {
6+ getTransaction ,
7+ showErrorMessage ,
8+ getAllNetworks ,
9+ getCurrentNetworkID ,
10+ openExternal ,
11+ openContextMenu ,
12+ } from 'services/remote'
613import { ckbCore } from 'services/chain'
714
815import { transactionState } from 'states/initStates/chain'
@@ -111,7 +118,7 @@ const Transaction = () => {
111118 name : t ( 'transaction.index' ) ,
112119 minWidth : 60 ,
113120 maxWidth : 60 ,
114- onRender : ( item ?: any | State . DetailedOutput ) => {
121+ onRender : ( item ?: State . DetailedOutput ) => {
115122 if ( item ) {
116123 return item . outPoint . index
117124 }
@@ -216,7 +223,7 @@ const Transaction = () => {
216223 return
217224 }
218225 getTransaction ( { hash, walletID : currentWallet . id } )
219- . then ( ( res : any ) => {
226+ . then ( res => {
220227 if ( res . status ) {
221228 setTransaction ( res . result )
222229 } else {
@@ -270,6 +277,75 @@ const Transaction = () => {
270277 [ t , transaction ]
271278 )
272279
280+ const onBasicInfoContextMenu = useCallback (
281+ ( property : { label : string ; value : string } , index ?: number ) => {
282+ if ( index === 0 && property && property . value ) {
283+ const menuTemplate = [
284+ {
285+ label : t ( 'common.copy-tx-hash' ) ,
286+ click : ( ) => {
287+ window . clipboard . writeText ( property . value )
288+ } ,
289+ } ,
290+ ]
291+ openContextMenu ( menuTemplate )
292+ }
293+ } ,
294+ [ t ]
295+ )
296+
297+ const onInputContextMenu = useCallback (
298+ ( input ?: State . DetailedInput ) => {
299+ if ( input && input . lock && input . lock . args ) {
300+ try {
301+ const address = ckbCore . utils . bech32Address ( input . lock . args , {
302+ prefix : addressPrefix ,
303+ type : ckbCore . utils . AddressType . HashIdx ,
304+ codeHashOrCodeHashIndex : '0x00' ,
305+ } )
306+ const menuTemplate = [
307+ {
308+ label : t ( 'common.copy-address' ) ,
309+ click : ( ) => {
310+ window . clipboard . writeText ( address )
311+ } ,
312+ } ,
313+ ]
314+ openContextMenu ( menuTemplate )
315+ } catch ( err ) {
316+ console . error ( err )
317+ }
318+ }
319+ } ,
320+ [ addressPrefix , t ]
321+ )
322+
323+ const onOutputContextMenu = useCallback (
324+ ( output ?: State . DetailedOutput ) => {
325+ if ( output && output . lock && output . lock . args ) {
326+ try {
327+ const address = ckbCore . utils . bech32Address ( output . lock . args , {
328+ prefix : addressPrefix ,
329+ type : ckbCore . utils . AddressType . HashIdx ,
330+ codeHashOrCodeHashIndex : '0x00' ,
331+ } )
332+ const menuTemplate = [
333+ {
334+ label : t ( 'common.copy-address' ) ,
335+ click : ( ) => {
336+ window . clipboard . writeText ( address )
337+ } ,
338+ } ,
339+ ]
340+ openContextMenu ( menuTemplate )
341+ } catch ( err ) {
342+ console . error ( err )
343+ }
344+ }
345+ } ,
346+ [ addressPrefix , t ]
347+ )
348+
273349 if ( error . code ) {
274350 return (
275351 < Stack verticalFill verticalAlign = "center" horizontalAlign = "center" >
@@ -290,6 +366,7 @@ const Transaction = () => {
290366 checkboxVisibility = { CheckboxVisibility . hidden }
291367 compact
292368 isHeaderVisible = { false }
369+ onItemContextMenu = { onBasicInfoContextMenu }
293370 />
294371 </ Stack >
295372 < Stack tokens = { { childrenGap : 15 } } verticalFill >
@@ -303,6 +380,7 @@ const Transaction = () => {
303380 items = { transaction . inputs }
304381 columns = { inputColumns }
305382 checkboxVisibility = { CheckboxVisibility . hidden }
383+ onItemContextMenu = { onInputContextMenu }
306384 compact
307385 isHeaderVisible
308386 />
@@ -317,6 +395,7 @@ const Transaction = () => {
317395 items = { transaction . outputs }
318396 columns = { outputColumns }
319397 checkboxVisibility = { CheckboxVisibility . hidden }
398+ onItemContextMenu = { onOutputContextMenu }
320399 compact
321400 isHeaderVisible
322401 />
0 commit comments