From f52b02bad1557568ed9574dda0e56a0fac100c9a Mon Sep 17 00:00:00 2001 From: Don Peat Date: Mon, 19 Jun 2023 14:33:27 -0500 Subject: [PATCH 01/29] fix: correct value for max eligible savings --- src/components/staking/SavingsTab.vue | 5 +++-- src/utils/string-utils.ts | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/staking/SavingsTab.vue b/src/components/staking/SavingsTab.vue index 0597aeff..f36e5140 100644 --- a/src/components/staking/SavingsTab.vue +++ b/src/components/staking/SavingsTab.vue @@ -3,7 +3,7 @@ import { defineComponent, ref, computed } from 'vue'; import { useStore } from 'src/store'; import ViewTransaction from 'src/components/ViewTransanction.vue'; import { API } from '@greymass/eosio'; -import { assetToAmount } from 'src/utils/string-utils'; +import { assetToAmount, formatNumberWithCommas } from 'src/utils/string-utils'; export default defineComponent({ name: 'SavingsTab', @@ -104,6 +104,7 @@ export default defineComponent({ rexSavings, transactionId, transactionError, + formatNumberWithCommas, formatDec, moveToSavings, moveFromSavings, @@ -126,7 +127,7 @@ export default defineComponent({
STAKE TO SAVINGS
-
{{ eligibleStaked }}
+
{{ formatNumberWithCommas(eligibleStaked) }}
Any balance currently maturing will be moved first, click to stake full amount
diff --git a/src/utils/string-utils.ts b/src/utils/string-utils.ts index bf72526e..ef39c627 100644 --- a/src/utils/string-utils.ts +++ b/src/utils/string-utils.ts @@ -69,12 +69,16 @@ export function formatCurrency( export function assetToAmount(asset: string): number { try { const qty: string = asset.split(' ')[0]; - return parseFloat(qty); + return parseFloat(qty.replace(/,/g, '')); // remove commas } catch (error) { return 0; } } +export function formatNumberWithCommas(num: number): string { + return num.toString().replace(/\B(? Date: Mon, 19 Jun 2023 14:42:02 -0500 Subject: [PATCH 02/29] test: format number string --- .../jest/__tests__/utils/string-utils.spec.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/jest/__tests__/utils/string-utils.spec.ts b/test/jest/__tests__/utils/string-utils.spec.ts index 17d0421b..4e48b892 100644 --- a/test/jest/__tests__/utils/string-utils.spec.ts +++ b/test/jest/__tests__/utils/string-utils.spec.ts @@ -4,6 +4,7 @@ import { isValidTransactionHex, formatCurrency, assetToAmount, + formatNumberWithCommas, formatDate, getRexHistoryAsset, } from 'src/utils/string-utils'; @@ -162,6 +163,24 @@ describe('string-utils utility functions', () => { }); }); + describe('formatNumberWithCommas', () => { + it('passed a number less than one thousand returns the same number as a string', () => { + const testValue = 123; + const expectedResult = '123'; + expect(formatNumberWithCommas(testValue)).toEqual(expectedResult); + }); + it('inserts commas for numbers larger than four digits', () => { + const testValue = 123456789; + const expectedResult = '123,456,789'; + expect(formatNumberWithCommas(testValue)).toEqual(expectedResult); + }); + it('does not insert commas for trailing decimal places exceeding four digits', () => { + const testValue = 12345.6789; + const expectedResult = '12,345.6789'; + expect(formatNumberWithCommas(testValue)).toEqual(expectedResult); + }); + }); + describe('formatDate', () => { it('formats ISO date timestamp string to ` , at H:MM:SS `', () => { const testDate = '2023-03-21T21:26:16+01:23'; From 01a6fd981e2083ff976cb5034908f0ad0b5f66be Mon Sep 17 00:00:00 2001 From: Don Date: Mon, 19 Jun 2023 16:14:49 -0500 Subject: [PATCH 03/29] Update src/utils/string-utils.ts Co-authored-by: Viterbo Rodriguez --- src/utils/string-utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/utils/string-utils.ts b/src/utils/string-utils.ts index ef39c627..0c502373 100644 --- a/src/utils/string-utils.ts +++ b/src/utils/string-utils.ts @@ -76,7 +76,10 @@ export function assetToAmount(asset: string): number { } export function formatNumberWithCommas(num: number): string { - return num.toString().replace(/\B(? Date: Mon, 19 Jun 2023 16:19:53 -0500 Subject: [PATCH 04/29] chore: lint --- src/utils/string-utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/string-utils.ts b/src/utils/string-utils.ts index 0c502373..1b8874e2 100644 --- a/src/utils/string-utils.ts +++ b/src/utils/string-utils.ts @@ -76,10 +76,10 @@ export function assetToAmount(asset: string): number { } export function formatNumberWithCommas(num: number): string { - return new Intl.NumberFormat('en-US', { - minimumFractionDigits: 0, - maximumFractionDigits: 20, - }).format(num); + return new Intl.NumberFormat('en-US', { + minimumFractionDigits: 0, + maximumFractionDigits: 20, + }).format(num); } export function formatDate(date: string, showTime = true): string { From 56e82c0262d03f4c208e4a8259057ec06026b8cf Mon Sep 17 00:00:00 2001 From: Karyne Mayer Date: Fri, 23 Jun 2023 13:34:54 -0700 Subject: [PATCH 05/29] Adding PrettyPayload --- src/components/transaction/DataFormat.vue | 119 +++++++++++-------- src/components/transaction/PrettyPayload.vue | 64 ++++++++++ 2 files changed, 136 insertions(+), 47 deletions(-) create mode 100644 src/components/transaction/PrettyPayload.vue diff --git a/src/components/transaction/DataFormat.vue b/src/components/transaction/DataFormat.vue index 7678e743..f4743faa 100644 --- a/src/components/transaction/DataFormat.vue +++ b/src/components/transaction/DataFormat.vue @@ -1,11 +1,12 @@ diff --git a/src/components/transaction/PrettyPayload.vue b/src/components/transaction/PrettyPayload.vue new file mode 100644 index 00000000..452b0022 --- /dev/null +++ b/src/components/transaction/PrettyPayload.vue @@ -0,0 +1,64 @@ + + + + + From 5cfa47e525f22572ad85ee02d5434d080171c2d9 Mon Sep 17 00:00:00 2001 From: Ezra Sowden-Guzman Date: Fri, 23 Jun 2023 17:13:37 -0400 Subject: [PATCH 06/29] fix ts errors --- src/components/transaction/DataFormat.vue | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/components/transaction/DataFormat.vue b/src/components/transaction/DataFormat.vue index f4743faa..071a18a8 100644 --- a/src/components/transaction/DataFormat.vue +++ b/src/components/transaction/DataFormat.vue @@ -22,8 +22,8 @@ export default defineComponent({ }, }, setup(props) { - const { actionName, actionData, useColor } = toRefs(props); - const dataBox = ref(null); + const { actionName, actionData } = toRefs(props); + const dataBox = ref(null); const showOverflow = ref(false); const maxHeight = ref(57); const switchHeight = ref(20); @@ -33,29 +33,32 @@ export default defineComponent({ let currentData = ref(null); - function compareJsonObjects(obj1: Record, obj2: Record): boolean { + function compareJsonObjects(obj1: unknown, obj2: unknown): boolean { if (typeof obj1 !== 'object' || typeof obj2 !== 'object') { return false; } + const objectOne = obj1 as Record; + const objectTwo = obj2 as Record; + for (const key of Object.keys(obj1)) { - if (!obj1?.[key]) { + if (!objectOne[key]) { // this is an empty key // sometimes the answer includes them, sometimes it doesn't // so we won't compare them continue; } - if (typeof obj1[key] !== typeof obj2[key]) { + if (typeof objectOne[key] !== typeof objectTwo[key]) { return false; } - if (obj1[key] !== null && typeof obj1[key] === 'object') { - if (!compareJsonObjects(obj1[key], obj2[key])) { + if (objectOne[key] !== null && typeof objectOne[key] === 'object') { + if (!compareJsonObjects(objectOne[key], objectTwo[key])) { return false; } } else { - if (obj1[key] !== obj2[key]) { + if (objectOne[key] !== objectTwo[key]) { return false; } } @@ -101,7 +104,6 @@ export default defineComponent({ } return { - actionData, currentData, transferData, name: actionName, @@ -113,7 +115,6 @@ export default defineComponent({ toggleOverflow, maxHeight, switchHeight, - useColor, }; }, }); From 4f8417d83695fd6f09151c6f0ae34c9eb86e6991 Mon Sep 17 00:00:00 2001 From: Karyne Mayer Date: Mon, 26 Jun 2023 08:42:02 -0700 Subject: [PATCH 07/29] Adding v-bind=key to PrettyPayload --- src/components/transaction/PrettyPayload.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/transaction/PrettyPayload.vue b/src/components/transaction/PrettyPayload.vue index 452b0022..f3b7aa2d 100644 --- a/src/components/transaction/PrettyPayload.vue +++ b/src/components/transaction/PrettyPayload.vue @@ -20,7 +20,6 @@ export default defineComponent({ return { indent, - depth: depth.value, type, list, }; @@ -30,7 +29,7 @@ export default defineComponent({