oliverschwendener / ueli

Cross-Platform Keystroke Launcher
https://ueli.app
MIT License
3.62k stars 239 forks source link

feat: Use fawazahmed0/currency-api for currency exchange #1043

Closed wywywywy closed 12 months ago

wywywywy commented 12 months ago

So currency exchange is broken right now, because exchangerate.host now requires an API key.

I propose that we migrate to fawazahmed0/currency-api instead, because:

  1. It's fast & reliable (hosted on jsdelivr.net)
  2. It's free forever
  3. Its API is stable
  4. It supports a lot more currencies (including crypto)

The risk is that @fawazahmed0 may stop maintaining it one day. But this is in my opinion a lower and less likely risk than a commercial provider start charging their free customers.

oliverschwendener commented 12 months ago

Makes sense to me, thanks for your contribution!

fawazahmed0 commented 12 months ago

@wywywywy Also consider adding fallback mechanism in your code:

Here is a JS example for fetching usd to eur rate:

const fetchWithFallback = async (links,obj) => {
  let response;
  for(let link of links)
  {  try{
      response = await fetch(link,obj)
      if(response.ok)
          return response
        }catch(e){}
  }
   return response
}

let from = `usd`
let to = `eur`

fetchWithFallback([
`https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/${from}/${to}.min.json`,
`https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/latest/currencies/${from}/${to}.json`,
`https://raw.githubusercontent.com/fawazahmed0/currency-api/1/latest/currencies/${from}/${to}.min.json`,
`https://raw.githubusercontent.com/fawazahmed0/currency-api/1/latest/currencies/${from}/${to}.json`
]).then(res => res.json()).then(console.log)