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

Show total balance (pending + available) instead of pending balance #8140

Merged
merged 47 commits into from
Feb 29, 2024

Conversation

shendy-a8c
Copy link
Contributor

@shendy-a8c shendy-a8c commented Feb 6, 2024

Fixes #8070

Changes proposed in this Pull Request

  • Show total balance and available balance instead of available balance and pending balance.

Before:
Screenshot 2024-02-07 at 07 50 22

After:
Screenshot 2024-02-07 at 07 51 36

Total balance will show tooltip if it is negative.

Screenshot 2024-02-07 at 07 34 50

Testing instructions

  • Open Payments > Overview page.
  • With base branch, you will see available and pending balance.
  • With PR branch, you will see total and available balance.
  • Hard-code available and pending balance like how I accidentally committed here: 3c33736. Set the value so total balance is negative, expects a tooltip next to total balance.

  • 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 Feb 6, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 8140 or branch name update/8070-total-balance 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: b8d822c
  • Build time: 2024-02-29 07:50:54 UTC

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

Copy link
Contributor

github-actions bot commented Feb 6, 2024

Size Change: +273 B (0%)

Total Size: 1.26 MB

Filename Size Change
release/woocommerce-payments/dist/index-rtl.css 37.3 kB +68 B (0%)
release/woocommerce-payments/dist/index.css 37.3 kB +69 B (0%)
release/woocommerce-payments/dist/index.js 291 kB +148 B (0%)
release/woocommerce-payments/dist/settings-rtl.css 10.2 kB -6 B (0%)
release/woocommerce-payments/dist/settings.css 10.2 kB -6 B (0%)
ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.06 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.06 kB
release/woocommerce-payments/assets/css/success.css 158 B
release/woocommerce-payments/assets/css/success.rtl.css 158 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 1.81 kB
release/woocommerce-payments/dist/blocks-checkout.css 1.81 kB
release/woocommerce-payments/dist/blocks-checkout.js 85.2 kB
release/woocommerce-payments/dist/checkout-rtl.css 318 B
release/woocommerce-payments/dist/checkout.css 319 B
release/woocommerce-payments/dist/checkout.js 36.4 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.05 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.25 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 59.4 kB
release/woocommerce-payments/dist/multi-currency.css 3.25 kB
release/woocommerce-payments/dist/multi-currency.js 54.4 kB
release/woocommerce-payments/dist/order-rtl.css 707 B
release/woocommerce-payments/dist/order.css 708 B
release/woocommerce-payments/dist/order.js 41.6 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.19 kB
release/woocommerce-payments/dist/payment-gateways.css 1.19 kB
release/woocommerce-payments/dist/payment-gateways.js 38.3 kB
release/woocommerce-payments/dist/payment-request-rtl.css 153 B
release/woocommerce-payments/dist/payment-request.css 153 B
release/woocommerce-payments/dist/payment-request.js 12.4 kB
release/woocommerce-payments/dist/product-details-rtl.css 149 B
release/woocommerce-payments/dist/product-details.css 149 B
release/woocommerce-payments/dist/product-details.js 1.19 kB
release/woocommerce-payments/dist/settings.js 230 kB
release/woocommerce-payments/dist/subscription-edit-page.js 669 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 519 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 19.4 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 710 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 117 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 18.5 kB
release/woocommerce-payments/dist/tos-rtl.css 230 B
release/woocommerce-payments/dist/tos.css 231 B
release/woocommerce-payments/dist/tos.js 21 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 3.54 kB
release/woocommerce-payments/dist/woopay-express-button-rtl.css 153 B
release/woocommerce-payments/dist/woopay-express-button.css 153 B
release/woocommerce-payments/dist/woopay-express-button.js 52.6 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.18 kB
release/woocommerce-payments/dist/woopay.css 4.19 kB
release/woocommerce-payments/dist/woopay.js 71 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 622 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 812 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.43 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.01 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 522 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 581 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/babel.config.js 160 B
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.css 2.37 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.js 13.5 kB
release/woocommerce-payments/vendor/automattic/jetpack-identity-crisis/build/index.rtl.css 2.37 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.03 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 291 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 403 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.6 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 299 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 742 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 572 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 411 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 544 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.8 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.83 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 544 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.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.6 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 502 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 355 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 429 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 781 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.1 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.27 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 392 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.05 kB

compressed-size-action

@shendy-a8c
Copy link
Contributor Author

Just to note, I also found that available balance can be negative while pending balance is positive. See pdjTHR-2Sz-p2#comment-3983. Currently, for such case, we don't show total balance.

@shendy-a8c shendy-a8c requested a review from a team February 7, 2024 01:28
@shendy-a8c shendy-a8c marked this pull request as ready for review February 7, 2024 01:28
Copy link
Contributor

@brucealdridge brucealdridge left a comment

Choose a reason for hiding this comment

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

I've had a play around with this PR and find it a little jarring that the information presented moves around unexpectedly.

Having Total balance / Available balance sometimes and other times Available balance / Pending balance seems confusing to me.

From the issue it sounds like we should always be presenting Total / Available.

@shendy-a8c
Copy link
Contributor Author

shendy-a8c commented Feb 7, 2024

From the issue it sounds like we should always be presenting Total / Available.
Ugh... that makes more sense actually. Thank you for pointing that out, @brucealdridge.

I jumped in and assumed we only want to show total balance and available balance only when pending balance is negative by reading the issue's title:

Show total balance instead of pending to reduce confusion when pending is negative

but now I see that it makes more sense to be read as:

Show total balance instead of pending, to reduce confusion when pending is negative

I read it as:

Show total balance instead of pending to reduce confusion, when pending is negative

Putting this PR back to in progress.

amount={ tab.availableFunds }
id={ `wcpay-account-balances-${ tab.currencyCode }-total` }
title={ fundLabelStrings.total }
amount={ 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In loading state, total balance will be 0.

amount={ tab.pendingFunds }
id={ `wcpay-account-balances-${ tab.currencyCode }-available` }
title={ fundLabelStrings.available }
amount={ 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In loading state, available balance is 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

In loading state merchant will see a grey box placeholder, so this 0 is all good (if it shows in UI could lead to questions).

Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2024-02-19 at 1 34 05 PM

@shendy-a8c
Copy link
Contributor Author

shendy-a8c commented Feb 9, 2024

Searching woo docs for 'pending', found this page that will need updating after this PR is released.

Found this too https://woo.com/document/woopayments/deposits/scheduled-deposit-vs-instant-deposit/ but probably safe to keep.

@shendy-a8c shendy-a8c requested review from a team and brucealdridge February 9, 2024 00:24
@rogermattic
Copy link

Hey @shendy-a8c! Thanks for working on those changes; it looks good with @haszari 's feedback and the revised logic for the negative balance case!

I made this mockup which would be a way to solve the "Learn more" weirdness :) Do you think this could work?

Screenshot 2024-02-25 at 12 34 45

@shendy-a8c
Copy link
Contributor Author

shendy-a8c commented Feb 25, 2024

Yes! That looks good @rogermattic. Thank you!

Copy link
Contributor

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Added some more comments - there's still a few tradeoffs in the code, maybe we can make it better/more flexible while we're here.

None of my feedback is blocking – this is working well and looking good. Note I only tested one scenario (no negative balance).

} ) => {
return (
<ClickTooltip
content={ content }
className="wcpay-account-balances__balances__item__tooltip"
buttonIcon={ <HelpOutlineIcon /> }
buttonLabel={ label }
maxWidth={ maxWidth }
Copy link
Contributor

Choose a reason for hiding this comment

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

I was suggesting to remove BalanceTooltip entirely, it doesn't add much value. The prop values it provides for would be more explicit directly inline in TotalBalanceTooltip and AvailableBalanceTooltip.

No worries if it stays, not causing problems, but if some future engineer feels constrained by it my advice would be to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I missed that. Good point that BalanceTooltip doesn't add much value. Removed in d607985

{ balance < 0 &&
interpolateComponents( {
mixedString: __(
'Negative account balance? {{discoverWhyLink}}Discover why.{{/discoverWhyLink}}',
Copy link
Contributor

Choose a reason for hiding this comment

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

To me account balance refers to the total balance, and that linked doc page is primarily about why a merchant's total (aka "account") balance is negative (typically: more refunds or disputes than sales).

I don't think showing this info in the pending balance will cause issues, but I'm not convinced it's necessary. When the pending balance is negative, I think (?) this is usually temporary due to how payouts work (possibly specific to instant?), and we don't explain much about this scenario on the help page.

Curious for thoughts from @csmcneill who has more experience of negative balances in practice!

Copy link
Contributor

Choose a reason for hiding this comment

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

When the pending balance is negative, I think (?) this is usually temporary due to how payouts work (possibly specific to instant?), and we don't explain much about this scenario on the help page.

That's my experience of it. I think that we can also include refunds and disputes in here, too, since those can also make an account go negative temporarily. If a balance is negative for an extended period of time, that's usually because we cannot debit the attached bank account or debit card.

I'm planning on including a new section in our document at https://woo.com/document/woopayments/deposits/deposit-schedule/#total-balance that focuses on the Total balance, what it means, and some nuances to keep an eye out for (e.g., it being lower than the available balance due to funds that are in flight).

@@ -21,7 +21,7 @@ export const greetingStrings = {

export const fundLabelStrings = {
available: __( 'Available funds', 'woocommerce-payments' ),
pending: __( 'Pending funds', 'woocommerce-payments' ),
total: __( 'Total balance', 'woocommerce-payments' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

I see this pattern is used in our code, but I'm not convinced – to me it makes the code less meaningful to extract the strings (and documentation links, etc). One of the wonderful things about react is you can look at the code/markup and understand what the component looks like and does. Moving strings to constants makes this a little harder, since the reader needs to look up each constant to see what the string is. So when I'm working on components that feel disconnected like this, I consider pulling string back in to make it easier to maintain and more self-contained.

Anyway, I'm just sharing my thoughts – no need to change this if it' working for you :)

return (
<BalanceTooltip
label={ `${ fundLabelStrings.total } tooltip` }
maxWidth={ '315px' }
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this maxWidth to ensure the equation (Total balance = Available funds + Pending funds) is not wrapped? Would be good to note that in the code, so future readers know why and can iterate on how we handle that constraint.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually prefer for more simple diff if we are OK with narrower tooltip like that.

Hmm, I guess we could render the equation on two lines like this:

Total balance = 
Available funds + Pending funds

Not sure if that's clear enough, curious for thoughts from @rogermattic (and on other ideas below).

Adding maxWidth was necessary because the BalanceTooltip renders ClickTooltip which renders TooltipBase which sets an inline max-width in a function that calculates tooltip position, window dimension etc, so it's pretty complex stuffs to modify.

I see! That's frustrating – an example of where an earlier decision / detail limits our options.

  • Can we undo this ? In your opinion, does TooltipBase need to force a max width in inline style, could it move to css?
  • Can we make the base tooltip width bigger (i.e. make all tooltips wider) to work better for our tooltip?
  • If TooltipBase needs to force a width, could it use minWidth, allowing overriding to make things wider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, it looks good in one line.

Would be good to note that in the code, so future readers know why and can iterate on how we handle that constraint.

Good call to put some description in a comment. Added comment in d607985.

In your opinion, does TooltipBase need to force a max width in inline style, could it move to css?

Can't tell for sure. I see that it's set and used in a useEffect() (ref).

If TooltipBase needs to force a width, could it use minWidth, allowing overriding to make things wider?

IMO the current intention is to not let the tooltip content 'stretches' the tooltip without control. This is more important in narrow screen I think.

Changing TooltipBase needs to be done carefully as it might affect other UI and out of scope of this PR. Created #8269.

Choose a reason for hiding this comment

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

Hmm, I guess we could render the equation on two lines like this:

Total balance = 
Available funds + Pending funds

Not sure if that's clear enough, curious for thoughts from @rogermattic (and on other ideas below).

I prefer it when it renders in a single line, BUT I don't think it is necessary as it reads OK when split into two lines.

…alanceTooltip` and `AvailableBalanceTooltip`. Add comment as to why `maxWidth is specified.
@shendy-a8c
Copy link
Contributor Author

None of my feedback is blocking

Thank you for the review, @haszari. I'll mark this PR as 'ready to merge' but will wait for other feedbacks before merging.

Any follow up can be done in a separate issue / PR.

Copy link
Contributor

@naman03malhotra naman03malhotra left a comment

Choose a reason for hiding this comment

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

Great work 🎉 , left some nitpicks. Nothing that blocks this PR.

client/components/account-balances/balance-tooltip.tsx Outdated Show resolved Hide resolved
client/components/account-balances/index.tsx Outdated Show resolved Hide resolved
@@ -73,7 +73,6 @@
&__tooltip {
// Specific styles for the click tooltip variant.
position: relative;
max-width: 292px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious to as to why we moved it from styles to props?

Copy link
Contributor Author

@shendy-a8c shendy-a8c Feb 28, 2024

Choose a reason for hiding this comment

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

This CSS is overridden by TooltipBase's in-line CSS, so it's unused and removed. We might set max-width using CSS class instead of in-line but since it will involve changing TooltipBase that is used by other UIs, I created #8269.

client/components/account-balances/style.scss Outdated Show resolved Hide resolved
client/components/account-balances/balance-tooltip.tsx Outdated Show resolved Hide resolved
@shendy-a8c
Copy link
Contributor Author

Thank you all for the feedback. I think I have addressed them all.

Let me know if there is anything else. I plan to merge this PR today at the latest tomorrow so it can make it before the code-freeze.

@Jinksi
Copy link
Member

Jinksi commented Feb 29, 2024

FYI: all E2E tests are failing due to #8291.

@shendy-a8c shendy-a8c added this pull request to the merge queue Feb 29, 2024
Merged via the queue into develop with commit 6550753 Feb 29, 2024
25 of 26 checks passed
@shendy-a8c shendy-a8c deleted the update/8070-total-balance branch February 29, 2024 17:03
Jinksi added a commit that referenced this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show total balance instead of pending to reduce confusion when pending is negative
8 participants