What is right or wrong motivation? The Anguttara Nikaya, a collection of texts in the Vinaya-pitaka section of the Pali Canon, lists a number of motivations for practicing charity. These include being shamed or intimidated into giving; giving to receive a favor; giving to feel good about yourself. These are impure motivations.
The Buddha taught that when we give to others, we give without expectation of reward. We give without attaching to either the gift or the recipient. We practice giving to release greed and self-clinging.
Some teachers propose that giving is good because it accrues merit and creates karma that will bring future happiness. Others say that even this is self-clinging and an expectation of reward. In Mahayana Buddhism in particular, any merit that might come with giving is to be dedicated to the liberation of others.