|
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,33 @@ 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 | + const currentID = internalID; |
| 55 | + getTransaction(accountCode, internalID) |
| 56 | + .then(transaction => { |
| 57 | + if (internalID !== currentID) { |
| 58 | + return; // Ignore if internalID has changed since the request was made. |
| 59 | + } |
52 | 60 | if (!transaction) {
|
53 | 61 | console.error(`Unable to retrieve transaction ${internalID}`);
|
| 62 | + return; |
54 | 63 | }
|
55 | 64 | setTransactionInfo(transaction);
|
56 | 65 | setOpen(true);
|
57 |
| - }).catch(console.error); |
58 |
| - } else { |
59 |
| - setOpen(true); |
60 |
| - } |
61 |
| - }, [accountCode, internalID, transactionInfo]); |
| 66 | + }) |
| 67 | + .catch(console.error); |
| 68 | + }, [accountCode, internalID]); |
| 69 | + |
| 70 | + useEffect(() => { |
| 71 | + fetchTransaction(); |
| 72 | + }, [fetchTransaction]); |
| 73 | + |
| 74 | + useEffect(() => { |
| 75 | + return syncdone(accountCode, fetchTransaction); |
| 76 | + }, [accountCode, fetchTransaction]); |
62 | 77 |
|
63 | 78 | if (!transactionInfo) {
|
64 | 79 | return null;
|
|
0 commit comments