1- import React , { useEffect , useMemo } from 'react'
2- import { RouteComponentProps } from 'react-router-dom'
1+ import React , { useEffect , useState , useMemo } from 'react'
32import { useTranslation } from 'react-i18next'
43import { Stack , DetailsList , Text , DetailsListLayoutMode , CheckboxVisibility , IColumn } from 'office-ui-fabric-react'
4+ import { currentWallet as currentWalletCache } from 'utils/localCache'
5+ import { getTransaction } from 'services/remote'
56
6- import { isMainWindow , getWinID } from 'services/remote'
7-
8- import { AppActions , StateWithDispatch } from 'states/stateProvider/reducer'
9- import { updateTransaction } from 'states/stateProvider/actionCreators'
10- import chainState from 'states/initStates/chain'
7+ import { transactionState } from 'states/initStates/chain'
118
129import { localNumberFormatter , uniformTimeFormatter } from 'utils/formatters'
1310
@@ -96,26 +93,38 @@ const basicInfoColumns: IColumn[] = [
9693 ...col ,
9794 } )
9895)
99- const Transaction = ( {
100- wallet : { id : walletID = '' } ,
101- chain : { transaction = chainState . transaction } ,
102- match,
103- dispatch,
104- } : React . PropsWithoutRef < StateWithDispatch & RouteComponentProps < { hash : string } > > ) => {
96+ const Transaction = ( ) => {
10597 const [ t ] = useTranslation ( )
98+ const [ transaction , setTransaction ] = useState ( transactionState )
99+ const [ error , setError ] = useState ( { code : '' , message : '' } )
106100 useEffect ( ( ) => {
107- if ( ( walletID && ! isMainWindow ( getWinID ( ) ) ) || ! walletID ) {
108- window . close ( )
101+ const currentWallet = currentWalletCache . load ( )
102+ if ( currentWallet ) {
103+ const hash = window . location . href . split ( '/' ) . pop ( )
104+ getTransaction ( { hash, walletID : currentWallet . id } )
105+ . then ( res => {
106+ if ( res . status ) {
107+ setTransaction ( res . result )
108+ } else {
109+ throw new Error ( res . message . title )
110+ }
111+ } )
112+ . catch ( ( err : Error ) => {
113+ setError ( {
114+ code : '-1' ,
115+ message : err . message ,
116+ } )
117+ } )
109118 }
110- } , [ walletID ] )
119+ } , [ ] )
111120
112121 useEffect ( ( ) => {
113- dispatch ( {
114- type : AppActions . CleanTransaction ,
115- payload : null ,
122+ window . addEventListener ( 'storage' , ( e : StorageEvent ) => {
123+ if ( e . key === 'currentWallet' ) {
124+ window . close ( )
125+ }
116126 } )
117- updateTransaction ( { walletID, hash : match . params . hash } ) ( dispatch )
118- } , [ match . params . hash , dispatch , walletID ] )
127+ } , [ ] )
119128
120129 const basicInfoItems = useMemo (
121130 ( ) => [
@@ -138,6 +147,14 @@ const Transaction = ({
138147 [ t , transaction ]
139148 )
140149
150+ if ( error . code ) {
151+ return (
152+ < Stack verticalFill verticalAlign = "center" horizontalAlign = "center" >
153+ { error . message || t ( 'messages.transaction-not-found' ) }
154+ </ Stack >
155+ )
156+ }
157+
141158 return (
142159 < Stack tokens = { { childrenGap : 15 } } >
143160 < Stack tokens = { { childrenGap : 15 } } >
0 commit comments