Update main_UI.js

Fixed only vout[0] being receiver address. Sometimes that could be change, and code was not recognizing it
This commit is contained in:
tripathyr 2025-09-03 16:47:04 +05:30 committed by GitHub
parent fb33363622
commit d3327d8406
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -430,11 +430,20 @@ const oldInterns = {
"FEHKFxQxycsxw2qQQSn2Y1BCT6Mfb8EMko": "Abhijeet Anand", "FEHKFxQxycsxw2qQQSn2Y1BCT6Mfb8EMko": "Abhijeet Anand",
} }
function getReceiverAddress(vout) { function getReceiverAddress(vout) {
// return the first address in outputs that isn't the payer
for (const output of vout) { for (const output of vout) {
for (const address of output.scriptPubKey.addresses) { const addrs = output?.scriptPubKey?.addresses || [];
if (address !== floGlobals.payer) return address for (const address of addrs) {
if (address && address !== floGlobals.payer) return address;
} }
} }
return undefined; // no distinct receiver (shouldn't happen for payments)
}
function parseFloAmount(floData) {
// matches "send 3000 rupee#" or "send 8000.0000000000 rupee#"
const m = /send\s+([\d.]+)\s+[A-Za-z0-9#]+/i.exec(floData || "");
return m ? parseFloat(m[1]) : 0;
} }
function main() { function main() {
return Promise.all([fetchTransactions(), fetchRibcData()]).then(([txs]) => { return Promise.all([fetchTransactions(), fetchRibcData()]).then(([txs]) => {
@ -444,7 +453,7 @@ function main() {
...oldInterns ...oldInterns
} }
txs.forEach((tx) => { txs.forEach((tx) => {
const floId = tx.vout[0].scriptPubKey.addresses[0]; const floId = getReceiverAddress(tx.vout);
if (!floGlobals.appObjects.RIBC.internList[floId]) return; // not an intern if (!floGlobals.appObjects.RIBC.internList[floId]) return; // not an intern
const { txid, floData, time } = tx const { txid, floData, time } = tx
if (!floGlobals.internTxs.has(floId)) if (!floGlobals.internTxs.has(floId))
@ -452,7 +461,7 @@ function main() {
total: 0, total: 0,
txs: [] txs: []
}); });
const amount = parseFloat(floData.match(/([0-9]+)/)[1]) || 0; // get amount from floData const amount = parseFloAmount(floData); // get amount from floData
floGlobals.internTxs.get(floId).total += amount; floGlobals.internTxs.get(floId).total += amount;
floGlobals.internTxs.get(floId).txs.push({ floGlobals.internTxs.get(floId).txs.push({
txid, txid,