Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: formatted supply amount component added, supply format issues fixed #1651

Merged
merged 1 commit into from
Aug 23, 2021
Merged
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
15 changes: 15 additions & 0 deletions src/components/SupplyAmount/SupplyAmount.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<FormRow>
<template v-slot:label> {{ $t(label) }}: </template>
<template v-slot:inputs>
<div class="display-value">
{{ relativeValue }}
</div>
</template>
</FormRow>
</template>

<script lang="ts">
import { SupplyAmountTs } from './SupplyAmountTs';
export default class SupplyAmount extends SupplyAmountTs {}
</script>
51 changes: 51 additions & 0 deletions src/components/SupplyAmount/SupplyAmountTs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2020 NEM (https://nem.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*
*/
// @ts-ignore
import FormRow from '@/components/FormRow/FormRow.vue';
import { Formatters } from '@/core/utils/Formatters';
// child components
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({
components: {
FormRow,
},
})
export class SupplyAmountTs extends Vue {
/**
* Supply Absolute Value
* @type {number}
*/
@Prop({ default: 0 }) supply: number;

/**
* Divisibility Value
* @type {number}
*/
@Prop({ default: 0 }) divisibility: number;

/**
* Form label
* @type {string}
*/
@Prop({ default: 'supply' }) label: string;

/// region computed properties getter/setter
public get relativeValue(): string {
return Formatters.formatNumber(this.supply / Math.pow(10, this.divisibility), this.divisibility);
}
/// end-region computed properties getter/setter
}
2 changes: 1 addition & 1 deletion src/components/SupplyInput/SupplyInputTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SupplyInputTs extends Vue {
* Form label
* @type {string}
*/
@Prop({ default: 'supply' }) label: string;
@Prop({ default: 'supply_absolute' }) label: string;

/**
* Validation rules
Expand Down
5 changes: 0 additions & 5 deletions src/components/TableRow/TableRowTs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ export class TableRowTs extends Vue {
protected get visibleRowValues() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { hiddenData, ...visible } = this.rowValues;
if (this.$route.fullPath === '/mosaicList') {
visible.supply = (visible.supply.replace(/\D/g, '') / Math.pow(10, visible.divisibility))
.toString()
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
return visible;
}
}
6 changes: 3 additions & 3 deletions src/core/utils/Formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import { Address } from 'symbol-sdk';
import { decode } from 'utf8';

export class Formatters {
public static formatNumber = (number: number): string => {
public static formatNumber = (number: number, fractionDigits = 0): string => {
if (number <= 1) {
return `${number}`;
}
if (number === Number(number.toFixed(0))) {
return number.toLocaleString('en-US', { minimumFractionDigits: 0 });
return number.toLocaleString('en-US', { minimumFractionDigits: fractionDigits });
}

const stringOfNumber = `${number}`;
const minimumFractionDigits = stringOfNumber.length - stringOfNumber.indexOf('.') - 1;
return number.toLocaleString('en-US', { minimumFractionDigits });
return number.toLocaleString('en-US', { minimumFractionDigits: fractionDigits || minimumFractionDigits });
};

public static formatAddress = function (address: string): string {
Expand Down
597 changes: 299 additions & 298 deletions src/language/en-US.json

Large diffs are not rendered by default.

597 changes: 299 additions & 298 deletions src/language/ja-JP.json

Large diffs are not rendered by default.

596 changes: 299 additions & 297 deletions src/language/ru-RU.json

Large diffs are not rendered by default.

609 changes: 305 additions & 304 deletions src/language/zh-CN.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/services/AssetTableService/MosaicTableService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { AssetTableService, TableField } from './AssetTableService';
import { MosaicModel } from '@/core/database/entities/MosaicModel';
import { MosaicService } from '@/services/MosaicService';
import { NetworkConfigurationModel } from '@/core/database/entities/NetworkConfigurationModel';
import { Formatters } from '@/core/utils/Formatters';

export class MosaicTableService extends AssetTableService {
constructor(
Expand Down Expand Up @@ -65,7 +66,7 @@ export class MosaicTableService extends AssetTableService {
return {
hexId: mosaicInfo.mosaicIdHex,
name: mosaicInfo.name || 'N/A',
supply: mosaicInfo.supply.toLocaleString(),
supply: Formatters.formatNumber(mosaicInfo.supply / Math.pow(10, mosaicInfo.divisibility), mosaicInfo.divisibility),
balance: (mosaicInfo.balance || 0) / Math.pow(10, mosaicInfo.divisibility),
expiration: expiration,
divisibility: mosaicInfo.divisibility,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<DivisibilityInput v-model="formItems.divisibility" />

<SupplyAmount v-if="!isAggregate" :supply="formItems.supply" :divisibility="formItems.divisibility" />

<DurationInput
v-show="!formItems.permanent"
v-model="formItems.duration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import SupplyInput from '@/components/SupplyInput/SupplyInput.vue';
// @ts-ignore
import DivisibilityInput from '@/components/DivisibilityInput/DivisibilityInput.vue';
// @ts-ignore
import SupplyAmount from '@/components/SupplyAmount/SupplyAmount.vue';
// @ts-ignore
import DurationInput from '@/components/DurationInput/DurationInput.vue';
// @ts-ignore
import ModalTransactionConfirmation from '@/views/modals/ModalTransactionConfirmation/ModalTransactionConfirmation.vue';
Expand All @@ -56,6 +58,7 @@ import RentalFee from '@/components/RentalFees/RentalFee.vue';
SignerSelector,
SupplyInput,
DivisibilityInput,
SupplyAmount,
DurationInput,
ModalTransactionConfirmation,
MaxFeeAndSubmit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import MaxFeeAndSubmit from '@/components/MaxFeeAndSubmit/MaxFeeAndSubmit.vue';
import { MosaicModel } from '@/core/database/entities/MosaicModel';
// @ts-ignore
import MosaicSelector from '@/components/MosaicSelector/MosaicSelector.vue';
import { Formatters } from '@/core/utils/Formatters';

@Component({
components: {
Expand Down Expand Up @@ -146,7 +147,7 @@ export class FormMosaicSupplyChangeTransactionTs extends FormTransactionBase {
return;
}
const relative = currentMosaicInfo.supply / Math.pow(10, currentMosaicInfo.divisibility);
return isNaN(relative) ? null : relative.toLocaleString();
return isNaN(relative) ? null : Formatters.formatNumber(relative, this.currentMosaicInfo.divisibility);
}

/**
Expand Down Expand Up @@ -179,7 +180,7 @@ export class FormMosaicSupplyChangeTransactionTs extends FormTransactionBase {
return;
}
const relative = this.newMosaicAbsoluteSupply / Math.pow(10, this.currentMosaicInfo.divisibility);
return isNaN(relative) ? null : relative.toLocaleString();
return isNaN(relative) ? null : Formatters.formatNumber(relative, this.currentMosaicInfo.divisibility);
}

/**
Expand Down