Render currencies etc.
This commit is contained in:
@@ -2,12 +2,12 @@
|
|||||||
{{#each this.itemsSorted as |reimbursement|}}
|
{{#each this.itemsSorted as |reimbursement|}}
|
||||||
<li>
|
<li>
|
||||||
{{reimbursement.id}}<br>
|
{{reimbursement.id}}<br>
|
||||||
{{reimbursement.amount}} WBTC<br>
|
{{sats-to-btc reimbursement.amount}} WBTC<br>
|
||||||
vetoed: {{reimbursement.vetoed}}<br>
|
vetoed: {{reimbursement.vetoed}}<br>
|
||||||
pay out to: {{reimbursement.contributor.name}}<br>
|
pay out to: {{reimbursement.contributor.name}}<br>
|
||||||
|
|
||||||
{{#each reimbursement.expenses as |expense|}}
|
{{#each reimbursement.expenses as |expense|}}
|
||||||
{{expense.date}}: {{expense.title}}
|
{{expense.date}}: {{expense.title}} - {{fmt-fiat-currency expense.amount expense.currency}}<br>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</li>
|
</li>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { helper } from '@ember/component/helper';
|
||||||
|
|
||||||
|
export default helper(function fmtFiatCurrency(params) {
|
||||||
|
const formatter = new Intl.NumberFormat('en-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: params[1] || 'EUR',
|
||||||
|
minimumFractionDigits: 2
|
||||||
|
})
|
||||||
|
return formatter.format(params[0]);
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import { helper } from '@ember/component/helper';
|
||||||
|
|
||||||
|
export default helper(function satsToBtc(amount/*, hash*/) {
|
||||||
|
return amount / 100000000;
|
||||||
|
});
|
||||||
@@ -13,14 +13,5 @@ module('Integration | Component | reimbursement-list', function(hooks) {
|
|||||||
await render(hbs`<ReimbursementList />`);
|
await render(hbs`<ReimbursementList />`);
|
||||||
|
|
||||||
assert.equal(this.element.textContent.trim(), '');
|
assert.equal(this.element.textContent.trim(), '');
|
||||||
|
|
||||||
// Template block usage:
|
|
||||||
await render(hbs`
|
|
||||||
<ReimbursementList>
|
|
||||||
template block text
|
|
||||||
</ReimbursementList>
|
|
||||||
`);
|
|
||||||
|
|
||||||
assert.equal(this.element.textContent.trim(), 'template block text');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupRenderingTest } from 'ember-qunit';
|
||||||
|
import { render } from '@ember/test-helpers';
|
||||||
|
import { hbs } from 'ember-cli-htmlbars';
|
||||||
|
|
||||||
|
module('Integration | Helper | fmt-fiat-currency', function(hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
test('it returns the number formatted as currency', async function(assert) {
|
||||||
|
this.set('amount', 13.9);
|
||||||
|
|
||||||
|
await render(hbs`{{fmt-fiat-currency this.amount}}`);
|
||||||
|
assert.equal(this.element.textContent.trim(), '€13.90', 'using EUR amount by default');
|
||||||
|
|
||||||
|
await render(hbs`{{fmt-fiat-currency this.amount 'USD'}}`);
|
||||||
|
assert.equal(this.element.textContent.trim(), '$13.90', 'using the defined currency');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { module, test } from 'qunit';
|
||||||
|
import { setupRenderingTest } from 'ember-qunit';
|
||||||
|
import { render } from '@ember/test-helpers';
|
||||||
|
import { hbs } from 'ember-cli-htmlbars';
|
||||||
|
|
||||||
|
module('Integration | Helper | sats-to-btc', function(hooks) {
|
||||||
|
setupRenderingTest(hooks);
|
||||||
|
|
||||||
|
test('it converts satoshis to full BTC amounts', async function(assert) {
|
||||||
|
this.set('amount', '166800');
|
||||||
|
|
||||||
|
await render(hbs`{{sats-to-btc this.amount}}`);
|
||||||
|
|
||||||
|
assert.equal(this.element.textContent.trim(), '0.001668');
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user