Show wallet balance for BTC instead of Gnosis Safe
This commit is contained in:
@@ -10,8 +10,8 @@
|
|||||||
{{#each this.balances as |balance|}}
|
{{#each this.balances as |balance|}}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{balance.token.symbol}}</th>
|
<th>{{balance.token.symbol}}</th>
|
||||||
<td class="amount">{{fmt-crypto-currency balance.balance balance.token.symbol}}</td>
|
<td class="amount">{{balance.confirmed_balance}}</td>
|
||||||
<td class="fiat-amount">~{{balance.balanceUsd}} USD</td>
|
<td class="fiat-amount">~{{balance.balanceUSD}} USD</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,44 +1,38 @@
|
|||||||
import Service from '@ember/service';
|
import Service, { inject as service } from '@ember/service';
|
||||||
import { tracked } from '@glimmer/tracking';
|
import { tracked } from '@glimmer/tracking';
|
||||||
import { A } from '@ember/array';
|
import { A } from '@ember/array';
|
||||||
import { task } from 'ember-concurrency-decorators';
|
import { task } from 'ember-concurrency-decorators';
|
||||||
import config from 'kredits-web/config/environment';
|
import config from 'kredits-web/config/environment';
|
||||||
|
|
||||||
const txServiceBaseUrl = `${config.gnosisSafe.txServiceHost}/api/v1/safes/${config.gnosisSafe.address}`;
|
|
||||||
|
|
||||||
export default class CommunityFundsService extends Service {
|
export default class CommunityFundsService extends Service {
|
||||||
|
@service exchangeRates;
|
||||||
|
|
||||||
@tracked balancesLoaded = false;
|
@tracked balancesLoaded = false;
|
||||||
@tracked balances = A([]);
|
@tracked balances = A([]);
|
||||||
|
|
||||||
@task
|
@task
|
||||||
*fetchBalances () {
|
*fetchBalances () {
|
||||||
const uri = `${txServiceBaseUrl}/balances/usd/`;
|
yield fetch(config.btcBalanceAPI).then(res => res.json())
|
||||||
|
.then(res => {
|
||||||
yield fetch(uri).then(res => res.json())
|
return this.processBalances(res);
|
||||||
.then(res => this.processBalances(res))
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
console.log(`[community-funds] Fetching balances failed:`);
|
console.log(`[community-funds] Fetching balances failed:`);
|
||||||
console.error(err);
|
console.error(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
processBalances (res) {
|
async processBalances (res) {
|
||||||
for (const balance of res) {
|
await this.exchangeRates.fetchRates();
|
||||||
// Format and round the approximate USD value
|
// Format and round the approximate USD value
|
||||||
const lang = navigator.language || navigator.userLanguage;
|
const lang = navigator.language || navigator.userLanguage;
|
||||||
balance.balanceUsd = Math.round(balance.balanceUsd).toLocaleString(lang);
|
const balanceUSD = res.confirmed_balance * this.exchangeRates.btcusd;
|
||||||
|
res.balanceUSD = Math.round(balanceUSD).toLocaleString(lang);
|
||||||
|
|
||||||
if (balance.token) {
|
this.balances.pushObject({
|
||||||
// ERC20 token, has all meta data
|
...res,
|
||||||
this.balances.pushObject(balance);
|
...{ token: { name: 'BTC', symbol: 'BTC'} }
|
||||||
} else {
|
});
|
||||||
// RBTC, missing meta data
|
|
||||||
this.balances.pushObject({
|
|
||||||
...balance,
|
|
||||||
...{ token: { name: 'RBTC', symbol: 'RBTC'} }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.balancesLoaded = true;
|
this.balancesLoaded = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const bitstampBaseUrl = `${config.corsProxy}https://www.bitstamp.net/api/v2`;
|
|||||||
async function fetchFromBitstamp(currencyPair) {
|
async function fetchFromBitstamp(currencyPair) {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${bitstampBaseUrl}/ticker/${currencyPair}/`).then(r => r.json());
|
const res = await fetch(`${bitstampBaseUrl}/ticker/${currencyPair}/`).then(r => r.json());
|
||||||
return res.vwap; // Last 24 hours volume weighted average price
|
return parseFloat(res.vwap); // Last 24 hours volume weighted average price
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.error('Could not fetch exchange rate from Bitstamp:', e);
|
console.error('Could not fetch exchange rate from Bitstamp:', e);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -21,15 +21,16 @@ section#funds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
th {
|
th {
|
||||||
|
font-size: 1.5rem;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
padding-right: 1.2rem;
|
padding-right: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
td {
|
td {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
|
|
||||||
&.amount {
|
&.amount {
|
||||||
font-size: 1.5rem;
|
font-size: 2rem;
|
||||||
padding-right: 1.2rem;
|
padding-right: 1.2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,7 @@ module.exports = function(environment) {
|
|||||||
'BTC': '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'
|
'BTC': '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'
|
||||||
},
|
},
|
||||||
|
|
||||||
gnosisSafe: {
|
btcBalanceAPI: 'https://api.kosmos.org/kredits/onchain_btc_balance',
|
||||||
txServiceHost: 'https://safe-transaction.mainnet.gnosis.io',
|
|
||||||
address: '0x9CC29b8373FF92B01C1f09F31B5DD862350c167E'
|
|
||||||
},
|
|
||||||
|
|
||||||
corsProxy: 'https://cors.5apps.com/?uri='
|
corsProxy: 'https://cors.5apps.com/?uri='
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user