Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useWallet.js
Show All 27 Lines | import { | ||||
xecReceivedNotificationWebsocket, | xecReceivedNotificationWebsocket, | ||||
eTokenReceivedNotification, | eTokenReceivedNotification, | ||||
} from 'components/Common/Notifications'; | } from 'components/Common/Notifications'; | ||||
import { ChronikClient } from 'chronik-client'; | import { ChronikClient } from 'chronik-client'; | ||||
// For XEC, eCash chain: | // For XEC, eCash chain: | ||||
const chronik = new ChronikClient(currency.chronikUrl); | const chronik = new ChronikClient(currency.chronikUrl); | ||||
const useWallet = () => { | const useWallet = () => { | ||||
const [walletRefreshInterval] = useState(currency.walletRefreshInterval); | |||||
const [wallet, setWallet] = useState(false); | const [wallet, setWallet] = useState(false); | ||||
const [chronikWebsocket, setChronikWebsocket] = useState(null); | const [chronikWebsocket, setChronikWebsocket] = useState(null); | ||||
const [contactList, setContactList] = useState(false); | const [contactList, setContactList] = useState(false); | ||||
const [cashtabSettings, setCashtabSettings] = useState(false); | const [cashtabSettings, setCashtabSettings] = useState(false); | ||||
const [fiatPrice, setFiatPrice] = useState(null); | const [fiatPrice, setFiatPrice] = useState(null); | ||||
const [apiError, setApiError] = useState(false); | const [apiError, setApiError] = useState(false); | ||||
const [checkFiatInterval, setCheckFiatInterval] = useState(null); | const [checkFiatInterval, setCheckFiatInterval] = useState(null); | ||||
const [hasUpdated, setHasUpdated] = useState(false); | const [hasUpdated, setHasUpdated] = useState(false); | ||||
▲ Show 20 Lines • Show All 1,302 Lines • ▼ Show 20 Lines | ) { | ||||
receivedSlpQty, | receivedSlpQty, | ||||
receivedSlpName, | receivedSlpName, | ||||
); | ); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Update wallet every 10s | // Update wallet according to defined interval | ||||
useAsyncTimeout(async () => { | useAsyncTimeout(async () => { | ||||
const wallet = await getWallet(); | const wallet = await getWallet(); | ||||
update({ | update({ | ||||
wallet, | wallet, | ||||
}).finally(() => { | }).finally(() => { | ||||
setLoading(false); | setLoading(false); | ||||
if (!hasUpdated) { | if (!hasUpdated) { | ||||
setHasUpdated(true); | setHasUpdated(true); | ||||
} | } | ||||
}); | }); | ||||
}, 1000); | }, walletRefreshInterval); | ||||
const fetchBchPrice = async ( | const fetchBchPrice = async ( | ||||
fiatCode = cashtabSettings ? cashtabSettings.fiatCurrency : 'usd', | fiatCode = cashtabSettings ? cashtabSettings.fiatCurrency : 'usd', | ||||
) => { | ) => { | ||||
// Split this variable out in case coingecko changes | // Split this variable out in case coingecko changes | ||||
const cryptoId = currency.coingeckoId; | const cryptoId = currency.coingeckoId; | ||||
// Keep this in the code, because different URLs will have different outputs require different parsing | // Keep this in the code, because different URLs will have different outputs require different parsing | ||||
const priceApiUrl = `https://api.coingecko.com/api/v3/simple/price?ids=${cryptoId}&vs_currencies=${fiatCode}&include_last_updated_at=true`; | const priceApiUrl = `https://api.coingecko.com/api/v3/simple/price?ids=${cryptoId}&vs_currencies=${fiatCode}&include_last_updated_at=true`; | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |