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

fix: don't accept extra fields inside the currency options on create #673

Merged
merged 1 commit into from
Nov 19, 2022

Conversation

fivism
Copy link
Contributor

@fivism fivism commented Nov 16, 2022

In order to save and retrieve dineros to/from our storage layer we map them to a copycat money-type. However, on retrievals we noticed that internal fields were leaking into the currency objects like so:

"amount": 0,
"currency": {
    "_type": "currencyObj",  <----
    "base": 10,
    "code": "USD",
    "exponent": 2
},
"scale": 2

... and upon further investigation one can pass anything into a dinero's currency object as long as the required subset of fields is met. This change makes the selection of fields as explicit as the base structure's (where amount, currency and scale are taken and everything else ignored).

@vercel
Copy link

vercel bot commented Nov 16, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
dinerojs ✅ Ready (Inspect) Visit Preview Nov 18, 2022 at 11:08PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Nov 16, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7953849:

Sandbox Source
@dinero.js/example-cart-react Configuration
@dinero.js/example-cart-vue Configuration
@dinero.js/example-pricing-react Configuration
@dinero.js/example-starter Configuration

Copy link
Collaborator

@sarahdayan sarahdayan left a comment

Choose a reason for hiding this comment

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

Good one, thanks!

I left two minor comments, then we'll be good to go.

packages/core/src/helpers/createDinero.ts Outdated Show resolved Hide resolved
packages/dinero.js/src/__tests__/dinero.test.ts Outdated Show resolved Hide resolved
@sarahdayan
Copy link
Collaborator

Thanks for your contribution @fivism!

@sarahdayan sarahdayan merged commit 9e72f9e into dinerojs:main Nov 19, 2022
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.

None yet

2 participants