|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import { useEffect, useState } from 'react'; |
| 17 | +import { useEffect, useState, useCallback } from 'react'; |
18 | 18 | import type { AccountCode, ITransaction } from '@/api/account';
|
19 | 19 | import { getTransaction } from '@/api/account';
|
| 20 | +import { syncdone } from '@/api/accountsync'; |
20 | 21 | import { usePrevious } from '@/hooks/previous';
|
21 | 22 | import { TxDetailsDialog } from './components/details-dialog';
|
22 | 23 | import { getTxSign } from '@/utils/transaction';
|
@@ -46,19 +47,32 @@ export const TransactionDetails = ({
|
46 | 47 | }
|
47 | 48 | }, [internalID, prevInternalID]);
|
48 | 49 |
|
49 |
| - useEffect(() => { |
50 |
| - if (internalID && !transactionInfo) { |
51 |
| - getTransaction(accountCode, internalID).then(transaction => { |
| 50 | + const fetchTransaction = useCallback(() => { |
| 51 | + if (!internalID) { |
| 52 | + return; |
| 53 | + } |
| 54 | + getTransaction(accountCode, internalID) |
| 55 | + .then(transaction => { |
52 | 56 | if (!transaction) {
|
53 | 57 | console.error(`Unable to retrieve transaction ${internalID}`);
|
| 58 | + return; |
54 | 59 | }
|
55 | 60 | setTransactionInfo(transaction);
|
56 | 61 | setOpen(true);
|
57 |
| - }).catch(console.error); |
58 |
| - } else { |
59 |
| - setOpen(true); |
| 62 | + }) |
| 63 | + .catch(console.error); |
| 64 | + }, [accountCode, internalID]); |
| 65 | + |
| 66 | + useEffect(() => { |
| 67 | + fetchTransaction(); |
| 68 | + }, [fetchTransaction]); |
| 69 | + |
| 70 | + useEffect(() => { |
| 71 | + if (!internalID) { |
| 72 | + return; |
60 | 73 | }
|
61 |
| - }, [accountCode, internalID, transactionInfo]); |
| 74 | + return syncdone(accountCode, fetchTransaction) |
| 75 | + }, [accountCode, internalID, fetchTransaction]); |
62 | 76 |
|
63 | 77 | if (!transactionInfo) {
|
64 | 78 | return null;
|
|
0 commit comments