Commit 5a16f934 authored by Allan Juma's avatar Allan Juma

linting resolved

parent ea6e86f3
import os
import sys
print("✅ Fixing PropTypes issues")
dir_path = os.path.dirname(os.path.realpath(__file__))
rnw_filename = dir_path + "/node_modules/react-native-web/dist/index.js"
def append_new_line(file_name, text_to_append):
"""Append given text as a new line at the end of file"""
if text_to_append in open(file_name).read():
print("⏭️ Skipping...")
else:
with open(file_name, "a+") as file_object:
file_object.write("\n")
file_object.write(text_to_append)
file_object.close()
# Fix
append_new_line(rnw_filename, "export const ViewPropTypes = { style: null };")
This diff is collapsed.
......@@ -21,6 +21,7 @@
"electron-only": "electron --no-sandbox .",
"preelectron-pack": "npm run build",
"prettier": "prettier --write --single-quote --trailing-comma es5 \"src/**/*.js\" public/electron.js",
"preinstall": "npx npm-force-resolutions",
"postinstall": "npm install -g @grpc/proto-loader @grpc/grpc-js react-dom faker --runtime=electron && npm run protobuf",
"storybook": "start-storybook -p 9009 -s public",
"build-storybook": "build-storybook -s public",
......@@ -33,6 +34,7 @@
"@capacitor/core": "^3.3.3",
"@grpc/grpc-js": "^1.3.7",
"@grpc/proto-loader": "^0.6.9",
"@react-native-async-storage/async-storage": "latest",
"@solana/web3.js": "latest",
"algosdk": "latest",
"chart.js": "^3.6.2",
......@@ -55,15 +57,15 @@
"react-chartjs-2": "^4.0.0",
"react-dom": "16.8.6",
"react-native-web": "^0.11.2",
"react-scripts": "4.0.3",
"react-scripts": "4.0.1",
"router-dom": "^2.2.9",
"svgs": "4.0.0",
"tinyman-ts-sdk": "^1.0.1",
"@react-native-async-storage/async-storage": "latest",
"tsc": "^2.0.4"
},
"devDependencies": {
"@babel/cli": "^7.2.3",
"react-error-overlay": "6.0.9",
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/plugin-transform-modules-commonjs": "^7.4.0",
......@@ -102,6 +104,9 @@
"wait-on": "^2.1.0",
"webpack": "4.44.2"
},
"resolutions": {
"react-error-overlay": "6.0.9"
},
"browserslist": [
"electron 4.0"
],
......
......@@ -84,6 +84,7 @@ ipcMain.on('logs-ready', () => {
logsReady = true;
});
function createWindow() {
console.log(path.join(__dirname, 'preload.js'));
const options = {
......
......@@ -59,29 +59,27 @@ class DaoAction {
*/
async getDao() {
try {
const uri =
'https://gateway.bitsoko.org/getEnterpriseRoute';
const uri = 'https://gateway.bitsoko.org/getEnterpriseRoute';
const response = checkHttpStatus(await fetch(uri));
const pools = await response.json();
//const pools = (await response.json()).tickers;
//const rate = tickers.find(t => t.ticker.toLowerCase() === fiat).rate;
this._store.pools = pools.map(pool => ({
id: pool.url,
cat: 'micro',
type: 'algorand',
title: pool.title ? pool.title : 'Sample merchant @ https://demo1.bitsoko.org',
desc: pool.desc ? pool.desc : '{name:"demo", desc:"a sample merchant", image:"",banner:"",link:"",url:"https://demo1.bitsoko.org"}',
title: pool.title
? pool.title
: 'Sample merchant @ https://demo1.bitsoko.org',
desc: pool.desc
? pool.desc
: '{name:"demo", desc:"a sample merchant", image:"",banner:"",link:"",url:"https://demo1.bitsoko.org"}',
amount: 0,
fee: 0,
confirmations: 5,
status: pool.active ? 'open' : 'closed',
date: parseDate(1604646525),
}));
} catch (err) {
log.error('Listing transactions failed', err);
}
......
......@@ -24,19 +24,15 @@ class GrpcAction {
* @return {Promise<undefined>}
*/
async initPyface(body) {
log.info('python starting');
try{
var ranID = 'pyFace:'+JSON.stringify(Math.floor(Math.random() * 10000));
body = [ranID].concat(body);
var res = await this._ipc.send('pyFace', ranID, { body });
return res;
}catch(err){
console.log(err);
}
log.info('python starting');
try {
var ranID = 'pyFace:' + JSON.stringify(Math.floor(Math.random() * 10000));
body = [ranID].concat(body);
var res = await this._ipc.send('pyFace', ranID, { body });
return res;
} catch (err) {
console.log(err);
}
}
//
......@@ -50,7 +46,6 @@ class GrpcAction {
* @return {Promise<undefined>}
*/
async initUnlocker() {
await this._sendIpc('unlockInit', 'unlockReady');
log.info('GRPC unlockerReady');
this._store.unlockerReady = true;
......
This diff is collapsed.
......@@ -4,7 +4,7 @@
*/
import * as log from './log';
import { parseDate, toHex } from '../helper';
import { parseDate } from '../helper';
class InvestmentAction {
constructor(store, grpc, nav, notification) {
......@@ -45,9 +45,7 @@ class InvestmentAction {
* @return {Promise<undefined>}
*/
async update() {
await Promise.all([
this.getAlgoTransactions(),
]);
await Promise.all([this.getAlgoTransactions()]);
}
/**
......@@ -55,10 +53,10 @@ class InvestmentAction {
* @return {Promise<undefined>}
*/
async updateLock(TransactionTime) {
let locked=true;
if(TransactionTime < new Date().setDate(new Date().getDate() - 1)){
locked=false;
}
let locked = true;
if (TransactionTime < new Date().setDate(new Date().getDate() - 1)) {
locked = false;
}
return locked;
}
......@@ -68,11 +66,8 @@ class InvestmentAction {
* @return {Promise<undefined>}
*/
async getAlgoTransactions() {
try {
const { transactions } = await this._grpc.sendCommand('listInvoices');
this._store.transactions = transactions.map(transaction => ({
id: transaction.txHash,
type: this.updateLock(transaction.timeStamp) ? 'locked' : 'unlocked',
......@@ -85,10 +80,6 @@ class InvestmentAction {
} catch (err) {
log.error('Listing transactions failed', err);
}
}
/**
......
/**
* @fileOverview a low level action to wrap electron's IPC renderer api.
*/
/*
/*
const _ipcRenderer = require('electron').ipcRenderer;
const filter = event => {
......@@ -27,7 +27,6 @@ window.ipcRenderer = {
*/
class IpcAction {
constructor(ipcRenderer) {
this._ipcRenderer = ipcRenderer;
}
......@@ -40,9 +39,8 @@ class IpcAction {
* @return {Promise<Object>}
*/
send(event, listen, payload) {
return new Promise(async (resolve, reject) => {
return new Promise((resolve, reject) => {
this._ipcRenderer.send(event, payload);
if (!listen) return resolve();
this._ipcRenderer.once(listen, (e, arg) => {
if (arg.err) {
......@@ -62,9 +60,8 @@ class IpcAction {
* @return {undefined}
*/
listen(event, callback) {
console.log(event, callback);
this._ipcRenderer.on(event, callback);
console.log(event, callback);
this._ipcRenderer.on(event, callback);
}
}
......
......@@ -160,8 +160,8 @@ class NavAction {
}
goURL(url) {
// this._store.route = 'Transactions';
window.open(url, '_blank');
// this._store.route = 'Transactions';
window.open(url, '_blank');
}
goPromotions() {
......@@ -170,11 +170,11 @@ class NavAction {
goTransactions() {
this._store.route = 'Transactions';
}
}
goInvestments() {
this._store.route = 'Investments';
}
}
goPools() {
this._store.route = 'Pools';
......@@ -198,7 +198,6 @@ class NavAction {
}
goContractSettings(contract) {
this._store.selectedContractSetting = contract;
this._store.route = 'SetContract';
}
......
......@@ -64,7 +64,6 @@ class PaymentAction {
}
this.init();
this.setAddress({ address: url });
}
/**
......@@ -78,7 +77,6 @@ class PaymentAction {
return;
}
this.setAddress({ address: data });
}
/**
......@@ -348,9 +346,9 @@ class PaymentAction {
});
stream.on('error', reject);
stream.write(JSON.stringify({ paymentRequest: invoice }), 'utf8');
this._notification.display({ msg: 'Lightning sent to swap!' });
});
if (failed) return;
this._notification.display({ msg: 'Lightning sent to swap!' });
//if (failed) return;
} catch (err) {
if (failed) return;
//this._nav.goPayLightningConfirm();
......
......@@ -5,14 +5,23 @@
import {
PREFIX_REGEX,
PREFIX_URI,
PAYMENT_TIMEOUT,
POLL_STORE_TIMEOUT,
LOW_TARGET_CONF,
MED_TARGET_CONF,
HIGH_TARGET_CONF,
} from '../config';
import { toSatoshis, toAmount, isLnUri, isAddress, nap, sendToEscrow } from '../helper';
/*
import {
toSatoshis,
toAmount,
isLnUri,
nap,
sendToEscrow,
} from '../helper';
*/
import { toSatoshis, toAmount, isLnUri, nap, sendToEscrow } from '../helper';
import * as log from './log';
class PoolAddAction {
......@@ -65,7 +74,6 @@ class PoolAddAction {
}
this.init();
this.setAddress({ address: url });
}
/**
......@@ -79,7 +87,6 @@ class PoolAddAction {
return;
}
this.setAddress({ address: data });
}
/**
......@@ -116,8 +123,6 @@ class PoolAddAction {
this._nav.goPoolAddLiquid();
}
/**
* Set the address input for the payment view. This can either be
* an on-chain bitcoin addres or an encoded lightning invoice.
......@@ -125,7 +130,6 @@ class PoolAddAction {
*/
async setAddress({ address }) {
this._store.payment.address = address.replace(PREFIX_REGEX, '');
}
/**
......@@ -133,29 +137,37 @@ class PoolAddAction {
* is either in btc or fiat depending on user settings.
* @param {string} options.amount The string formatted number
*/
async setAmount({ amount }) {
this._store.payment.amount = amount;
async setAmount({ amo }) {
this._store.payment.amount = amo;
this._store.payment.sendAll = false;
this.setAddress({ address: '' });
const { settings } = this._store;
var amount = toSatoshis(amount, settings);
//check if contract has enough balance first
console.log(parseFloat(this._store.settings.chains.algo.account.balance)*1000000, (amount*1.01));
if(parseFloat(this._store.settings.chains.algo.account.balance)*1000000 > (amount*1.01)){
console.log('INFO! contract has sufficient balance');
}else{
//get new pool quotation from server
var escrowInvoice = await sendToEscrow(amount, '{"state":"pool", "action":"add", "account":"'+this._store.settings.chains.algo.account.address+'", "pool":"'+this._store.selectedPool.id+'", "type":"float"}');
console.log(escrowInvoice);
this.setAddress({ address: escrowInvoice });
}
const { settings } = this._store;
var amount = toSatoshis(amo, settings);
//check if contract has enough balance first
console.log(
parseFloat(this._store.settings.chains.algo.account.balance) * 1000000,
amount * 1.01
);
if (
parseFloat(this._store.settings.chains.algo.account.balance) * 1000000 >
amount * 1.01
) {
console.log('INFO! contract has sufficient balance');
} else {
//get new pool quotation from server
var escrowInvoice = await sendToEscrow(
amount,
'{"state":"pool", "action":"add", "account":"' +
this._store.settings.chains.algo.account.address +
'", "pool":"' +
this._store.selectedPool.id +
'", "type":"float"}'
);
console.log(escrowInvoice);
this.setAddress({ address: escrowInvoice });
}
}
/**
......@@ -185,13 +197,17 @@ class PoolAddAction {
* @return {Promise<undefined>}
*/
async checkType() {
const { settings } = this._store;
var amount = toSatoshis(this._store.payment.amount, settings);
if(parseFloat(this._store.settings.chains.algo.account.balance)*1000000 > (amount*1.01)){
console.log('INFO! sufficient BTC in contract. skipping lightning swap...');
this._store.payment.address = '';
} else if (!this._store.payment.address) {
const { settings } = this._store;
var amount = toSatoshis(this._store.payment.amount, settings);
if (
parseFloat(this._store.settings.chains.algo.account.balance) * 1000000 >
amount * 1.01
) {
console.log(
'INFO! sufficient BTC in contract. skipping lightning swap...'
);
this._store.payment.address = '';
} else if (!this._store.payment.address) {
return this._notification.display({ msg: 'Enter an invoice or address' });
}
/*
......@@ -209,8 +225,7 @@ class PoolAddAction {
*/
this._nav.goPayPoolConfirm();
this._nav.goPayPoolConfirm();
}
/**
......@@ -331,8 +346,6 @@ class PoolAddAction {
});
}
}
/**
* Send the specified amount as an on-chain transaction to the provided
......
......@@ -22,7 +22,8 @@ class PoolRedeemLiqAction {
*/
init() {
this._store.invoice.amount = '';
this._store.invoice.note = 'POOL:REDEEM:98044b80f029ae6d007a6344b66d850435dace8533fb4aa16848d37031c4d459';
this._store.invoice.note =
'POOL:REDEEM:98044b80f029ae6d007a6344b66d850435dace8533fb4aa16848d37031c4d459';
this._store.invoice.encoded = '';
this._store.invoice.uri = '';
this._nav.goPoolRemoveLiquid();
......
......@@ -3,10 +3,9 @@
* a.k.a invoice that can be sent to another user.
*/
import { PREFIX_URI } from '../config';
//import { PREFIX_URI } from '../config';
import { toSatoshis, addAsaQuote } from '../helper';
class PoolRemoveLiqAction {
constructor(store, grpc, nav, notification, clipboard) {
this._store = store;
......@@ -21,13 +20,14 @@ class PoolRemoveLiqAction {
* and then navigating to the view.
* @return {undefined}
*/
async init() {
async init() {
this._store.invoice.amount = '';
this._store.invoice.note = 'POOL:REMOVE:98044b80f029ae6d007a6344b66d850435dace8533fb4aa16848d37031c4d459';
this._store.invoice.note =
'POOL:REMOVE:98044b80f029ae6d007a6344b66d850435dace8533fb4aa16848d37031c4d459';
this._store.invoice.encoded = '';
this._store.invoice.uri = '';
this._nav.goPoolRemoveLiquid();
this._quote = await addAsaQuote(this._grpc,this._store,75685483, 0);
this._quote = await addAsaQuote(this._grpc, this._store, 75685483, 0);
}
/**
......@@ -37,10 +37,7 @@ class PoolRemoveLiqAction {
*/
setAmount({ amount }) {
this._store.invoice.amount = amount;
console.log('INFO! ASA tokens sold are :', amount/this._quote);
console.log('INFO! ASA tokens sold are :', amount / this._quote);
}
/**
......@@ -65,38 +62,37 @@ class PoolRemoveLiqAction {
* @return {Promise<undefined>}
*/
async confirmRem() {
this._nav.goWait();
var amount = this._store.invoice.amount/this._store.selectedPool.quote;
var res = await this._grpc.initPyface(['/data/lightning-bits/src/chains/algo/pools.py', 'swap', this._store.selectedPool.assetID , 0, parseInt(amount), this._store.settings.chains.algo.account.address, this._store.settings.chains.algo.account.mnemonic, 'remove' ]);
console.log(res);
if(res.includes('confirmed in round')){
console.log('INFO! swap completed by contract only! skiping lightning swap.');
this._nav.goWait();
var amount = this._store.invoice.amount / this._store.selectedPool.quote;
var res = await this._grpc.initPyface([
'/data/lightning-bits/src/chains/algo/pools.py',
'swap',
this._store.selectedPool.assetID,
0,
parseInt(amount),
this._store.settings.chains.algo.account.address,
this._store.settings.chains.algo.account.mnemonic,
'remove',
]);
console.log(res);
if (res.includes('confirmed in round')) {
console.log(
'INFO! swap completed by contract only! skiping lightning swap.'
);
this._nav.goPayPoolDone();
return true;
}else{
} else {
this._nav.goPaymentFailed();
return false;
}
return res;
return false;
}
}
async generateUri() {
try {
const { invoice, settings } = this._store;
const satAmount = toSatoshis(invoice.amount, settings);
console.log(satAmount);
this._nav.goPoolRemLiqConf();
} catch (err) {
this._notification.display({ msg: 'Creating invoice failed!', err });
}
......
......@@ -4,7 +4,15 @@
*/
import * as log from './log';
import { parseDate, toHex, checkHttpStatus, toAmountLabel, addAsaQuote } from '../helper';
/*
import {
parseDate,
toHex,
checkHttpStatus,
addAsaQuote,
} from '../helper';
*/
import { parseDate, toHex, checkHttpStatus, addAsaQuote } from '../helper';
var hii;
......@@ -24,9 +32,9 @@ class PoolAction {
*/
async init() {
var nav = this._nav;
this.update().then(function(){
console.log('INFO! loaded pools');
//nav.goPools();
this.update().then(function() {
console.log('INFO! loaded pools');
//nav.goPools();
});
nav.goPools();
//nav.goWait();
......@@ -59,40 +67,38 @@ class PoolAction {
//this.getPayments(),
]);
}
async poolsToPool(pool){
var grpc = hii._grpc;
var store = hii._store;
try{
var pDat = await addAsaQuote(grpc,store,pool.poolID.id, 0);
}catch(er){
throw pDat;
}
//TEMORARY HACK!!
pool.active = [true,false].sort(() => Math.random() - Math.random()).slice(0, 1)[0];
var ret = {
id: pool.id,
cat: 'micro',
type: 'algorand',
icon: pool.bannerPath,
quote: pDat.q,
assetID: pool.poolID.id,
banner: pool.bannerPath,
url: 'https://demo1.bitsoko.org',
title: pool.name,
desc: pool.description,
amount: pDat.b/Math.pow(10,6),
fee: 0,
confirmations: 5,
status: pool.active ? 'open' : 'closed',
date: parseDate(1604646525),
};
return ret;
async poolsToPool(pool) {
var grpc = hii._grpc;
var store = hii._store;
try {
var pDat = await addAsaQuote(grpc, store, pool.poolID.id, 0);
} catch (er) {
throw pDat;
}
//TEMORARY HACK!!
pool.active = [true, false]
.sort(() => Math.random() - Math.random())
.slice(0, 1)[0];
var ret = {
id: pool.id,
cat: 'micro',
type: 'algorand',
icon: pool.bannerPath,
quote: pDat.q,
assetID: pool.poolID.id,
banner: pool.bannerPath,
url: 'https://demo1.bitsoko.org',
title: pool.name,
desc: pool.description,
amount: pDat.b / Math.pow(10, 6),
fee: 0,
confirmations: 5,
status: pool.active ? 'open' : 'closed',
date: parseDate(1604646525),
};
return ret;
}
/**
* List the on-chain transactions by calling the respective grpc api and updating
* the transactions array in the global store.
......@@ -100,32 +106,26 @@ var ret = {
*/
async getPools() {
try {
const uri = 'https://dooca.bitsoko.org/getEnterprise/?servEntID=1';
const uri = 'https://dooca.bitsoko.org/getEnterprise/?servEntID=1';
const response = checkHttpStatus(await fetch(uri));
const svs = await response.json();
var pools = svs.services;
//const pools = (await response.json()).tickers;
//const rate = tickers.find(t => t.ticker.toLowerCase() === fiat).rate;
var quote = await this.addQuote;
//var quote = await this.addQuote;
var pooled = await Promise.allSettled(pools.map(this.poolsToPool));
pooled = pooled.filter(function(pl){
return pl.status == 'fulfilled' && pl.value.quote != undefined;
pooled = pooled.filter(function(pl) {
return pl.status == 'fulfilled' && pl.value.quote != undefined;
});
console.log(pooled);
this._store.pools = pooled.map(function(pl){
if(pl.status == 'fulfilled'){
var ret = pl.value;
return ret;
}
this._store.pools = pooled.map(function(pl) {
if (pl.status == 'fulfilled') {
var ret = pl.value;
return ret;
}
});
} catch (err) {
log.error('Listing transactions failed', err);
}
}
......