Navigation Menu

Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
greysonn committed Aug 4, 2019
1 parent 629211a commit 224aee8
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 14 deletions.
28 changes: 28 additions & 0 deletions public/scss/home.scss
Expand Up @@ -135,6 +135,8 @@ $tableBackground: #fff;
}
.sync-container {
margin: 0 0 0 auto;
display: flex;
flex-direction: row;
.goat-btn {
height: 51px;
width: 220px;
Expand All @@ -145,6 +147,7 @@ $tableBackground: #fff;
border-radius: 4px;
color: #000000;
font-size: 14px;
margin-left: 18px;
padding: 12px 36px;
background: #fff;
outline: none;
Expand All @@ -156,6 +159,31 @@ $tableBackground: #fff;
max-width: 100%;
}
}
.stockx-btn {
height: 51px;
width: 216px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
border-radius: 4px;
color: #fff;
font-size: 14px;
padding: 12px 36px;
background: #3bae2b;
outline: none;
background-image: radial-gradient(
at top left,
#51bf43, #3bae2b
);
box-shadow: 0px 15px 85px -7px rgba(0,0,0,0.2);
.img {
margin-left: .6rem;
width: 70px;
height: auto;
max-width: 100%;
}
}
}
}
.sales-table {
Expand Down
5 changes: 4 additions & 1 deletion src/classes/data.ts
Expand Up @@ -25,7 +25,10 @@ export const data: DataManager = {
fs.writeFileSync(settingsPath, JSON.stringify({
goatUsername: '',
goatPassword: '',
goatAuthToken: ''
goatAuthToken: '',
stockxEmail: '',
stockxPassword: '',
stockxJwtToken: ''
}));
}
saleStorage = JSON.parse(fs.readFileSync(salesPath).toString());
Expand Down
8 changes: 5 additions & 3 deletions src/classes/stockx.ts
Expand Up @@ -30,12 +30,14 @@ export class Stockx {
password
},
json: true,
jar: this.jar
jar: this.jar,
resolveWithFullResponse: true
});
this.jwtToken = res.headers['Jwt-Authorization'];
this.jwtToken = res.headers['jwt-authorization'];

return '';
return this.jwtToken;
} catch (e) {
console.error(e);
return '';
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/common/types.ts
Expand Up @@ -19,6 +19,9 @@ export type Settings = {
goatUsername: string;
goatPassword: string;
goatAuthToken: string;
stockxEmail: string;
stockxPassword: string;
stockxJwtToken: string;
};

export type DataManager = {
Expand Down
15 changes: 15 additions & 0 deletions src/main/main.ts
Expand Up @@ -9,8 +9,10 @@ import * as url from 'url';
import { data } from '@/classes/data';
import { SaleInfo, Settings } from '@/common/types';
import { Goat } from '../classes/goat';
import { Stockx } from '../classes/stockx';

const goat: Goat = new Goat();
const stockx: Stockx = new Stockx();
const devtools: boolean = false;
let mainWindow: Electron.BrowserWindow | null;

Expand Down Expand Up @@ -93,6 +95,19 @@ ipcMain.on('goatLogin', async (event: IpcMessageEvent, arg: { username: string;
}
});

ipcMain.on('stockxLogin', async (event: IpcMessageEvent, arg: { email: string; password: string }) => {
// tslint:disable: possible-timing-attack
const token: string = await stockx.logIn(arg.email, arg.password);
if (token) {
data.setSetting('stockxEmail', arg.email);
data.setSetting('stockxPassword', arg.password);
data.setSetting('stockxJwtToken', token);
mainWindow!.webContents.send('stockxLoginResponse', true);
} else {
mainWindow!.webContents.send('stockxLoginResponse', false);
}
});

ipcMain.on('syncGoatSales', async (event: IpcMessageEvent) => {
await goat.getSales();
mainWindow!.webContents.send('getSales', data.getSales());
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/tableItem.tsx
@@ -1,6 +1,7 @@
import * as React from 'react';
import Select from 'react-select';
import { ipcRenderer } from 'electron';
import { SaleInfo } from '@/common/types';

type Action = { label: string; value: string };
type TableItemProps = {
Expand Down
14 changes: 12 additions & 2 deletions src/renderer/routes/Home.tsx
Expand Up @@ -4,6 +4,7 @@ import Modal from 'react-responsive-modal';

import { SaleInfo, Settings } from '@/common/types';
import * as GoatLogo from '@public/img/goat.png';
import * as StockxLogo from '@public/img/stockx.png';
import '@public/scss/home.scss';
import { AddSale } from '../components/addSale';
import { TableItem } from '../components/tableItem';
Expand All @@ -19,6 +20,7 @@ type HomeState = {
sales: SaleInfo[];
addModalOpen: boolean;
goatConnected: boolean;
stockxConnected: boolean;
};

let storedSales: SaleInfo[] = [];
Expand All @@ -42,7 +44,8 @@ export class Home extends React.Component<HomeProps, HomeState> {
this.state = {
sales: [],
addModalOpen: false,
goatConnected: false
goatConnected: false,
stockxConnected: false
};

this.grossProfit = 0;
Expand Down Expand Up @@ -77,7 +80,6 @@ export class Home extends React.Component<HomeProps, HomeState> {
}
}


let mostProfitable: number = 0;
for (const sale of sales) {
this.netProfit += sale.netProfit;
Expand Down Expand Up @@ -107,6 +109,9 @@ export class Home extends React.Component<HomeProps, HomeState> {
if (settings.goatAuthToken) {
this.setState({ goatConnected: true });
}
if (settings.stockxJwtToken) {
this.setState({ stockxConnected: true });
}
});
}

Expand Down Expand Up @@ -210,6 +215,11 @@ export class Home extends React.Component<HomeProps, HomeState> {
{this.state.sales.length} {this.state.sales.length === 1 ? 'Sale' : 'Sales'}
</div>
<div className='sync-container'>
{this.state.goatConnected ? (
<button onClick={this.syncGoat} className='stockx-btn'>
Pull Sales <img className='img' src={StockxLogo.toString()}/>
</button>
) : null }
{this.state.goatConnected ? (
<button onClick={this.syncGoat} className='goat-btn'>
Pull Sales <img className='img' src={GoatLogo.toString()}/>
Expand Down
27 changes: 19 additions & 8 deletions src/renderer/routes/Settings.tsx
Expand Up @@ -8,7 +8,7 @@ import { IpcMessageEvent, ipcRenderer } from 'electron';

type SettingProps = {};
type SettingState = {
stockxUsername: string;
stockxEmail: string;
stockxPassword: string;
goatUsername: string;
goatPassword: string;
Expand All @@ -22,21 +22,29 @@ ipcRenderer.on('goatLoginResponse', (event: IpcMessageEvent, success: boolean) =
}
});

ipcRenderer.on('stockxLoginResponse', (event: IpcMessageEvent, success: boolean) => {
if (success) {
toast.success('Successfully logged into stockx and saved credentials.');
} else {
toast.error('There was an issue logging into stockx, please try again later');
}
});

/**
* Home component to be used as main homepage
*/
export class Settings extends React.Component<SettingProps, SettingState> {
constructor(props: SettingProps) {
super(props);
this.state = {
stockxUsername: '',
stockxEmail: '',
stockxPassword: '',
goatUsername: '',
goatPassword: ''
};

this.handleChange = this.handleChange.bind(this);
this.showToast = this.showToast.bind(this);
this.stockxLogin = this.stockxLogin.bind(this);
this.goatLogin = this.goatLogin.bind(this);
}

Expand Down Expand Up @@ -70,8 +78,8 @@ export class Settings extends React.Component<SettingProps, SettingState> {
<div className='row'>
<div className='col'>
<p>Stockx Account</p>
<input value={this.state.stockxUsername} className='input' placeholder='Username'
onChange={this.handleChange} name='stockxUsername' />
<input value={this.state.stockxEmail} className='input' placeholder='Email'
onChange={this.handleChange} name='stockxEmail' />
</div>
</div>
<div className='row'>
Expand All @@ -82,7 +90,7 @@ export class Settings extends React.Component<SettingProps, SettingState> {
</div>
<div className='row' style={{ marginTop: '22px', marginBottom: '22px' }}>
<div className='col'>
<button onClick={this.showToast} className='stockx-btn'>Login to <img className='img' src={StockxLogo.toString()}/></button>
<button onClick={this.stockxLogin} className='stockx-btn'>Login to <img className='img' src={StockxLogo.toString()}/></button>
</div>
</div>
</div>
Expand Down Expand Up @@ -126,7 +134,10 @@ export class Settings extends React.Component<SettingProps, SettingState> {
});
}

private showToast(): void {
toast.error('Stockx connections may be coming soon.');
private stockxLogin(): void {
ipcRenderer.send('stockxLogin', {
email: this.state.stockxEmail,
password: this.state.stockxPassword
});
}
}

0 comments on commit 224aee8

Please sign in to comment.