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

Refactor money formatters in base presenter #491

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Nov 1, 2023

https://eaflood.atlassian.net/browse/WATER-4070
https://eaflood.atlassian.net/browse/WATER-4155
https://eaflood.atlassian.net/browse/WATER-4132
https://eaflood.atlassian.net/browse/WATER-4156

We are working on replacing the legacy bill view page because it crashes for large bills. As we are doing this work we are creating some new presenters and have found all rely on taking a value stored in the DB as pence, for example 12776805 and formatting it as money £127,768.05.

This means each presenter is going through the same steps

  • make the value positive (we don't show a sign but instead will add credit after the formatted number)
  • convert it to pounds
  • format it with £ and commas for large numbers

We're doing this enough it is time to move the logic to our base presenter. But another money formatter? We already have 2!

When we checked formatNumberAsMoney() is only used by one mock-data endpoint which never asks for the currency symbol. formatNumberAsMoneyWithCommas() was added to deal with the final step we listed above in the new presenters we wish to add.

So, rather than add another formatter we are refactoring the 2 we have

  • formatNumberAsMoney() becomes formatPounds() it will just take a value in pence and return it as pounds which deals with the mock-data endpoint's needs
  • formatNumberAsMoneyWithCommas() becomes formatMoney() which will cover the 3 steps listed above

@Cruikshanks Cruikshanks added the enhancement New feature or request label Nov 1, 2023
@Cruikshanks Cruikshanks self-assigned this Nov 1, 2023
https://eaflood.atlassian.net/browse/WATER-4070
https://eaflood.atlassian.net/browse/WATER-4155
https://eaflood.atlassian.net/browse/WATER-4132
https://eaflood.atlassian.net/browse/WATER-4156

We are working on replacing the legacy bill view page because it crashes for large bills. As were doing this work we are creating some new presenters and have found all rely on taking a value stored in the DB as pence, for example `12776805` and formatting it as money `£127,768.05`.

This means each presenter is going through the same steps

- make the value positive (we don't show a sign but instead will add ` credit` after the formatted number)
- convert it to pounds
- format it with `£` and commas for large numbers

We're doing this enough it is time to move the logic to our base presenter.
@Cruikshanks Cruikshanks force-pushed the add-money-formatter-to-base-presenter branch from 9fdbdb6 to 21eb301 Compare November 1, 2023 11:48
@Cruikshanks Cruikshanks changed the title Add money formatter to base presenter Refactor money formatters in base presenter Nov 1, 2023
@Cruikshanks Cruikshanks marked this pull request as ready for review November 1, 2023 16:55
@Cruikshanks Cruikshanks merged commit ed2f3d7 into main Nov 1, 2023
6 checks passed
@Cruikshanks Cruikshanks deleted the add-money-formatter-to-base-presenter branch November 1, 2023 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant