Skip to content

Commit

Permalink
Merge pull request #138 from hunterjm/develop
Browse files Browse the repository at this point in the history
v0.4.3
  • Loading branch information
hunterjm authored Feb 16, 2017
2 parents 6c0dbb5 + 0730a7f commit c601b4e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 28 deletions.
33 changes: 25 additions & 8 deletions app/actions/bid.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function setBINStatus(won) {
export function snipe(player, settings) {
return async (dispatch, getState) => {
let state = getState();
const api = getApi(state.account.email);
let api = getApi(state.account.email);
dispatch(addMessage('log', `Preparing to snipe ${player.name}...`));
// Snipe
const binFilter = _.merge({}, filter, {
Expand All @@ -93,6 +93,8 @@ export function snipe(player, settings) {
binResponse = { auctionInfo: [] };
}
dispatch(addMessage('log', `${binResponse.auctionInfo.length} BIN found for ${player.name}...`));
// drop RPM for sniping
api = getApi(state.account.email, 60);
for (const trade of binResponse.auctionInfo) {
// refresh state every trade
state = getState();
Expand Down Expand Up @@ -140,14 +142,15 @@ export function snipe(player, settings) {
}
}
}
api = getApi(state.account.email, settings.rpm);
};
}

export function placeBid(player, settings) {
return async (dispatch, getState) => {
if (!settings.snipeOnly) {
let state = getState();
const api = getApi(state.account.email);
let api = getApi(state.account.email);
dispatch(addMessage('log', `Getting ready to search auctions for ${player.name}...`));
const bidFilter = _.merge({}, filter, {
definitionId: player.id,
Expand Down Expand Up @@ -189,12 +192,21 @@ export function placeBid(player, settings) {
// The card has at least one contract
&& trade.itemData.contract > 0
) {
// Get the latest status of this trade
let latestTrade;
try {
const status = await api.getStatus([trade.tradeId]);
dispatch(setCredits(status.credits));
latestTrade = _.get(status, 'auctionInfo[0]', trade);
} catch (e) {
latestTrade = trade;
}
// Set our bid
let bid;
if (trade.currentBid) {
bid = Fut.calculateNextHigherPrice(trade.currentBid);
if (latestTrade.currentBid) {
bid = Fut.calculateNextHigherPrice(latestTrade.currentBid);
} else {
bid = trade.startingBid;
bid = latestTrade.startingBid;
}

// If the next step up is our max, go ahead and bid max
Expand All @@ -204,16 +216,19 @@ export function placeBid(player, settings) {
}

// Make sure we aren't trying to spend more than we want to
if (bid <= player.price.buy && bid <= state.account.credits) {
if (latestTrade.expires > 0 && bid <= player.price.buy && bid <= state.account.credits) {
// Bid!
let tradeResult = {};
api = getApi(state.account.email, 0);
try {
const placeBidResponse = await api.placeBid(trade.tradeId, bid);
// No delay between status and bid
const placeBidResponse = await api.placeBid(latestTrade.tradeId, bid);
dispatch(setCredits(placeBidResponse.credits));
tradeResult = _.get(placeBidResponse, 'auctionInfo[0]', {});
} catch (e) {
dispatch(addMessage('error', `Error placing bid on ${player.name}`, e));
}
api = getApi(state.account.email, settings.rpm);
// tradeResult = {
// bidState: 'highest',
// tradeId: trade.tradeId,
Expand All @@ -238,6 +253,8 @@ export function placeBid(player, settings) {
// TODO: do something about this
dispatch(addMessage('warn', `Something happened when trying to bid on ${player.name}`));
}
} else if (latestTrade.expires === -1 && latestTrade.currentBid < player.price.bid) {
dispatch(addMessage('warn', `TOO SLOW: Trade has expired for ${player.name} (sold for ${latestTrade.currentBid})`));
} else {
dispatch(addMessage('log', `Required bid (${bid}) is more than we are willing to pay for ${player.name} (${player.price.buy})`));
}
Expand Down Expand Up @@ -378,7 +395,7 @@ export function continueTracking(settings) {
return async (dispatch, getState) => {
let state = getState();
const api = getApi(state.account.email);
const tradeIds = Object.keys(state.bid.trades);
const tradeIds = Object.keys(state.bid.trades).filter(id => id > 0);
if (!settings.snipeOnly && tradeIds.length) {
dispatch(addMessage('log', `Updating status on ${tradeIds.length} active trades...`));
let statuses;
Expand Down
5 changes: 0 additions & 5 deletions app/actions/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ export function bidCycle() {
await dispatch(bidActions.placeBid(player, settings));
}

// Update items always when bidding
// await dispatch(bidActions.updateItems(player, settings));

state = getState();
if (state.bid.bidding) {
if (!settings.snipeOnly) {
Expand All @@ -96,8 +93,6 @@ export function bidCycle() {
}

// buy now goes directly to unassigned now
state = getState();
dispatch(bidActions.setBINStatus(!!state.bid.unassigned.length));
await dispatch(bidActions.binNowToUnassigned());

// Log sold items
Expand Down
3 changes: 2 additions & 1 deletion app/components/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ Settings.propTypes = {
sell: PropTypes.string,
bin: PropTypes.string,
relistAll: PropTypes.bool
})
}),
errors: PropTypes.shape({})
};

Settings.contextTypes = {
Expand Down
3 changes: 2 additions & 1 deletion app/components/player/PlayerSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ PlayerSettings.propTypes = {
player: PropTypes.shape({
list: PropTypes.shape({})
}),
settings: PropTypes.shape({})
settings: PropTypes.shape({}),
errors: PropTypes.shape({})
};

PlayerSettings.contextTypes = {
Expand Down
3 changes: 2 additions & 1 deletion app/containers/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ Account.propTypes = {
platform: PropTypes.string,
code: PropTypes.string,
}),
next: PropTypes.func // only used for tests
next: PropTypes.func, // only used for tests
errors: PropTypes.shape({})
};

Account.contextTypes = {
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fifa-autobuyer",
"productName": "FIFA Autobuyer",
"version": "0.4.2",
"version": "0.4.3",
"description": "Autobuyer for FIFA 17 Ultimate Team",
"main": "./main.js",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fifa-autobuyer",
"productName": "FIFA Autobuyer",
"version": "0.4.2",
"version": "0.4.3",
"description": "Autobuyer for FIFA 17 Ultimate Team",
"main": "main.js",
"scripts": {
Expand Down
20 changes: 10 additions & 10 deletions test/actions/bid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
expect(cleanActions.length).to.eql(0);
Expand All @@ -191,7 +191,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
expect(cleanActions.length).to.eql(0);
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('actions', () => {
const settings = { minCredits: 10000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(bidStub.called).to.eql(false);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
Expand Down Expand Up @@ -256,7 +256,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(bidStub.called).to.eql(false);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
Expand Down Expand Up @@ -300,7 +300,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(bidStub.calledOnce).to.eql(true);
/*
Expand Down Expand Up @@ -354,7 +354,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(bidStub.calledOnce).to.eql(true);
/*
Expand Down Expand Up @@ -397,7 +397,7 @@ describe('actions', () => {
const settings = { minCredits: 1000, maxCard: 5 };
const store = mockStore(initialState);
await store.dispatch(actions.snipe(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(bidStub.calledOnce).to.eql(true);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
Expand Down Expand Up @@ -518,7 +518,7 @@ describe('actions', () => {
const settings = { minCredits: 10000, maxCard: 5, snipeOnly: false };
const store = mockStore(initialState);
await store.dispatch(actions.placeBid(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(highestPriceStub.calledTwice).to.eql(true);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
expect(cleanActions).to.be.eql(
Expand Down Expand Up @@ -586,7 +586,7 @@ describe('actions', () => {
const settings = { minCredits: 10000, maxCard: 5, snipeOnly: false };
const store = mockStore(initialState);
await store.dispatch(actions.placeBid(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(highestPriceStub.calledOnce).to.eql(true);
const cleanActions = _.filter(store.getActions(), a => a.type !== types.ADD_MESSAGE);
expect(cleanActions).to.be.eql(
Expand Down Expand Up @@ -642,7 +642,7 @@ describe('actions', () => {
const settings = { minCredits: 10000, maxCard: 5, snipeOnly: false };
const store = mockStore(initialState);
await store.dispatch(actions.placeBid(player, settings));
expect(apiStub.calledOnce).to.eql(true);
expect(apiStub.callCount).to.eql(3);
expect(searchStub.calledOnce).to.eql(true);
expect(highestPriceStub.calledTwice).to.eql(true);
expect(bidStub.calledOnce).to.eql(true);
Expand Down

0 comments on commit c601b4e

Please sign in to comment.