Skip to content

Commit

Permalink
added support for terra-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aydin Tekin committed May 31, 2022
1 parent 8425dd1 commit dfbcb0c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions public/js/grabber/terragrabber.js
Original file line number Diff line number Diff line change
@@ -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'}});
Expand All @@ -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;
};

Expand Down

0 comments on commit dfbcb0c

Please # to comment.