Skip to content

Commit

Permalink
chore: NatAmountInput is usable from dapp-token-economy (#2711)
Browse files Browse the repository at this point in the history
  • Loading branch information
katelynsills authored Mar 24, 2021
1 parent c9ae4fd commit cc6cff2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
10 changes: 5 additions & 5 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"version": "0.0.1",
"description": "Reusable UI Components for Agoric Dapps, built with React and MaterialUI",
"main": "src/index.js",
"peerDependencies": {
"dependencies": {
"@agoric/assert": "^0.2.3",
"@agoric/ertp": "^0.10.0",
"@agoric/eventual-send": "^0.13.3",
"@agoric/install-ses": "^0.5.3",
"@agoric/nat": "^4.0.0"
},
"peerDependencies": {
"@material-ui/core": "^4.11.3",
"react": "^16.14.0",
"react-dom": "^16.8.0"
Expand Down Expand Up @@ -102,8 +105,5 @@
"dist",
"NEWS.md",
"exported.js"
],
"dependencies": {
"@agoric/nat": "^4.0.0"
}
]
}
34 changes: 15 additions & 19 deletions packages/ui-components/src/components/NatAmountInput.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from 'react';
import { TextField } from '@material-ui/core';

import { parseAsNat } from '../display/natValue/parseAsNat';
import { stringifyNat } from '../display/natValue/stringifyNat';

// https://material-ui.com/api/text-field/

const NatAmountInput = ({
const makeNatAmountInput = (react, textfield) => ({
label,
value,
decimalPlaces = 0,
Expand All @@ -27,20 +24,19 @@ const NatAmountInput = ({
}
};

return (
<TextField
label={label}
type="number"
variant="outlined"
fullWidth
InputProps={noNegativeValues}
onChange={ev => onChange(parseAsNat(ev.target.value, decimalPlaces))}
onKeyPress={preventSubtractChar}
value={stringifyNat(value, decimalPlaces, placesToShow)}
disabled={disabled}
error={error}
/>
);
return react.createElement(textfield, {
label,
type: 'number',
variant: 'outlined',
fullWidth: true,
InputProps: noNegativeValues,
onChange: ev => onChange(parseAsNat(ev.target.value, decimalPlaces)),
onKeyPress: preventSubtractChar,
value:
value === null ? '0' : stringifyNat(value, decimalPlaces, placesToShow),
disabled,
error,
});
};

export default NatAmountInput;
export default makeNatAmountInput;
2 changes: 1 addition & 1 deletion packages/ui-components/src/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as NatAmountInput } from './components/NatAmountInput';
export { default as makeNatAmountInput } from './components/NatAmountInput';
export * from './display/display';
7 changes: 5 additions & 2 deletions packages/ui-components/test/components/test-NatAmountInput.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// @ts-check

import '@agoric/install-ses';
import React from 'react';
import { TextField } from '@material-ui/core';

// eslint-disable-next-line import/no-extraneous-dependencies
import test from 'ava';
import React from 'react';
// eslint-disable-next-line import/no-extraneous-dependencies
import { shallow, render } from 'enzyme';

// @ts-ignore path is correct for compiled output
import { NatAmountInput } from '../../../dist'; // eslint-disable-line import/no-unresolved
import { makeNatAmountInput } from '../../../dist'; // eslint-disable-line import/no-unresolved

const NatAmountInput = makeNatAmountInput(React, TextField);

const makeShallowNatAmountInput = ({
label = 'myLabel',
Expand Down

0 comments on commit cc6cff2

Please sign in to comment.