From 6f59377afd8fb5ebe175bc565e240d69475ea899 Mon Sep 17 00:00:00 2001 From: Taha Paksu <3295+tpaksu@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:46:42 +0300 Subject: [PATCH] Fix currency negative sign position on JS rendered amounts (#7935) --- ...700-remove-currency-sign-modification-code | 4 +++ .../test/__snapshots__/index.test.tsx.snap | 26 +++++++-------- .../summary/test/index.test.tsx | 2 +- .../timeline/test/__snapshots__/index.js.snap | 2 +- .../test/__snapshots__/map-events.js.snap | 12 +++---- .../list/test/__snapshots__/index.tsx.snap | 32 +++++++++---------- client/utils/currency/index.js | 32 +++++++++++++++---- includes/class-wc-payments-utils.php | 10 +----- .../fixtures/captured-payments/discount.json | 2 +- .../captured-payments/foreign-card.json | 2 +- .../captured-payments/fx-decimal.json | 2 +- .../captured-payments/fx-foreign-card.json | 2 +- .../captured-payments/fx-with-capped-fee.json | 2 +- tests/fixtures/captured-payments/fx.json | 2 +- .../captured-payments/jpy-payment.json | 2 +- .../captured-payments/only-base-fee.json | 2 +- .../captured-payments/subscription.json | 2 +- tests/unit/test-class-wc-payments-utils.php | 2 +- 18 files changed, 78 insertions(+), 62 deletions(-) create mode 100644 changelog/fix-6700-remove-currency-sign-modification-code diff --git a/changelog/fix-6700-remove-currency-sign-modification-code b/changelog/fix-6700-remove-currency-sign-modification-code new file mode 100644 index 00000000000..74634338357 --- /dev/null +++ b/changelog/fix-6700-remove-currency-sign-modification-code @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Fix currency negative sign position on JS rendered amounts diff --git a/client/payment-details/summary/test/__snapshots__/index.test.tsx.snap b/client/payment-details/summary/test/__snapshots__/index.test.tsx.snap index 30c5c237e49..e9a596d35d5 100644 --- a/client/payment-details/summary/test/__snapshots__/index.test.tsx.snap +++ b/client/payment-details/summary/test/__snapshots__/index.test.tsx.snap @@ -42,7 +42,7 @@ exports[`PaymentDetailsSummary capture notification and fraud buttons renders ca
Fees: - $-0.70 + -$0.70
@@ -343,7 +343,7 @@ exports[`PaymentDetailsSummary capture notification and fraud buttons renders th
Fees: - $-0.70 + -$0.70
@@ -654,7 +654,7 @@ exports[`PaymentDetailsSummary correctly renders a charge 1`] = `
Fees: - $-0.70 + -$0.70
@@ -914,7 +914,7 @@ exports[`PaymentDetailsSummary order missing notice does not render notice if or
Fees: - $-0.70 + -$0.70
@@ -1174,7 +1174,7 @@ exports[`PaymentDetailsSummary order missing notice renders notice if order miss
Fees: - $-0.70 + -$0.70
@@ -1456,7 +1456,7 @@ exports[`PaymentDetailsSummary renders a charge with subscriptions 1`] = `
Fees: - $-0.70 + -$0.70
@@ -1742,16 +1742,16 @@ exports[`PaymentDetailsSummary renders fully refunded information for a charge 1 >
Refunded: - $-20.00 + -$20.00
Fees: - $-0.70 + -$0.70
Net: - $-0.70 + -$0.70
@@ -2238,11 +2238,11 @@ exports[`PaymentDetailsSummary renders partially refunded information for a char >Refunded: - $-12.00 + -$12.00
Fees: - $-0.70 + -$0.70
@@ -2502,7 +2502,7 @@ exports[`PaymentDetailsSummary renders the Tap to Pay channel from metadata 1`]
Fees: - $-0.70 + -$0.70
@@ -2762,7 +2762,7 @@ exports[`PaymentDetailsSummary renders the information of a dispute-reversal cha
Fees: - $-0.70 + -$0.70
diff --git a/client/payment-details/summary/test/index.test.tsx b/client/payment-details/summary/test/index.test.tsx
index 58de0645616..522c613d5ff 100755
--- a/client/payment-details/summary/test/index.test.tsx
+++ b/client/payment-details/summary/test/index.test.tsx
@@ -251,7 +251,7 @@ describe( 'PaymentDetailsSummary', () => {
} );
const container = renderCharge( charge );
- screen.getByText( /Refunded: \$-20.00/i );
+ screen.getByText( /Refunded: -\$20.00/i );
expect( container ).toMatchSnapshot();
} );
diff --git a/client/payment-details/timeline/test/__snapshots__/index.js.snap b/client/payment-details/timeline/test/__snapshots__/index.js.snap
index df78052123c..e4753b57f06 100644
--- a/client/payment-details/timeline/test/__snapshots__/index.js.snap
+++ b/client/payment-details/timeline/test/__snapshots__/index.js.snap
@@ -1494,7 +1494,7 @@ exports[`PaymentDetailsTimeline renders subscription fee correctly 1`] = `
>
- Fee (3.9% + $0.30): $-0.34
+ Fee (3.9% + $0.30): -$0.34
@@ -412,7 +412,7 @@ Array [
Variable fee: -4.9%
@@ -455,7 +455,7 @@ Array [
Object {
"body": Array [
undefined,
- "Base fee (1.95% + $0.15): $-3.50",
+ "Base fee (1.95% + $0.15): -$3.50",
undefined,
"Net deposit: $59.50 USD",
],
@@ -695,7 +695,7 @@ Array [
Object {
"body": Array [
undefined,
- "Fee (2.6% + $0.20): $-0.61",
+ "Fee (2.6% + $0.20): -$0.61",
@@ -745,7 +745,7 @@ Array [
Object {
"body": Array [
undefined,
- "Fee (1.95% + $0.15): $-3.50",
+ "Fee (1.95% + $0.15): -$3.50",
undefined,
"Net deposit: $59.50 USD",
],
diff --git a/client/transactions/list/test/__snapshots__/index.tsx.snap b/client/transactions/list/test/__snapshots__/index.tsx.snap
index c7bfca77b45..3e5c77a9a7a 100644
--- a/client/transactions/list/test/__snapshots__/index.tsx.snap
+++ b/client/transactions/list/test/__snapshots__/index.tsx.snap
@@ -542,7 +542,7 @@ exports[`Transactions list renders correctly when can filter by several currenci
href="admin.php?page=wc-admin&path=%2Fpayments%2Ftransactions%2Fdetails&id=pi_mock&transaction_id=txn_j23jda9JJa&transaction_type=refund"
tabindex="-1"
>
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.75
+ -$0.75
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.75
+ -$0.75
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.75
+ -$0.75
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.75
+ -$0.75
- $-0.50
+ -$0.50
- $-0.50
+ -$0.50
- $-0.75
+ -$0.75
= 0 ) {
- return $formatted;
- }
-
- // Handle the subtle display difference for the negative amount between PHP wc_price `-$0.74` vs JavaScript formatCurrency `$-0.74` for the same input.
- // Remove the minus sign, and then move it right before the number.
- $formatted = str_replace( '-', '', $formatted );
-
- return preg_replace( '/([0-9,\.]+)/', '-$1', $formatted );
+ return $formatted;
}
/**
diff --git a/tests/fixtures/captured-payments/discount.json b/tests/fixtures/captured-payments/discount.json
index 939a6b7bb8d..af1b0f8cf77 100644
--- a/tests/fixtures/captured-payments/discount.json
+++ b/tests/fixtures/captured-payments/discount.json
@@ -61,7 +61,7 @@
"discount": {
"label": "Discount",
"variable": "Variable fee: -4.9%",
- "fixed": "Fixed fee: $-0.30"
+ "fixed": "Fixed fee: -$0.30"
}
},
"netString": "Net deposit: $105.48 USD"
diff --git a/tests/fixtures/captured-payments/foreign-card.json b/tests/fixtures/captured-payments/foreign-card.json
index 8f5f7f214c6..9a121e3a7ed 100644
--- a/tests/fixtures/captured-payments/foreign-card.json
+++ b/tests/fixtures/captured-payments/foreign-card.json
@@ -49,7 +49,7 @@
},
"expectation": {
"fxString": "1.00 CAD → 0.774692 USD: $100.71 USD",
- "feeString": "Fee (4.9% + $0.30): $-5.24",
+ "feeString": "Fee (4.9% + $0.30): -$5.24",
"feeBreakdown": {
"base": "Base fee: 2.9% + $0.30",
"additional-international": "International card fee: 1%",
diff --git a/tests/fixtures/captured-payments/fx-decimal.json b/tests/fixtures/captured-payments/fx-decimal.json
index 0088ab63680..77a136924f8 100644
--- a/tests/fixtures/captured-payments/fx-decimal.json
+++ b/tests/fixtures/captured-payments/fx-decimal.json
@@ -42,7 +42,7 @@
},
"expectation": {
"fxString": "1.00 EUR → 1.0504 USD: $105.04 USD",
- "feeString": "Fee (3.9% + $0.30): $-4.39",
+ "feeString": "Fee (3.9% + $0.30): -$4.39",
"feeBreakdown": {
"base": "Base fee: 2.9% + $0.30",
"additional-fx": "Foreign exchange fee: 1%"
diff --git a/tests/fixtures/captured-payments/fx-foreign-card.json b/tests/fixtures/captured-payments/fx-foreign-card.json
index 7d9ea59e557..9b26ad48fc1 100644
--- a/tests/fixtures/captured-payments/fx-foreign-card.json
+++ b/tests/fixtures/captured-payments/fx-foreign-card.json
@@ -42,7 +42,7 @@
}
},
"expectation": {
- "feeString": "Fee (3.9% + $0.30): $-3.20",
+ "feeString": "Fee (3.9% + $0.30): -$3.20",
"feeBreakdown": {
"base": "Base fee: 2.9% + $0.30",
"additional-international": "International card fee: 1%"
diff --git a/tests/fixtures/captured-payments/fx-with-capped-fee.json b/tests/fixtures/captured-payments/fx-with-capped-fee.json
index 1eaecc3e9d7..23c3cbf1387 100644
--- a/tests/fixtures/captured-payments/fx-with-capped-fee.json
+++ b/tests/fixtures/captured-payments/fx-with-capped-fee.json
@@ -51,7 +51,7 @@
},
"expectation": {
"fxString": "1.00 EUR → 1.05483 USD: $1,002.09 USD",
- "feeString": "Fee (2.5% + $6.00): $-31.05",
+ "feeString": "Fee (2.5% + $6.00): -$31.05",
"feeBreakdown": {
"base": "Base fee: capped at $6.00",
"additional-international": "International card fee: 1.5%",
diff --git a/tests/fixtures/captured-payments/fx.json b/tests/fixtures/captured-payments/fx.json
index 9dfe492153b..166deab4a86 100644
--- a/tests/fixtures/captured-payments/fx.json
+++ b/tests/fixtures/captured-payments/fx.json
@@ -43,7 +43,7 @@
},
"expectation": {
"fxString": "1 VND → 0.000044 USD: $100.04 USD",
- "feeString": "Fee (3.9% + $0.30): $-4.20",
+ "feeString": "Fee (3.9% + $0.30): -$4.20",
"feeBreakdown": {
"base": "Base fee: 2.9% + $0.30",
"additional-fx": "Foreign exchange fee: 1%"
diff --git a/tests/fixtures/captured-payments/jpy-payment.json b/tests/fixtures/captured-payments/jpy-payment.json
index 50af38dd483..c5bc6eb7dd6 100644
--- a/tests/fixtures/captured-payments/jpy-payment.json
+++ b/tests/fixtures/captured-payments/jpy-payment.json
@@ -50,7 +50,7 @@
},
"expectation": {
"fxString": "1.00 EUR → 159.13333 JPY: ¥4,774 JPY",
- "feeString": "Fee (7.6% + ¥0): ¥-267",
+ "feeString": "Fee (7.6% + ¥0): -¥267",
"feeBreakdown": {
"base": "Base fee: 3.6%",
"additional-international": "International card fee: 2%",
diff --git a/tests/fixtures/captured-payments/only-base-fee.json b/tests/fixtures/captured-payments/only-base-fee.json
index 39a3dfccdd4..0385bd61c6f 100644
--- a/tests/fixtures/captured-payments/only-base-fee.json
+++ b/tests/fixtures/captured-payments/only-base-fee.json
@@ -34,7 +34,7 @@
}
},
"expectation": {
- "feeString": "Base fee (2.9% + $0.30): $-0.74",
+ "feeString": "Base fee (2.9% + $0.30): -$0.74",
"netString": "Net deposit: $14.26 USD"
}
}
diff --git a/tests/fixtures/captured-payments/subscription.json b/tests/fixtures/captured-payments/subscription.json
index 1ee34195c2a..a9a4d01eae4 100644
--- a/tests/fixtures/captured-payments/subscription.json
+++ b/tests/fixtures/captured-payments/subscription.json
@@ -50,7 +50,7 @@
},
"expectation": {
"fxString": "1.00 EUR → 1.05491 USD: $55.91 USD",
- "feeString": "Fee (4.9% + $0.30): $-3.04",
+ "feeString": "Fee (4.9% + $0.30): -$3.04",
"feeBreakdown": {
"base": "Base fee: 2.9% + $0.30",
"additional-fx": "Foreign exchange fee: 1%",
diff --git a/tests/unit/test-class-wc-payments-utils.php b/tests/unit/test-class-wc-payments-utils.php
index f9ed09117f6..0248b757f3b 100644
--- a/tests/unit/test-class-wc-payments-utils.php
+++ b/tests/unit/test-class-wc-payments-utils.php
@@ -518,7 +518,7 @@ public function test_format_currency( float $amount, string $currency, string $e
public function provider_format_currency(): array {
return [
'US dollar' => [ 123.456, 'USD', '$123.46' ],
- 'US dollar with negative amount' => [ -123.456, 'USD', '$-123.46' ],
+ 'US dollar with negative amount' => [ -123.456, 'USD', '-$123.46' ],
'Euro' => [ 12000, 'EUR', '12.000,00 €' ],
'CHF - no currency symbol' => [ 123, 'CHF', 'CHF 123.00' ],
'VND - decimal currency' => [ 123456, 'VND', '123.456 ₫' ],