Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOOK-776: as a user my unmatched and matched bets should be displayed sorted #20

Open
wants to merge 7 commits into
base: pbsa-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 69 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"moment": "~2.17.1",
"numeral": "~2.0.4",
"object-assign": "4.1.1",
"peerplaysjs-lib": "pbsa/peerplaysjs-lib",
"peerplaysjs-ws": "pbsa/peerplaysjs-ws",
"peerplaysjs-lib": "peerplays-network/peerplaysjs-lib",
"peerplaysjs-ws": "peerplays-network/peerplaysjs-ws",
"perfect-scrollbar": "~0.6.11",
"postcss-loader": "1.2.2",
"promise": "7.1.1",
Expand Down
10 changes: 7 additions & 3 deletions src/actions/MarketDrawerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import Immutable from 'immutable';
import moment from 'moment';
import BetActions from './BetActions';
import {CurrencyUtils, ObjectUtils} from '../utility';
import {CurrencyUtils, ObjectUtils, BettingModuleUtils} from '../utility';

class MarketDrawerPrivateActions {
static updateOpenBetsLoadingStatus(loadingStatus) {
Expand Down Expand Up @@ -379,15 +379,19 @@ class MarketDrawerActions {
return formattedBet;
};

const openedUnmatchedBets = unmatchedBetsById
let openedUnmatchedBets = unmatchedBetsById
.filter(filterRelatedBet)
.map(formatBet)
.toList();
const openedMatchedBets = matchedBetsById
let openedMatchedBets = matchedBetsById
.filter(filterRelatedBet)
.map(formatBet)
.toList();

// Sort the bets by id incrementally
openedUnmatchedBets = BettingModuleUtils.sortBetsById(openedUnmatchedBets);
openedMatchedBets = BettingModuleUtils.sortBetsById(openedMatchedBets);

dispatch(
MarketDrawerPrivateActions.getOpenBets(
openedUnmatchedBets,
Expand Down
26 changes: 26 additions & 0 deletions src/utility/BettingModuleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ var BettingModuleUtils = {
}
}
}
},

/**
* Takes in an immutable list of bets and sorts them by id incrementally.
* @param {Immutable.List} bets
* @returns {Immutable.List} sorted.
*/
sortBetsById: function(bets) {
const sorted = bets.sort((a, b) => {
// Split by .
const aId = a.get('id').split('.');
// Select the ending number of the id
const aIdEnd = parseInt(aId[2], 0);

const bId = b.get('id').split('.');
const bIdEnd = parseInt(bId[2], 0);

// Sort
if (aIdEnd < bIdEnd) {
return -1;
} else {
return 1;
}
});

return sorted;
}
};

Expand Down