Workflow updating files of btcwallet

This commit is contained in:
RanchiMall Dev 2024-01-04 21:25:12 +00:00
parent 490c9b9f4e
commit 021c9ae458
3 changed files with 22 additions and 15 deletions

View File

@ -1279,8 +1279,9 @@
} }
txDetailsAbortController = new AbortController(); txDetailsAbortController = new AbortController();
btcOperator.getTx(txid).then(result => { btcOperator.getTx(txid).then(result => {
console.log(result)
const { block, time, size, fee, inputs, outputs, confirmations = 0, total_input_value, total_output_value } = result; const { block, time, size, fee, inputs, outputs, confirmations = 0, total_input_value, total_output_value } = result;
const isUnconfirmed = block === null || confirmations === 0 || confirmations === null || block <= 0; const isUnconfirmed = block < 0 || block === null || block === undefined
renderElem(getRef('tx_details'), html` renderElem(getRef('tx_details'), html`
<h3>Transaction Details</h3> <h3>Transaction Details</h3>
<div class="flex align-center gap-1 space-between flex-wrap"> <div class="flex align-center gap-1 space-between flex-wrap">

View File

@ -1,4 +1,4 @@
(function (EXPORTS) { //btcOperator v1.2.6 (function (EXPORTS) { //btcOperator v1.2.7
/* BTC Crypto and API Operator */ /* BTC Crypto and API Operator */
const btcOperator = EXPORTS; const btcOperator = EXPORTS;
const SATOSHI_IN_BTC = 1e8; const SATOSHI_IN_BTC = 1e8;
@ -75,6 +75,9 @@
return util.Sat_to_BTC(balance) return util.Sat_to_BTC(balance)
}) })
}, },
latestBlock() {
return fetch_api(`blocks/tip/height`, { url: this.url })
},
// tx({ txid, url }) { // tx({ txid, url }) {
// return fetch_api(`tx/${txid}`, { url: url || this.url }) // return fetch_api(`tx/${txid}`, { url: url || this.url })
// .then(result => formatTx(result)) // .then(result => formatTx(result))
@ -108,6 +111,9 @@
return fetch_api(`address/${addr}`, { url: this.url }) return fetch_api(`address/${addr}`, { url: this.url })
.then(result => util.Sat_to_BTC(result.chain_stats.funded_txo_sum - result.chain_stats.spent_txo_sum)) .then(result => util.Sat_to_BTC(result.chain_stats.funded_txo_sum - result.chain_stats.spent_txo_sum))
}, },
latestBlock() {
return fetch_api(`blocks/tip/height`, { url: this.url })
},
// tx({ txid }) { // tx({ txid }) {
// return fetch_api(`tx/${txid}`, { url: this.url }) // return fetch_api(`tx/${txid}`, { url: this.url })
// .then(result => formatTx(result)) // .then(result => formatTx(result))
@ -157,6 +163,9 @@
return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url }) return fetch_api(`rawaddr/${addr}${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
.then(result => result.txs) .then(result => result.txs)
}, },
latestBlock() {
return fetch_api(`q/getblockcount`, { url: this.url })
},
async block({ id }) { async block({ id }) {
try { try {
let block let block
@ -234,10 +243,14 @@
const formatTx = btcOperator.util.format.tx = async (tx) => { const formatTx = btcOperator.util.format.tx = async (tx) => {
try { try {
const { txid, hash, time, block_height, fee, fees, received, let { txid, hash, time, block_height, fee, fees, received,
confirmed, size, double_spend, block_hash, confirmations, confirmed, size, double_spend, block_hash, confirmations,
status: { block_height: statusBlockHeight, block_hash: statusBlockHash, block_time } = {} status: { block_height: statusBlockHeight, block_hash: statusBlockHash, block_time } = {}
} = tx; } = tx;
if ((block_height || statusBlockHeight) && confirmations === undefined || confirmations === null) {
const latestBlock = await multiApi('latestBlock');
confirmations = latestBlock - (block_height || statusBlockHeight);
}
const inputs = tx.vin || tx.inputs; const inputs = tx.vin || tx.inputs;
const outputs = tx.vout || tx.outputs || tx.out; const outputs = tx.vout || tx.outputs || tx.out;
return { return {
@ -294,9 +307,9 @@
throw "No API available" throw "No API available"
} catch (error) { } catch (error) {
console.error(error) console.error(error)
if (error.code && [429, 404].includes(error.code)) { APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes return multiApi(fnName, { index: index + 1, ...args });
return multiApi(fnName, { index: index + 1, ...args }); if (error.code && [301, 429, 404].includes(error.code)) {
} else { } else {
throw error.message || error; throw error.message || error;
} }
@ -1380,18 +1393,11 @@
return Crypto.util.bytesToHex(txid); return Crypto.util.bytesToHex(txid);
} }
const getLatestBlock = btcOperator.getLatestBlock = () => new Promise((resolve, reject) => {
fetch_api(`q/getblockcount`)
.then(result => resolve(result))
.catch(error => reject(error))
})
const getTx = btcOperator.getTx = txid => new Promise(async (resolve, reject) => { const getTx = btcOperator.getTx = txid => new Promise(async (resolve, reject) => {
try { try {
const result = await multiApi('tx', { txid }); const result = await multiApi('tx', { txid });
if (!result.hasOwnProperty('confirmations'))
result.confirmations = await getLatestBlock() - result.block_height;
resolve({ resolve({
confirmations: result.confirmations,
block: result.block_height, block: result.block_height,
txid: result.hash, txid: result.hash,
time: result.time, time: result.time,

File diff suppressed because one or more lines are too long