Skip to content

Commit

Permalink
Use mask for native input on send sheet (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchung committed Apr 28, 2020
1 parent e2700aa commit 2a58de1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/components/fields/UnderlineField.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class UnderlineField extends PureComponent {
buttonText: PropTypes.string,
format: PropTypes.func,
keyboardType: Input.propTypes.keyboardType,
mask: PropTypes.string,
maxLength: PropTypes.number,
onBlur: PropTypes.func,
onChange: PropTypes.func,
Expand Down Expand Up @@ -130,6 +131,7 @@ export default class UnderlineField extends PureComponent {
autoFocus,
buttonText,
keyboardType,
mask,
maxLength,
placeholder,
...props
Expand All @@ -147,7 +149,7 @@ export default class UnderlineField extends PureComponent {
keyboardAppearance="light"
keyboardType={keyboardType}
letterSpacing={fonts.letterSpacing.roundedTightest}
mask="[099999999999999999].[999999999999999999]"
mask={mask}
maxLength={maxLength}
onBlur={this.onBlur}
onChange={this.onChange}
Expand Down
3 changes: 3 additions & 0 deletions src/components/send/SendAssetFormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SendAssetFormField = ({
format,
label,
labelMaxLength,
mask,
onChange,
onPressButton,
placeholder,
Expand All @@ -29,6 +30,7 @@ const SendAssetFormField = ({
buttonText="Max"
format={format}
keyboardType="decimal-pad"
mask={mask}
onChange={onChange}
onPressButton={onPressButton}
placeholder={placeholder}
Expand All @@ -48,6 +50,7 @@ SendAssetFormField.propTypes = {
format: PropTypes.func,
label: PropTypes.string,
labelMaxLength: PropTypes.number,
mask: PropTypes.string,
onChange: PropTypes.func,
onPressButton: PropTypes.func,
placeholder: PropTypes.string,
Expand Down
25 changes: 9 additions & 16 deletions src/components/send/SendAssetFormToken.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { pick } from 'lodash';
import PropTypes from 'prop-types';
import React, { Fragment, useCallback } from 'react';
import React, { Fragment } from 'react';
import supportedNativeCurrencies from '../../references/native-currencies.json';
import { deviceUtils } from '../../utils';
import { removeLeadingZeros } from '../../utils/formatters';
import { ColumnWithMargins } from '../layout';
Expand All @@ -17,19 +19,10 @@ const SendAssetFormToken = ({
txSpeedRenderer,
...props
}) => {
const formatNativeInput = useCallback(
(value = '') => {
const nativeCurrencyDecimals = nativeCurrency !== 'ETH' ? 2 : 18;
const formattedValue = removeLeadingZeros(value);
const parts = formattedValue.split('.');
const decimals = parts[1] || '';

return decimals.length > nativeCurrencyDecimals
? `${parts[0]}.${decimals.substring(0, nativeCurrencyDecimals)}`
: formattedValue;
},
[nativeCurrency]
);
const {
mask: nativeMask,
placeholder: nativePlaceholder,
} = pick(supportedNativeCurrencies[nativeCurrency], ['mask', 'placeholder']);

return (
<Fragment>
Expand All @@ -44,11 +37,11 @@ const SendAssetFormToken = ({
/>
<SendAssetFormField
autoFocus
format={formatNativeInput}
label={nativeCurrency}
mask={nativeMask}
onChange={onChangeNativeAmount}
onPressButton={sendMaxBalance}
placeholder="0.00"
placeholder={nativePlaceholder}
value={nativeAmount}
/>
</ColumnWithMargins>
Expand Down

0 comments on commit 2a58de1

Please sign in to comment.