From 3d5eedeca36008e95f506fccb8e0a9acce5d60e4 Mon Sep 17 00:00:00 2001 From: Kate Sills Date: Mon, 22 Mar 2021 13:25:16 -0700 Subject: [PATCH] chore: address PR comments --- packages/ui-components/README.md | 4 +++- packages/ui-components/jsconfig.json | 2 +- packages/ui-components/package.json | 4 ++-- packages/ui-components/src/display/display.js | 24 +++++++++---------- .../src/display/natValue/parseAsNat.js | 12 ++++++++-- .../src/display/natValue/stringifyNat.js | 4 ++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/packages/ui-components/README.md b/packages/ui-components/README.md index c724731b709..7179cdfd45a 100644 --- a/packages/ui-components/README.md +++ b/packages/ui-components/README.md @@ -1,8 +1,10 @@ # UI Components +Reusable UI Components for [Agoric](https://agoric.com) [Dapps](https://agoric.com/documentation/dapps/), built with [React](https://reactjs.org) and [MaterialUI](https://materialui.com). + ## NatAmountInput -A [MaterialUI TextField +A [React](https://reactjs.org) [MaterialUI TextField Input](https://material-ui.com/api/text-field/) which allows the user to enter a `Nat`. Handles `decimalPlaces` appropriately. This is a controlled component. diff --git a/packages/ui-components/jsconfig.json b/packages/ui-components/jsconfig.json index 0e345c4feae..7871376ade8 100644 --- a/packages/ui-components/jsconfig.json +++ b/packages/ui-components/jsconfig.json @@ -1,7 +1,7 @@ // This file can contain .js-specific Typescript compiler config. { "compilerOptions": { - "target": "es2020", + "target": "esnext", "noEmit": true, /* diff --git a/packages/ui-components/package.json b/packages/ui-components/package.json index 0535aa5f859..89faea9870b 100644 --- a/packages/ui-components/package.json +++ b/packages/ui-components/package.json @@ -1,8 +1,8 @@ { - "name": "ui-components", + "name": "@agoric/ui-components", "version": "0.0.1", "description": "Reusable UI Components for Agoric Dapps, built with React and MaterialUI", - "main": "dist/index.js", + "main": "src/index.js", "peerDependencies": { "@agoric/assert": "^0.2.3", "@agoric/ertp": "^0.10.0", diff --git a/packages/ui-components/src/display/display.js b/packages/ui-components/src/display/display.js index 13dfe568eec..dc3515f79cf 100644 --- a/packages/ui-components/src/display/display.js +++ b/packages/ui-components/src/display/display.js @@ -11,8 +11,8 @@ import { stringifySet } from './setValue/stringifySet'; /** * * @param {string} str - string to parse as a value - * @param {AmountMathKind=} mathKind - mathKind of the value - * @param {number=} decimalPlaces - places to move the decimal to the left + * @param {AmountMathKind} [mathKind] - mathKind of the value + * @param {number} [decimalPlaces] - places to move the decimal to the left * @returns {Value} */ export const parseAsValue = ( @@ -26,14 +26,14 @@ export const parseAsValue = ( if (mathKind === MathKind.SET) { return parseAsSet(str); } - assert.fail(details`MathKind must be NAT or SET`); + assert.fail(details`MathKind ${mathKind} must be NAT or SET`); }; /** * @param {string} str - string to parse as a value * @param {Brand} brand - brand to use in the amount - * @param {AmountMathKind=} mathKind - mathKind of the value - * @param {number=} decimalPlaces - places to move the decimal to the left + * @param {AmountMathKind} [mathKind] - mathKind of the value + * @param {number} [decimalPlaces] - places to move the decimal to the left * @returns {Amount} */ export const parseAsAmount = ( @@ -48,10 +48,10 @@ export const parseAsAmount = ( /** * * @param {Value} value - value to stringify - * @param {AmountMathKind=} mathKind - mathKind of the value - * @param {number=} decimalPlaces - places to move the decimal to the + * @param {AmountMathKind} [mathKind] - mathKind of the value + * @param {number} [decimalPlaces] - places to move the decimal to the * right in the string - * @param {number=} placesToShow - places after the decimal to show + * @param {number} [placesToShow] - places after the decimal to show * @returns {string} */ export const stringifyValue = ( @@ -68,7 +68,7 @@ export const stringifyValue = ( // @ts-ignore Value is a SetValue return stringifySet(value); } - assert.fail(details`MathKind must be NAT or SET`); + assert.fail(details`MathKind ${mathKind} must be NAT or SET`); }; /** @@ -92,10 +92,10 @@ export const stringifyPurseValue = purse => { * Stringify the value in an amount * * @param {Amount} amount - * @param {AmountMathKind=} mathKind - mathKind of the value - * @param {number=} decimalPlaces - places to move the decimal to the + * @param {AmountMathKind} [mathKind] - mathKind of the value + * @param {number} [decimalPlaces] - places to move the decimal to the * right in the string - * @param {number=} placesToShow - places after the decimal to show + * @param {number} [placesToShow] - places after the decimal to show * @returns {string} */ export function stringifyAmountValue( diff --git a/packages/ui-components/src/display/natValue/parseAsNat.js b/packages/ui-components/src/display/natValue/parseAsNat.js index 4139b3cac2b..3db18eea2da 100644 --- a/packages/ui-components/src/display/natValue/parseAsNat.js +++ b/packages/ui-components/src/display/natValue/parseAsNat.js @@ -7,8 +7,16 @@ import { captureNum } from './captureNum'; import { roundToDecimalPlaces } from './roundToDecimalPlaces'; /** - * Parse a string as a Nat, given displayInfo such as `decimalPlaces`, - * the number of places to move the decimal over to create an integer + * Parse a string as a Nat, using `decimalPlaces`, the number of + * places to move the decimal over to the right to create an integer. + * For example, "3.00" dollars turns into 300n cents with + * decimalPlaces = 2. + * + * Note that if places beyond the decimalPlaces are specified, the + * number is rounded to the floor. For instance, "3.009" dollars is + * still 300n cents with decimalPlaces =2 because the thousandths place is dropped. + * + * In the future, we may add a parameter to change the rounding rules. * * @param {string} str * @param {number} decimalPlaces diff --git a/packages/ui-components/src/display/natValue/stringifyNat.js b/packages/ui-components/src/display/natValue/stringifyNat.js index e655fe5090c..f70b72dd0ef 100644 --- a/packages/ui-components/src/display/natValue/stringifyNat.js +++ b/packages/ui-components/src/display/natValue/stringifyNat.js @@ -4,8 +4,8 @@ const CONVENTIONAL_DECIMAL_PLACES = 2; /** * @param {NatValue} natValue - * @param {number=} decimalPlaces - * @param {number=} placesToShow + * @param {number} [decimalPlaces] + * @param {number} [placesToShow] * @returns {string} */ export const stringifyNat = (