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

integrate spark into Electron #200

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

env:
EXOLIX_AUTHORIZATION: ${{ secrets.EXOLIX_AUTHORIZATION }}
SWAPZONE_API_KEY: ${{ secrets.SWAPZONE_API_KEY }}
CHANGENOW_API_KEY: ${{ secrets.CHANGENOW_API_KEY }}

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Extract version
id: pkg
run: echo "::set-output name=version::$(node -p "require('./package.json').version")"

- name: Install electron-builder
run: npm install -g electron-builder

- name: Build
shell: bash
env:
USE_HARD_LINKS: "false"
run: |
node electron-vue/build.js
electron-builder build --publish=never

- name: Upload Artifact
if: success()
uses: actions/upload-artifact@v3
with:
name: Firo-Client-${{ steps.pkg.outputs.version }}-${{ matrix.os }}
path: |
./build/Firo-Client-${{ steps.pkg.outputs.version }}.exe
./build/Firo-Client-${{ steps.pkg.outputs.version }}.AppImage
./build/Firo-Client-${{ steps.pkg.outputs.version }}.tar.xz
./build/Firo-Client-${{ steps.pkg.outputs.version }}.dmg
9 changes: 0 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
},
"linux": {
"category": "Network",
"target": ["AppImage", "snap", "tar.xz"],
"icon": "assets/icons",
"files": [
"!assets/core/darwin",
Expand Down Expand Up @@ -106,7 +107,6 @@
"sass-embedded": "^1.57.1",
"sha.js": "^2.4.11",
"simple-plist": "^1.3.1",
"source-map": "^0.5.7",
"time-ago": "^0.2.1",
"typeface-overpass-mono": "^1.1.13",
"vee-validate": "^4.7.3",
Expand Down
49 changes: 21 additions & 28 deletions src/daemon/firod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1295,11 +1295,19 @@ export class Firod {
console.info("Waiting for firod to shutdown.");
await this.awaitFirodStopped();

await this.closeSockets();
await this.firodHasShutdown.release(true);
}

// Close our sockets, without stopping the daemon.
async closeSockets(): Promise<void> {
if (this.hasShutdown)
return;

this.statusPublisherSocket.close();
this.publisherSocket.close();
this.requesterSocket.close();

await this.firodHasShutdown.release(true);
}

// This is called when an error sending to firod has occurred.
Expand Down Expand Up @@ -1744,7 +1752,7 @@ export class Firod {
}

async mintSpark(auth: string, label: string, recipient: string, amount: number, feePerKb: number,
subtractFeeFromAmount: boolean, coinControl?: CoinControl): Promise<{txid: string}> {
subtractFeeFromAmount: boolean, coinControl?: CoinControl): Promise<{txids: string[]}> {
const data = await this.send(auth, 'create', 'mintSpark', {
label,
recipient,
Expand All @@ -1755,8 +1763,17 @@ export class Firod {
selected: coinControlToString(coinControl)
}
});
function isValidResponse(x: any): x is {txid: string} {
return x !== null && typeof x === 'object' && typeof x.txid === 'string';
function isValidResponse(x: any): x is {txids: string[]} {
if (x === null ||
typeof x !== 'object') {
return false;
}
for (const v of x.txids) {
if (typeof v !== 'string') {
return false;
}
}
return true;
}
if (isValidResponse(data)) {
return data;
Expand Down Expand Up @@ -1802,28 +1819,4 @@ export class Firod {
throw new UnexpectedFirodResponse('create/validateSparkAddress', data);
}
}

async getAvailableSparkBalance(): Promise<{amount: number}> {
const data = await this.send('', 'create', 'getAvailableSparkBalance', {});
function isValidResponse(x: any): x is {amount: number} {
return x !== null && typeof x === 'object' && typeof x.amount === 'number';
}
if (isValidResponse(data)) {
return data;
} else {
throw new UnexpectedFirodResponse('create/getAvailableSparkBalance', data);
}
}

async getUncomfirmedSparkBalance(): Promise<{amount: number}> {
const data = await this.send('', 'create', 'getUncomfirmedSparkBalance', {});
function isValidResponse(x: any): x is {amount: number} {
return x !== null && typeof x === 'object' && typeof x.amount === 'number';
}
if (isValidResponse(data)) {
return data;
} else {
throw new UnexpectedFirodResponse('create/getUncomfirmedSparkBalance', data);
}
}
}
47 changes: 15 additions & 32 deletions src/main/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from "fs";
import path from "path";
import {SourceMapConsumer} from "source-map";
import {app, ipcMain, BrowserWindow, Menu, dialog} from 'electron';
import menuTemplate from './lib/menuTemplate';
import OpenDialogOptions = Electron.OpenDialogOptions;
Expand Down Expand Up @@ -69,36 +68,10 @@ app.once('ready', async () => {
const logPath = path.join(app.getPath('userData'), 'firo-client.log');
// This will overwrite the old log so as to reduce clutter.
const logFile = await fs.promises.open(logPath, 'w');
ourWindow.webContents.on('console-message', async (event, level, msg, mangledLine, sourceId) => {
ourWindow.webContents.on('console-message', async (event, level, msg, line, source) => {
if (level < LOG) return;

let map;
let sourceMapFile = undefined;
if (sourceMaps[sourceId]) {
map = sourceMaps[sourceId];
} else if (sourceMapFile) {
let rawMapData;
try {
rawMapData = (await fs.promises.readFile(sourceMapFile)).toString();
} catch (e) {}
if (rawMapData) {
try {
let rawMap = JSON.parse(rawMapData);
map = new SourceMapConsumer(rawMap);
sourceMaps[sourceId] = map;
} catch (e) {
console.info(e);
}
}
}

let location;
if (map) {
const {source, line} = map.originalPositionFor({line: mangledLine, column: 0});
location = `${source}:${line}`;
} else {
location = `${sourceId}:${mangledLine}`;
}
let location = `${source}:${line}`;

const levelStrs = {
0: 'debug',
Expand All @@ -108,9 +81,15 @@ app.once('ready', async () => {
};
const levelStr: 'debug' | 'info' | 'warn' | 'error' = levelStrs[level] || 'info';

const output = `${levelStr}: ${msg} (${location})`;
console[levelStr](output);
await logFile.write(output + "\n");
await logFile.write(`${levelStr}: ${msg} (${location})\n`);

const red = '\x1b[31m';
const reset = '\x1b[0m';
const log = console[levelStr];
if (level >= 2)
log(`${red}${levelStr}${reset}: ${msg} (${location})`);
else
log(`${levelStr}: ${msg} (${location})`);
});

// Fire the shutdown-requested listener in renderer/main.js when the user tries to close us.
Expand Down Expand Up @@ -138,6 +117,10 @@ app.once('ready', async () => {
return r.filePaths;
});

// This is used to check if we're reloading, so we can avoid restarting firod.
let count = 0;
ipcMain.handle('count', () => count++);

app.on('open-url', async (ev, msg) => {
ev.preventDefault();
ourWindow.webContents.emit('open-url', msg);
Expand Down
16 changes: 15 additions & 1 deletion src/renderer/components/AnimatedTable/AddressBookItemAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
</th>

<td v-else class="address">
{{ rowData.address }}
<div class="inner-address">
{{ rowData.address }}
</div>
</td>
</template>

Expand All @@ -21,4 +23,16 @@ export default {
</script>

<style scoped lang="scss">

td.address {
width: available;
max-width: 1px;

.inner-address {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-right: 5px;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
Type
</th>

<td v-else class="address-book-item-label">
{{ rowData.inputPrivacy || rowData.addressType.toLowerCase() }}
<td v-else class="address-type">
<div class="inner-address-type">
{{ rowData.addressType.toLowerCase() }}
</div>
</td>
</template>

Expand All @@ -21,10 +23,15 @@ export default {
</script>

<style scoped lang="scss">
td.address-book-item-label {
td.address-type {
width: 180px;
max-width: 180px;
overflow: hidden;
white-space: nowrap;

.inner-address-type {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-right: 5px;
}
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<template>
<th v-if="isHeader">
Type
</th>

<td v-else class="input-privacy">
<div class="inner-input-privacy">
{{ rowData.inputPrivacy }}
</div>
</td>
</template>

<script>
import VuetableFieldMixin from 'vue3-vuetable/src/components/VuetableFieldMixin.vue';

export default {
name: "AnimatedTableInputPrivacy",

mixins: [
VuetableFieldMixin
]
}
</script>

<style scoped lang="scss">
td.input-privacy {
width: 180px;
max-width: 180px;

.inner-input-privacy {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-right: 5px;
}
}
</style>
2 changes: 1 addition & 1 deletion src/renderer/components/AnimatedTable/TxAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import VuetableFieldMixin from 'vue3-vuetable/src/components/VuetableFieldMixin.
import {bigintToString} from "lib/convert";

export default {
name: 'TxAmount',
name: 'Amount',

mixins: [
VuetableFieldMixin
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/AnimatedTable/TxId.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import VuetableFieldMixin from 'vue3-vuetable/src/components/VuetableFieldMixin.vue'

export default {
name: 'UTXOSelector',
name: 'TxId',

mixins: [
VuetableFieldMixin
Expand Down
Loading