Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #18 from ellcrys/dev
Browse files Browse the repository at this point in the history
Analytics, Elld Shell FIx & Onboarding
  • Loading branch information
ncodes authored Apr 18, 2019
2 parents b2f1258 + 7428a7e commit bc73f3d
Show file tree
Hide file tree
Showing 47 changed files with 3,339 additions and 2,177 deletions.
49 changes: 12 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Safehold - Ellcrys Desktop Client
# SafeHold - Ellcrys Desktop Client

Safehold is the official desktop client that allows users to join the Ellcrys network, manage their Ellcrys accounts, send and receive
the native cryptocurrency and more. Safehold provides a beautiful graphic user interface that allows all categories of users experience and interact with the network easily.
SafeHold is the official desktop client that allows users to join the Ellcrys network, manage their Ellcrys accounts, send and receive
the native cryptocurrency and more. SafeHold provides a beautiful graphic user interface that allows all categories of users experience and interact with the network easily.

## Installation

[TODO]

## Development

Safehold is actively being developed by the Ellcrys team. It will continue to mature as the protocol itself gains more features and improvements.
SafeHold is actively being developed by the Ellcrys team. It will continue to mature as the protocol itself gains more features and improvements.

### Install Dependencies

Expand All @@ -21,16 +21,17 @@ npm install

### Embedded ELLD

Internally, Safehold embeds and execute a copy of [ELLD](https://github.com/ellcrys/elld) (our official CLI network client) to gain access to all features supported by the protocol. During development, you will need to add pre-built binaries into the [binaries](https://github.com/ellcrys/safehold/tree/master/binaries) directory where it will be picked up by the build script and embedded into the build.
Internally, SafeHold embeds and execute a copy of [ELLD](https://github.com/ellcrys/elld) (our official CLI network client) to gain access to all features supported by the protocol. During development, you will need to add pre-built binaries into the [binaries](https://github.com/ellcrys/safehold/tree/master/binaries) directory where it will be picked up by the build script and embedded into the build.

```bash
env TARGET=darwin npm run dev
# TARGET = darwin, linux or windows
env npm run dev
#env npm run dev-linux
#env npm run dev-win
```

## SetUp Development Environment

You will need to start up two terminals to run the build processes for vue-electron and typescript compilation.
You will need to start up two terminals for vue-electron and typescript compilation.

**Build vue-electron**

Expand All @@ -45,37 +46,11 @@ npm run compile // On terminal 2
```

## Build

To create a production build, run the following command:

```bash
npm install cpy-cli -g
npm run build
```

## Troubleshooting

```
sh: cpy: command not found
```

#### Solution

To solve the above error, you need to install `cpy-cli` globally with nom.

- code `npm install cpy-cli -g`

```
An unhandled error occurred inside electron-rebuild
CXX(target) Release/obj.target/bignum/bignum.o
../bignum.cc:9:10: fatal error: 'openssl/bn.h' file not found
#include <openssl/bn.h>
```

#### Solution :

(Mac)

```
brew update
brew upgrade openssl
# npm run build-win
# npm run build-linux
```
Binary file modified build/icons/icon.ico
Binary file not shown.
37 changes: 37 additions & 0 deletions dev/core/analytics.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { app } from "electron";
const ua = require("universal-analytics");
const uuid = require("uuid/v4");
const { JSONStorage } = require("node-localstorage");
const nodeStorage = new JSONStorage(app.getPath("userData"));

// Retrieve the userId value, and if it's not there, assign it a new uuid.
const userId = nodeStorage.getItem("userId") || uuid();
nodeStorage.setItem("userId", userId);

const usr = ua("UA-101346362-5", userId);

export default function trackEvent(
category: string,
action: string,
label?: string,
value?: any,
) {
usr.event({
ec: category,
ea: action,
el: label,
ev: value,
}).send();
}

export function exceptionEvent(desc: string, fatal?: boolean) {
usr.exception(desc, fatal);
}

export function timingEvent(category: string, variable: string, time: number) {
usr.timing(category, variable, time);
}

export function trackPage(path: string) {
usr.pageview(path);
}
31 changes: 29 additions & 2 deletions dev/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ import {
} from "../..";
import { kdf } from "../utilities/crypto";
import Account from "./account";
import trackEvent, {
exceptionEvent,
timingEvent,
trackPage,
} from "./analytics";
import AverageBlockTime from "./average_block_time";
import { Base } from "./base";
import ChannelCodes from "./channel_codes";
Expand All @@ -43,6 +48,9 @@ import Transactions from "./transactions";
import Wallet from "./wallet";
const moment = require("moment");

(global as any).trackEvent = trackEvent;
(global as any).trackPage = trackPage;

/**
* Returns the file path of the wallet
* @returns {string}
Expand Down Expand Up @@ -152,6 +160,8 @@ export default class App extends Base {
win.webContents.send(ChannelCodes.AppLaunched, {
hasWallet: mHasWallet,
});

trackEvent("App", "run");
}

/**
Expand Down Expand Up @@ -195,6 +205,7 @@ export default class App extends Base {
public stop() {
if (this.elld) {
this.elld.stop();
trackEvent("App", "stopped");
}
}

Expand Down Expand Up @@ -257,6 +268,7 @@ export default class App extends Base {
}
i++;
}
trackEvent("Wallet", "restore");
return resolve();
});
}
Expand Down Expand Up @@ -373,9 +385,7 @@ export default class App extends Base {
Interval.clear("runUnconfirmedTx");

const dbOps = DBOps.fromDB(this.db);

const txCheck = await dbOps.find({ _type: "txPool" });

const Spells = this.elld.getSpell();

for (const t of txCheck) {
Expand Down Expand Up @@ -505,6 +515,7 @@ export default class App extends Base {
await this.makeWallet(secInfo);
this.kdfPass = secInfo.kdfPass;
if (this.win) {
trackEvent("Wallet", "new");
return this.send(
this.win,
ChannelCodes.WalletCreated,
Expand All @@ -529,7 +540,11 @@ export default class App extends Base {

if (this.win) {
try {
const now = moment().unix();
await this.execELLD();
// prettier-ignore
timingEvent("App", "elld:started:timed", now - moment().unix() * 1000);
trackEvent("App", "elld:started");
Menu.setApplicationMenu(
makeMenu(app, {
afterAuth: true,
Expand All @@ -540,14 +555,17 @@ export default class App extends Base {
await this.startBgProcesses();
this.applyPreferences();
this.normalizeWindow();
trackEvent("Wallet", "loaded");
// prettier-ignore
return this.send(this.win, ChannelCodes.WalletLoaded, null);
} catch (error) {
exceptionEvent("WalletLoad failed");
log.error("Failed to load wallet", error.message);
}
}
} catch (error) {
if (this.win) {
log.error("Failed to load wallet", error.message);
return this.sendError(this.win, {
code: ErrCodes.FailedToLoadWallet.code,
msg: ErrCodes.FailedToLoadWallet.msg,
Expand Down Expand Up @@ -593,12 +611,14 @@ export default class App extends Base {

// Request to start the miner
ipcMain.on(ChannelCodes.MinerStart, () => {
trackEvent("App", "miner:started");
this.preference.set(PrefMinerOn, true);
this.elld.getSpell().miner.start();
});

// Request to stop the miner
ipcMain.on(ChannelCodes.MinerStop, async () => {
trackEvent("App", "miner:stopped");
this.preference.set(PrefMinerOn, false);
this.elld.getSpell().miner.stop();
});
Expand Down Expand Up @@ -647,6 +667,7 @@ export default class App extends Base {
ChannelCodes.AccountRedirect,
newAcct.getAddress().toString(),
);
trackEvent("Account", "created");
} catch (err) {
this.wallet.removeAccount(newAcct);
return this.sendError(this.win, {
Expand Down Expand Up @@ -711,13 +732,16 @@ export default class App extends Base {
hash: txHash.id.toString(),
});

trackEvent("App:Tx", "sent");
return this.send(
this.win,
ChannelCodes.TransactionSend,
dataObject,
);
} catch (error) {
const jsonErr = JSON.parse(error.data);
trackEvent("App:Tx", "failed", "error", error.data);
exceptionEvent("App:Tx:Send");

return this.send(
this.win,
Expand Down Expand Up @@ -955,6 +979,7 @@ export default class App extends Base {

// Request to force account resynchronization
ipcMain.on(ChannelCodes.AccountsReSync, async (e) => {
trackEvent("Account", "resync");
await this.transactions.clearCursors();
});
}
Expand Down Expand Up @@ -995,6 +1020,7 @@ export default class App extends Base {
.then(resolve)
.catch(reject);
} catch (error) {
trackEvent("App", "elld:exec:failed");
if (this.win) {
this.sendError(this.win, {
code: ErrCodes.FailedToLoadElldObject.code,
Expand Down Expand Up @@ -1027,6 +1053,7 @@ export default class App extends Base {
});
});
} catch (error) {
trackEvent("Wallet", "persist:failed");
return reject(error);
}
});
Expand Down
5 changes: 2 additions & 3 deletions dev/core/elld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ export default class Elld {
ELLD_RPC_PASSWORD: rpcPass,
};

console.log(env);

const elld = spawn("elld", args, { shell: true, cwd: this.execPath, env });
const command = (process.platform === "win32") ? "elld" : "./elld";
const elld = spawn(command, args, { cwd: this.execPath, env });
this.elld = elld;

// hook a callback to stdout
Expand Down
17 changes: 11 additions & 6 deletions dev/core/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export function makeBaseMenuTemplate(app: Electron.App, opts: IMenuOpts) {
{ label: "Application data", click: showAppDir(app) },
],
},
{
role: "quit",
click: opts.onQuit,
},
],
},
{
Expand Down Expand Up @@ -135,11 +131,20 @@ interface IMenuOpts {
// prettier-ignore
export const makeMenu = (app: Electron.App, opts: IMenuOpts) => {
const template = makeBaseMenuTemplate(app, opts);

if (opts.afterAuth) {
template.splice(3, 0, { label: "View", submenu: [{ role: "togglefullscreen" }]});
(template[1].submenu as MenuItemConstructorOptions[]).push({ type: "separator" });
template.splice(3, 0, { label: "View", submenu: [{ role: "togglefullscreen" }]});
(template[1].submenu as MenuItemConstructorOptions[])
.push({ label: "New Account", click: opts.onNewAccount });
.push({ label: "New Account", click: opts.onNewAccount });
}

const t = (process.platform === "darwin") ? 1 : 0;
(template[t].submenu as MenuItemConstructorOptions[]).push({ type: "separator" });
(template[t].submenu as MenuItemConstructorOptions[]).push({
role: "quit",
click: opts.onQuit,
});

return Menu.buildFromTemplate(template as any);
};
2 changes: 1 addition & 1 deletion dev/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<head>
<meta charset="utf-8">
<title>Safehold <%= process.env.APP_VERSION %></title>
<title>SafeHold <%= process.env.APP_VERSION %></title>
<% if (htmlWebpackPlugin.options.nodeModules) { %>
<!-- Add `node_modules/` to global paths so `require` works properly in development -->
<script>
Expand Down
2 changes: 1 addition & 1 deletion dev/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Object.defineProperties(Vue.prototype, {
});
export default {
name: 'safehold',
name: 'SafeHold',
};
</script>
Loading

0 comments on commit bc73f3d

Please sign in to comment.