apibara / starknet-react

A collection of React providers and hooks for StarkNet
https://starknet-react.com
MIT License
369 stars 147 forks source link

useTransactionManager not updating #247

Closed fricoben closed 1 year ago

fricoben commented 1 year ago

I'm using useTransactionManager and I made this code

  const { hashes } = useTransactionManager();
  const transactions = useTransactions({ hashes });

  useEffect(() => {
    console.log("transactions", transactions);
    console.log("hashes", hashes);
    console.log("txLoading", transactions.filter((tx) => tx.isLoading).length);
  }, [hashes, transactions]);

  useEffect(() => {
    if (transactions) {
      // Give the number of tx that are loading (I use any because there is a problem on Starknet React types)
      setTxLoading(
        transactions.filter((tx) => (tx?.data as any)?.status === "RECEIVED")
          .length
      );
    }
  }, [transactions]);

In this code the transactions constant does not update when the status changes. It's always RECEIVED because we don't get any tx update after this state).

Do you have a way to fix that ?

Thx

fracek commented 1 year ago

Looks like we should refetch all transactions on new blocks. For now the workaround is to trigger a refetch when a block changes. IIRC the current behaviour is to not refresh because it could trigger a lot of requests in some cases, but on the other hand I can see why it's useful to refresh their status.

My proposal is to add a watch: boolean argument to opt-in into refreshing transactions on every block.

fricoben commented 1 year ago

Hey do we have news on that ? Thx