Skip to content

Commit

Permalink
Final progress
Browse files Browse the repository at this point in the history
QR codes fully operational
package updates
  • Loading branch information
grctest committed Mar 10, 2024
1 parent 439abd0 commit e43804c
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 171 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
"@babel/runtime": "^7.24.0",
"@noble/ed25519": "^1.6.1",
"@noble/secp256k1": "^1.6.3",
"balm-ui": "^10.26.0",
"balm-ui": "^10.27.0",
"bitsharesjs": "https://github.com/bitshares/bitsharesjs#develop",
"crypto-js": "^4.2.0",
"dexie": "^3.2.5",
"dexie": "^3.2.6",
"electron-devtools-installer": "^3.2.0",
"eosjs": "^22.1.0",
"eosjs-ecc": "^4.0.7",
Expand Down Expand Up @@ -87,7 +87,7 @@
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"babel-loader": "^9.1.3",
"css-loader": "^6.10.0",
"electron": "^29.1.0",
"electron": "^29.1.1",
"electron-builder": "^24.13.3",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.22.0",
Expand Down
113 changes: 55 additions & 58 deletions src/background.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// This is main process of Electron, started as first thing when your
// app starts. It runs through entire life of your application.
// It doesn't have any windows which you can see on screen, but we can open
// window from here.
import path from "path";
import url from "url";
import fs from 'fs';
import os from 'os';
//import { argv } from 'node:process';

import queryString from "query-string";
import {PrivateKey} from "bitsharesjs";

Expand Down Expand Up @@ -299,7 +295,7 @@ ipcMain.on('modalError', (event, arg) => {
}
});

function _parseDeeplink(
async function _parseDeeplink(
requestContent,
type,
chain,
Expand Down Expand Up @@ -412,15 +408,17 @@ function _parseDeeplink(
if (["BTS", "BTS_TEST", "TUSC"].includes(chain)) {
let tr;
try {
tr = blockchain._parseTransactionBuilder(request.payload.params);
tr = await blockchain._parseTransactionBuilder(request.payload.params);
} catch (error) {
console.log(error)
}
for (let i = 0; i < tr.operations.length; i++) {
let operation = tr.operations[i];
if (settingsRows && settingsRows.includes(operation[0])) {
authorizedUse = true;
break;
if (tr) {
for (let i = 0; i < tr.operations.length; i++) {
let operation = tr.operations[i];
if (settingsRows && settingsRows.includes(operation[0])) {
authorizedUse = true;
break;
}
}
}
} else if (["EOS", "BEOS", "TLOS"].includes(chain)) {
Expand Down Expand Up @@ -757,7 +755,7 @@ const createWindow = async () => {

let apiobj;
try {
apiobj = _parseDeeplink(
apiobj = await _parseDeeplink(
requestContent,
'totp',
chain,
Expand Down Expand Up @@ -787,11 +785,9 @@ const createWindow = async () => {
if (methods.includes("getRawLink")) {
const { requestBody, allowedOperations } = arg;

console.log({requestBody});

let apiobj;
try {
apiobj = _parseDeeplink(
apiobj = await _parseDeeplink(
requestBody,
'raw',
chain,
Expand Down Expand Up @@ -825,7 +821,7 @@ const createWindow = async () => {
if (!error) {
let apiobj;
try {
apiobj = _parseDeeplink(
apiobj = await _parseDeeplink(
data,
'local',
chain,
Expand Down Expand Up @@ -858,21 +854,14 @@ const createWindow = async () => {
}

if (methods.includes("processQR")) {
const { qrChoice, qrData, allowedOperations } = arg;
let qrTX;
try {
qrTX = ["BTS", "BTS_TEST", "TUSC"].includes(chain)
? await blockchain.handleQR(qrData)
: JSON.parse(qrData);
} catch (error) {
console.log({error, location: "background"});
}
const { qrChoice, qrData, allowedOperations } = arg;

if (qrTX) {
let parsedData = JSON.parse(qrData);
let authorizedUse = false;
if (["BTS", "BTS_TEST", "TUSC"].includes(chain)) {
for (let i = 0; i < qrTX.operations.length; i++) {
let operation = qrTX.operations[i];
const ops = parsedData.operations[0].operations;
for (let i = 0; i < ops.length; i++) {
let operation = ops[i];
if (allowedOperations && allowedOperations.includes(operation[0])) {
authorizedUse = true;
break;
Expand All @@ -881,45 +870,53 @@ const createWindow = async () => {
} else if (
["EOS", "BEOS", "TLOS"].includes(chain)
) {
for (let i = 0; i < qrTX.actions.length; i++) {
let operation = qrTX.actions[i];
const ops = parsedData.operations[0].actions;
for (let i = 0; i < ops.length; i++) {
let operation = ops[i];
if (allowedOperations && allowedOperations.includes(operation.name)) {
authorizedUse = true;
break;
}
}
}

if (authorizedUse) {
console.log('Authorized use of QR codes');

let apiobj = {
type: Actions.INJECTED_CALL,
id: await uuidv4(),
payload: {
origin: 'localhost',
appName: 'qr',
browser: qrChoice,
params: ["BTS", "BTS_TEST", "TUSC"].includes(chain)
? qrTX.toObject()
: qrTX,
chain: chain
}
}
let qrTX;
try {
qrTX = ["BTS", "BTS_TEST", "TUSC"].includes(chain)
? await blockchain.handleQR(JSON.stringify(parsedData.operations[0]))
: parsedData.operations[0].actions;
} catch (error) {
console.log({error, location: "background"});
}

let status;
try {
status = await inject(blockchain, apiobj, mainWindow.webContents);
} catch (error) {
console.log({error, location: 'processQR'});
}
console.log('Authorized use of QR codes');

let apiobj = {
type: Actions.INJECTED_CALL,
id: await uuidv4(),
payload: {
origin: 'localhost',
appName: 'qr',
browser: qrChoice,
params: ["BTS", "BTS_TEST", "TUSC"].includes(chain)
? qrTX.toObject()
: qrTX,
chain: chain
}
}

if (status && status.result && !status.result.isError && !status.result.canceled) {
responses['qrData'] = status.result;
}
}
}
let status;
try {
status = await inject(blockchain, apiobj, mainWindow.webContents);
} catch (error) {
console.log({error, location: 'processQR'});
}

if (status && status.result && !status.result.isError && !status.result.canceled) {
responses['qrData'] = status.result;
}
}
}

if (methods.includes("verifyAccount")) {
Expand Down
1 change: 0 additions & 1 deletion src/components/popups/transactionrequestpopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
onMounted(() => {
if (props.visualizedParams) {
const _parsedparsedParameters = JSON.parse(props.visualizedParams);
//console.log({parsed: _parsedparsedParameters});
parsedParameters.value = _parsedparsedParameters;
}
});
Expand Down
1 change: 0 additions & 1 deletion src/components/popups/transactionresultpopup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
onMounted(() => {
if (props.visualizedParams) {
const _parsedparsedParameters = JSON.parse(props.visualizedParams);
//console.log({parsed: _parsedparsedParameters});
parsedParameters.value = _parsedparsedParameters;
total.value = _parsedparsedParameters.length;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/qr.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
});
async function evaluateQR (data) {
if (!data) {
return;
}
window.electron.resetTimer();
qrInProgress.value = true;
Expand Down Expand Up @@ -66,7 +69,6 @@
return;
}
console.log({ qr: blockchainResponse.processQR });
window.electron.notify(t("common.qr.prompt_success"));
qrInProgress.value = false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/qr/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
let qrContent = ref();
function onDecode (result) {
if (result) {
if (result && result.length) {
qrContent.value = true;
emit('detection', result);
emit('detection', result[0].rawValue);
}
}
Expand All @@ -24,7 +24,7 @@
<template>
<span v-if="qrContent">
<p>
{{ t('common.qr.scan.detected') }}
{{ t('common.qr.scan.scanned') }}
</p>
<ui-button @click="uploadAnother">
{{ t('common.qr.scan.another') }}
Expand All @@ -41,7 +41,7 @@
>
<qrcode-capture
:capture="selected"
@decode="onDecode"
@detect="onDecode"
/>
</ui-card>
</span>
Expand Down
1 change: 0 additions & 1 deletion src/components/raw-link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
return;
}
console.log({result: blockchainRequest.getRawLink});
window.electron.notify(t("common.local.promptSuccess"));
deepLinkInProgress.value = false;
Expand Down
Loading

0 comments on commit e43804c

Please sign in to comment.