I think Xavi's decision to resign is the right one. Xavi loves this club. And he is a living legend of Barcelona. He was the coach of this club for the last 2 years. And despite Barcelona not being in a good position, the team won the La Liga title last season with the help of Xavi. But now Barcelona face a bigger problem. The team's performance this season has been erratic.
Xavi did a right thing to step down from a coach position proactively. He loves the club like you said and he wants best for the club. In addition, he already achieved big things with them, one La Liga title that is a milestone for his young coach career. He still has many years ahead in his coach career and he can return to Barcelona in future as a head coach.
Also their financial condition is not good. So Barcelona needs a more experienced coach.
If Xavi remains as the coach of the team, it will not be good for Barcelona and Xavi. Barcelona fans might start trolling Xavi too. Perhaps this is why Xavi has decided not to stay at Barcelona at the end of this season.
With Barcelona's financial status, it will be so hard for them to resolve it by depending on their results in La Liga and Champions League. It's hard to win titles and get rewards for winners to resolve their financial problem. It is a very risky bet from Barcelona and they know it, Xavi know it, so when things become worse and he feels he can not help them to achieve it, it's wise decision to leave.