"No API available" issue fix
This commit is contained in:
parent
bb8a5a4dd1
commit
d6d3da01e0
51
index.html
51
index.html
@ -1341,7 +1341,7 @@
|
|||||||
},
|
},
|
||||||
async transactions(address) {
|
async transactions(address) {
|
||||||
try {
|
try {
|
||||||
if (!address || address === '') return
|
if (!address || address === '' || !btcOperator.validateAddress(address)) return;
|
||||||
getRef('address_details').classList.remove('hidden')
|
getRef('address_details').classList.remove('hidden')
|
||||||
getRef('transactions_list').innerHTML = '<sm-spinner class="justify-self-center margin-top-1-5"></sm-spinner>';
|
getRef('transactions_list').innerHTML = '<sm-spinner class="justify-self-center margin-top-1-5"></sm-spinner>';
|
||||||
getRef('address_balance').innerHTML = '<sm-spinner class="justify-self-center margin-top-1-5"></sm-spinner>';
|
getRef('address_balance').innerHTML = '<sm-spinner class="justify-self-center margin-top-1-5"></sm-spinner>';
|
||||||
@ -1554,6 +1554,7 @@
|
|||||||
},
|
},
|
||||||
queryResult(query) {
|
queryResult(query) {
|
||||||
const type = checkQueryStringType(query);
|
const type = checkQueryStringType(query);
|
||||||
|
console.log(type)
|
||||||
if (type === 'address') {
|
if (type === 'address') {
|
||||||
getRef('tx_details').classList.add('hidden')
|
getRef('tx_details').classList.add('hidden')
|
||||||
render.addressDetails(query)
|
render.addressDetails(query)
|
||||||
@ -1591,16 +1592,18 @@
|
|||||||
}
|
}
|
||||||
let globalExchangeRate = {}
|
let globalExchangeRate = {}
|
||||||
async function getExchangeRate() {
|
async function getExchangeRate() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
Promise.all(['usd', 'inr'].map(cur => fetch(`https://bitpay.com/api/rates/btc/${cur}`))).then(responses => {
|
try {
|
||||||
Promise.all(responses.map(res => res.json())).then(rates => {
|
const responses = await Promise.all(['usd', 'inr'].map(cur => fetch(`https://bitpay.com/api/rates/btc/${cur}`)))
|
||||||
rates.forEach(rate => {
|
const rates = await Promise.all(responses.map(res => res.json()))
|
||||||
globalExchangeRate[rate.code.toLowerCase()] = rate.rate
|
rates.forEach(rate => {
|
||||||
})
|
globalExchangeRate[rate.code.toLowerCase()] = rate.rate
|
||||||
globalExchangeRate.btc = 1
|
})
|
||||||
resolve(globalExchangeRate)
|
globalExchangeRate.btc = 1;
|
||||||
}).catch(err => reject(err))
|
resolve(globalExchangeRate)
|
||||||
}).catch(err => reject(err))
|
} catch (err) {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function getConvertedAmount(amount, { shouldFormatAmount = false, onDate } = {}) {
|
function getConvertedAmount(amount, { shouldFormatAmount = false, onDate } = {}) {
|
||||||
@ -1934,21 +1937,17 @@
|
|||||||
return [senders, privKeys, receivers, amounts]
|
return [senders, privKeys, receivers, amounts]
|
||||||
}
|
}
|
||||||
function calculateApproxFee() {
|
function calculateApproxFee() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
fetch('https://bitcoiner.live/api/fees/estimates/latest')
|
try {
|
||||||
.then(res => {
|
const res = await fetch('https://bitcoiner.live/api/fees/estimates/latest')
|
||||||
res.json()
|
const data = await res.json()
|
||||||
.then(data => {
|
const satPerByte = data.estimates['60'].sat_per_vbyte;
|
||||||
const satPerByte = data.estimates['60'].sat_per_vbyte;
|
const legacyBytes = 200;
|
||||||
const legacyBytes = 200;
|
const segwitBytes = 77;
|
||||||
const segwitBytes = 77;
|
resolve((legacyBytes * satPerByte + (0.25 * satPerByte) * segwitBytes) / Math.pow(10, 8));
|
||||||
resolve((legacyBytes * satPerByte + (0.25 * satPerByte) * segwitBytes) / Math.pow(10, 8));
|
} catch (e) {
|
||||||
}).catch(e => {
|
reject(e)
|
||||||
reject(e)
|
}
|
||||||
})
|
|
||||||
}).catch(e => {
|
|
||||||
reject(e)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
function calculateExactFee() {
|
function calculateExactFee() {
|
||||||
|
|||||||
@ -1459,11 +1459,13 @@
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
reject(error)
|
reject(error)
|
||||||
}
|
}
|
||||||
}).catch(error => reject(error))
|
})
|
||||||
|
|
||||||
getTx.hex = btcOperator.getTx.hex = txid => multiApi('txHex', { txid });
|
getTx.hex = btcOperator.getTx.hex = txid => multiApi('txHex', { txid });
|
||||||
|
|
||||||
btcOperator.getAddressData = address => new Promise((resolve, reject) => {
|
btcOperator.getAddressData = address => new Promise((resolve, reject) => {
|
||||||
|
if (!validateAddress(address))
|
||||||
|
return reject("Invalid address");
|
||||||
Promise.all([
|
Promise.all([
|
||||||
multiApi('balance', { addr: address }),
|
multiApi('balance', { addr: address }),
|
||||||
multiApi('txs', { addr: address })
|
multiApi('txs', { addr: address })
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user