Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ 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

### Fixed
- New version of vue: 2.7.14
- New version of vue-template-compiler": 2.7.14
Expand Down
44 changes: 0 additions & 44 deletions src/i18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
34 changes: 34 additions & 0 deletions src/js/helpers/date-helpers.js
Original file line number Diff line number Diff line change
@@ -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 ''
Expand Down
21 changes: 21 additions & 0 deletions src/js/helpers/money-helper.js
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions src/js/helpers/number-helper.js
Original file line number Diff line number Diff line change
@@ -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,
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function cropAddress (value) {
export function abbrCenter (value) {
return `${value.slice(0, 4)}…${value.slice(-4)}`
}
20 changes: 0 additions & 20 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ 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'
Expand Down Expand Up @@ -55,17 +45,7 @@ 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
Expand Down
13 changes: 10 additions & 3 deletions src/vue/common/EmailGetter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</template>

<template v-else-if="accountId || balanceId">
{{ accountId || balanceId | cropAddress }}
{{ accountId || abbrCenter(balanceId) }}
</template>

<template v-else>
Expand Down Expand Up @@ -55,12 +55,14 @@ import IdentityGetterMixin from '@/vue/mixins/identity-getter'

import { api } from '@/api'
import { ErrorHandler } from '@/js/helpers/error-handler'
import { defineComponent } from 'vue'
import { abbrCenter } from '@/js/helpers/text-helper'
import Clipboard from 'clipboard'
import Tooltip from '@/vue/common/Tooltip'

import safeGet from 'lodash/get'

export default {
export default defineComponent({
components: {
Tooltip,
},
Expand Down Expand Up @@ -170,7 +172,12 @@ export default {
}, hideTooltipTimeout)
},
},
}
setup () {
return {
abbrCenter,
}
},
})
</script>

<style lang="scss" scoped>
Expand Down
21 changes: 13 additions & 8 deletions src/vue/common/TradeTopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@
v-if="formattedPairs.length && isLoaded"
class="trade-asset-selector__balances-value"
>
{{
// eslint-disable-next-line
{ value: assetPairBalances.base, currency: assetPair.base } | formatMoney
}}
{{ formatMoney({
value: assetPairBalances.base, currency: assetPair.base
}) }}
/
{{
// eslint-disable-next-line
{ value: assetPairBalances.quote, currency: assetPair.quote } | formatMoney
}}
{{ formatMoney({
value:assetPairBalances.quote, currency: assetPair.quote
}) }}
</p>
<skeleton-loader
v-else-if="!isLoaded"
Expand Down Expand Up @@ -154,6 +152,8 @@ import { vueRoutes } from '@/vue-router/routes'
import { ErrorHandler } from '@/js/helpers/error-handler'
import { Bus } from '@/js/helpers/event-bus'

import { formatMoney } from '@/js/helpers/money-helper'

const EVENTS = {
reloadTradeData: 'reload-trade-data',
}
Expand Down Expand Up @@ -287,6 +287,11 @@ export default {
this.loadBalances()
},
},
setup () {
return {
formatMoney,
}
},
}
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/vue/common/chart/Chart.Renderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</template>

<script>
import { formatMoney } from '@/vue/filters/formatMoney'
import { formatMoney } from '@/js/helpers/money-helper'
import { mapGetters } from 'vuex'
import { vuexTypes } from '@/vuex'
import * as d3Array from 'd3-array'
Expand Down Expand Up @@ -167,7 +167,7 @@ export default {
.domain([0, 12])
this.yAxisLine = d3.axisRight(y)
.tickValues([0, 5, 10])
.tickFormat((d) => `${formatMoney(d)} ${this.defaultAsset}`)
.tickFormat((d) => `${formatMoney({ value: d })} ${this.defaultAsset}`)
.tickSizeInner(this.width)
.tickSizeOuter(0)
.tickPadding(25)
Expand Down Expand Up @@ -293,7 +293,7 @@ export default {
if (this.isTicksShown) {
const yAxisLine = d3.axisRight(this.y)
.ticks(4)
.tickFormat((d) => `${formatMoney(d.toFixed(2))} ${this.defaultAsset}`)
.tickFormat((d) => `${formatMoney({ value: d.toFixed(2) })} ${this.defaultAsset}`)
.tickSizeInner(this.width)
.tickSizeOuter(0)
.tickPadding(25)
Expand Down
15 changes: 11 additions & 4 deletions src/vue/common/fees/FeeViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="fee-viewer__total"
@click="toggleDetails"
>
{{ formatFee(fee.total) | formatMoney }}
{{ formatMoney(formatFee(fee.total)) }}
</a>
</p>

Expand All @@ -24,7 +24,7 @@
</span>

<span class="fee-viewer__details-row-text">
{{ formatFee(fee.fixed) | formatMoney }}
{{ formatMoney(formatFee(fee.fixed)) }}
</span>
</p>

Expand All @@ -34,7 +34,7 @@
</span>

<span class="fee-viewer__details-row-text">
{{ formatFee(fee.calculatedPercent) | formatMoney }}
{{ formatMoney(formatFee(fee.calculatedPercent)) }}
</span>
</p>

Expand All @@ -47,7 +47,7 @@
</span>

<span class="fee-viewer__details-row-text">
{{ formatFee(fee.additional) | formatMoney }}
{{ formatMoney(formatFee(fee.additional)) }}
</span>
</p>
</div>
Expand All @@ -57,6 +57,7 @@

<script>
import { Fee } from './fee'
import { formatMoney } from '@/js/helpers/money-helper'

export default {
name: 'fee-viewer',
Expand Down Expand Up @@ -108,6 +109,12 @@ export default {
this.isDetailsShown = !this.isDetailsShown
},
},

setup () {
return {
formatMoney,
}
},
}
</script>

Expand Down
5 changes: 0 additions & 5 deletions src/vue/filters/formatCalendar.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/vue/filters/formatCalendarInline.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/vue/filters/formatDate.js

This file was deleted.

Loading