diff --git a/public/js/grabber/terragrabber.js b/public/js/grabber/terragrabber.js index c9209aa..b6770e2 100644 --- a/public/js/grabber/terragrabber.js +++ b/public/js/grabber/terragrabber.js @@ -1,7 +1,7 @@ const fetch = require('node-fetch'); -const api = 'https://lcd.terra.dev/cosmos/bank/v1beta1/balances/'; -const apiStake = 'https://api.extraterrestrial.finance/v1/staking/'; -const priceAPI = 'https://api.coingecko.com/api/v3/simple/price?vs_currencies=eur&ids=terra-luna'; +const api = 'https://phoenix-lcd.terra.dev/cosmos/bank/v1beta1/balances/'; +const apiStake = 'https://phoenix-lcd.terra.dev/cosmos/staking/v1beta1/delegations/'; +const priceAPI = 'https://api.coingecko.com/api/v3/simple/price?vs_currencies=eur&ids=terra-luna-2'; const getLUNA = async (address) => { const response = await fetch(api + address, {method: 'GET', headers: {'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'PostmanRuntime/7.26.8'}}); @@ -19,15 +19,19 @@ const getLUNA = async (address) => { const responseStake = await fetch(apiStake + address, {method: 'GET', headers: {'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'PostmanRuntime/7.26.8'}}); const jsonStake = await responseStake.json(); - if (jsonStake.delegationTotal) { - stake += jsonStake.delegationTotal * 1; - total += stake; + if (jsonStake.delegation_responses && jsonStake.delegation_responses.length > 0) { + for (let j = 0; j < jsonStake.delegation_responses.length; j++) { + if (jsonStake.delegation_responses[j].balance && jsonStake.delegation_responses[j].balance.denom == 'uluna') { + stake += jsonStake.delegation_responses[j].balance.amount * 1; + total += stake; + } + } } const responsePrice = await fetch(priceAPI, {method: 'GET', headers: {'Content-Type': 'application/json', 'Accept': 'application/json', 'User-Agent': 'PostmanRuntime/7.26.8'}}); const jsonPrice = await responsePrice.json(); - const retObj = {total: parseFloat(total / 1000000), staked: parseFloat(stake / 1000000), rewards: 0, price: parseFloat(jsonPrice['terra-luna'].eur)}; + const retObj = {total: parseFloat(total / 1000000), staked: parseFloat(stake / 1000000), rewards: 0, price: parseFloat(jsonPrice['terra-luna-2'].eur)}; return retObj; };