-
Notifications
You must be signed in to change notification settings - Fork 212
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
feat: add a decimals parameter, and decimals method to brand #1964
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
The brand is a good place to put this information, in case amountMath is later sensitive to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The downside is that this hardcodes a certain interpretation.
I think the right way to think of this is that 'decimals' tells the display software which position corresponds to whole numbers. If the display wants to display Millions, then it knows that it should be millions of that unit, rather than millions of the most precise division.
if mills are the unit, and decimals is set to 3, then
- 3000 is $3.00
- 3 000 000 is $3000.00
- 3 000 000 000 could be rendered $3.0M
8b57c4b
to
153caff
Compare
Addressed PR comments. In order to ensure |
28ee0c8
to
104a1a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the safety issue is addressed with the pureCopy
, LGTM.
packages/ERTP/src/types.js
Outdated
* numbers. We require fungible digital assets to be represented in | ||
* integers, in the smallest unit (i.e. USD might be represented in mill, | ||
* a thousandth of a dollar. In that case, `decimalPlaces` would be 3.) | ||
* For non-fungible digital assets, this should be left as undefined. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisplayInfo
should be expected to grow over time as one would expect of an options bag. Each use would only contain properties appropriate for the kind of amount math it is used on. Rather than having decimalPlaces
be undefined
, the property should be optional. AFAICT your assertDisplayInfo
already allows it to be absent so it is just an issue of how you type and describe it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, yep, that is what I intended. Will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -23,7 +23,7 @@ function makeIssuerKit( | |||
displayInfo = undefined, | |||
) { | |||
assert.typeof(allegedName, 'string'); | |||
assertDisplayInfo(displayInfo); | |||
displayInfo = coerceDisplayInfo(displayInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good you changed the assert into a coerce and let it do the coercion. Better than what I suggested.
|
||
export const coerceDisplayInfo = allegedDisplayInfo => { | ||
if (passStyleOf(allegedDisplayInfo) === REMOTE_STYLE) { | ||
return harden({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too loose. Once you see it is a remotable, you should also assert that it is an empty object before returning a new empty object. Otherwise, an accidental passing of a substantive remotable object will silently become an empty object rather than rejected with a nice diagnostic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erights How would you assert it is an empty object if it's a presence? I thought doing something like getting the ownPropertyNames wouldn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1981
330086c
to
a5fbbc6
Compare
…d is being miscategorized (for this purpose) as a presence
a5fbbc6
to
eff15a4
Compare
This PR adds a
displayInfo
object to an ERTP issuerKit, including adecimalPlaces
property in the same way that Ethereum uses theirdecimals
property. We intend for fungible digital assets to be represented as integers in the smallest unit. (In finance, this is often mills.) However, we want to display in a more user-friendly way.decimalPlaces
is meant only for display, and informs the UI how many decimal places to move the decimal over to the left. For instance, for mills, one thousandth of a dollar, decimals would be 3.The downside is that this hardcodes a certain interpretation. For instance, it would hard-code a dollar as the standard representation instead of millions or thousands of dollars. However, the UI is free to ignore
decimals
.One upside is that compared to something like a custom
toString
, decimals is very safe. An attacker can't do much with the ability to choose an integer that will later be returned.Closes #119