Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
feat: apply new linter and prettier settings
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-calavera committed Sep 17, 2019
1 parent 18ea027 commit 32c8e66
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 62 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {extends: ['@commitlint/config-conventional']};
module.exports = { extends: ['@commitlint/config-conventional'] };
6 changes: 3 additions & 3 deletions fetch-solana-install-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ async function main() {
case 'Windows_NT':
download(
'solana-install-init-x86_64-pc-windows-msvc.exe',
'solana-install-init.exe',
'solana-install-init.exe'
);
break;
case 'Darwin':
download(
'solana-install-init-x86_64-apple-darwin',
'solana-install-init',
'solana-install-init'
);
// Set user write bit so that ShipIt can remove the quarantine attribute
// after unzipping an update archive, otherwise the update fails
Expand All @@ -74,7 +74,7 @@ async function main() {
case 'Linux':
download(
'solana-install-init-x86_64-unknown-linux-gnu',
'solana-install-init',
'solana-install-init'
);
fs.chmodSync('solana-install-init', 0o555);
break;
Expand Down
44 changes: 25 additions & 19 deletions src/app.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/* eslint no-console: ["error", { allow: ["log", "warn", "info", "error"] }] */
/* eslint max-classes-per-file: 0 */
/* eslint react/prefer-stateless-function: 0 */
/* eslint react/destructuring-assignment: 0 */
/* eslint react/sort-comp: 0 */

import Container from '@material-ui/core/Container';
import CssBaseline from '@material-ui/core/CssBaseline';
import FormControlLabel from '@material-ui/core/FormControlLabel';
Expand All @@ -11,16 +17,16 @@ import Switch from '@material-ui/core/Switch';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import log from 'electron-log';
import {Connection, PublicKey} from '@solana/web3.js';
import {withStyles} from '@material-ui/core/styles';
import { Connection, PublicKey } from '@solana/web3.js';
import { withStyles } from '@material-ui/core/styles';
import Store from 'electron-store';
import IconButton from '@material-ui/core/IconButton';
import SaveIcon from '@material-ui/icons/Save';
import autoscroll from 'autoscroll-react';
import {Hook, Console, Decode} from 'console-feed';
import { Hook, Console, Decode } from 'console-feed';

import {url} from './url';
import {Replicator} from './replicator';
import url from './url';
import Replicator from './replicator';

const styles = theme => ({
root: {
Expand Down Expand Up @@ -69,7 +75,7 @@ class LogConsole extends React.Component {
overflowY: 'hidden',
}}
>
<div style={{width: '1000%'}}>
<div style={{ width: '1000%' }}>
<Console logs={this.props.logs} variant="dark" />
</div>
</div>
Expand Down Expand Up @@ -110,13 +116,13 @@ class App extends React.Component {
Hook(console, newLog => {
const decodeLog = Decode(newLog);
log.info('term:', decodeLog.data[0]);
const {logs} = this.state;
const { logs } = this.state;
logs.push(decodeLog);
const max = 20;
if (logs.length > max) {
logs.splice(0, logs.length - max);
}
this.setState({logs});
this.setState({ logs });
});
this.connection = new Connection(url);

Expand All @@ -139,7 +145,7 @@ class App extends React.Component {
}

clearTerminal() {
this.setState({logs: []});
this.setState({ logs: [] });
}

clusterRestart() {
Expand All @@ -157,21 +163,21 @@ class App extends React.Component {

if (transactionCount < this.state.transactionCount / 2) {
console.warn(
`Transaction count decreased from ${this.state.transactionCount} to ${transactionCount}`,
`Transaction count decreased from ${this.state.transactionCount} to ${transactionCount}`
);
this.clusterRestart();
return;
}

const totalSupply = await this.connection.getTotalSupply();
const newMined = await this.replicator.adjustedReplicatorBalance();
let totalMined = this.state.totalMined;
let { totalMined } = this.state;

if (newMined > this.state.depositMinimumLamports) {
if (isValidPublicKey(this.depositPublicKey)) {
const success = await this.replicator.depositMiningRewards(
new PublicKey(this.depositPublicKey),
newMined,
newMined
);
if (success) {
totalMined += newMined;
Expand All @@ -184,12 +190,12 @@ class App extends React.Component {
if (isValidPublicKey(this.depositPublicKey)) {
try {
const balance = await this.connection.getBalance(
new PublicKey(this.depositPublicKey),
new PublicKey(this.depositPublicKey)
);
depositPublicKeyBalance = `Account Balance: ${balance} lamports`;
} catch (err) {
log.warn(
`Unable to getBalance of ${this.depositPublicKey}: ${err.message}`,
`Unable to getBalance of ${this.depositPublicKey}: ${err.message}`
);
}
}
Expand All @@ -209,7 +215,7 @@ class App extends React.Component {
onEnabledSwitch = event => {
const enabled = event.target.checked;
this.store.set('enabled', enabled);
this.setState({enabled});
this.setState({ enabled });
if (enabled) {
this.clearTerminal();
this.replicator.start();
Expand All @@ -223,7 +229,7 @@ class App extends React.Component {

const unsavedDepositPublicKey = event.target.value;
const unsavedDepositPublicKeyValid = isValidPublicKey(
unsavedDepositPublicKey,
unsavedDepositPublicKey
);
const unsavedDepositPublicKeySavePrompt =
unsavedDepositPublicKeyValid &&
Expand Down Expand Up @@ -265,15 +271,15 @@ class App extends React.Component {
};

render() {
const {classes} = this.props;
const { classes } = this.props;

const AutoscrollLogConsole = autoscroll(LogConsole, {
isScrolledDownThreshold: 0,
});

// eslint-disable-next-line no-restricted-properties
const totalSupplySOL = (this.state.totalSupply / Math.pow(2, 34)).toFixed(
2,
2
);

return (
Expand All @@ -283,7 +289,7 @@ class App extends React.Component {
<Grid container spacing={0}>
<Grid
item
style={{display: 'flex', alignItems: 'center'}}
style={{ display: 'flex', alignItems: 'center' }}
xs={10}
sm={5}
>
Expand Down
16 changes: 9 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {app, ipcMain, BrowserWindow, Menu} from 'electron';
/* eslint no-console: ["error", { allow: ["log", "warn", "info", "error"] }] */

import { app, ipcMain, BrowserWindow, Menu } from 'electron';
import installExtension, {
REACT_DEVELOPER_TOOLS,
} from 'electron-devtools-installer';
Expand All @@ -7,8 +9,8 @@ import path from 'path';
import os from 'os';
import log from 'electron-log';
import './updater';
import {Replicator} from './replicator';
import {sleep} from './sleep';
import Replicator from './replicator';
import sleep from './sleep';

// eslint-disable-next-line global-require
if (require('electron-squirrel-startup')) app.quit();
Expand Down Expand Up @@ -91,12 +93,12 @@ app.on('ready', async () => {
{
label: 'Edit',
submenu: [
{label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:'},
{label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:'},
{label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:'},
{ label: 'Cut', accelerator: 'CmdOrCtrl+X', selector: 'cut:' },
{ label: 'Copy', accelerator: 'CmdOrCtrl+C', selector: 'copy:' },
{ label: 'Paste', accelerator: 'CmdOrCtrl+V', selector: 'paste:' },
],
},
]),
])
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/renderer.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {AppContainer} from 'react-hot-loader';
import { AppContainer } from 'react-hot-loader';
import App from './app';
import pkg from '../package.json';

Expand All @@ -11,7 +11,7 @@ const render = () => {
<AppContainer>
<App />
</AppContainer>,
document.getElementById('App'),
document.getElementById('App')
);
};

Expand Down
47 changes: 25 additions & 22 deletions src/replicator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint no-console: ["error", { allow: ["log", "warn", "info", "error"] }] */
/* eslint react/destructuring-assignment: 0 */

import log from 'electron-log';
import {spawn} from 'promisify-child-process';
import { spawn } from 'promisify-child-process';
import path from 'path';
import os from 'os';
import electron from 'electron';
Expand All @@ -11,14 +14,14 @@ import {
SystemProgram,
} from '@solana/web3.js';
import fs from 'mz/fs';
import {solanaInstallInit} from './solana-install-init';
import {sleep} from './sleep';
import {url} from './url';
import solanaInstallInit from './solana-install-init';
import sleep from './sleep';
import url from './url';

// TODO: https://github.com/solana-labs/solana/issues/4344
const airdropAmount = 100000;

export class Replicator {
export default class Replicator {
constructor(connection) {
const userDataPath = electron.remote.app.getPath('userData');

Expand All @@ -32,7 +35,7 @@ export class Replicator {
userDataPath,
'install',
'active_release',
'bin',
'bin'
),
replicatorKeypair: null,
replicatorKeypairFile: path.join(userDataPath, 'replicator-keypair.json'),
Expand Down Expand Up @@ -66,7 +69,7 @@ export class Replicator {
],
{
force: true,
},
}
);
} catch (err) {
log.debug('fkill errored with:', err);
Expand Down Expand Up @@ -105,11 +108,11 @@ export class Replicator {
if (this.replicatorKeypair !== null) {
try {
const realBalance = await this.connection.getBalance(
this.replicatorKeypair.publicKey,
this.replicatorKeypair.publicKey
);
const adjustedBalance = Math.max(0, realBalance - airdropAmount);
log.info(
`adjustedReplicatorBalance: real=${realBalance} adjusted=${adjustedBalance}`,
`adjustedReplicatorBalance: real=${realBalance} adjusted=${adjustedBalance}`
);
return adjustedBalance;
} catch (err) {
Expand All @@ -130,26 +133,26 @@ export class Replicator {

try {
log.info(
`depositMiningRewards: ${amount} lamports to ${destinationPublicKey}`,
`depositMiningRewards: ${amount} lamports to ${destinationPublicKey}`
);
const transaction = SystemProgram.transfer(
this.replicatorKeypair.publicKey,
destinationPublicKey,
amount,
amount
);
const signature = await sendAndConfirmTransaction(
this.connection,
transaction,
this.replicatorKeypair,
this.replicatorKeypair
);
console.info(
`Deposited mining rewards (${amount} lamports). Transaction signature: ${signature}`,
`Deposited mining rewards (${amount} lamports). Transaction signature: ${signature}`
);
return true;
} catch (err) {
console.error(
`Deposit mining rewards failed (${amount} lamports):`,
err.message,
err.message
);
return false;
} finally {
Expand All @@ -166,8 +169,8 @@ export class Replicator {
}
console.log(`$ ${command} ${args.join(' ')}`);
log.info(`$ ${command} ${args.join(' ')}`);
const env = Object.assign({}, {RUST_LOG: 'solana=info'}, process.env);
const child = spawn(command, args, {env});
const env = { RUST_LOG: 'solana=info', ...process.env };
const child = spawn(command, args, { env });
log.info(`pid ${child.pid}`);

function logData(data) {
Expand Down Expand Up @@ -210,7 +213,7 @@ export class Replicator {
try {
await fs.access(keypairFile, fs.constants.R_OK);
const keypair = new Account(
Buffer.from(jsonfile.readFileSync(keypairFile)),
Buffer.from(jsonfile.readFileSync(keypairFile))
);
const balance = await this.connection.getBalance(keypair.publicKey);
if (balance > 0) {
Expand Down Expand Up @@ -250,29 +253,29 @@ export class Replicator {
]);

const newReplicatorKeypair = await this.maybeGenerateKeypair(
this.replicatorKeypairFile,
this.replicatorKeypairFile
);
const newStorageKeypair = await this.maybeGenerateKeypair(
this.storageKeypairFile,
newReplicatorKeypair,
newReplicatorKeypair
);

console.info(`identity keypair: ${this.replicatorKeypairFile}`);
console.info(`storage keypair: ${this.storageKeypairFile}`);

const replicatorKeypair = new Account(
Buffer.from(jsonfile.readFileSync(this.replicatorKeypairFile)),
Buffer.from(jsonfile.readFileSync(this.replicatorKeypairFile))
);
this.replicatorKeypair = replicatorKeypair;
const storageKeypair = new Account(
Buffer.from(jsonfile.readFileSync(this.storageKeypairFile)),
Buffer.from(jsonfile.readFileSync(this.storageKeypairFile))
);

console.info(`identity pubkey: ${replicatorKeypair.publicKey}`);
console.info(`storage pubkey: ${storageKeypair.publicKey}`);

const replicatorStartingBalance = await this.connection.getBalance(
this.replicatorKeypair.publicKey,
this.replicatorKeypair.publicKey
);
if (replicatorStartingBalance < airdropAmount) {
await this.cmd(solanaCli, [
Expand Down
2 changes: 1 addition & 1 deletion src/sleep.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function sleep(ms) {
export default function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
4 changes: 3 additions & 1 deletion src/solana-install-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import path from 'path';
const isDevMode = process.execPath.match(/[\\/]electron/);
const dotexe = os.type() === 'Windows_NT' ? '.exe' : '';

export const solanaInstallInit = isDevMode
const solanaInstallInit = isDevMode
? `solana-install-init${dotexe}` // in dev mode assume it's in the path
: path.join(process.resourcesPath, `solana-install-init${dotexe}`); // bundled in the app when not in dev mode

export default solanaInstallInit;
Loading

0 comments on commit 32c8e66

Please sign in to comment.