saturn-network / saturn.js

Javascript client for Saturn API
9 stars 8 forks source link

Ethgasstationapi CORS Issue #7

Closed WizardsOrb closed 4 years ago

WizardsOrb commented 4 years ago

https://github.com/saturn-network/saturn.js/blob/2918c17c2a8be86cf6bccfbb459605fc8ce2cad5/src/exchange/exchange.ts#L330-L333

Finally i did find some time for coding again, and i started to use SaturnJs on Ethereum. I am facing a CORS issue on Brave and Chrome/ium - Firefox seems to work fine. Its only solvable through a CORS plugin. For "normal" users this could be annoying.

CORSERRORSCREEN

As a quick and simple solution we can put this function into a try / catch blockand return for example 5 Gwei gasprice by default. This can also be useful in case the the gasstation api is down.

Note, this bug is only on Browser, on nodejs / ts-node i dont see this issue.

if (this.blockchain.toUpperCase() === "ETH") { 
  try{
    let gasApiUrl = 'https://www.ethgasstationapi.com/api/standard' 
    return (await axios.get(gasApiUrl)).data * 1000000000 
  }catch(e){
    console.error("CORS ERROR GASSTATION")
    return 5000000000 // 5 gwei
  }
 } 

if you have a better solution on this issue, please let me know.

future is bright.

saturn-network commented 4 years ago

Thanks for reporting this! Fixed in v0.1.7