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
23 changes: 21 additions & 2 deletions packages/fether-react/src/Send/TxForm/TxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import withBalance, { withEthBalance } from '../../utils/withBalance';
import withTokens from '../../utils/withTokens';
import TxDetails from './TxDetails';

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 Down Expand Up @@ -68,6 +70,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 @@ -196,11 +211,15 @@ class Send extends Component {
/>

<Field
className='form_field_amount'
className={`form_field_amount ${
!values.amount
? '-resize-font-default'
: this.changeAmountFontSize(values.amount)
}`}
disabled={this.state.maxSelected}
formNoValidate
label='Amount'
name='amount'
disabled={this.state.maxSelected}
placeholder='0.00'
render={FetherForm.Field}
required
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 @@ -139,12 +139,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