How to overcome a mistake you make in your proof and regain motivation?
As an early-career mathematician, I have had this experience, more or less exactly, several times. I think I've solved a problem (or made good progress toward doing so) and I become proud and emotionally invested, only to show it to a mentor (first my PhD advisor, then my postdoc supervisor) who quickly points out a fatal flaw in my reasoning. Sometimes, he will propose a different and much better method. I completely get how demotivating this can be. After all, I would think, why am I even working on this project if my mentor could do it himself more quickly?

But you have to overcome these feelings. Here are some points of view that helped me do so:


Trying things and failing is how we learn. There's a mathematical lesson here about why my techniques failed and my mentor's succeeded. There's also a lesson about how to do research: how to do sanity checks, how to avoid "premature optimization," etc.
My mentor is a professional researcher with decades of experience. Of course he can solve things more quickly than me. Even if it feels like my role is to work out the details of his ideas, I'm learning a lot by doing that. And these "brilliant ideas" are usually adapted from previously existing techniques anyway--it's more an experience gap than an intelligence gap.
Experiences like this keep me humble, which comes in very handy when teaching people who understand less than I do.


I would encourage you to try to power through these feelings of inadequacy. Part of being a mature researcher is not being afraid of being wrong. 

Having said all that, a good way to avoid situations like this is to keep the person you're working under more in the loop while you're doing the work, so that they can steer you away from dead ends. In your case, it wasn't necessarily your fault that your supervisor didn't devote much time to your project, but in the future you should try to get high-level feedback earlier in the process.