diff --git a/server/.env.sample b/server/.env.sample index 510dbe0..251e54c 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -15,3 +15,9 @@ DISPLAY_SERVER_PORT=3030 # Shall the fallbacks be used? DISPLAY_FALLBACK_BLOCK=true DISPLAY_FALLBACK_RATES=true + +# Shall a second exchange rate be shown? +DISPLAY_SECOND_EXCHANGE_RATE=true +# choose second exchange rate to show (supported: EUR, CHF) +SECOND_EXCHANGE_RATE=EUR + diff --git a/server/data.sh b/server/data.sh index 8640a80..d10c7ac 100755 --- a/server/data.sh +++ b/server/data.sh @@ -25,19 +25,34 @@ fi # Fetch rates using custom BTCPay or Kraken as fallback if [[ "${BTCPAY_API_TOKEN}" && "${BTCPAY_HOST}" ]]; then usdrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/USD | jq -r '.data.rate') - eurrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/EUR | jq -r '.data.rate') -fi -if [[ "${usdrate}" = "" && ${DISPLAY_FALLBACK_RATES} = true ]]; then - usdrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTUSD | jq -r '.result.XXBTZUSD.c[0] // "[]"') -fi -if [[ "${eurrate}" = "" && ${DISPLAY_FALLBACK_RATES} = true ]]; then - eurrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTEUR | jq -r '.result.XXBTZEUR.c[0] // "[]"') + + if [[ ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then + if [[ "${SECOND_EXCHANGE_RATE}" = "EUR" ]]; then + eurrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/EUR | jq -r '.data.rate') + fi + if [[ "${SECOND_EXCHANGE_RATE}" = "CHF" ]]; then + chfrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/CHF | jq -r '.data.rate') + fi + fi fi -if [[ "${usdrate}" && "${eurrate}" ]]; then - rates=$(jo -p -a $(jo rate="$usdrate" code="USD") $(jo rate="$eurrate" code="EUR")) +if [[ ${DISPLAY_FALLBACK_RATES} = true ]]; then + if [[ "${usdrate}" = "" ]]; then + usdrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTUSD | jq -r '.result.XXBTZUSD.c[0] // "[]"') + fi + + if [[ ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then + if [[ "${eurrate}" = "" && "${SECOND_EXCHANGE_RATE}" = "EUR" ]]; then + eurrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTEUR | jq -r '.result.XXBTZEUR.c[0] // "[]"') + fi + if [[ "${chfrate}" = "" && "${SECOND_EXCHANGE_RATE}" = "CHF" ]]; then + chfrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker?pair=XBTCHF | jq -r '.result.XBTCHF.c[0] // "[]"') + fi + fi fi +rates=$(jo -p -a $(jo rate="$usdrate" code="USD") $(jo rate="$eurrate" code="EUR") $(jo rate="$chfrate" code="CHF")) + # Bitcoin Quotes quote=$( $tor curl -s -f https://www.bitcoin-quotes.com/quotes/random.json 2> /dev/null || echo "null") diff --git a/server/public/style.css b/server/public/style.css index e86e00f..d6f13ea 100644 --- a/server/public/style.css +++ b/server/public/style.css @@ -53,6 +53,9 @@ body { .price--euro { margin-left: 1rem; } +.price--chf { + margin-left: 1rem; +} .price--sats { position: absolute; top: 645px; diff --git a/server/views/index.pug b/server/views/index.pug index 1aafd6c..192a172 100644 --- a/server/views/index.pug +++ b/server/views/index.pug @@ -1,9 +1,10 @@ extends _layout block content - const usdRate = rates && rates.find(rate => rate.code === 'USD') - - const eurRate = rates && rates.find(rate => rate.code === 'EUR') + - const eurRate = rates && rates.find(rate => rate.rate != null && rate.code === 'EUR') + - const chfRate = rates && rates.find(rate => rate.rate != null && rate.code === 'CHF') - const displayQuote = quote && quote.body.length < 220 - - const displayEuro = eurRate && (!displayQuote || quote && quote.body.length < 115) + - const displaySecondRate = (eurRate || chfRate) && (!displayQuote || quote && quote.body.length < 115) .bg .info if usdRate @@ -14,9 +15,13 @@ block content h1!= blockcount || ' ' if eurRate - h3.price.price--euro(class=displayEuro ? null : 'price--hidden') + h3.price.price--euro(class=displaySecondRate ? null : 'price--hidden') span.curr € span.rate= Math.round(eurRate.rate) + if chfRate + h3.price.price--chf(class=displaySecondRate ? null : 'price--hidden') + span.curr CHF + span.rate= Math.round(chfRate.rate) if displayQuote blockquote