Skip to content

Commit

Permalink
Merge pull request #30 in FFE/ffe-account-selector-react from master_…
Browse files Browse the repository at this point in the history
…DIG-27962-show-correct-currency to master

* commit '47d47fa17dc9ac975c0b6e2b2b8b6da5c1792861':
  DIG-27962 viser valuta før sum for engelsk locale
  DIG-27962 viser korrekt valuta for kontoer med andre valutaer enn NOK
  • Loading branch information
Eivind Wikheim committed Oct 26, 2017
2 parents 99a6471 + be3b470 commit 14517af
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Changelog
# v.7.10.0
* Show correct currency for accounts with currencyCodes other than NOK.

# v7.9.2
* Fixed issue where iOS9 units may not receive click event
Expand Down
1 change: 1 addition & 0 deletions examples/account-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class AccountSelectorExample extends Component {
locale='nb'
id='account-selector'
suggestionsHeightMax={500}
showBalance={true}
/>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffe-account-selector-react",
"version": "7.9.2",
"version": "7.10.0",
"main": "lib/index.js",
"scripts": {
"build": "babel -d lib/. --ignore=*.test.js src/.",
Expand Down
4 changes: 2 additions & 2 deletions src/account/account-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {accountFormatter, balanceWithCurrency} from '../util/format';
import {Account, Locale} from '../util/types';

function AccountDetails({account, locale, showBalance = true}) {
const {balance, accountNumber} = account;
const {balance, accountNumber, currencyCode} = account;
const hasBalance = balance != null;
return (
<div className='ffe-account-selector__details'>
Expand All @@ -13,7 +13,7 @@ function AccountDetails({account, locale, showBalance = true}) {
</div>
{showBalance && hasBalance &&
<div className='ffe-account-selector__details--right'>
{ balanceWithCurrency(balance, locale) }
{ balanceWithCurrency(balance, locale, currencyCode) }
</div>
}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/account/account-suggestion-multi.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {accountFormatter, balanceWithCurrency} from '../util/format';
import {Account, Locale} from '../util/types';

function AccountSuggestionMulti({account, locale, selected}) {
const {accountNumber, balance, name}= account;
const {accountNumber, balance, name, currencyCode} = account;
const hasBalance = balance !== null;
return (
<div className='ffe-account-suggestion__account--multi'>
Expand All @@ -24,7 +24,7 @@ function AccountSuggestionMulti({account, locale, selected}) {
</span>
{hasBalance &&
<span className='ffe-account-suggestion__balance'>
{balanceWithCurrency(balance, locale)}
{balanceWithCurrency(balance, locale, currencyCode)}
</span>
}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/account/account-suggestion.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {accountFormatter, balanceWithCurrency} from '../util/format';
import {Account, Locale} from '../util/types';

const AccountSuggestionItem = ({account, locale, showBalance = true}) => {
const {accountNumber, balance, name}= account;
const {accountNumber, balance, name, currencyCode }= account;
const hasBalance = balance !== null;
return (
<div className='ffe-account-suggestion__account'>
Expand All @@ -15,7 +15,7 @@ const AccountSuggestionItem = ({account, locale, showBalance = true}) => {
</span>
{showBalance && hasBalance &&
<span className='ffe-account-suggestion__balance'>
{ balanceWithCurrency(balance, locale)}
{ balanceWithCurrency(balance, locale, currencyCode)}
</span>
}
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/util/format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import amountFormatter from 'nfe-amount-formatter';
import {currencyPostfix} from './types';
import { currencyAffixNOK } from './types';

const getWeightedSumOfDigits = (accountNumber) => {
const weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1];
Expand All @@ -26,7 +26,9 @@ export function accountFormatter(accountNumber) {
return accountNumber;
}

export function balanceWithCurrency(balance = '', locale) {
return `${amountFormatter(balance, locale)} ${currencyPostfix[locale]}`;
export function balanceWithCurrency(balance = '', locale, currencyCode) {
const amount = amountFormatter(balance, locale);
const currencyAffix = (currencyCode && currencyCode !== "NOK")? currencyCode : currencyAffixNOK[locale];
return (locale === 'en')? `${currencyAffix} ${amount}` : `${amount} ${currencyAffix}`;
}

2 changes: 1 addition & 1 deletion src/util/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const nb = 'nb';
export const en = 'en';
export const nn = 'nn';

export const currencyPostfix = {
export const currencyAffixNOK = {
[nb]: 'kr',
[nn]: 'kr',
[en]: 'NOK'
Expand Down

0 comments on commit 14517af

Please sign in to comment.