diff --git a/app/components/reimbursement-list/template.hbs b/app/components/reimbursement-list/template.hbs index 0ef5075..4c3fe9e 100644 --- a/app/components/reimbursement-list/template.hbs +++ b/app/components/reimbursement-list/template.hbs @@ -2,12 +2,12 @@ {{#each this.itemsSorted as |reimbursement|}}
  • {{reimbursement.id}}
    - {{reimbursement.amount}} WBTC
    + {{sats-to-btc reimbursement.amount}} WBTC
    vetoed: {{reimbursement.vetoed}}
    pay out to: {{reimbursement.contributor.name}}
    {{#each reimbursement.expenses as |expense|}} - {{expense.date}}: {{expense.title}} + {{expense.date}}: {{expense.title}} - {{fmt-fiat-currency expense.amount expense.currency}}
    {{/each}}
  • {{/each}} diff --git a/app/helpers/fmt-fiat-currency.js b/app/helpers/fmt-fiat-currency.js new file mode 100644 index 0000000..712987a --- /dev/null +++ b/app/helpers/fmt-fiat-currency.js @@ -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]); +}); diff --git a/app/helpers/sats-to-btc.js b/app/helpers/sats-to-btc.js new file mode 100644 index 0000000..319004e --- /dev/null +++ b/app/helpers/sats-to-btc.js @@ -0,0 +1,5 @@ +import { helper } from '@ember/component/helper'; + +export default helper(function satsToBtc(amount/*, hash*/) { + return amount / 100000000; +}); diff --git a/tests/integration/components/reimbursement-list/component-test.js b/tests/integration/components/reimbursement-list/component-test.js index 0e8114a..7c0c2aa 100644 --- a/tests/integration/components/reimbursement-list/component-test.js +++ b/tests/integration/components/reimbursement-list/component-test.js @@ -13,14 +13,5 @@ module('Integration | Component | reimbursement-list', function(hooks) { await render(hbs``); assert.equal(this.element.textContent.trim(), ''); - - // Template block usage: - await render(hbs` - - template block text - - `); - - assert.equal(this.element.textContent.trim(), 'template block text'); }); }); diff --git a/tests/integration/helpers/fmt-fiat-currency-test.js b/tests/integration/helpers/fmt-fiat-currency-test.js new file mode 100644 index 0000000..26dceb5 --- /dev/null +++ b/tests/integration/helpers/fmt-fiat-currency-test.js @@ -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'); + }); +}); diff --git a/tests/integration/helpers/sats-to-btc-test.js b/tests/integration/helpers/sats-to-btc-test.js new file mode 100644 index 0000000..1773874 --- /dev/null +++ b/tests/integration/helpers/sats-to-btc-test.js @@ -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'); + }); +});