Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show First 20 Lines • Show All 1,236 Lines • ▼ Show 20 Lines | const fetchBchPrice = async () => { | ||||
//console.log(`bchPrice`, bchPrice); | //console.log(`bchPrice`, bchPrice); | ||||
} catch (err) { | } catch (err) { | ||||
console.log(`Error fetching BCH Price`); | console.log(`Error fetching BCH Price`); | ||||
console.log(err); | console.log(err); | ||||
} | } | ||||
try { | try { | ||||
bchPriceJson = await bchPrice.json(); | bchPriceJson = await bchPrice.json(); | ||||
//console.log(`bchPriceJson`, bchPriceJson); | //console.log(`bchPriceJson`, bchPriceJson); | ||||
const bchPriceInFiat = bchPriceJson[cryptoId][fiatCode]; | let bchPriceInFiat = bchPriceJson[cryptoId][fiatCode] / 1e6; | ||||
//console.log(`bchPriceInFiat`, bchPriceInFiat); | |||||
// Error handling here | |||||
// Temp condition until price API has supported rebrand | |||||
// If eCash price is > 1, throw error | |||||
// If eCash price is < 0.0000001, throw error | |||||
// At BCHA price of $33, 1 XEC = 0.000033 | |||||
// 0.000033 | |||||
// 0.0000001 <== so if price is less than this, it's dividing an already correct price by 1,000,000 | |||||
const validEcashPrice = | |||||
bchPriceInFiat < 1 && bchPriceInFiat > 0.0000001; | |||||
if (validEcashPrice) { | |||||
setFiatPrice(bchPriceInFiat); | setFiatPrice(bchPriceInFiat); | ||||
} else { | |||||
// If API price looks fishy, do not allow app to send using fiat settings | |||||
setFiatPrice(null); | |||||
} | |||||
} catch (err) { | } catch (err) { | ||||
console.log(`Error parsing price API response to JSON`); | console.log(`Error parsing price API response to JSON`); | ||||
console.log(err); | console.log(err); | ||||
} | } | ||||
}; | }; | ||||
useEffect(() => { | useEffect(() => { | ||||
handleUpdateWallet(setWallet); | handleUpdateWallet(setWallet); | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |