Skip to content

Commit

Permalink
Merge pull request #77 from ZeusJunior/development
Browse files Browse the repository at this point in the history
Merge development with master
  • Loading branch information
ZeusJunior authored May 24, 2020
2 parents a272a46 + 78620ac commit ded7abe
Show file tree
Hide file tree
Showing 17 changed files with 158 additions and 82 deletions.
13 changes: 10 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module.exports = {
"no-tabs": 0,
"max-len": 0,
"linebreak-style": 0,
"quote-props": ["warn", "consistent-as-needed", {"numbers": false}],
"quote-props": ["warn", "consistent-as-needed", {
"numbers": false
}],
"no-trailing-spaces": ["error", {
"skipBlankLines": true,
"ignoreComments": true
Expand All @@ -31,8 +33,13 @@ module.exports = {
"named": "never",
"asyncArrow": "always"
}],
"object-curly-spacing": 0,
"object-curly-spacing": ["error", "always"],
"object-property-newline": ["error", {
"allowAllPropertiesOnSameLine": false
}],
"new-cap": 0,
"no-useless-catch": "error"
"no-useless-catch": "error",
"arrow-spacing": 2,
"camelcase": "error"
}
};
7 changes: 7 additions & 0 deletions app/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ exports.wear = {
'4': '(Well-Worn)',
'5': '(Battle Scarred)'
};

exports.ETradeOfferState = {
Invalid: 1,
Active: 2, // This trade offer has been sent, neither party has acted on it yet.
Expand All @@ -1154,6 +1155,7 @@ exports.ETradeOfferState = {
10: 'CanceledBySecondFactor',
11: 'InEscrow'
};

exports.qualityColors = {
0: '#B2B2B2',
1: '#4D7455',
Expand Down Expand Up @@ -1203,3 +1205,8 @@ exports.paintCanColors = {
'5036;6': '7c6c57', // Ye Olde Rustic Colour
'5028;6': '424f3b' // Zepheniah's Greed
};

exports.defindexes = {
'Mann Co. Supply Crate Key': 5021,
'Lugermorph': 160
};
27 changes: 15 additions & 12 deletions app/profit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.get = async function get(start, interval, end, enableTrades) {
}
);
const keyVal = response.data.sell.metal;
const trades = Object.keys(polldata.offerData).map((key)=>{
const trades = Object.keys(polldata.offerData).map((key) => {
const ret = polldata.offerData[key];
ret.time = polldata.timestamps[key];
ret.id = key;
Expand All @@ -34,7 +34,7 @@ exports.get = async function get(start, interval, end, enableTrades) {

const tracker = new itemTracker(start, interval, end, keyVal);

trades.sort((a, b)=>{
trades.sort((a, b) => {
a = a.time;
b = b.time;

Expand Down Expand Up @@ -120,14 +120,14 @@ exports.get = async function get(start, interval, end, enableTrades) {
overpriceProfit += tracker.convert(trade.value.their, trade.value.rate) - tracker.convert(trade.value.our, trade.value.rate);
tracker.profitTrack.countProfit( tracker.convert(trade.value.their, trade.value.rate) - tracker.convert(trade.value.our, trade.value.rate), trade.time);
}
tradeProfits[trade.id] = tracker.profitTrack.getFormated(tradeProfit);
tradeProfits[trade.id] = tracker.profitTrack.getFormatted(tradeProfit);
}
const returnObj = {
profitTotal: tracker.profitTrack.getFormated(tracker.profitTrack.profit),
profitTimed: tracker.profitTrack.getFormated(tracker.profitTrack.profitTimed),
profitTotal: tracker.profitTrack.getFormatted(tracker.profitTrack.profit),
profitTimed: tracker.profitTrack.getFormatted(tracker.profitTrack.profitTimed),
profitPlot: tracker.profitTrack.profitPlot,
numberOfTrades: iter,
overpriceProfit: tracker.profitTrack.getFormated(overpriceProfit),
overpriceProfit: tracker.profitTrack.getFormatted(overpriceProfit),
keyValue: keyVal
};
if (enableTrades) returnObj['tradeProfits'] = tradeProfits;
Expand Down Expand Up @@ -174,13 +174,13 @@ class profitTracker {
this.profitPlot.push({
time: lastTradePlotBlock*this.interval + this.start,
profit: this.tempProfit,
formated: this.getFormated(this.tempProfit)
formatted: this.getFormatted(this.tempProfit)
});
for (let i = lastTradePlotBlock+1; i < thisTradePlotBlock; i++) { // create block even if no trades happend
this.profitPlot.push({
time: i*this.interval + this.start,
profit: 0,
formated: this.getFormated(0)
formatted: this.getFormatted(0)
});
}
this.tempProfit = normalizedAmount; // reset temp to value of current trade
Expand All @@ -194,7 +194,7 @@ class profitTracker {
this.profitPlot.push({
time: lastTradePlotBlock*this.interval + this.start,
profit: this.tempProfit,
formated: this.getFormated(this.tempProfit)
formatted: this.getFormatted(this.tempProfit)
});
this.tempProfit = 0;
}
Expand All @@ -203,15 +203,18 @@ class profitTracker {
/**
*
* @param {Number} normalPrice
* @return {String} formated string
* @return {String} formatted string
*/
getFormated(normalPrice) {
getFormatted(normalPrice) {
const key = new Currency({
metal: this.currentKey
}).toValue(this.currentKey); // get value in scrap
const metal = Currency.toRefined(normalPrice % key);
const keys = normalPrice>0 ? Math.floor(normalPrice / key) : Math.ceil(normalPrice / key);
return new Currency({keys, metal}).toString();
return new Currency({
keys,
metal
}).toString();
}
}
/**
Expand Down
11 changes: 9 additions & 2 deletions app/routes/addItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ router.post('/', (req, res) => {
let sellvalues;
let buyvalues;
if (!autopriced) {
sellvalues = new Currency({ keys: sellkeys, metal: sellmetal}).toJSON();
buyvalues = new Currency({ keys: buykeys, metal: buymetal}).toJSON();
sellvalues = new Currency({
keys: sellkeys,
metal: sellmetal
}).toJSON();

buyvalues = new Currency({
keys: buykeys,
metal: buymetal
}).toJSON();

// lower sell keys
if (sellvalues.keys < buyvalues.keys && intent != 0) {
Expand Down
11 changes: 9 additions & 2 deletions app/routes/addItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ router.post('/', (req, res) => {
});

if (!req.body.autoprice) {
sellvalues = { keys: Number(req.body.sell_keys), metal: Number(req.body.sell_metal)};
buyvalues = { keys: Number(req.body.buy_keys), metal: Number(req.body.buy_metal)};
sellvalues = {
keys: Number(req.body.sell_keys),
metal: Number(req.body.sell_metal)
};

buyvalues = {
keys: Number(req.body.buy_keys),
metal: Number(req.body.buy_metal)
};

// lower sell keys
if (sellvalues.keys < buyvalues.keys && req.body.intent != 0) {
Expand Down
13 changes: 10 additions & 3 deletions app/routes/changeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Currency = require('tf2-currencies');
const pricelist = require('../pricelist');

router.post('/', (req, res) => {
const { sku, intent, autoprice, min, max, sellkeys, sellmetal, buykeys, buymetal, enabled} = req.body;
const { sku, intent, autoprice, min, max, sellkeys, sellmetal, buykeys, buymetal, enabled } = req.body;
if (parseInt(max) < parseInt(min)) {
res.json({
success: 0,
Expand All @@ -16,8 +16,15 @@ router.post('/', (req, res) => {
return;
}

const sellvalues = new Currency({keys: sellkeys, metal: sellmetal}).toJSON();
const buyvalues = new Currency({keys: buykeys, metal: buymetal}).toJSON();
const sellvalues = new Currency({
keys: sellkeys,
metal: sellmetal
}).toJSON();

const buyvalues = new Currency({
keys: buykeys,
metal: buymetal
}).toJSON();

// lower sell keys
if (!autoprice) {
Expand Down
2 changes: 1 addition & 1 deletion app/routes/trades.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ router.get('/', (req, res) => {
return;
}

trades.get(Number(req.query.first), Number(req.query.count), Number(req.query.dir)==1)
trades.get(Number(req.query.first), Number(req.query.count), Number(req.query.dir)==1, req.query.search)
.then((data) => {
res.json({
success: 1,
Expand Down
74 changes: 40 additions & 34 deletions app/trades.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ const profit = require('./profit');
* @param {Number} first index of first trade to be included in results
* @param {Number} count how many trades to include in results, set to -1 to return all
* @param {Boolean} descending sort
* @param {String} search string to search listings for
*/
exports.get = async function(first, count, descending) {
exports.get = async function(first, count, descending, search) {
search = search.trim().toLowerCase();
const polldata = await fs.readJSON(paths.files.polldata);
const profitData = (await profit.get(undefined, undefined, undefined, true)).tradeProfits;
let tradeList = Object.keys(polldata.offerData).map((key)=>{
let tradeList = Object.keys(polldata.offerData).map((key) => {
const ret = polldata.offerData[key];
ret.id = key;
return ret;
});
const tradeCount = tradeList.length;
tradeList = tradeList.sort((a, b)=>{
tradeList = tradeList.sort((a, b) => {
a = a.finishTimestamp;
b = b.finishTimestamp;

Expand All @@ -30,15 +32,25 @@ exports.get = async function(first, count, descending) {
if ( !(!a || isNaN(a)) && (!b || isNaN(b))) return -1;
if ( (!a || isNaN(a)) && (!b || isNaN(b))) return 0;

if (descending) {
b = [a, a = b][0];
}
if (descending) b = [a, a = b][0];

return a - b;
});
tradeList = tradeList.filter((offer) => {
let offerSearchResults = false;
if (Object.prototype.hasOwnProperty.call(offer, 'dict')) {
offerSearchResults = Object.keys(offer.dict.our).reduce((accumulator, item) => {
return accumulator || getName(item).toLowerCase().indexOf(search) > -1;
}, false);
offerSearchResults |= Object.keys(offer.dict.our).reduce((accumulator, item) => {
return accumulator || getName(item).toLowerCase().indexOf(search) > -1;
}, false);
}
return offer.id.indexOf(search) > -1 || offerSearchResults;
});
if (count != -1) tradeList = tradeList.slice(first, first + count);
const items = {};
const trades = tradeList.map((offer)=>{
const trades = tradeList.map((offer) => {
const ret = {
id: offer.id,
items: {
Expand All @@ -53,36 +65,30 @@ exports.get = async function(first, count, descending) {
value: offer.value,
accepted: offer.handledByUs === true && offer.isAccepted === true
};
if (typeof polldata.sent[offer.id] != 'undefined') {
ret.lastState = data.ETradeOfferState[polldata.sent[offer.id]];
} else if (typeof polldata.received[offer.id] != 'undefined') {
ret.lastState = data.ETradeOfferState[polldata.received[offer.id]];
}

if (typeof polldata.sent[offer.id] != 'undefined') ret.lastState = data.ETradeOfferState[polldata.sent[offer.id]];
else if (typeof polldata.received[offer.id] != 'undefined') ret.lastState = data.ETradeOfferState[polldata.received[offer.id]];

if (Object.prototype.hasOwnProperty.call(offer, 'dict')) {
if (Object.keys(offer.dict.our).length > 0) {
Object.keys(offer.dict.our).forEach((k)=>{
if (!Object.prototype.hasOwnProperty.call(items, k)) {
items[k] = createTradeItem(k);
}
ret.items.our.push({
sku: k,
amount: offer.dict.our[k]
});
});
}
if (Object.keys(offer.dict.their).length > 0) {
Object.keys(offer.dict.their).forEach((k)=>{
if (!Object.prototype.hasOwnProperty.call(items, k)) {
items[k] = createTradeItem(k);
}
ret.items.their.push({
sku: k,
amount: offer.dict.their[k]
});
});
}
if (Object.keys(offer.dict.our).length > 0) tradeSide('our');
if (Object.keys(offer.dict.their).length > 0) tradeSide('their');
}

return ret;

/**
* Get items from one side of a trade
* @param {'our'|'their'} side
*/
function tradeSide(side) {
Object.keys(offer.dict[side]).forEach((k) => {
if (!Object.prototype.hasOwnProperty.call(items, k)) items[k] = createTradeItem(k);
ret.items[side].push({
sku: k,
amount: offer.dict[side][k]
});
});
}
});
return {
trades,
Expand Down
29 changes: 29 additions & 0 deletions assets/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
position: relative;
}
.info {
line-height: 1.2;
position:relative;
z-index: 1000;
width: 100%;
Expand Down Expand Up @@ -102,13 +103,21 @@
left: 2px;
position: absolute;
z-index: 2;
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
}
.item-grid .autoprice-symbol {
top: 2px;
right: 2px;
position: absolute;
z-index: 2;
color: #29a30e;
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
}
.item-list .autoprice-symbol {
color: #29a30e;
Expand All @@ -123,4 +132,24 @@
.item-list{
width: 100%;
height: 64px;
}
.price {
line-height: 1.3;
font-size: small;
position: absolute;
bottom: 0;
z-index: 1001;
width: 100%;
visibility: hidden;
background-color:rgba(255, 255, 255, 0.7);
overflow-x: wrap;
overflow-y: hidden;
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
background-color: #666;
}
.item:hover .price {
visibility: visible;
}
2 changes: 1 addition & 1 deletion assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const app = new Vue({
url: '/addItems',
data: postData
})
.then((resp)=>{
.then((resp) => {
app.sendMessage(resp.data.msg.type, resp.data.msg.message);
app.loadItems();
});
Expand Down
Loading

0 comments on commit ded7abe

Please sign in to comment.