123456789101112131415161718192021222324252627282930 |
- import { tickers, ticker, sel, graph, err } from "./App.vue";
- export function add(nameToAdd) {
- const newTicker = {
- name: nameToAdd,
- price: '-'
- };
- localStorage.setItem(
- 'cryptonomicon-list',
- JSON.stringify(tickers.value));
- if (tickers.value.find(n => n.name === newTicker.name) === undefined) {
- tickers.value.push(newTicker);
- ticker.value = '';
- setInterval(async () => {
- const f = await fetch(
- `https://min-api.cryptocompare.com/data/price?fsym=${newTicker.name}&tsyms=USD&api_key=ce3fd966e7a1d10d65f907b20bf000552158fd3ed1bd614110baa0ac6cb57a7e`
- );
- const data = await f.json();
- tickers.value.find(t => t.name === newTicker.name).price = data.USD > 1 ? data.USD.toFixed(2) :
- data.USD.toPrecision(2);
- if (sel.value?.name === newTicker.name) {
- graph.value.push(data.USD);
- }
- }, 3000);
- }
- else { err.value = 1; }
- }
|