diff --git a/package.json b/package.json index ac73069..f9d7951 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "steam-enchanter", - "version": "1.1.2", + "version": "1.1.3", "description": "Google Chrome extension for Steam. Automating some actions for Level up your account.", "main": "index.js", "scripts": { diff --git a/public/manifest.json b/public/manifest.json index 4a29b0d..8f30223 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Steam Enchanter", "description": "Automating some actions for Level up your Steam account.", - "version": "1.1.2", + "version": "1.1.3", "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyPmdRVJ9XxGnV4qLbRm7pEM8kUzOa6MnJFJ43fstWn6wIktC6lWZ7Qz9oIyvGua9ytYSTaqsavQksPa8eBY8L9V+Hd6xOEap82SfT353N0P9M/ZLQsG1X/KtUijaoMxoPl5VNBz+h0tuVhNHFYjeFqtujTU1JrY+Dv4U0COQv4wiGUUfdh0QVIxLg/ELK/ltmM4xsIz6EehrowY6GGjQiT7PJPda6MwS0WaJeJa6HgvIAILISVDNMFD2CipiuHZjcxC3FQQGMabciNwiv5a3sY7wyum1zWUJb71DAJV3X0eqLuDXuCtoJm+O0HOFnhtVXeR9b4WtqYyOGk92yDuFmwIDAQAB", "action": { "default_icon": "icon.png" diff --git a/src/__tests__/service/SteamCardTraderServiceTest.ts b/src/__tests__/service/SteamCardTraderServiceTest.ts index 6850ad1..726031f 100644 --- a/src/__tests__/service/SteamCardTraderServiceTest.ts +++ b/src/__tests__/service/SteamCardTraderServiceTest.ts @@ -20,7 +20,7 @@ test("Create trader process.", async () => { currency: 5, appId: 10, marketHashName: "112", - priceTotal: (91 + 200) * 2, + priceTotal: Math.ceil(91 * 1.10) * 2, quantity: 2 }).mockReturnValue(new Promise(resolve => resolve("order-1"))); @@ -31,7 +31,7 @@ test("Create trader process.", async () => { quantity: 2, price: 91 } - ], 5); + ], 5, 10); expect(process.getCurrentStatus()).toBe(Status.pending); }); @@ -49,6 +49,6 @@ test("When session id is not initialized", async () => { quantity: 2, price: 91 } - ], 5); + ], 5, 10); }).rejects.toThrowError("Session id is not initialized"); }); \ No newline at end of file diff --git a/src/service/SteamCardTraderService.ts b/src/service/SteamCardTraderService.ts index 9018990..3e41cc8 100644 --- a/src/service/SteamCardTraderService.ts +++ b/src/service/SteamCardTraderService.ts @@ -15,13 +15,13 @@ class SteamCardTraderService { } - public async createTrader(positions: Array, currencyId: number): Promise { + public async createTrader(positions: Array, currencyId: number, overpricePercent: number): Promise { const sessionId = this.getSessionId(); const cardOrderOperationContexts: Array = []; for (const position of positions) { - const result = await this.createOrder(sessionId, position, currencyId); + const result = await this.createOrder(sessionId, position, currencyId, overpricePercent); cardOrderOperationContexts.push( { orderId: result, @@ -33,15 +33,13 @@ class SteamCardTraderService { } - private async createOrder(sessionId: string, position: CardMarketPosition, currencyId: number): Promise { - const maximumOverprice = 200;// TODO 200 is maximum overprice for position, move to options. - + private async createOrder(sessionId: string, position: CardMarketPosition, currencyId: number, overpricePercent: number): Promise { return await this.steamMarketApi.createOrder({ sessionId: sessionId, currency: currencyId, appId: position.appId, marketHashName: position.hashName, - priceTotal: (position.price + maximumOverprice) * position.quantity, + priceTotal: Math.ceil(position.price * (1 + overpricePercent / 100)) * position.quantity, quantity: position.quantity }); } diff --git a/src/steam/pages/component/CardBuyerTable.ts b/src/steam/pages/component/CardBuyerTable.ts index 885ca7f..e1c8ce2 100644 --- a/src/steam/pages/component/CardBuyerTable.ts +++ b/src/steam/pages/component/CardBuyerTable.ts @@ -49,7 +49,7 @@ class CardBuyerTable extends Table implements SteamElement { return { quantity: parseInt(rowKeyValue.get("quantity") as string), - price: currency(rowKeyValue.get("price") as string).value, + price: currency(rowKeyValue.get("price") as string, { decimal: ",", separator: "." }).intValue, appId: parseInt(metaData[0]), hashName: metaData[1], }; diff --git a/src/ui/react/component/Badge.tsx b/src/ui/react/component/Badge.tsx index 5ad638d..72e2fa6 100644 --- a/src/ui/react/component/Badge.tsx +++ b/src/ui/react/component/Badge.tsx @@ -1,4 +1,5 @@ import React from "react"; +import currency from "currency.js"; import Loading from "./ui/Loading"; import LevelUpService from "../../../service/LevelUpService"; import SteamCurrency from "../../../steam/utils/SteamCurrency"; @@ -11,7 +12,8 @@ import NeedConfirmationStreamApiException from "../../../api/steam/exception/Nee interface BadgeProperties { steamId: string, appId: number, - appName: string + appName: string, + overpricePercent: number } enum BadgeStatus { @@ -126,9 +128,17 @@ Items will be purchased at the cheapest price available, so the order may end up private calculateBadgePrice(): string { - const { price } = this.state; + const { price, orderDetails } = this.state; - return price?.toFormat() ?? "XXX"; + if (price === undefined || orderDetails === undefined) { + return "XXX"; + } + + const totalCents = orderDetails.reduce((sum, position) => { + return sum + Math.ceil(position.price * (1 + this.props.overpricePercent / 100)) * position.quantity; + }, 0); + + return currency(totalCents, { fromCents: true, symbol: SteamCurrency.getCurrencySymbolByWalletCurrencyNumber(price.getId()) }).format(); } private calculateApp() { @@ -159,7 +169,8 @@ Items will be purchased at the cheapest price available, so the order may end up injector.resolve(SteamCardTraderService).createTrader( orderDetails, - price.getId() + price.getId(), + this.props.overpricePercent ).then(a => { //TODO promise? const interval = setInterval(() => { diff --git a/src/ui/react/component/Badges.tsx b/src/ui/react/component/Badges.tsx index 95a262d..5dd1337 100644 --- a/src/ui/react/component/Badges.tsx +++ b/src/ui/react/component/Badges.tsx @@ -12,7 +12,8 @@ interface BadgesProperties { interface BadgesState { badges?: Array, - currentPage: number + currentPage: number, + overpricePercent: number } export default class Badges extends React.Component { @@ -21,9 +22,10 @@ export default class Badges extends React.Component) { + const value = parseInt(event.target.value, 10); + if (!isNaN(value) && value >= 0) { + this.setState({ overpricePercent: value }); + } + } + render() { const pagination = this.state.badges !== undefined ? -
Uncompleted badges (Price stats provided by SteamCardExchange)
+
+ Uncompleted badges + (Price stats provided by SteamCardExchange) + + Overprice: % + +
{pagination} @@ -98,6 +124,7 @@ export default class Badges extends React.Component { return ( ); });