@@ -4,15 +4,8 @@ import { WalletWizardPath } from 'components/WalletWizard'
44import { NeuronWalletActions , StateDispatch , AppActions } from 'states/stateProvider/reducer'
55import { actionCreators } from 'states/stateProvider/actionCreators'
66
7- import UILayer , {
8- AppMethod ,
9- ChainMethod ,
10- TransactionsMethod ,
11- WalletsMethod ,
12- walletsCall ,
13- transactionsCall ,
14- } from 'services/UILayer'
15- import { initWindow } from 'services/remote'
7+ import UILayer , { AppMethod , ChainMethod , WalletsMethod , walletsCall } from 'services/UILayer'
8+ import { initWindow , getTransactionList , getTransaction } from 'services/remote'
169import {
1710 SystemScript as SystemScriptSubject ,
1811 DataUpdate as DataUpdateSubject ,
@@ -95,71 +88,6 @@ export const useChannelListeners = ({
9588 }
9689 } )
9790
98- UILayer . on ( Channel . Transactions , ( _e : Event , method : TransactionsMethod , args : ChannelResponse < any > ) => {
99- if ( args . status ) {
100- switch ( method ) {
101- case TransactionsMethod . GetAllByKeywords : {
102- // TODO: verify the wallet id the transactions belong to
103- dispatch ( {
104- type : NeuronWalletActions . Chain ,
105- payload : { transactions : { ...chain . transactions , ...args . result } } ,
106- } )
107- break
108- }
109- case TransactionsMethod . Get : {
110- dispatch ( {
111- type : NeuronWalletActions . Chain ,
112- payload : { transaction : args . result } ,
113- } )
114- break
115- }
116- case TransactionsMethod . TransactionUpdated : {
117- const updatedTransaction : State . Transaction = args . result
118- if (
119- ( ! chain . transactions . items . length ||
120- updatedTransaction . timestamp === null ||
121- + ( updatedTransaction . timestamp || updatedTransaction . createdAt ) >
122- + ( chain . transactions . items [ 0 ] . timestamp || chain . transactions . items [ 0 ] . createdAt ) ) &&
123- chain . transactions . pageNo === 1
124- ) {
125- /**
126- * 1. transaction list is empty or the coming transaction is pending or the coming transaction is later than latest transaction in current list
127- * 2. the current page number is 1
128- */
129- const newTransactionItems = [ updatedTransaction , ...chain . transactions . items ] . slice (
130- 0 ,
131- chain . transactions . pageSize
132- )
133- dispatch ( {
134- type : NeuronWalletActions . Chain ,
135- payload : { transactions : { ...chain . transactions , items : newTransactionItems } } ,
136- } )
137- } else {
138- const newTransactionItems = [ ...chain . transactions . items ]
139- const idx = newTransactionItems . findIndex ( item => item . hash === updatedTransaction . hash )
140- if ( idx >= 0 ) {
141- newTransactionItems [ idx ] = updatedTransaction
142- dispatch ( {
143- type : NeuronWalletActions . Chain ,
144- payload : { transactions : { ...chain . transactions , items : newTransactionItems } } ,
145- } )
146- }
147- }
148- if ( chain . transaction . hash === updatedTransaction . hash ) {
149- dispatch ( {
150- type : NeuronWalletActions . Chain ,
151- payload : { transaction : updatedTransaction } ,
152- } )
153- }
154- break
155- }
156- default : {
157- break
158- }
159- }
160- }
161- } )
162-
16391 UILayer . on ( Channel . Wallets , ( _e : Event , method : WalletsMethod , args : ChannelResponse < any > ) => {
16492 if ( args . status ) {
16593 switch ( method ) {
@@ -334,11 +262,18 @@ export const useOnCurrentWalletChange = ({
334262 useEffect ( ( ) => {
335263 if ( walletID ) {
336264 walletsCall . getAllAddresses ( walletID )
337- transactionsCall . getAllByKeywords ( {
265+ getTransactionList ( {
338266 walletID,
339267 keywords : '' ,
340268 pageNo,
341269 pageSize,
270+ } ) . then ( res => {
271+ if ( res . status ) {
272+ dispatch ( {
273+ type : NeuronWalletActions . UpdateTransactionList ,
274+ payload : res . result ,
275+ } )
276+ }
342277 } )
343278 } else {
344279 initWindow ( )
@@ -387,13 +322,19 @@ export const useSubscription = ({
387322 break
388323 }
389324 case 'transaction' : {
390- transactionsCall . getAllByKeywords ( {
325+ getTransactionList ( {
391326 walletID,
392327 keywords,
393328 pageNo,
394329 pageSize,
330+ } ) . then ( res => {
331+ if ( res . status ) {
332+ dispatch ( { type : NeuronWalletActions . UpdateTransactionList , payload : res . result } )
333+ } else {
334+ // TODO: notification
335+ }
395336 } )
396- transactionsCall . get ( walletID , txHash )
337+ getTransaction ( { walletID, hash : txHash } )
397338 break
398339 }
399340 case 'wallet' : {
0 commit comments