Skip to content

Commit

Permalink
Merge pull request #105 from hunterjm/develop
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
hunterjm authored Feb 8, 2017
2 parents 5380093 + c9a216d commit e5a1a09
Show file tree
Hide file tree
Showing 13 changed files with 437 additions and 57 deletions.
6 changes: 6 additions & 0 deletions app/actions/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ export function placeBid(player, settings) {
bid = trade.startingBid;
}

// If the next step up is our max, go ahead and bid max
const nextBid = Fut.calculateNextHigherPrice(bid);
if (nextBid === Fut.calculateValidPrice(player.price.buy)) {
bid = nextBid;
}

// Make sure we aren't trying to spend more than we want to
if (bid <= player.price.buy && bid <= state.account.credits) {
// Bid!
Expand Down
85 changes: 85 additions & 0 deletions app/actions/watch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import _ from 'lodash';
import * as types from './watchTypes';
import { getApi } from '../utils/ApiUtil';
import { setCredits } from './account';

const filter = {
type: 'player',
num: 50,
};

let cycleTimeout;

const search = async (api, player, page = 0) => {
const searchFilter = _.merge({}, filter, {
definitionId: player.id,
start: page
});
let searchResults = 0;
let last20Min = [];
try {
const searchResponse = await api.search(searchFilter);
searchResults = searchResponse.auctionInfo.length;
last20Min = _.filter(searchResponse.auctionInfo, trade => trade.expires <= 1200);
} catch (e) {
console.error(`Error watching auctions for ${player.name}`, e); // eslint-disable-line
}
if (searchResults > 0 && last20Min.length === searchResults) {
// Increment page and search again
last20Min = last20Min.concat(await search(api, player, page + 51));
}
return last20Min;
};

export function start(player) {
return async (dispatch, getState) => {
dispatch({ type: types.START_WATCHING });
dispatch(clearWatched(player.id));
const state = getState();
const api = getApi(state.account.email);
const watched = await search(api, player);
await dispatch(setWatched(player.id, _.keyBy(watched, 'tradeId')));
await dispatch(cycle(player));
};
}

export function clearWatched(id) {
return { type: types.CLEAR_WATCH, id };
}

export function setWatched(id, trades) {
return { type: types.SET_WATCH, id, trades };
}

export function cycle(player) {
return async (dispatch, getState) => {
const state = getState();
const api = getApi(state.account.email);
const tradeIds = Object.keys(_.get(state.watch, `trades[${player.id}]`, {}));
if (state.watch.watching && tradeIds.length) {
let statuses;
try {
statuses = await api.getStatus(tradeIds);
dispatch(setCredits(statuses.credits));
} catch (e) {
console.error(`Error getting trade statuses: ${JSON.stringify(tradeIds)}`, e); // eslint-disable-line
statuses = { auctionInfo: [] };
}
dispatch(setWatched(player.id, _.keyBy(statuses.auctionInfo, 'tradeId')));
const active = _.filter(statuses.auctionInfo, trade => trade.expires > 0);
if (active.length) {
cycleTimeout = window.setTimeout(() => {
dispatch(cycle(player));
}, 10000);
}
}
};
}

export function stop() {
if (cycleTimeout) {
window.clearTimeout(cycleTimeout);
cycleTimeout = undefined;
}
return { type: types.STOP_WATCHING };
}
4 changes: 4 additions & 0 deletions app/actions/watchTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const START_WATCHING = 'watch/start';
export const STOP_WATCHING = 'watch/stop';
export const CLEAR_WATCH = 'watch/clear';
export const SET_WATCH = 'watch/set';
63 changes: 63 additions & 0 deletions app/components/PlatformIcon.js

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

7 changes: 7 additions & 0 deletions app/components/player/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Header extends Component {
'details-tab': true,
active: (
!this.props.router.isActive(`/players/${player.id}/history`)
&& !this.props.router.isActive(`/players/${player.id}/watch`)
&& !this.props.router.isActive(`/players/${player.id}/settings`)
),
});
Expand All @@ -23,6 +24,11 @@ class Header extends Component {
'player-history': true,
active: this.props.router.isActive(`/players/${player.id}/history`),
});
const tabWatchClasses = classNames({
'details-tab': true,
'player-watch': true,
active: this.props.router.isActive(`/players/${player.id}/watch`),
});
const tabSettingsClasses = classNames({
'details-tab': true,
'player-settings': true,
Expand Down Expand Up @@ -61,6 +67,7 @@ class Header extends Component {
<div className="details-subheader-tabs">
<span className={tabBioClasses}><Link to={`/players/${player.id}`}>Bio</Link></span>
<span className={tabHistoryClasses}><Link to={`/players/${player.id}/history`}>History</Link></span>
<span className={tabWatchClasses}><Link to={`/players/${player.id}/watch`}>Watch</Link></span>
<span className={tabSettingsClasses}><Link to={`/players/${player.id}/settings`}>Settings</Link></span>
</div>
</div>
Expand Down
Loading

0 comments on commit e5a1a09

Please sign in to comment.