diff --git a/CHANGELOG.md b/CHANGELOG.md index a70ec9a6f..a6102e929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,19 @@ Please check our [developers guide](https://gitlab.com/tokend/developers-guide) for further information about branching and tagging conventions. ## [Unreleased] +#### Changed +- Move formatNumber filter to helper +- Move formatPercent to formatNumber helper +- Move formatInteger to formatNumber helper +- Move cropAddress to text helper and rename to abbrCenter +- Move formatMoney to helper +- Move formatDate to helper +- Move formatDateDMY to helper +- Move formatDateDMYT to helper +- Move formatCalendar to helper +- Move formatCalendarInline to helper +- Move abbreviate to helper + ### Fixed - New version of vue: 2.7.14 - New version of vue-template-compiler": 2.7.14 diff --git a/src/i18n/index.js b/src/i18n/index.js index b41265547..b290e8d9a 100644 --- a/src/i18n/index.js +++ b/src/i18n/index.js @@ -9,14 +9,9 @@ import i18nextBrowserLanguageDetector from 'i18next-browser-languagedetector' // TODO: make i18n.language and i18n.languages responsive -import moment from 'moment-timezone' - import _isObject from 'lodash/isObject' -import _get from 'lodash/get' import _merge from 'lodash/merge' -import { MathUtil } from '@/js/utils' - class I18n { constructor () { this._i18nextInstance = i18next.createInstance() @@ -165,46 +160,7 @@ class I18n { nonExplicitWhitelist: false, interpolation: { format: (param, format) => { - const lngConfig = this._i18nextInstance - .getResourceBundle(this.language, 'config') - switch (format.toLowerCase()) { - case 'date': - return moment(param) - .format(_get(lngConfig, 'date.presets.datetime')) - case 'dmy': - return moment(param) - .format(_get(lngConfig, 'date.presets.dmy')) - case 'dmyt': - return moment(param) - .format(_get(lngConfig, 'date.presets.dmyt')) - case 'calendar': - return moment(param) - .calendar(null, _get(lngConfig, 'date.calendar')) - case 'calendar-inline': - return moment(param) - .calendar(null, _get(lngConfig, 'date.calendarInline')) - case 'money': - const value = (_isObject(param) ? param.value : param) || '0' - const defaultFormat = - _get(lngConfig, 'number.formats.amounts.default') - - const result = MathUtil.format(value, defaultFormat) - return param.currency - ? result.concat(' ', param.currency) - : result - case 'number': - return MathUtil - .format(param, _get(lngConfig, 'number.formats.default')) - case 'integer': - return MathUtil - .format(param, _get(lngConfig, 'number.formats.integer')) - case 'percent': - const convertedPercent = MathUtil.multiply(param, 100) - return MathUtil.format( - convertedPercent, - _get(lngConfig, 'number.formats.percent') - ) default: console.warn(`Unknown format: ${format}, skipping…`) return param diff --git a/src/i18n/resources/en.json b/src/i18n/resources/en.json index d45d2b260..c4a5667da 100644 --- a/src/i18n/resources/en.json +++ b/src/i18n/resources/en.json @@ -1113,7 +1113,7 @@ "assets-list": { "update-asset-title": "Update asset", "details-title": "Asset details", - "list-item-balance-line": "Balance: {{value, money}}", + "list-item-balance-line": "Balance:", "no-balance-msg": "No balance" }, "requests-page": { diff --git a/src/vue/filters/abbreviate.js b/src/js/helpers/abbreviate.js similarity index 100% rename from src/vue/filters/abbreviate.js rename to src/js/helpers/abbreviate.js diff --git a/src/vue/filters/abbreviate.spec.js b/src/js/helpers/abbreviate.spec.js similarity index 96% rename from src/vue/filters/abbreviate.spec.js rename to src/js/helpers/abbreviate.spec.js index 232155182..defe42c3a 100644 --- a/src/vue/filters/abbreviate.spec.js +++ b/src/js/helpers/abbreviate.spec.js @@ -1,6 +1,6 @@ import { abbreviate } from './abbreviate' -describe('abbreviate filter', () => { +describe('abbreviate helper', () => { describe('transforms the given', () => { const testCases = [ { input: 'account', expectedOutput: 'A' }, diff --git a/src/js/helpers/date-helpers.js b/src/js/helpers/date-helpers.js index acbc69aaa..726cf2bdb 100644 --- a/src/js/helpers/date-helpers.js +++ b/src/js/helpers/date-helpers.js @@ -1,5 +1,39 @@ import moment from 'moment' +export function formatDate (date) { + return moment(date).format('DD.MM.YYYY [at] H:mm') +} + +export function formatDateDMY (date) { + return moment(date).format('DD.MM.YYYY') +} + +export function formatDateDMYT (date) { + return moment(date).format('DD.MM.YYYY [at] H:mm') +} + +export function formatCalendar (date) { + return moment(date).calendar(null, { + sameDay: '[Today at] H:mm', + lastDay: '[Yesterday at] H:mm', + nextDay: '[Tomorrow at] H:mm', + lastWeek: '[Last] dddd [at] H:mm', + nextWeek: '[Next] dddd [at] H:mm', + sameElse: 'MMMM D, YYYY [at] H:mm', + }) +} + +export function formatCalendarInline (date) { + return moment(date).calendar(null, { + sameDay: '[today at] H:mm', + lastDay: '[yesterday at] H:mm', + nextDay: '[tomorrow at] H:mm', + lastWeek: '[last] dddd [at] H:mm', + nextWeek: '[next] dddd [at] H:mm', + sameElse: '[at] MMMM D, YYYY [at] H:mm', + }) +} + export function toRFC3339 (date) { if (!date) { return '' diff --git a/src/js/helpers/money-helper.js b/src/js/helpers/money-helper.js new file mode 100644 index 000000000..221fe7884 --- /dev/null +++ b/src/js/helpers/money-helper.js @@ -0,0 +1,21 @@ +import { MathUtil } from '@/js/utils' + +export function formatMoney ({ + value, + currency, +}) { + const cfg = + ({ + decimalSeparator: '.', + groupSeparator: ',', + groupSize: 3, + decimalPlaces: 6, + }) + + const result = value + ? MathUtil.format(value, cfg) + : '0' + return currency + ? result.concat(' ', currency) + : result +} diff --git a/src/js/helpers/number-helper.js b/src/js/helpers/number-helper.js new file mode 100644 index 000000000..9d1ad9670 --- /dev/null +++ b/src/js/helpers/number-helper.js @@ -0,0 +1,20 @@ +import { MathUtil } from '@/js/utils' + +export function formatNumber ( + number, + decimalPlaces = 6, + suffix = 0, +) { + const cfg = + ({ + decimalSeparator: '.', + groupSeparator: ',', + groupSize: 3, + suffix, + decimalPlaces, + }) + return MathUtil.format( + number, + cfg, + ) +} diff --git a/src/vue/filters/cropAddress.js b/src/js/helpers/text-helper.js similarity index 59% rename from src/vue/filters/cropAddress.js rename to src/js/helpers/text-helper.js index 6e4c158bb..823d02cb4 100644 --- a/src/vue/filters/cropAddress.js +++ b/src/js/helpers/text-helper.js @@ -1,3 +1,3 @@ -export function cropAddress (value) { +export function abbrCenter (value) { return `${value.slice(0, 4)}…${value.slice(-4)}` } diff --git a/src/main.js b/src/main.js index c03325c6b..f4944b5f6 100644 --- a/src/main.js +++ b/src/main.js @@ -17,17 +17,6 @@ import { ripple } from '@/vue/directives/ripple' import { i18n, i18nComponent } from '@/i18n' import { globalize } from '@/vue/filters/globalize' import { globalizeCountry } from './vue/filters/globalizeCountry' -import { formatDate } from '@/vue/filters/formatDate' -import { formatMoney } from '@/vue/filters/formatMoney' -import { formatNumber } from '@/vue/filters/formatNumber' -import { formatInteger } from '@/vue/filters/formatInteger' -import { formatPercent } from '@/vue/filters/formatPercent' -import { formatCalendar } from '@/vue/filters/formatCalendar' -import { formatCalendarInline } from '@/vue/filters/formatCalendarInline' -import { formatDateDMY } from '@/vue/filters/formatDateDMY' -import { formatDateDMYT } from '@/vue/filters/formatDateDMYT' -import { abbreviate } from '@/vue/filters/abbreviate' -import { cropAddress } from '@/vue/filters/cropAddress' import { ErrorTracker } from '@/js/helpers/error-tracker' import { vueRoutes } from './vue-router/routes' import { useBrowserUpdateBanner } from './browser-update' @@ -55,17 +44,6 @@ async function init () { Vue.directive('ripple', ripple) Vue.filter('globalize', globalize) Vue.filter('globalizeCountry', globalizeCountry) - Vue.filter('formatDate', formatDate) - Vue.filter('formatDateDMY', formatDateDMY) - Vue.filter('formatDateDMYT', formatDateDMYT) - Vue.filter('formatMoney', formatMoney) - Vue.filter('formatNumber', formatNumber) - Vue.filter('formatPercent', formatPercent) - Vue.filter('formatInteger', formatInteger) - Vue.filter('formatCalendar', formatCalendar) - Vue.filter('formatCalendarInline', formatCalendarInline) - Vue.filter('abbreviate', abbreviate) - Vue.filter('cropAddress', cropAddress) Vue.component('i18n', i18nComponent) Vue.prototype.$config = config Vue.prototype.$routes = vueRoutes diff --git a/src/vue/common/CardLogo.vue b/src/vue/common/CardLogo.vue index 4fd482d69..4fcad6b34 100644 --- a/src/vue/common/CardLogo.vue +++ b/src/vue/common/CardLogo.vue @@ -17,7 +17,7 @@