background.js
/**
 * Updates the conversion rate RAI/USD
 */
Updates the conversion rate RAI/USD
Updates the conversion rate RAI / USD
async function updateConversion() {
  const retrievedConversion = await getMarketPrice();
  storedDataBg.supportedCurrencies = defaultPreferences.supportedCurrencies;
  storedDataBg.supportedCoins = defaultPreferences.supportedCoins;
  if (retrievedConversion) {
    const newConversion = retrievedConversion.rai || {};
    let otherConversions = {};
    const supportedCoinIds = defaultPreferences.supportedCoinIds;
    supportedCoinIds.forEach((value, index) => {
      if (value !== 'rai') {
        const coinName = defaultPreferences.supportedCoins[index];
        const coinData = retrievedConversion[value];
        coinData.rai = coinData.usd / newConversion.usd;
        otherConversions[coinName] = coinData;
      }
    });
    storedDataBg.conversion = newConversion.usd;
    storedDataBg.conversions = newConversion;
    storedDataBg.otherConversions = otherConversions;
    printLog('storedDataBg:', storedDataBg);
    chrome.storage.sync.set({ data: storedDataBg });
    chrome.runtime.sendMessage({ newConversion });
    chrome.tabs.query({}, (tabs) => {
      for (let i = 0; i < tabs.length; ++i) {
        chrome.tabs.sendMessage(tabs[i].id, storedDataBg);
      }
    });
  }
}
async function updateConversion ( ) { const retrievedConversion = await getMarketPrice ( ) ; storedDataBg . supportedCurrencies = defaultPreferences . supportedCurrencies ; storedDataBg . supportedCoins = defaultPreferences . supportedCoins ; if ( retrievedConversion ) { const newConversion = retrievedConversion . rai || { } ; let otherConversions = { } ; const supportedCoinIds = defaultPreferences . supportedCoinIds ; supportedCoinIds . forEach ( ( value , index ) => { if ( value !== 'rai' ) { const coinName = defaultPreferences . supportedCoins [ index ] ; const coinData = retrievedConversion [ value ] ; coinData . rai = coinData . usd / newConversion . usd ; otherConversions [ coinName ] = coinData ; } } ) ; storedDataBg . conversion = newConversion . usd ; storedDataBg . conversions = newConversion ; storedDataBg . otherConversions = otherConversions ; printLog ( 'storedDataBg:' , storedDataBg ) ; chrome . storage . sync . set ( { data : storedDataBg } ) ; chrome . runtime . sendMessage ( { newConversion } ) ; chrome . tabs . query ( { } , ( tabs ) => { for ( let i = 0 ; i < tabs . length ; ++ i ) { chrome . tabs . sendMessage ( tabs [ i ] . id , storedDataBg ) ; } } ) ; } }
Updates the conversion rate RAI/USD
Updates the conversion rate RAI / USD
// const retrievedConversionRai = retrievedConversion.rai; // const keys = Object.keys(retrievedConversionRai); // keys.forEach(key => { //   const value = retrievedConversionRai[key]; //   newConversion[key] = Number(value).toFixed( //     storedDataBg.decimals //   ); // }); // Store current conversion // Send new conversion to the popup // Send new conversion to the foreground