From 0369b6675e53ca382f182d85248f17447e43718b Mon Sep 17 00:00:00 2001 From: Christoph Sperle Date: Thu, 9 Jul 2020 13:35:24 +0200 Subject: [PATCH 1/2] added option to show/hide the second exchange rate --- server/.env.sample | 4 ++++ server/data.sh | 11 ++++++----- server/views/index.pug | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/server/.env.sample b/server/.env.sample index 510dbe0..65143a0 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -15,3 +15,7 @@ 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 + diff --git a/server/data.sh b/server/data.sh index 8640a80..90772e8 100755 --- a/server/data.sh +++ b/server/data.sh @@ -25,18 +25,19 @@ 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') + + if [[ ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then + eurrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/EUR | jq -r '.data.rate') + fi 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 +if [[ "${eurrate}" = "" && ${DISPLAY_FALLBACK_RATES} = true && ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then eurrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTEUR | jq -r '.result.XXBTZEUR.c[0] // "[]"') fi -if [[ "${usdrate}" && "${eurrate}" ]]; then - rates=$(jo -p -a $(jo rate="$usdrate" code="USD") $(jo rate="$eurrate" code="EUR")) -fi +rates=$(jo -p -a $(jo rate="$usdrate" code="USD") $(jo rate="$eurrate" code="EUR")) # Bitcoin Quotes quote=$( $tor curl -s -f https://www.bitcoin-quotes.com/quotes/random.json 2> /dev/null || echo "null") diff --git a/server/views/index.pug b/server/views/index.pug index 1aafd6c..697ac41 100644 --- a/server/views/index.pug +++ b/server/views/index.pug @@ -1,7 +1,7 @@ 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 displayQuote = quote && quote.body.length < 220 - const displayEuro = eurRate && (!displayQuote || quote && quote.body.length < 115) .bg From 8cb3cc1f624303fe784f0b86641f510dfbc6b7c9 Mon Sep 17 00:00:00 2001 From: Christoph Sperle Date: Thu, 9 Jul 2020 13:55:20 +0200 Subject: [PATCH 2/2] added CHF as second exchange rate --- server/.env.sample | 2 ++ server/data.sh | 28 +++++++++++++++++++++------- server/public/style.css | 3 +++ server/views/index.pug | 9 +++++++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/server/.env.sample b/server/.env.sample index 65143a0..251e54c 100644 --- a/server/.env.sample +++ b/server/.env.sample @@ -18,4 +18,6 @@ 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 90772e8..d10c7ac 100755 --- a/server/data.sh +++ b/server/data.sh @@ -27,17 +27,31 @@ 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') if [[ ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then - eurrate=$($tor curl -s -f -H "Authorization: Basic $BTCPAY_API_TOKEN" $BTCPAY_HOST/rates/BTC/EUR | jq -r '.data.rate') + 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}" = "" && ${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 && ${DISPLAY_SECOND_EXCHANGE_RATE} = true ]]; then - eurrate=$($tor curl -s -f https://api.kraken.com/0/public/Ticker\?pair=XBTEUR | jq -r '.result.XXBTZEUR.c[0] // "[]"') + +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")) +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 697ac41..192a172 100644 --- a/server/views/index.pug +++ b/server/views/index.pug @@ -2,8 +2,9 @@ extends _layout block content - const usdRate = rates && rates.find(rate => rate.code === 'USD') - 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