Advertisement
Guest User

Updated Storj Calculator

a guest
Dec 7th, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Storj Pricing
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.3
  5. // @description  Convert bandwidth to earnings for Storj dashboard
  6. // @author       You
  7. // @match        http://192.168.1.65:14002/
  8. // ==/UserScript==
  9.  
  10. const currency = "CAD"
  11.  
  12. window.addEventListener('load', () => {
  13.   const [$target] = document.getElementsByClassName('info-area__title')
  14.   const { textContent } = $target
  15.   const json = response => response.json()
  16.  
  17.   updateBenefits()
  18.   setInterval(updateBenefits, 30 * 1000)
  19.  
  20.   function updateBenefits() {
  21.     Promise.all([
  22.       fetch('https://api.coinpaprika.com/v1/tickers/storj-storj?quotes='+currency).then(json),
  23.       fetch('https://api.exchangeratesapi.io/latest?base=USD').then(json),
  24.       fetch(`${document.location.href}/api/satellites`).then(json)
  25.     ])
  26.     .then(([priceData, exchangeRateData, satellites]) => {
  27.       const priceStorj = priceData.quotes[currency].price
  28.  
  29.       const rateExchange = exchangeRateData.rates[currency]
  30.       const { data: { bandwidthDaily, storageDaily } } = satellites
  31.       const pricePerGbBandwidthNormal = (20 * rateExchange) / 1000; // $20USD/TB
  32.       const pricePerGbBandwidth = (10 * rateExchange) / 1000; // $10USD/TB
  33.       const pricePerGbStorage = (1.5 * rateExchange) / 1000; // $1.5USD/TB
  34.       const bandwidthNormal = bandwidthDaily.reduce((acc, row) => acc + row.egress.usage, 0) / 1000000000
  35.       const bandwidth = bandwidthDaily.reduce((acc, row) => acc + row.egress.audit + row.egress.repair, 0) / 1000000000
  36.       const storage = storageDaily.reduce((acc, row) => acc + row.atRestTotal, 0) / 1000000000 / 730
  37.       const sum = ((bandwidthNormal * pricePerGbBandwidthNormal) + (bandwidth * pricePerGbBandwidth) + (storage * pricePerGbStorage)).toFixed(6);
  38.  
  39.       $target.textContent = `${textContent} (Value = $${sum} ${currency} or ${(sum / priceStorj).toFixed(6)} STORJ)`;
  40.     })
  41.   }
  42. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement