Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed Apr 8, 2021
2 parents 140c12e + 8652bfc commit 3117c43
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 153 deletions.
8 changes: 2 additions & 6 deletions app/src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ export default class Account {
client.on('wallet', (_hasWallet: boolean, currency: number) => this.setCurrency(currency));
client.on('loggedOn', () => this.onLogin());
client.on('disconnected', (_eResult: number, msg: string) => this.onDisconnect(msg));
client.on('steamGuard', (_domain: any, callback: (code: string) => void) =>
callback(this.getAuthCode())
);
client.on('steamGuard', (_domain: any, callback: (code: string) => void) => callback(this.getAuthCode()));
manager.on('newOffer', (offer: Offer) => trader.begin(offer));
client.on('error', (err: any) =>
this.logger.error(`Occurred an error on the last operation: ${err.message}`)
);
client.on('error', (err: any) => this.logger.error(`Occurred an error on the last operation: ${err.message}`));
}

logoff() {
Expand Down
6 changes: 1 addition & 5 deletions app/src/ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ function log(...msg: string[]) {
}

export function startup() {
log(
'This app was developed by Arthur Fiorette',
'Visit us on GitHub!',
'https://github.com/ArthurFiorette/steam-trader'
);
log('This app was developed by Arthur Fiorette', 'Visit us on GitHub!', 'https://github.com/ArthurFiorette/steam-trader');
}

export function listening(port: any) {
Expand Down
6 changes: 1 addition & 5 deletions app/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ export const socketTransport = new SocketTransport(levelFormat);
const loggers: Logger[] = [];

export default function createLogger(account: string) {
const logger = _createLogger(
account,
new transports.File({ filename: `${getPath(account)}.log` }),
socketTransport
);
const logger = _createLogger(account, new transports.File({ filename: `${getPath(account)}.log` }), socketTransport);
loggers.push(logger);
return logger;
}
Expand Down
6 changes: 1 addition & 5 deletions app/src/steam/currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ function replaceInvalid(str: string) {
return str.split('-').join('0').split(' ').join('');
}

function currency(
name: string,
currencyId: number,
/* [index at pos 0, index at last pos] */ [a, b]: number[]
): ICurrency {
function currency(name: string, currencyId: number, /* [index at pos 0, index at last pos] */ [a, b]: number[]): ICurrency {
return {
name,
currencyId,
Expand Down
4 changes: 1 addition & 3 deletions app/src/transactions/logic/calculatePrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ export function isTrash(item: ItemPrice, options: AccountOptions): boolean {
}

export function calculatePrice({ median_price, lowest_price }: ItemPrice): number {
return !median_price || lowest_price > median_price
? lowest_price
: median_price + lowest_price / 2;
return !median_price || lowest_price > median_price ? lowest_price : median_price + lowest_price / 2;
}

function reducePrices(items: ItemPrice[]): number {
Expand Down
14 changes: 2 additions & 12 deletions app/src/transactions/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@ function writeFile(id: string, content: any) {
});
}

function serializeTransaction(
account: string,
{ offer, profit }: OfferContext,
reason: string,
accepted: boolean
) {
function serializeTransaction(account: string, { offer, profit }: OfferContext, reason: string, accepted: boolean) {
return {
account,
partner: offer.partner.getSteamID64(),
Expand All @@ -54,12 +49,7 @@ function serializeTransaction(
};
}

function serializeTransactionSocket(
account: string,
context: OfferContext,
reason: string,
accepted: boolean
) {
function serializeTransactionSocket(account: string, context: OfferContext, reason: string, accepted: boolean) {
const { offer } = context;
return {
...serializeTransaction(account, context, reason, accepted),
Expand Down
5 changes: 1 addition & 4 deletions web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
></script>
<!-- React -->
<script crossorigin src="https://unpkg.com/react@17/umd/react.production.min.js"></script>
<script
crossorigin
src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"
></script>
<script crossorigin src="https://unpkg.com/react-dom@17/umd/react-dom.production.min.js"></script>
<!-- Socket.io -->
<script
src="https://cdn.socket.io/3.1.3/socket.io.min.js"
Expand Down
5 changes: 1 addition & 4 deletions web/server/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [
"node_modules/@types",
"src/@types"
] /* List of folders to include type definitions from. */,
"typeRoots": ["node_modules/@types", "src/@types"] /* List of folders to include type definitions from. */,
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
Expand Down
17 changes: 2 additions & 15 deletions web/src/components/accounts/account.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { useState, useEffect } from 'react';
import { fetchSteamUserImage } from './util';
import {
AccountOptions,
getAccount,
logout as logoutAcc,
login as loginAcc
} from '../../services/accounts';
import { AccountOptions, getAccount, logout as logoutAcc, login as loginAcc } from '../../services/accounts';
import { IconButton } from '../button';
import { PencilFill, Power } from 'react-bootstrap-icons';
import socket from '../../services/socket';
Expand Down Expand Up @@ -45,15 +40,7 @@ export default function Account({ account }: any) {
}

function AccountButton({ icon, color, onClick }: any) {
return (
<IconButton
icon={icon}
color={color}
onClick={onClick}
classes="m-1 p-1"
iconProps={{ className: 'm-1' }}
/>
);
return <IconButton icon={icon} color={color} onClick={onClick} classes="m-1 p-1" iconProps={{ className: 'm-1' }} />;
}

// TODO [#4]: Standardize thumbnail images
Expand Down
7 changes: 1 addition & 6 deletions web/src/components/accounts/form/inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ export function CheckInput({ title, help, required, onChange }: InputProps) {
const helpId = `${id}Help`;
return (
<div className="mb-3 form-check">
<input
className="form-check-input"
type="checkbox"
area-describedby={helpId}
{...{ id, onChange, required }}
/>
<input className="form-check-input" type="checkbox" area-describedby={helpId} {...{ id, onChange, required }} />
<label className="form-check-label" htmlFor={id}>
{title}
</label>
Expand Down
42 changes: 6 additions & 36 deletions web/src/components/accounts/form/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,12 @@ export default function Form({ initialData = emptyAccount() }: FormProps) {
const INPUTS: [string, string, string, (val: any) => void, boolean?][] = [
['text', 'Username', 'Your steam username', (val) => (login.username = val), true],
['password', 'Password', 'Your steam password', (val) => (login.password = val), true],
[
'password',
'Shared Secret',
'Your steam shared secret',
(val) => (login.sharedSecret = val),
true
],
[
'password',
'Identity Secret',
'Your steam identity secret',
(val) => (login.identity = val),
true
],
['password', 'Shared Secret', 'Your steam shared secret', (val) => (login.sharedSecret = val), true],
['password', 'Identity Secret', 'Your steam identity secret', (val) => (login.identity = val), true],
['number', 'Game Id', 'A steam game id to keep playing', (val) => (status.gameId = val)],
[
'number',
'Trash Limit',
'The minimum item price accepted',
(val) => (trading.trashLimit = val),
true
],
[
'number',
'Owner Id',
'It will ALWAYS accept trades from this steam id',
(val) => (trading.owners = [val])
],
[
'checkbox',
'Trade With 0 profit',
'Accept trades with the same two prices?',
(val) => (trading.tradeWith0Profit = val)
]
['number', 'Trash Limit', 'The minimum item price accepted', (val) => (trading.trashLimit = val), true],
['number', 'Owner Id', 'It will ALWAYS accept trades from this steam id', (val) => (trading.owners = [val])],
['checkbox', 'Trade With 0 profit', 'Accept trades with the same two prices?', (val) => (trading.tradeWith0Profit = val)]
];

return (
Expand All @@ -70,9 +42,7 @@ export default function Form({ initialData = emptyAccount() }: FormProps) {
return (
<Input
{...{ type, title, help, required }}
onChange={({
target: { type, checked, value }
}: React.ChangeEvent<HTMLInputElement>) => {
onChange={({ target: { type, checked, value } }: React.ChangeEvent<HTMLInputElement>) => {
callback(type === 'checkbox' ? checked : value);
setData({ login, status, trading });
}}
Expand Down
25 changes: 3 additions & 22 deletions web/src/components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ type CloseButtonProps = ButtonProps & {
};

type ColoredButtonProps = ButtonProps & {
color?:
| 'primary'
| 'secondary'
| 'success'
| 'danger'
| 'warning'
| 'info'
| 'light'
| 'dark'
| 'link';
color?: 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark' | 'link';
};

type IconButtonProps = ColoredButtonProps & {
Expand All @@ -35,25 +26,15 @@ function ButtonTemplate({ children, classes, ...props }: ButtonProps) {
);
}

export function CloseButton({
children,
classes = '',
ariaLabel = 'Close',
...props
}: CloseButtonProps) {
export function CloseButton({ children, classes = '', ariaLabel = 'Close', ...props }: CloseButtonProps) {
return (
<ButtonTemplate classes={`btn-close text-reset ${classes}`} {...props} aria-label={ariaLabel}>
{children}
</ButtonTemplate>
);
}

export function ColoredButton({
children,
color = 'primary',
classes = '',
...props
}: ColoredButtonProps) {
export function ColoredButton({ children, color = 'primary', classes = '', ...props }: ColoredButtonProps) {
return (
<ButtonTemplate classes={`btn btn-outline-${color} ${classes}`} {...props}>
{children}
Expand Down
4 changes: 1 addition & 3 deletions web/src/components/infoBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export default function InfoBox({ title, children }: any) {
return (
<Fragment>
<h6 className="px-3 display-6 text-dark text-center mb-2">{title}</h6>
<div
className="shadow-lg p-2 rounded-3 border overflow-auto"
style={{ height: '35vh', minHeight: '300px' }}>
<div className="shadow-lg p-2 rounded-3 border overflow-auto" style={{ height: '35vh', minHeight: '300px' }}>
{children}
</div>
</Fragment>
Expand Down
6 changes: 1 addition & 5 deletions web/src/components/logs/log.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { getColor } from './util';

export default function Log({ level, message, date, account }: any) {
return (
<li
key={date.getTime()}
data-bs-toggle="tooltip"
data-bs-placement="top"
title={getTooltipTitle(account)}>
<li key={date.getTime()} data-bs-toggle="tooltip" data-bs-placement="top" title={getTooltipTitle(account)}>
<span className={`pe-3 text-${getColor(level)}`}>{date.toLocaleTimeString()}</span>
<span className="text-wrap text-muted mw-100">{message}</span>
</li>
Expand Down
5 changes: 1 addition & 4 deletions web/src/components/trades/trade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { ArrowLeftRight } from 'react-bootstrap-icons';
export default function Trade({ trade }: { trade: ITrade }) {
const title = `Profit: ${trade.profit} - Partner: ${trade.partner} - Trade Id: ${trade.offerId}`;
return (
<li
className="d-flex justify-content-between align-items-center my-1 py-1"
data-bs-toggle="tooltip"
title={title}>
<li className="d-flex justify-content-between align-items-center my-1 py-1" data-bs-toggle="tooltip" title={title}>
<ItemSet items={trade.theirItems} received={true} />
<ArrowLeftRight className="text-secondary mx-5" size="40px" />
<ItemSet items={trade.ourItems} />
Expand Down
7 changes: 1 addition & 6 deletions web/src/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ export default function Header() {
<nav className="navbar navbar-expand navbar-dark bg-dark px-4 justify-content-between">
<div className="navbar-brand">Steam Trader</div>
<a href={GIT_URL} target="_blank">
<IconButton
icon={Github}
color="light"
classes="border-0 p-1"
iconProps={{ size: '32' }}
/>
<IconButton icon={Github} color="light" classes="border-0 p-1" iconProps={{ size: '32' }} />
</a>
</nav>
</header>
Expand Down
4 changes: 1 addition & 3 deletions web/src/services/ping.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import axios from 'axios';

export async function ping() {
return (
(await axios({ method: 'GET', url: 'http://localhost:1228/ping' })).data.response === 'Pong'
);
return (await axios({ method: 'GET', url: 'http://localhost:1228/ping' })).data.response === 'Pong';
}
11 changes: 2 additions & 9 deletions web/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
// "incremental": true, /* Enable incremental compilation */
"target": "es6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */,
"lib": [
"DOM",
"DOM.Iterable",
"ESNext"
] /* Specify library files to be included in the compilation. */,
"lib": ["DOM", "DOM.Iterable", "ESNext"] /* Specify library files to be included in the compilation. */,
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', 'react', 'react-jsx' or 'react-jsxdev'. */,
Expand Down Expand Up @@ -51,10 +47,7 @@
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
"typeRoots": [
"node_modules/@types",
"src/@types"
] /* List of folders to include type definitions from. */,
"typeRoots": ["node_modules/@types", "src/@types"] /* List of folders to include type definitions from. */,
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
Expand Down

0 comments on commit 3117c43

Please sign in to comment.