Skip to content

Commit 8b44ef7

Browse files
committed
Merge branch 'updatetx'
2 parents c44ff42 + f127e76 commit 8b44ef7

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

frontends/web/src/components/transactions/details.tsx

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect, useState } from 'react';
17+
import { useEffect, useState, useCallback } from 'react';
1818
import type { AccountCode, ITransaction } from '@/api/account';
1919
import { getTransaction } from '@/api/account';
20+
import { syncdone } from '@/api/accountsync';
2021
import { usePrevious } from '@/hooks/previous';
2122
import { TxDetailsDialog } from './components/details-dialog';
2223
import { getTxSign } from '@/utils/transaction';
@@ -46,19 +47,33 @@ export const TransactionDetails = ({
4647
}
4748
}, [internalID, prevInternalID]);
4849

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+
}
5260
if (!transaction) {
5361
console.error(`Unable to retrieve transaction ${internalID}`);
62+
return;
5463
}
5564
setTransactionInfo(transaction);
5665
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]);
6277

6378
if (!transactionInfo) {
6479
return null;

0 commit comments

Comments
 (0)