Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Commit

Permalink
feat(intl): use custom currency formatting to support NANO
Browse files Browse the repository at this point in the history
  • Loading branch information
devinus committed Feb 20, 2018
1 parent fa193c7 commit 4bbe402
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/helpers/format-amount.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export default Helper.extend({
compute([value = 0], { unit = 'Mxrb', precision = 6 } = {}) {
const divisor = getConversion(unit);
const quotient = BigNumber(value).dividedBy(divisor);
const maximumFractionDigits = Math.min(precision, Math.max(2, quotient.decimalPlaces()));
return this.get('intl').formatNumber(quotient, {
const maximumFractionDigits = Math.min(precision, Math.min(2, quotient.decimalPlaces()));
const maximumSignificantDigits = Math.max(21, quotient.precision());
const amount = this.get('intl').formatNumber(quotient, {
maximumFractionDigits,
style: 'currency',
currency: 'XRB',
currencyDisplay: 'name',
maximumSignificantDigits,
});
return this.get('intl').t('currency', { amount });
},
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { it, describe } from 'mocha';
import { beforeEach, it, describe } from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

Expand All @@ -8,6 +8,11 @@ describe('Integration | Component | account amount', () => {
integration: true,
});

beforeEach(function () {
this.inject.service('intl');
this.get('intl').setLocale('en-us');
});

it('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
Expand Down
11 changes: 8 additions & 3 deletions tests/integration/helpers/format-amount-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from 'chai';

import { it, describe } from 'mocha';
import { beforeEach, it, describe } from 'mocha';

import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
Expand All @@ -10,6 +10,11 @@ describe('helper:format-amount', () => {
integration: true,
});

beforeEach(function () {
this.inject.service('intl');
this.get('intl').setLocale('en-us');
});

it('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
Expand All @@ -20,8 +25,8 @@ describe('helper:format-amount', () => {
// {{/format-amount}}
// `);

this.set('inputValue', '1000000000000000000000000000000');
this.set('inputValue', '1100000000000000000000000000000');
this.render(hbs`{{format-amount inputValue}}`);
expect(this.$().text().trim()).to.equal('1.00 XRB');
expect(this.$().text().trim()).to.equal('1.1 NANO');
});
});
3 changes: 2 additions & 1 deletion translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ node: 'node'
data: 'data'
downloading: 'Downloading {asset}'
starting: 'Starting node'
currency: '{amount} NANO'
status:
state: 'Status'
online: 'Online'
Expand Down Expand Up @@ -66,7 +67,7 @@ wallets:
search: 'Search for account'
destination: 'Destination Account'
placeholder: 'e.g. xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo'
amount: 'Amount (XRB)'
amount: 'Amount (NANO)'
insufficient: 'Amount is greater than total account balance'
history:
none: 'No history found.'
Expand Down
3 changes: 2 additions & 1 deletion translations/es-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ node: 'nodo'
data: 'datos'
downloading: 'Descargando {asset}'
starting: 'Encendiendo nodo'
currency: '{amount} NANO'
status:
state: 'Estado'
online: 'Conectado'
Expand Down Expand Up @@ -59,7 +60,7 @@ wallets:
search: 'Buscar cuenta'
destination: 'Cuenta Destinataria'
placeholder: 'e.g. xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo'
amount: 'Cantidad (XRB)'
amount: 'Cantidad (NANO)'
insufficient: 'La cantidad es mayor que el balance total en la cuenta.'
history:
none: 'No hay historial.'
Expand Down

0 comments on commit 4bbe402

Please sign in to comment.