stoodkev / SteemPlus

SteemPlus is a lightweight browser extension adding new features to your Steemit/Busy experience: - Voting slider for minnows - Possibility to filter (by tag/resteem/reputation) and sort ( by date/payout/votes) - Switch between Busy Steemit and Steemd by keyboard shortcuts - Delegation of Steem Power directly from the wallet
GNU General Public License v3.0
27 stars 32 forks source link

[busy.org] Clicking on Pending tab under SteemPlus - Rewards - Curation throws error #178

Open ng-gist opened 5 years ago

ng-gist commented 5 years ago

Expected behavior

On busy.org platform, clicking on Pending under SteemPlus -> Rewards -> Curation should show only Paid option.

Actual behavior

Clicking on Pending under SteemPlus -> Rewards -> Curation throws undefined error in console and both Pending and Paid links are displayed with none selected.

How to reproduce

  1. Install and Enable SteemPlus chrome extension version (3.5.0.1).
  2. Start on a new tab by typing busy.org. Its important that you start from feed page.
  3. On busy.org, click the avatar on top right to go to profile.
  4. Click on the caret next to SteemPlus menu item and select Rewards.
  5. This should take you rewards page, with author selected.
  6. Click on Curation.
  7. You will see Paid and Pending. Page should only show Paid link and as selected. Clicking on Pending shows error in console.

ezgif-2-7f898e60fcd7

Technical Analysis and Solution

When Curation Rewards tab is clicked, following code executes:

            $('.subtypeItem').eq(0).parent().hide();
            if (isSteemit) {
                $('.subtypeItem').removeClass('active');
                $('.subtypeItem').eq(1).addClass('active');
            } else if (isBusy) {
                $('.subtypeItem').removeClass('UserMenu__item--active');
                $('.subtypeItem').eq(1).addClass('UserMenu__item--active');
            }

This code is supposed to get 2 items (Pending and Paid) and then remove Pending and select Paid. But following the steps above, $('.subtypeItem') gets 4 items. There is another set of Pending and Paid tabs in code somewhere. To solve this issue, you can remove all DOM elements except last 2.

To remove elements:

if ($('.subtypeItem').length > 2) {
   _.forEach($('.subtypeItem'), (elem, idx) => {
      if (idx <= $('.subtypeItem').length-2)
       $(elem).parent().remove();
})
}
stoodkev commented 5 years ago

Indeed you seem to have the solution for this problem. Please go ahead and make a PR to get the credit for your work.

ng-gist commented 5 years ago

Solution above was just remedying the symptoms but I found the disease. I will create a PR in a bit. Actual cause was createRewardsTab function was getting called twice, once from base file and once from rawards file when #reward was present in the url. I added another check to prevent creation of reward tab again. This should also increase the performance for the rewards tab.