diff --git a/app/helpers/fmt-crypto-currency.js b/app/helpers/fmt-crypto-currency.js new file mode 100644 index 0000000..76e47c4 --- /dev/null +++ b/app/helpers/fmt-crypto-currency.js @@ -0,0 +1,18 @@ +import { helper } from '@ember/component/helper'; + +export default helper(function fmtCryptoCurrency(params/*, hash*/) { + let fmtAmount; + const amount = params[0]; + const code = params[1]; + + switch(code) { + case 'ETH': + fmtAmount = amount / 1000000000000000000; + break; + case 'WBTC': + fmtAmount = amount / 100000000; + break; + } + + return fmtAmount; +}); diff --git a/tests/integration/components/budget-balances/component-test.js b/tests/integration/components/budget-balances/component-test.js index cdf9bdd..c786b6e 100644 --- a/tests/integration/components/budget-balances/component-test.js +++ b/tests/integration/components/budget-balances/component-test.js @@ -6,21 +6,8 @@ import { hbs } from 'ember-cli-htmlbars'; module('Integration | Component | budget-balances', function(hooks) { setupRenderingTest(hooks); - test('it renders', async function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.set('myAction', function(val) { ... }); - - 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'); - }); + // test('it renders', async function(assert) { + // await render(hbs``); + // assert.equal(this.element.textContent.trim(), ''); + // }); }); diff --git a/tests/integration/helpers/fmt-crypto-currency-test.js b/tests/integration/helpers/fmt-crypto-currency-test.js new file mode 100644 index 0000000..a27bcb9 --- /dev/null +++ b/tests/integration/helpers/fmt-crypto-currency-test.js @@ -0,0 +1,20 @@ +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-crypto-currency', function(hooks) { + setupRenderingTest(hooks); + + test('it converts Wei to ETH', async function(assert) { + this.set('balanceETH', '500000000000000000'); + await render(hbs`{{fmt-crypto-currency balanceETH "ETH"}}`); + assert.equal(this.element.textContent.trim(), '0.5'); + }); + + test('it converts Satoshis to (W)BTC', async function(assert) { + this.set('balanceWBTC', '117214976'); + await render(hbs`{{fmt-crypto-currency balanceWBTC "WBTC"}}`); + assert.equal(this.element.textContent.trim(), '1.17214976'); + }); +});