Merge pull request #200 from 67P/feature/wbtc_to_btc
Switch from ETH/WBTC to BTC
This commit was merged in pull request #200.
This commit is contained in:
@@ -115,14 +115,14 @@ export default class AddReimbursementComponent extends Component {
|
|||||||
@action
|
@action
|
||||||
submit (e) {
|
submit (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!this.kredits.currentUser) { window.alert('You need to connect your Ethereum account first.'); return false }
|
if (!this.kredits.currentUser) { window.alert('You need to connect your RSK account first.'); return false }
|
||||||
if (!this.kredits.currentUserIsCore) { window.alert('Only core contributors can submit reimbursements.'); return false }
|
if (!this.kredits.currentUserIsCore) { window.alert('Only core contributors can submit reimbursements.'); return false }
|
||||||
|
|
||||||
const contributor = this.contributors.findBy('id', parseInt(this.recipientId));
|
const contributor = this.contributors.findBy('id', parseInt(this.recipientId));
|
||||||
|
|
||||||
const attributes = {
|
const attributes = {
|
||||||
amount: parseInt(parseFloat(this.total) * 100000000), // convert to sats
|
amount: parseInt(parseFloat(this.total) * 100000000), // convert to sats
|
||||||
token: config.tokens['WBTC'],
|
token: config.tokens['BTC'],
|
||||||
recipientId: parseInt(this.recipientId),
|
recipientId: parseInt(this.recipientId),
|
||||||
title: `Expenses covered by ${contributor.name}`,
|
title: `Expenses covered by ${contributor.name}`,
|
||||||
description: this.description,
|
description: this.description,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
</label>
|
</label>
|
||||||
<fieldset class="horizontal thirds total-amounts">
|
<fieldset class="horizontal thirds total-amounts">
|
||||||
<label>
|
<label>
|
||||||
<p class="label">Total amount (WBTC):</p>
|
<p class="label">Total amount (BTC):</p>
|
||||||
<p>
|
<p>
|
||||||
<Input @type="text"
|
<Input @type="text"
|
||||||
@placeholder="0.0015"
|
@placeholder="0.0015"
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</p>
|
</p>
|
||||||
<p class="token-amount">
|
<p class="token-amount">
|
||||||
<span class="amount">
|
<span class="amount">
|
||||||
{{sats-to-btc reimbursement.amount}}</span> <span class="symbol">WBTC</span>
|
{{sats-to-btc reimbursement.amount}}</span> <span class="symbol">BTC</span>
|
||||||
</p>
|
</p>
|
||||||
<ul class="expense-list">
|
<ul class="expense-list">
|
||||||
{{#each reimbursement.expenses as |expense|}}
|
{{#each reimbursement.expenses as |expense|}}
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ export default helper(function fmtCryptoCurrency(params/*, hash*/) {
|
|||||||
const code = params[1];
|
const code = params[1];
|
||||||
|
|
||||||
switch(code) {
|
switch(code) {
|
||||||
case 'ETH':
|
case 'RBTC':
|
||||||
fmtAmount = amount / 1000000000000000000;
|
fmtAmount = amount / 1000000000000000000;
|
||||||
break;
|
break;
|
||||||
case 'WBTC':
|
case 'BTC':
|
||||||
fmtAmount = amount / 100000000;
|
fmtAmount = amount / 100000000;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
});
|
||||||
// ETH, missing meta data
|
|
||||||
this.balances.pushObject({
|
|
||||||
...balance,
|
|
||||||
...{ token: { name: 'Ether', symbol: 'ETH'} }
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,12 @@ module.exports = function(environment) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
tokens: {
|
tokens: {
|
||||||
'WBTC': '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'
|
// TODO this is still the WBTC address, since contracts currently
|
||||||
|
// requires a token address for reimbursements
|
||||||
|
'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='
|
||||||
};
|
};
|
||||||
@@ -67,8 +66,6 @@ module.exports = function(environment) {
|
|||||||
protocol: 'http',
|
protocol: 'http',
|
||||||
gatewayUrl: 'http://localhost:8080/ipfs'
|
gatewayUrl: 'http://localhost:8080/ipfs'
|
||||||
};
|
};
|
||||||
|
|
||||||
ENV.corsProxy = 'https://cors-anywhere.herokuapp.com/';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environment === 'test') {
|
if (environment === 'test') {
|
||||||
|
|||||||
@@ -6,15 +6,15 @@ import { hbs } from 'ember-cli-htmlbars';
|
|||||||
module('Integration | Helper | fmt-crypto-currency', function(hooks) {
|
module('Integration | Helper | fmt-crypto-currency', function(hooks) {
|
||||||
setupRenderingTest(hooks);
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
test('it converts Wei to ETH', async function(assert) {
|
test('it converts Wei to RBTC', async function(assert) {
|
||||||
this.set('balanceETH', '500000000000000000');
|
this.set('balanceRBTC', '500000000000000000');
|
||||||
await render(hbs`{{fmt-crypto-currency balanceETH "ETH"}}`);
|
await render(hbs`{{fmt-crypto-currency balanceRBTC "RBTC"}}`);
|
||||||
assert.equal(this.element.textContent.trim(), '0.5');
|
assert.equal(this.element.textContent.trim(), '0.5');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it converts Satoshis to (W)BTC', async function(assert) {
|
test('it converts Satoshis to BTC', async function(assert) {
|
||||||
this.set('balanceWBTC', '117214976');
|
this.set('balanceBTC', '117214976');
|
||||||
await render(hbs`{{fmt-crypto-currency balanceWBTC "WBTC"}}`);
|
await render(hbs`{{fmt-crypto-currency balanceBTC "BTC"}}`);
|
||||||
assert.equal(this.element.textContent.trim(), '1.17214976');
|
assert.equal(this.element.textContent.trim(), '1.17214976');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user