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-769: Sportsbook #33

Open
wants to merge 68 commits into
base: pbsa-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f0b86a4
Add sportsbook files
MuffinLightning Feb 28, 2019
9495046
Re-enable the title bar and mode toggle
MuffinLightning Feb 28, 2019
fef61d6
Updated Selectors, Constants, and Utils.
MuffinLightning Feb 28, 2019
a419cd6
Remove instances of /betting/
MuffinLightning Feb 28, 2019
1618482
Update params for bet place
MuffinLightning Feb 28, 2019
e8c1687
Sidebar.jsx update
MuffinLightning Feb 28, 2019
645bbe4
Route update to enable sidebar
MuffinLightning Mar 4, 2019
cf47d9d
Added missing functions to MarketDrawer
MuffinLightning Mar 4, 2019
61813e2
Highlight active view
MuffinLightning Mar 6, 2019
5672fee
Updated home logo button functionality to support Sportsbook view
MuffinLightning Mar 6, 2019
a601072
Only show Moneyline/Match Odds in the SB view.
MuffinLightning Mar 7, 2019
d4a33f9
Fix broken iterators and event flag check
MuffinLightning Mar 11, 2019
c9d5f00
Completed missing view
MuffinLightning Mar 12, 2019
3eed9c3
Added eventRoute prop
MuffinLightning Mar 12, 2019
52a891c
Updated routing and links to account for multiple modes
MuffinLightning Mar 12, 2019
8b48dec
Update time format in sportsbook
MuffinLightning Mar 13, 2019
9edd133
Fix bet place issue with Drawer
MuffinLightning Mar 14, 2019
9a9ff60
Linting :)
MuffinLightning Mar 14, 2019
b260745
Use AppUtils in sidebar for home path.
MuffinLightning Mar 14, 2019
ddaa4e9
Update library urls
MuffinLightning Mar 18, 2019
c1a69eb
Update library urls
MuffinLightning Mar 18, 2019
73c03f7
Update library urls
MuffinLightning Mar 18, 2019
5ac7c74
Update library urls
MuffinLightning Mar 18, 2019
2b5e75a
Merge pull request #17 from peerplays-network/BOOK-1167-Fix-Links-Spo…
MuffinLightning Mar 18, 2019
6a74472
Addressed an issue in which filter rules within Sportsbook were not c…
MuffinLightning Mar 20, 2019
b913a03
Remove useless filter functions
MuffinLightning Mar 21, 2019
658f435
Update time to ensure it's local
MuffinLightning Mar 21, 2019
3df8454
Updated an id selector that should have been a class selector
MuffinLightning Mar 21, 2019
5f1c7ba
Updated some styling, use eventpath route to determine depth for spec…
MuffinLightning Mar 21, 2019
a652702
Remove console.log
MuffinLightning Mar 21, 2019
9dc37d5
Rearrange style
MuffinLightning Mar 21, 2019
f7ff17e
Added a minimum width to Sportsbook date string.
MuffinLightning Mar 22, 2019
ee0caf5
Merge pull request #14 from peerplays-network/BOOK-1111-sportsbook-fi…
MuffinLightning Mar 22, 2019
6840d09
Merge pull request #18 from peerplays-network/BOOK-1168-Timezones
MuffinLightning Mar 26, 2019
ba73a29
Addressed a variety of pagination issues
MuffinLightning Mar 26, 2019
24cb5dc
BMG should sort the same in Sportsbook v Exchange side bar
MuffinLightning Mar 26, 2019
e66a171
Merge branch 'BOOK-850-bmgs-update' into BOOK-1173-Pagination
MuffinLightning Mar 26, 2019
8adb261
Match Odds will be on one line in the event that there are 3 choices.
MuffinLightning Mar 26, 2019
a9ada96
Address Windows Electron issue, toggle should now be clickable.
MuffinLightning Mar 27, 2019
d5271e1
Merge branch 'sportsbook-merge' into BOOK-850-bmgs-update
MuffinLightning Mar 28, 2019
2e96abb
Merge branch 'BOOK-1183-Electron-Toggle-Windows' into BOOK-850-bmgs-u…
MuffinLightning Mar 28, 2019
0bf4427
Min width
MuffinLightning Mar 28, 2019
daaa553
Changed min
MuffinLightning Mar 28, 2019
a83dac6
Media Queries for 125%/150% zoom levels.
MuffinLightning Mar 28, 2019
ee28a28
Removed unused code
MuffinLightning Mar 28, 2019
9ec7671
Use var name
MuffinLightning Apr 1, 2019
eb79a37
Merge branch 'BOOK-850-bmgs-update' into BOOK-1173-Pagination
MuffinLightning Apr 2, 2019
edeb2ab
Merge pull request #16 from peerplays-network/BOOK-850-bmgs-update
MuffinLightning Apr 2, 2019
d59823c
Added a comment
MuffinLightning Apr 2, 2019
b28e709
Added some content checks (code previously did not check for empty da…
MuffinLightning Apr 2, 2019
1c7fe17
Linting
MuffinLightning Apr 2, 2019
ef7dcc9
Lint the entire project (needed to be done since we added a new rule)
MuffinLightning Apr 3, 2019
d128e99
Added pagination arrows < > to Sportsbook
MuffinLightning Apr 4, 2019
5548a6e
Merge pull request #29 from peerplays-network/BOOK-1173-Pagination
MuffinLightning Apr 4, 2019
95c72ec
1.3.0
mamokin Apr 5, 2019
5eeae08
Increment version to 1.3.0-sportsbook.0
mamokin Apr 5, 2019
d0b5e68
Merge pull request #32 from peerplays-network/sportsbook-v-bump
mseaward Apr 5, 2019
e346da1
Merge branch 'pbsa-develop' into BOOK-769-Update-1
MuffinLightning Apr 10, 2019
2900709
Update version
MuffinLightning Apr 10, 2019
813f30c
Update lock file
MuffinLightning Apr 10, 2019
9ba992e
Merge pull request #39 from peerplays-network/BOOK-769-Update-1
mseaward Apr 10, 2019
3733659
refactor(selectors): update filters in EvetnPageSelector
MuffinLightning Apr 10, 2019
c99fdf3
Fix EventPageSelector
MuffinLightning Apr 11, 2019
85b4c64
Merge pull request #40 from peerplays-network/BOOK-1192
mseaward Apr 12, 2019
d63a5f6
chore(libs): update lib references to exclude ws
MuffinLightning Apr 16, 2019
10fbc15
Update package.json
MuffinLightning Apr 16, 2019
8719029
Update package-lock.json
MuffinLightning Apr 16, 2019
329dddd
Merge pull request #45 from peerplays-network/BOOK-769-update-libs
MuffinLightning Apr 16, 2019
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
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "bookie",
"author": "Peerplays Blockchain Standards Association",
"description": "Electron app powered by CRA",
"version": "1.3.0-rc.0",
"version": "1.3.0-sportsbook.1",
"private": true,
"homepage": "./",
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions src/actions/AppActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ class AppActions {
};
}

/**
* Action to set the Book mode ( Exchange or SportsBook )
*/
static setBookMode(mode) {
return {
type: ActionTypes.APP_SET_BOOK_MODE,
mode
};
}

/**
* Action to show logout popup
*/
Expand Down
2 changes: 1 addition & 1 deletion src/actions/BetActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class BetActions {
betDiff.map((item) => {
item[0] = CurrencyUtils.correctFloatingPointPrecision([item[0], item[2]], currencyType);

if(item[1] === 'decrement') {
if (item[1] === 'decrement') {
changeType = BetTypes.DECREMENT;
}

Expand Down
172 changes: 172 additions & 0 deletions src/actions/MarketDrawerActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,178 @@ class MarketDrawerActions {
};
}

static getOpenBetsForEvent(eventId) {
return (dispatch, getState) => {
const bmgs = getState().getIn(['bettingMarketGroup', 'bettingMarketGroupsById']);

if (!bmgs || bmgs.isEmpty()) {
return null;
}

let openUnmatchedBets = Immutable.List();
let openMatchedBets = Immutable.List();

// For each BMG that belongs to the event
bmgs.forEach((bmg) => {
if (bmg.get('event_id') === eventId) {
// Get the associated bets and push them into their respective list. Forming a single list
let bets = MarketDrawerActions.getOpenBetsForBMG(getState(), bmg.get('id'));
bets.openUnmatchedBets.forEach((bet) => {
openUnmatchedBets = openUnmatchedBets.push(bet);
});

bets.openMatchedBets.forEach((bet) => {
openMatchedBets = openMatchedBets.push(bet);
});
}
});

// Send the list off to the private action, to be added to state.
// - Pass in the eventId so that Bookie knows that we're on a event page.
// - Pass in null for the bettingMarketGroupId so that Bookie knows we're not on a BMG page.
dispatch(
MarketDrawerPrivateActions.getOpenBets(
openUnmatchedBets,
openMatchedBets,
null, // betting Market Group Id
eventId
)
);
};
}

static getOpenBetsForBMG(state, bettingMarketGroupId) {

const bettingMarketGroup = state.getIn([
'bettingMarketGroup',
'bettingMarketGroupsById',
bettingMarketGroupId
]);

if (!bettingMarketGroup || bettingMarketGroup.isEmpty()) {
// If betting market group doesn't exist, clear open bets
return null;
} else {
const unmatchedBetsById = state.getIn(['bet', 'unmatchedBetsById']);
const matchedBetsById = state.getIn(['bet', 'matchedBetsById']);

const bettingMarketsById = state.getIn(['bettingMarket', 'bettingMarketsById']);
const assetsById = state.getIn(['asset', 'assetsById']);
const bettingMarketGroupDescription =
bettingMarketGroup && bettingMarketGroup.get('description');

// Helper function to filter related bet
const filterRelatedBet = (bet) => {
// Only get bet that belongs to this betting market group
const bettingMarket = bettingMarketsById.get(bet.get('betting_market_id'));
return bettingMarket && bettingMarket.get('group_id') === bettingMarketGroupId;
};

// Helper function to format bets to market drawer bet object structure
const formatBet = (bet) => {
const accountId = state.getIn(['account', 'account', 'id']);
const setting =
state.getIn(['setting', 'settingByAccountId', accountId]) ||
state.getIn(['setting', 'defaultSetting']);
const bettingMarket = bettingMarketsById.get(bet.get('betting_market_id'));
const bettingMarketDescription = bettingMarket && bettingMarket.get('description');
const precision =
assetsById.get(bettingMarketGroup.get('asset_id')).get('precision') || 0;
const odds = bet.get('backer_multiplier');
const betType = bet.get('back_or_lay');
const currencyFormat = setting.get('currencyFormat');

// Get the stake from the bet object
// BACK: The stake is present in a back bet by default
// LAY: The backer's stake needs to be calculated from the values recorded in the
// lay bet on the blockchain
let stake = ObjectUtils.getStakeFromBetObject(bet) / Math.pow(10, precision);

// This if statement sets the profit/liability according to the kind of bet it is.
// Values are then converted to string format for consistent comparison
// BACK: ALWAYS have a liability of 0, profit to be calculated
// LAY: ALWAYS have a profit of 0, profit to be calculated
let profit = 0,
profitAsString = '0';
let liability = 0,
liabilityAsString = '0';

if (betType === BetTypes.BACK) {
// Get the raw value of the profit
profit = bet.get('original_profit') / Math.pow(10, precision);
profitAsString = CurrencyUtils.formatFieldByCurrencyAndPrecision(
'profit',
profit,
currencyFormat
).toString(); // Record it as a string
} else if (betType === BetTypes.LAY) {
liability = bet.get('original_liability') / Math.pow(10, precision);
liabilityAsString = CurrencyUtils.formatFieldByCurrencyAndPrecision(
'liability',
liability,
currencyFormat
).toString();
} else {
console.error('Serious Error - Bet with no type has been detected');
}

// store odds and stake values as String for easier comparison
const oddsAsString = CurrencyUtils.formatFieldByCurrencyAndPrecision(
'odds',
odds,
currencyFormat
).toString();
const stakeAsString = CurrencyUtils.formatFieldByCurrencyAndPrecision(
'stake',
stake,
currencyFormat
).toString();

let formattedBet = Immutable.fromJS({
id: bet.get('id'),
original_bet_id: bet.get('original_bet_id'),
bet_type: bet.get('back_or_lay'),
bettor_id: bet.get('bettor_id'),
betting_market_id: bet.get('betting_market_id'),
betting_market_description: bettingMarketDescription,
betting_market_group_description: bettingMarketGroupDescription,
odds: oddsAsString,
stake: stakeAsString,
profit: profitAsString,
liability: liabilityAsString
});

if (bet.get('category') === BetCategories.UNMATCHED_BET) {
// Keep all of the original values for precision and accuracy in future calculations
formattedBet = formattedBet
.set('original_odds', oddsAsString)
.set('original_stake', stakeAsString)
.set('original_profit', profitAsString)
.set('original_liability', liabilityAsString)
.set('updated', false);
}

return formattedBet;
};

const openUnmatchedBets = unmatchedBetsById
.filter(filterRelatedBet)
.map(formatBet)
.toList();
const openMatchedBets = matchedBetsById
.filter(filterRelatedBet)
.map(formatBet)
.toList();

return {
openUnmatchedBets,
openMatchedBets
};
}
}



static getOpenBets(bettingMarketGroupId) {
return (dispatch, getState) => {
const bettingMarketGroup = getState().getIn([
Expand Down
24 changes: 24 additions & 0 deletions src/components/App/App.less
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,27 @@ body {
line-height: 1.42857143; //reference from bootstrap
color: @primary_label;
}

.sportsBookToggle {
z-index: 100;
margin: 5px;
-webkit-app-region: no-drag;

p {
display: inline-block;
padding: 2px 6px 2px 6px;
border: 1px solid @cello;
text-transform: uppercase;

&.active {
background-color: @cello;
color: @update_highlight;
}

&:hover {
background-color: @cello;
cursor: pointer;
color: @update_highlight;
}
}
}
5 changes: 5 additions & 0 deletions src/components/App/TitleBar/MacTitleBar/MacTitleBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import Clock from '../Clock';
import {I18n} from 'react-redux-i18n';
import {Config} from '../../../../constants';
import SportsbookToggle from '../SportsbookToggle';

class MacTitleBar extends PureComponent {
render() {
Expand All @@ -14,6 +15,7 @@ class MacTitleBar extends PureComponent {
onResizeClick,
onCloseClick,
isFullscreen,
loggedIn,
...props
} = this.props;

Expand All @@ -33,6 +35,9 @@ class MacTitleBar extends PureComponent {
/>
</div>
<div className='right'>
{loggedIn && (
<SportsbookToggle />
)}
<Clock className='clock' />
</div>
</div>
Expand Down
Loading