Habitica: buying gems with gold gives two notifications when language is not 'en'

Created on 19 Nov 2016  路  8Comments  路  Source: HabitRPG/habitica

If you set your language to some of the non-English languages and then go to the Market to buy a gem with gold, you receive two notifications for +1 gem, one in your chosen language and then after a short delay, another one in English:

image

I've tested a few languages and it happens with only those that have a translation for the plusOneGem text that is different than the English version. For example, it happens with German and French, but not with en_GB, en@pirate, or zh_TW all of which still use the default text: "plusOneGem": "+1 Gem"

minor status in progress translations

Most helpful comment

I can work on this

All 8 comments

Possible [translations] issue?

Since I was looking at gems: This is the plusOneGem string in the "purchase" API call. Quite interesting, as it is also the only user besides a test.

I can work on this

If no one has claimed it

@mjackson714 Thank you! Please do.

I was able to get the bug to be reproduced. To do this, I had to "trick" habitica into thinking it was purchasing gems.

In the file /website/common/script/ops/purchase.js you need to change

let type = _.get(req.params, 'type');
let key = _.get(req.params, 'key');

to

let type = 'gems';
let key = 'gem';

and comment out or remove the lines

    if (!user.purchased || !user.purchased.plan || !user.purchased.plan.customerId) {
      throw new NotAuthorized(i18n.t('mustSubscribeToPurchaseGems', req.language));
    }

    if (user.stats.gp < convRate) {
      throw new NotAuthorized(i18n.t('messageNotEnoughGold', req.language));
    }

    if (user.purchased.plan.gemsBought >= convCap) {
      throw new NotAuthorized(i18n.t('reachedGoldToGemCap', {convCap}, req.language));
    }

(this will break all other purchasing I believe)
In /website/client-old/js/services/userServices.js I changed (around line 378)

          $http({
            method: "POST",
            url: 'api/v3/debug/add-ten-gems',
          })
          .then(function(response) {
            Notification.text('+10 Gems!');
            sync();
          })

to

          $http({
            method: "POST",
            url: 'api/v3/debug/add-ten-gems',
          })
          .then(function(response) {
            var type = 'gems';
            var key = 'gem';
            callOpsFunctionAndRequest('purchase', 'purchase', "POST", type + '/' + key, {});

            Notification.text('+10 Gems!');
            sync();
          })

After making these changes and switching my language to French, I could click the +10 gems button and have the error occur

@mjackson714 @Alys I would like to work on this. It's ok for you if I try to fix this?

@myoshuGO Thank you! Please go ahead!

Was this page helpful?
0 / 5 - 0 ratings