Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

feat: Fixes #308. Change amount font size on Send page to fit in input field #321

Merged
merged 9 commits into from
Jan 7, 2019
22 changes: 21 additions & 1 deletion packages/fether-react/src/Send/TxForm/TxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import withAccount from '../../utils/withAccount.js';
import withBalance, { withEthBalance } from '../../utils/withBalance';
import withTokens from '../../utils/withTokens';

const DEFAULT_AMOUNT_MAX_CHARS = 9;
const MEDIUM_AMOUNT_MAX_CHARS = 14;
const MAX_GAS_PRICE = 40; // In Gwei
const MIN_GAS_PRICE = 3; // Safelow gas price from GasStation, in Gwei

Expand All @@ -39,6 +41,7 @@ class Send extends Component {
state = {
maxSelected: false
};

handleSubmit = values => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert. handleSubmit is already somewhere else in the class

const { accountAddress, history, sendStore, token } = this.props;

Expand All @@ -61,6 +64,19 @@ class Send extends Component {
}
});

changeAmountFontSize = amount => {
const amountLen = amount.toString().length;
if (amountLen > MEDIUM_AMOUNT_MAX_CHARS) {
return '-resize-font-small'; // Resize to fit an amount as small as one Wei
} else if (
MEDIUM_AMOUNT_MAX_CHARS >= amountLen &&
amountLen > DEFAULT_AMOUNT_MAX_CHARS
) {
return '-resize-font-medium';
}
return '-resize-font-default';
};

calculateMax = (gas, gasPrice) => {
const { token, balance } = this.props;
const gasBn = gas ? new BigNumber(gas) : new BigNumber(21000);
Expand Down Expand Up @@ -133,7 +149,11 @@ class Send extends Component {
<fieldset className='form_fields'>
<Field
autoFocus
className='form_field_amount'
className={`form_field_amount ${
!values.amount
? '-resize-font-default'
: this.changeAmountFontSize(values.amount)
}`}
formNoValidate
label='Amount'
name='amount'
Expand Down
15 changes: 14 additions & 1 deletion packages/fether-react/src/assets/sass/shared/_form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,25 @@
}

input.form_field_amount[type='number'] {
font-size: ms(6);
line-height: ms(6) * 1.1;
font-weight: 200;
width: 100%;
text-align: center;
-webkit-appearance: none;
-webkit-transition: font-size 0.5s;
transition: font-size 0.5s;

&.-resize-font-default {
font-size: ms(6);
}

&.-resize-font-medium {
font-size: ms(4);
}

&.-resize-font-small {
font-size: ms(2);
}

&::-webkit-inner-spin-button,
&::-webkit-outer-spin-button {
Expand Down