If you have meaningful equity and the startup you work for is going to get you FU money(a lot of money), you have to decide: chance of FU money(= happiness) OR chance of being employed by a better place(= happiness). Both are a chance, you might find an even worse place to work... (common)
If you don't have much equity there and can get a salary somehow good in another company/startup, I don't see why you are still working for them.
Also, before you leave, try to negotiate with them to get some equity/more equity. Maybe it will work out better to work with this shitty code for a while and make it big. Be rational and not emotional.
My 2 cents.