Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Wait for transaction when user gets disconnected #46

Open
midgerate opened this issue Oct 21, 2021 · 4 comments
Open

Handle Wait for transaction when user gets disconnected #46

midgerate opened this issue Oct 21, 2021 · 4 comments

Comments

@midgerate
Copy link

I was looking at ways to handle situations where we want to display a loader to the user if their transactions is currently ongoing.
we can use useWaitForTransaction for that. However, how do we handle the case, if the user refreshes the page?

Ideally, I want to be able to fetch user's pending transactions and display a UI suitable to my needs.

What's your thought on this?

@midgerate
Copy link
Author

Secondly, how else could I use useWaitForTransaction so that I am able to set loading state elsewhere allowing me to show loaders on the page?

@kesne
Copy link
Owner

kesne commented Oct 21, 2021

From what I can tell, the refresh case would need to be solved through means outside of this library. I can easily add a useTransaction hook, which would let you use a transaction hash to read the current state of the transaction. I don't think there's a way to get a list of pending transactions though, so you'd need to persist the transaction into localstorage or something to make it resilient to refreshes.

For displaying loading state while you useWaitForTransaction, you just use suspense. There's an example of it here: https://kesne.github.io/ethereal-react/getting-started/contracts/#waiting-for-transactions

@midgerate
Copy link
Author

So you are suggesting that I can store the transaction to localstorage and then create a component like this.

const Page = () => {
  const [transaction, setTransaction] = useState()

  useEffect(() => {
    const tx = getTransactionFromLocalStorage()
    setTranasction(tx)
  }, [])

  const SubmitButton = () => {
    // would this throw error if transaction is undefined? 
    useWaitForTransaction(transaction)
    return <button>Submit</button>
  }
  return <Suspense fallback={<>Loading</>}><SubmitButton /></Suspense>
  
}

@kesne
Copy link
Owner

kesne commented Oct 29, 2021

I'll try to put together an example to demonstrate this next week, it'll require the addition of a new useTransaction hook as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants