Commit ea6e86f3 authored by Allan Juma's avatar Allan Juma

update broken

parent 919b0187
This diff is collapsed.
......@@ -4,9 +4,11 @@
* flags on the global store are set to true.
*/
import { PREFIX_URI } from '../config';
import { when } from 'mobx';
import { AsyncStorage, Clipboard } from 'react-native';
import { nap } from '../helper';
import { Clipboard } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { nap, checkHttpStatus, toSatoshis } from '../helper';
import store from '../store';
import AppStorage from './app-storage';
import IpcAction from './ipc';
......@@ -30,7 +32,7 @@ import InvoiceAction from './invoice';
import SettingAction from './setting';
import AtplAction from './autopilot';
import Algorand from '../chains/algo/algo.js';
import Solana from '../chains/sol/sol.js';
//import Solana from '../chains/sol/sol.js';
//
// Inject dependencies
......@@ -211,6 +213,45 @@ var poolStats = await grpc.initPyface(['/data/lightning-bits/src/chains/algo/poo
* Initialize autopilot after syncing is finished and the grpc client
* is ready
*/
/**
* Verify that the user has a channel with enough receive capacity to
* receive the given amount.
* @param {number} options.satAmount The amount to receive.
* @return {undefined}
*/
function checkAmount({ satAmount }) {
const { channels } = store;
const hasInbound = channels.find(c => c.remoteBalance >= satAmount);
if (hasInbound) {
return;
}
notify.display({
msg: "You don't have enough inbound capacity to receive this payment.",
});
}
async function generateWebUri(amount, expiry) {
try {
const { settings } = store;
const satAmount = toSatoshis(amount, settings);
checkAmount({ satAmount });
const response = await grpc.sendCommand('addInvoice', {
value: satAmount,
memo: 'web invoice v1',
expiry: expiry,
private: true,
});
var res = {};
res.encoded = response.paymentRequest;
res.uri = `${PREFIX_URI}${invoice.encoded}`;
return res;
} catch (err) {
notify.display({ msg: 'Creating web invoice failed!', err });
}
}
when(
() => store.syncedToChain && store.network && store.autopilotReady,
async () => {
......@@ -218,5 +259,46 @@ when(
autopilot.init();
if(store.balanceSatoshis < 60000) nav.goDeposit();
if(store.balanceSatoshis > 25000 && store.channelBalanceSatoshis < (store.balanceSatoshis*0.2) && store.pendingChannels.length==0 && store.channelBalanceSatoshis < 20000) channel.connectAndOpen();
// initialize soko timers if enabled
if(store.settings.soko.enabled){
// invoice generation interval and count for multiple paypoints
// every hour
const webInvInt = 3600000;
const webInvCount = 2;
const sokoInt = setInterval(async function () {
if(!store.settings.soko.enabled){
clearInterval(sokoInt);
}
var invList = [];
for (let i = 0; i < webInvCount; i++) {
try{
var inv = await generateWebUri('100', webInvInt);
invList.push(inv.encoded);
}catch(e){
console.warn(e);
continue;
}
}
const uri = 'https://'+store.settings.soko.domain+'/updateINV/?invIDs='+JSON.stringify(invList);
try{
var response = checkHttpStatus(await fetch(uri));
//var r = await response.json();
}catch(err){
console.warn(err);
notify.display({ msg: 'Store offline! web invoice not updated. Disable?' });
return;
}
//console.log(r);
notify.display({ msg: 'SOKO Web invoice updated!' });
}, webInvInt);
}
}
);
......@@ -22,7 +22,6 @@ const ComputedPool = store => {
store.poolBalance = store.poolBalance + (parseInt(t.quoteFiat*t.amount));
t.key = String(i);
t.idName = t.id+':BITS:MSM1 | '+t.title;
t.icon = t.icon;
t.typeLabel = toCaps(t.type);
t.statusLabel = toCaps(t.status);
t.merchantLabel = t.title;
......
......@@ -111,6 +111,7 @@ export class Store {
displayFiat: true,
exchangeRate: {},
restoring: false,
soko: {enabled: false, domain: ''},
autopilot: true,
nodeScores: {},
chains: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment