Skip to content

Commit

Permalink
#1691 - add guard to prevent infinite loop and only trigger search on…
Browse files Browse the repository at this point in the history
… landing (#1699)
  • Loading branch information
sebastianscatularo authored Feb 22, 2024
1 parent 6d838bf commit 728bb4a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions wormhole-connect/src/views/TxSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function TxSearch() {
const [state, setState] = useState({
chain: EMPTY,
tx: EMPTY,
autoSearch: false,
});
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
Expand Down Expand Up @@ -106,8 +107,9 @@ function TxSearch() {

// set the txHash and chainName from configs and reset it to undefined
useEffect(() => {
if (hasExternalSearch && txHash && chainName) {
setState({ chain: chainName, tx: txHash });
const autoSearch = !!(hasExternalSearch && txHash && chainName);
if (autoSearch) {
setState({ chain: chainName, tx: txHash, autoSearch });
clear();
}
}, [hasExternalSearch, txHash, chainName, clear]);
Expand All @@ -116,7 +118,9 @@ function TxSearch() {

// search on load if txHash and chainName are set
useEffect(() => {
if (state.chain !== EMPTY && state.tx !== EMPTY && !loading) {
const { chain, tx, autoSearch } = state;
if (autoSearch && chain !== EMPTY && tx !== EMPTY && !loading) {
setState((prev) => ({ ...prev, autoSearch: false }));
doSearch();
}
}, [doSearch, state, loading]);
Expand Down

0 comments on commit 728bb4a

Please sign in to comment.