Skip to content

update: MCCY settings with unbundled wp components #10930

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

Merged
merged 5 commits into from
Jul 15, 2025

Conversation

frosso
Copy link
Contributor

@frosso frosso commented Jul 14, 2025

Fixes WOOPMNT-5120

Changes proposed in this Pull Request

Updating the components in the MCCY settings to use the WP components that come with the WP installation, rather than the WP components we bundle.

There might be some visual differences (with spacing or uppercase labels or with inputs being full-width), but that's how the components are rendered.

I took the opportunity for consolidating some of the UI to look and act more like the "main" WooPayments settings page: using WP components almost everywhere (I think the only one left out is the radio control in the currency edit screen); I ensured the styles are consistent with the main settings page.

The previous approach was not semantically correct not accessible: the labels for some of the inputs were h4s and didn't have a related input, so the inputs appeared without label. Moreover, the help text was not associated with the input.

I also took the opportunity for consolidating some of the internal states, which could benefit from a little refactor.

I did not change the UI to have the white background like the main settings screen - I'm not sure why it wasn't done before, so leaving as-is.

There is a difference in bundle size due to the import of the WP input components. But it won't be a problem once we unbundle them:
Screenshot 2025-07-14 at 6 50 41 PM
Screenshot 2025-07-14 at 6 50 31 PM

Before:
Screenshot 2025-07-14 at 6 43 54 PM
Screenshot 2025-07-14 at 6 43 59 PM
Screenshot 2025-07-14 at 6 44 11 PM

After:
Screenshot 2025-07-14 at 6 44 16 PM
Screenshot 2025-07-14 at 6 44 21 PM
Screenshot 2025-07-14 at 6 44 39 PM

Testing instructions

  • Ensure you have the multi-currency feature enabled in the main WooPayments settings
  • Navigate to WooCommerce > Settings > Multi-currency
  • You should be able to add/remove currencies
  • Click "manage" on one of the currencies
  • You should be able to update the single currency settings and save the changes
  • The changes should be persisted

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Jul 14, 2025

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 10930 or branch name update/mccy-wp-components-usage in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 93ba2f4
  • Build time: 2025-07-15 08:12:59 UTC

Note: the build is updated when a new commit is pushed to this PR.


const MultiCurrencySettingsPage = () => {
const [
Copy link
Contributor Author

@frosso frosso Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous implementation was using two useState: one for isSingleCurrencyScreenOpen, and another for currencyCodeToShowSettingsFor.

But we can only use currencyCodeToShowSettingsFor, isSingleCurrencyScreenOpen is basically a "falsy" version of currencyCodeToShowSettingsFor.
Having two state values where one can be inferred from the other seems wasteful, and can create sync issues (where there's the potential that only one of them updates).

<h2>{ __( 'Enabled currencies', 'woocommerce-payments' ) }</h2>
<p>
{ createInterpolateElement(
sprintf(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to use sprintf - there is no placeholder

{
learnMoreLink: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous link was just using a a component, but opening in a new page.
Ensuring that we use the ExternalLink component, which adds the "Opens in a new tab" text for a11y.

@@ -81,7 +64,7 @@ const EnabledCurrencies = () => {
return (
<SettingsSection
description={ EnabledCurrenciesSettingsDescription }
className={ 'multi-currency-settings-enabled-currencies-section' }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed an inconsistent usage of braces for strings in this file - consolidating

@@ -113,7 +95,7 @@ const EnabledCurrencies = () => {
<EnabledCurrenciesListItemPlaceholder
key={ 'loadable-placeholder-' + i }
isLoading={ 1 }
></EnabledCurrenciesListItemPlaceholder>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the component usage to be self-closing, since there's no children.

@@ -100,7 +83,6 @@ const EnabledCurrencies = () => {
<EnabledCurrenciesListItem
key={ enabledCurrencies[ code ].id }
currency={ enabledCurrencies[ code ] }
defaultCurrency={ defaultCurrency }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaultCurrency can be gathered by the EnabledCurrenciesListItem component without prop-drilling

@@ -20,29 +20,17 @@ const EnabledCurrenciesListItemPlaceholder = ( { isLoading } ) => {
</LoadableBlock>
</div>
<div className="enabled-currency__label">
<LoadableBlock
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the component usage to be self-closing, since there's no children.

Comment on lines -23 to -24
// TODO: This works when saving, but list does not refresh.
// TODO: Should we reset selected currencies on modal close?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't reproduce this - cleaning up

{
learnMoreLink: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
<a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous link was just using a a component, but opening in a new page.
Ensuring that we use the ExternalLink component, which adds the "Opens in a new tab" text for a11y.

Copy link
Contributor

github-actions bot commented Jul 14, 2025

Size Change: +5.2 kB (0%)

Total Size: 1.24 MB

Filename Size Change
release/woocommerce-payments/dist/index.js 246 kB +35 B (0%)
release/woocommerce-payments/dist/multi-currency-rtl.css 4.07 kB -319 B (-7%)
release/woocommerce-payments/dist/multi-currency-switcher-block.js 61.1 kB +16 B (0%)
release/woocommerce-payments/dist/multi-currency.css 4.07 kB -314 B (-7%)
release/woocommerce-payments/dist/multi-currency.js 61.8 kB +5.64 kB (+10%) ⚠️
release/woocommerce-payments/dist/order.js 42.8 kB +26 B (0%)
release/woocommerce-payments/dist/plugins-page.js 21.2 kB +25 B (0%)
release/woocommerce-payments/dist/settings.js 229 kB +11 B (0%)
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.5 kB +26 B (0%)
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.6 kB +24 B (0%)
release/woocommerce-payments/dist/tos.js 22.6 kB +25 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.45 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.45 kB
release/woocommerce-payments/assets/css/success.css 1.06 kB
release/woocommerce-payments/assets/css/success.rtl.css 1.06 kB
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.73 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.73 kB
release/woocommerce-payments/dist/blocks-checkout.js 54.1 kB
release/woocommerce-payments/dist/cart-block.js 17.1 kB
release/woocommerce-payments/dist/cart.js 5.71 kB
release/woocommerce-payments/dist/checkout-rtl.css 1.08 kB
release/woocommerce-payments/dist/checkout.css 1.08 kB
release/woocommerce-payments/dist/checkout.js 33.9 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 367 B
release/woocommerce-payments/dist/express-checkout.css 367 B
release/woocommerce-payments/dist/express-checkout.js 16.8 kB
release/woocommerce-payments/dist/frontend-tracks.js 833 B
release/woocommerce-payments/dist/index-rtl.css 21.9 kB
release/woocommerce-payments/dist/index.css 21.9 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/order-rtl.css 740 B
release/woocommerce-payments/dist/order.css 740 B
release/woocommerce-payments/dist/plugins-page-rtl.css 484 B
release/woocommerce-payments/dist/plugins-page.css 484 B
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12.3 kB
release/woocommerce-payments/dist/settings-rtl.css 12.3 kB
release/woocommerce-payments/dist/settings.css 12.2 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/success.js 6.03 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.11 kB
release/woocommerce-payments/dist/woopay-express-button.js 23.1 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.31 kB
release/woocommerce-payments/dist/woopay.css 4.28 kB
release/woocommerce-payments/dist/woopay.js 71.1 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 957 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.3 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.css 10.1 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.js 29.7 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.rtl.css 10.1 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 417 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-users-connection.js 161 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 585 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 625 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

'woocommerce-payments'
) }
/>
<div className="multi-currency-settings__description">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this multi-currency-settings__description in favor of the help prop on the CheckboxControl, to be consistent with the other settings pages

@@ -1,14 +0,0 @@
.settings-section__controls {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed


const calculateCurrencyConversion = useCallback(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component was using a double state - where calculatedValue was dependent on baseValue, and always updated whenever baseValue changed.
Clearly, calculatedValue is just a differently formatted baseValue (with a prefix/suffix and an updated formatting).

This can create sync issues. Ensuring that calculateCurrencyConversion is the calculated value that is rendered in the UI based off baseValue

<Card>
<CardBody>
<div>
<h4>{ storeCurrency.name }</h4>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These h4s were used as labels for the input - updating them to be actual labels

@@ -116,21 +132,6 @@ const SingleCurrencySettings = () => {
moment.unix( targetCurrency.last_updated ).toISOString()
)
: '';

const CurrencySettingsDescription = () => (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a component - it shouldn't be declared within the SingleCurrencySettings method's body. It's a performance issue within React.

}
>
<CardBody>
<h3>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating these to be in line with the main settings pages

'Manual Rate',
'woocommerce-payments'
) }
</h4>
<input
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating these to be TextControl from WP components

'Price rounding',
'woocommerce-payments'
) }
</h4>
{ /* eslint-disable jsx-a11y/no-onchange */ }
<select
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating these to be SelectControl from WP components

@frosso frosso requested a review from Copilot July 14, 2025 16:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the multi-currency settings UI to use unbundled WordPress components, refactors styling and state handling for consistency with the main WooPayments settings, and refreshes related tests and snapshots.

  • Replace bundled WP component wrappers with external SelectControl, TextControl, ExternalLink, etc.
  • Remove custom SCSS form styles in favor of WP component styling and add __nextHasNoMarginBottom support in the wrapper.
  • Refactor context and navigation to toggle views via currencyCodeToShowSettingsFor, and update tests/snapshots accordingly.

Reviewed Changes

Copilot reviewed 22 out of 34 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
includes/multi-currency/client/setup/tasks/store-settings-task/index.js Added __nextHasNoMarginBottom prop and standardized className
includes/multi-currency/client/settings/single-currency/index.js Swapped in WP SelectControl/TextControl, extracted descriptions
includes/multi-currency/client/settings/single-currency/style.scss Removed bespoke form styles, adjusted margin rules
includes/multi-currency/client/settings/single-currency/currency-preview.js Simplified conversion with useMemo, unified inputs
includes/multi-currency/client/settings/multi-currency/store-settings/index.js Merged description into help prop, removed custom SCSS import
includes/multi-currency/client/settings/multi-currency/enabled-currencies-list/* Refactored default currency hook usage, introduced ExternalLink
includes/multi-currency/client/index.js Wrapped root in UnbundledWpComponentsProvider, simplified context
includes/multi-currency/MultiCurrency.php Added wp-components as script dependency
client/components/wp-components-wrapped/make-wrapped-component.tsx Extended prop types to include __nextHasNoMarginBottom
Tests & Snapshots Updated snapshots and assertions to match new component APIs
Comments suppressed due to low confidence (3)

client/components/wp-components-wrapped/make-wrapped-component.tsx:26

  • [nitpick] Consider documenting the __nextHasNoMarginBottom prop in the TypeScript interface or a README to clearly explain its purpose and usage for future maintainers.
		// extracting the `__nextHasNoMarginBottom` from the list of props to avoid issues when running tests.

includes/multi-currency/client/settings/single-currency/index.js:194

  • The heading level under the CardBody was changed from

    to

    ; please confirm this maintains a correct semantic outline for screen readers and document structure.

								<h4>

@frosso frosso self-assigned this Jul 14, 2025
@frosso frosso requested a review from a team July 14, 2025 16:54
Copy link
Member

@rtio rtio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, and testing steps worked as described.

Unrelated: when I change something on this form, save, and change the page I still see this message:
image
Nothing to do with this PR, develop also has this behavior, but I wanted to point this out.

@frosso
Copy link
Contributor Author

frosso commented Jul 15, 2025

when I change something on this form, save, and change the page I still see this message

I noticed that, too, but I thought it was a glitch. I now see that it happens almost every time. Taking a look, now!

@frosso frosso enabled auto-merge July 15, 2025 08:09
@frosso frosso disabled auto-merge July 15, 2025 08:14
@frosso frosso merged commit 39d2422 into develop Jul 15, 2025
26 of 29 checks passed
@frosso frosso deleted the update/mccy-wp-components-usage branch July 15, 2025 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants