Can we mention in our du’as our righteous deeds and sacrifices for Allah when a stressful problem or calamity has befallen us? Like in the Hadeeth where the 3 people were trapped in the cave? For example: “O Allah I did such and such good deed for You, so grant me this/protect me from this”, etc.

Ustadh AbdulAziz al-Haqqan
Yes, this is from the legislated tawassul, as the three in the cave did (agreed upon). Say it with humility, such as O Allah, if I did this sincerely for Your sake then relieve me, and not in a way that sounds like reminding Allah of a favour.