Fund continuation
- Added support to continue funds with new tx data. - Improved parseNumber - createFundString now requires funds parameter to be array instead of object (as same investor can have multiple investments in same fund)
This commit is contained in:
parent
397cc4236c
commit
74439c5c1a
154
index.html
154
index.html
@ -14,7 +14,7 @@
|
|||||||
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
|
FLO_TEST: ['https://testnet-flosight.duckdns.org/', 'https://testnet.flocha.in/']
|
||||||
},
|
},
|
||||||
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
adminID: "FKAEdnPfjXLHSYwrXQu377ugN4tXU7VGdf",
|
||||||
application: "bobsFundTest",
|
application: "bobsFund_Test",
|
||||||
productStr: "Bob's Fund",
|
productStr: "Bob's Fund",
|
||||||
sendAmt: 0.001,
|
sendAmt: 0.001,
|
||||||
fee: 0.0005
|
fee: 0.0005
|
||||||
@ -8129,13 +8129,34 @@ Bitcoin.Util = {
|
|||||||
txid: true,
|
txid: true,
|
||||||
filter: d => d.startsWith(floGlobals.productStr)
|
filter: d => d.startsWith(floGlobals.productStr)
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
let data = {}
|
Promise.all(result.data.reverse().map(d => new Promise((res, rej) => {
|
||||||
result.data.forEach(d => {
|
if (/continue: /i.test(d[1])) {
|
||||||
compactIDB.addData('funds', d[1], floID + "|" + d[0])
|
let ctx = d[1].match(/continue: [0-9a-z]{64}/i).toString().split(": ")[1];
|
||||||
data[floID + "|" + d[0]] = d[1];
|
console.info(floID + "|" + ctx)
|
||||||
});
|
compactIDB.readData('funds', floID + "|" + ctx).then(fd => {
|
||||||
compactIDB.writeData('appendix', result.totalTxs, "lastTx|" + floID);
|
fd.push({
|
||||||
resolve(data);
|
txid: d[0],
|
||||||
|
data: d[1]
|
||||||
|
})
|
||||||
|
compactIDB.writeData('funds', fd, floID + "|" + ctx)
|
||||||
|
.then(r => res([floID + "|" + ctx, fd]))
|
||||||
|
.catch(e => rej(e))
|
||||||
|
}).catch(error => rej(error))
|
||||||
|
} else {
|
||||||
|
let fd = [{
|
||||||
|
txid: d[0],
|
||||||
|
data: d[1]
|
||||||
|
}]
|
||||||
|
compactIDB.addData('funds', fd, floID + "|" + d[0])
|
||||||
|
.then(r => res([floID + "|" + d[0], fd]))
|
||||||
|
.catch(e => rej(e))
|
||||||
|
}
|
||||||
|
}))).then(results => {
|
||||||
|
compactIDB.writeData('appendix', result.totalTxs, "lastTx|" + floID);
|
||||||
|
let data = {};
|
||||||
|
results.forEach(r => data[r[0]] = r[1])
|
||||||
|
resolve(data);
|
||||||
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
}).catch(error => reject(error))
|
}).catch(error => reject(error))
|
||||||
})
|
})
|
||||||
@ -8214,10 +8235,16 @@ Bitcoin.Util = {
|
|||||||
date.setDate(date.getDate() + d);
|
date.setDate(date.getDate() + d);
|
||||||
return date;
|
return date;
|
||||||
}
|
}
|
||||||
|
const removeElementIfExist = id => {
|
||||||
|
let existing = document.getElementById(id);
|
||||||
|
if (existing)
|
||||||
|
existing.remove();
|
||||||
|
}
|
||||||
|
|
||||||
let fundContainer = document.getElementById("funds-container");
|
let fundContainer = document.getElementById("funds-container");
|
||||||
console.info(term);
|
console.info(term);
|
||||||
for (let t in funds) {
|
for (let k in funds) {
|
||||||
let f = parseFunds(funds[t]);
|
let f = parseFunds(funds[k]);
|
||||||
console.info(f);
|
console.info(f);
|
||||||
let startDate = new Date(f.start_date).getTime(),
|
let startDate = new Date(f.start_date).getTime(),
|
||||||
fundBlock = document.getElementById("templates").getElementsByClassName("fund-block")[0].cloneNode(true),
|
fundBlock = document.getElementById("templates").getElementsByClassName("fund-block")[0].cloneNode(true),
|
||||||
@ -8235,20 +8262,24 @@ Bitcoin.Util = {
|
|||||||
detailTxt += `<tr><th>Tapout ${k+1}</th><td>${dateFormat(ts)} to ${dateFormat(te)}</td></tr>`
|
detailTxt += `<tr><th>Tapout ${k+1}</th><td>${dateFormat(ts)} to ${dateFormat(te)}</td></tr>`
|
||||||
})
|
})
|
||||||
detailsTable.innerHTML = detailTxt;
|
detailsTable.innerHTML = detailTxt;
|
||||||
for (let h in f.amounts) {
|
f.amounts.forEach(a => {
|
||||||
let netVal = calcNetValue(f.BTC_base, f.USD_base, f.start_date, f.amounts[h], term.fee);
|
let investor = a[0],
|
||||||
console.info(h, f.amounts[h], netVal);
|
amount = a[1],
|
||||||
|
netVal = calcNetValue(f.BTC_base, f.USD_base, f.start_date, amount, term.fee);
|
||||||
|
console.info(investor, amount, netVal);
|
||||||
let row = fundTable.insertRow();
|
let row = fundTable.insertRow();
|
||||||
row.insertCell().textContent = h;
|
row.insertCell().textContent = investor;
|
||||||
row.insertCell().textContent = f.amounts[h].toFixed(2);
|
row.insertCell().textContent = amount.toFixed(2);
|
||||||
row.insertCell().textContent = (f.amounts[h] / f.USD_base).toFixed(2);
|
row.insertCell().textContent = (amount / f.USD_base).toFixed(2);
|
||||||
row.insertCell().textContent = netVal.toFixed(2);
|
row.insertCell().textContent = netVal.toFixed(2);
|
||||||
row.insertCell().textContent = (netVal / USD_current).toFixed(2);
|
row.insertCell().textContent = (netVal / USD_current).toFixed(2);
|
||||||
}
|
});
|
||||||
let blockTitle = '--(Terms and condition)--\n' + term.data.replace(/\|/g, "\n") + '\n\n--(Fund Details)--\n' +
|
fundBlock.setAttribute("title", '--(Terms and condition)--\n' + term.data.replace(/\|/g, "\n") +
|
||||||
funds[t].replace(/\|/g, "\n").replace(/:=/g, "\t:\t").replace(/{/g, "\n\t").replace(/},?/g, "").replace(/]/g, "\n]");
|
'\n\n--(Fund Details)--\n' + funds[k].map(fd => fd.data).join("\n-----\n")
|
||||||
fundBlock.setAttribute("title", blockTitle);
|
.replace(/\|/g, "\n").replace(/:=/g, "\t:\t").replace(/{/g, "\n\t").replace(/},?/g, "").replace(/]/g, "\n]"));
|
||||||
//add link to view tx in blockchain [1. term txn(variable = term.txid), 2. fund tnx (variable = t.split("|")[1])];
|
removeElementIfExist(k);
|
||||||
|
fundBlock.id = k;
|
||||||
|
//add link to view tx in blockchain [1. term txn(variable = term.txid), 2. fund tnx {variable = funds[k].map(fd => fd.txid)}];
|
||||||
fundContainer.appendChild(fundBlock);
|
fundContainer.appendChild(fundBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8262,39 +8293,39 @@ Bitcoin.Util = {
|
|||||||
"crores": 10000000,
|
"crores": 10000000,
|
||||||
}
|
}
|
||||||
const parseNumber = (str) => {
|
const parseNumber = (str) => {
|
||||||
let n = 0,
|
let n = 0
|
||||||
g = 0;
|
str.replace(/,/g, '').match(/[\d.]+ *[a-z]*/gi).forEach(s => {
|
||||||
str.toLowerCase().replace(/,/g, '').split(" ").forEach(s => {
|
let v = s.match(/\d+/),
|
||||||
if (s in magnitude) {
|
m = s.match(/[a-z]+/i);
|
||||||
n += magnitude[s] * g;
|
n += parseFloat(v) * (m ? magnitude[m] : 1)
|
||||||
g = 0;
|
|
||||||
} else if (!isNaN(s))
|
|
||||||
g = parseFloat(s);
|
|
||||||
})
|
})
|
||||||
return n + g;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
let funds = {}
|
let funds = {};
|
||||||
data.split("|").forEach(d => {
|
data.forEach(fd => {
|
||||||
d = d.split(': ');
|
let cont = /continue: [a-z0-9]{64}\|/.test(fd);
|
||||||
switch (d[0].toLowerCase()) {
|
fd.data.split("|").forEach(d => {
|
||||||
case "fund start date":
|
d = d.split(': ');
|
||||||
funds["start_date"] = d[1];
|
switch (d[0].toLowerCase()) {
|
||||||
break;
|
case "fund start date":
|
||||||
case "base value":
|
cont ? null : funds["start_date"] = d[1];
|
||||||
funds["BTC_base"] = parseFloat(d[1].slice(0, -4));
|
break;
|
||||||
break;
|
case "base value":
|
||||||
case "usd inr rate at start":
|
cont ? null : funds["BTC_base"] = parseFloat(d[1].slice(0, -4));
|
||||||
funds["USD_base"] = parseFloat(d[1]);
|
break;
|
||||||
break;
|
case "usd inr rate at start":
|
||||||
case "fund invesments (inr)":
|
cont ? null : funds["USD_base"] = parseFloat(d[1]);
|
||||||
funds["amounts"] = {};
|
break;
|
||||||
d[1].match(/\w{34}:=[\w ,.]+/gi).forEach(a => {
|
case "fund invesments (inr)":
|
||||||
a = a.split(":=");
|
funds["amounts"] = funds["amounts"] || [];
|
||||||
funds["amounts"][a[0]] = parseNumber(a[1]);
|
d[1].match(/\w{34}:=[\w ,.]+/gi).forEach(a => {
|
||||||
});
|
a = a.split(":=");
|
||||||
break;
|
funds["amounts"].push([a[0], parseNumber(a[1])]);
|
||||||
}
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
return funds;
|
return funds;
|
||||||
}
|
}
|
||||||
@ -8340,15 +8371,28 @@ Bitcoin.Util = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createFundString(BTC_base, USD_base, start_date, funds) {
|
function createFundString(BTC_base, USD_base, start_date, funds) {
|
||||||
let fList = [];
|
funds = funds.map(f => {
|
||||||
for (let f in funds)
|
f = f.replace(":=", ":").split(":");
|
||||||
fList.push(`{${f}:=${funds[f]}}`);
|
return `{${f[0].trim()}:=${f[1].trim()}}`
|
||||||
|
});
|
||||||
return [
|
return [
|
||||||
floGlobals.productStr,
|
floGlobals.productStr,
|
||||||
`Base Value: ${BTC_base} USD`,
|
`Base Value: ${BTC_base} USD`,
|
||||||
`USD INR rate at start: ${USD_base}`,
|
`USD INR rate at start: ${USD_base}`,
|
||||||
`Fund Start date: ${dateFormat(start_date)}`,
|
`Fund Start date: ${dateFormat(start_date)}`,
|
||||||
`Fund invesments (INR): [${fList.join(",")}]`
|
`Fund invesments (INR): [${funds.join(",")}]`
|
||||||
|
].join("|");
|
||||||
|
}
|
||||||
|
|
||||||
|
function continueFund(fundID, funds) {
|
||||||
|
funds = funds.map(f => {
|
||||||
|
f = f.replace(":=", ":").split(":");
|
||||||
|
return `{${f[0].trim()}:=${f[1].trim()}}`
|
||||||
|
})
|
||||||
|
return [
|
||||||
|
floGlobals.productStr,
|
||||||
|
"Continue: " + fundID,
|
||||||
|
`Fund invesments (INR): [${funds.join(",")}]`
|
||||||
].join("|");
|
].join("|");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user