From 491f2d03cfd790e4246a9fa638a2eecb07a6488a Mon Sep 17 00:00:00 2001 From: trejgun Date: Mon, 2 Jul 2018 09:36:57 +0800 Subject: move removeLeadingZeroes to utils, add test --- ui/app/components/send_/send.utils.js | 5 +++++ ui/app/components/send_/send.utils.test.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 ui/app/components/send_/send.utils.test.js (limited to 'ui/app/components/send_') diff --git a/ui/app/components/send_/send.utils.js b/ui/app/components/send_/send.utils.js index dfd459731..313465fed 100644 --- a/ui/app/components/send_/send.utils.js +++ b/ui/app/components/send_/send.utils.js @@ -32,6 +32,7 @@ module.exports = { getToAddressForGasUpdate, isBalanceSufficient, isTokenBalanceSufficient, + removeLeadingZeroes, } function calcGasTotal (gasLimit, gasPrice) { @@ -273,3 +274,7 @@ function estimateGasPriceFromRecentBlocks (recentBlocks) { function getToAddressForGasUpdate (...addresses) { return [...addresses, ''].find(str => str !== undefined && str !== null).toLowerCase() } + +function removeLeadingZeroes (str) { + return str.replace(/^0*(?=\d)/, '') +} diff --git a/ui/app/components/send_/send.utils.test.js b/ui/app/components/send_/send.utils.test.js new file mode 100644 index 000000000..36f3a5c10 --- /dev/null +++ b/ui/app/components/send_/send.utils.test.js @@ -0,0 +1,30 @@ +import assert from 'assert' +import { removeLeadingZeroes } from './send.utils' + + +describe('send utils', () => { + describe('removeLeadingZeroes()', () => { + it('should remove leading zeroes from int when user types', () => { + assert.equal(removeLeadingZeroes('0'), '0') + assert.equal(removeLeadingZeroes('1'), '1') + assert.equal(removeLeadingZeroes('00'), '0') + assert.equal(removeLeadingZeroes('01'), '1') + }) + + it('should remove leading zeroes from int when user copy/paste', () => { + assert.equal(removeLeadingZeroes('001'), '1') + }) + + it('should remove leading zeroes from float when user types', () => { + assert.equal(removeLeadingZeroes('0.'), '0.') + assert.equal(removeLeadingZeroes('0.0'), '0.0') + assert.equal(removeLeadingZeroes('0.00'), '0.00') + assert.equal(removeLeadingZeroes('0.001'), '0.001') + assert.equal(removeLeadingZeroes('0.10'), '0.10') + }) + + it('should remove leading zeroes from float when user copy/paste', () => { + assert.equal(removeLeadingZeroes('00.1'), '0.1') + }) + }) +}) -- cgit From a8f745f9fe74751b87f500af3857b66d4c80f45e Mon Sep 17 00:00:00 2001 From: brunobar79 Date: Mon, 2 Jul 2018 18:49:33 -0400 Subject: eslint --fix . --- ui/app/components/send_/account-list-item/index.js | 2 +- ui/app/components/send_/index.js | 2 +- ui/app/components/send_/send-content/index.js | 2 +- .../send_/send-content/send-amount-row/amount-max-button/index.js | 2 +- ui/app/components/send_/send-content/send-amount-row/index.js | 2 +- ui/app/components/send_/send-content/send-dropdown-list/index.js | 2 +- .../components/send_/send-content/send-from-row/from-dropdown/index.js | 2 +- ui/app/components/send_/send-content/send-from-row/index.js | 2 +- .../send-gas-row/gas-fee-display/gas-fee-display.component.js | 2 +- .../send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js | 2 +- ui/app/components/send_/send-content/send-gas-row/index.js | 2 +- ui/app/components/send_/send-content/send-row-wrapper/index.js | 2 +- .../send_/send-content/send-row-wrapper/send-row-error-message/index.js | 2 +- ui/app/components/send_/send-content/send-to-row/index.js | 2 +- ui/app/components/send_/send-footer/index.js | 2 +- ui/app/components/send_/send-header/index.js | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) (limited to 'ui/app/components/send_') diff --git a/ui/app/components/send_/account-list-item/index.js b/ui/app/components/send_/account-list-item/index.js index 1fca540be..907485cf7 100644 --- a/ui/app/components/send_/account-list-item/index.js +++ b/ui/app/components/send_/account-list-item/index.js @@ -1 +1 @@ -export { default } from './account-list-item.container' \ No newline at end of file +export { default } from './account-list-item.container' diff --git a/ui/app/components/send_/index.js b/ui/app/components/send_/index.js index 9a4dd5727..b5114babc 100644 --- a/ui/app/components/send_/index.js +++ b/ui/app/components/send_/index.js @@ -1 +1 @@ -export { default } from './send.container' \ No newline at end of file +export { default } from './send.container' diff --git a/ui/app/components/send_/send-content/index.js b/ui/app/components/send_/send-content/index.js index 10b3c850e..891c17e6a 100644 --- a/ui/app/components/send_/send-content/index.js +++ b/ui/app/components/send_/send-content/index.js @@ -1 +1 @@ -export { default } from './send-content.component' \ No newline at end of file +export { default } from './send-content.component' diff --git a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/index.js b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/index.js index 548b51f33..ee8271494 100644 --- a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/index.js +++ b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/index.js @@ -1 +1 @@ -export { default } from './amount-max-button.container' \ No newline at end of file +export { default } from './amount-max-button.container' diff --git a/ui/app/components/send_/send-content/send-amount-row/index.js b/ui/app/components/send_/send-content/send-amount-row/index.js index 94a7da56f..abc6852fe 100644 --- a/ui/app/components/send_/send-content/send-amount-row/index.js +++ b/ui/app/components/send_/send-content/send-amount-row/index.js @@ -1 +1 @@ -export { default } from './send-amount-row.container' \ No newline at end of file +export { default } from './send-amount-row.container' diff --git a/ui/app/components/send_/send-content/send-dropdown-list/index.js b/ui/app/components/send_/send-content/send-dropdown-list/index.js index ee7736376..04af6536c 100644 --- a/ui/app/components/send_/send-content/send-dropdown-list/index.js +++ b/ui/app/components/send_/send-content/send-dropdown-list/index.js @@ -1 +1 @@ -export { default } from './send-dropdown-list.component' \ No newline at end of file +export { default } from './send-dropdown-list.component' diff --git a/ui/app/components/send_/send-content/send-from-row/from-dropdown/index.js b/ui/app/components/send_/send-content/send-from-row/from-dropdown/index.js index 6ab9a157a..2314ef4e3 100644 --- a/ui/app/components/send_/send-content/send-from-row/from-dropdown/index.js +++ b/ui/app/components/send_/send-content/send-from-row/from-dropdown/index.js @@ -1 +1 @@ -export { default } from './from-dropdown.component' \ No newline at end of file +export { default } from './from-dropdown.component' diff --git a/ui/app/components/send_/send-content/send-from-row/index.js b/ui/app/components/send_/send-content/send-from-row/index.js index 4a0916dba..0a79726b2 100644 --- a/ui/app/components/send_/send-content/send-from-row/index.js +++ b/ui/app/components/send_/send-content/send-from-row/index.js @@ -1 +1 @@ -export { default } from './send-from-row.container' \ No newline at end of file +export { default } from './send-from-row.container' diff --git a/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js b/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js index b1fd67412..c8d619be5 100644 --- a/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js +++ b/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/gas-fee-display.component.js @@ -14,7 +14,7 @@ export default class GasFeeDisplay extends Component { onClick: PropTypes.func, }; - render() { + render () { const { conversionRate, gasTotal, diff --git a/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js b/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js index 66f3a94df..7cbe8d0df 100644 --- a/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js +++ b/ui/app/components/send_/send-content/send-gas-row/gas-fee-display/test/gas-fee-display.component.test.js @@ -10,7 +10,7 @@ const propsMethodSpies = { showCustomizeGasModal: sinon.spy(), } -describe('SendGasRow Component', function() { +describe('SendGasRow Component', function () { let wrapper beforeEach(() => { diff --git a/ui/app/components/send_/send-content/send-gas-row/index.js b/ui/app/components/send_/send-content/send-gas-row/index.js index 060ed7fd3..3c7ff1d5f 100644 --- a/ui/app/components/send_/send-content/send-gas-row/index.js +++ b/ui/app/components/send_/send-content/send-gas-row/index.js @@ -1 +1 @@ -export { default } from './send-gas-row.container' \ No newline at end of file +export { default } from './send-gas-row.container' diff --git a/ui/app/components/send_/send-content/send-row-wrapper/index.js b/ui/app/components/send_/send-content/send-row-wrapper/index.js index 5715f55c6..d17545dcc 100644 --- a/ui/app/components/send_/send-content/send-row-wrapper/index.js +++ b/ui/app/components/send_/send-content/send-row-wrapper/index.js @@ -1 +1 @@ -export { default } from './send-row-wrapper.component' \ No newline at end of file +export { default } from './send-row-wrapper.component' diff --git a/ui/app/components/send_/send-content/send-row-wrapper/send-row-error-message/index.js b/ui/app/components/send_/send-content/send-row-wrapper/send-row-error-message/index.js index bf49c55bd..c00617f83 100644 --- a/ui/app/components/send_/send-content/send-row-wrapper/send-row-error-message/index.js +++ b/ui/app/components/send_/send-content/send-row-wrapper/send-row-error-message/index.js @@ -1 +1 @@ -export { default } from './send-row-error-message.container' \ No newline at end of file +export { default } from './send-row-error-message.container' diff --git a/ui/app/components/send_/send-content/send-to-row/index.js b/ui/app/components/send_/send-content/send-to-row/index.js index 4e7aa9747..121f15148 100644 --- a/ui/app/components/send_/send-content/send-to-row/index.js +++ b/ui/app/components/send_/send-content/send-to-row/index.js @@ -1 +1 @@ -export { default } from './send-to-row.container' \ No newline at end of file +export { default } from './send-to-row.container' diff --git a/ui/app/components/send_/send-footer/index.js b/ui/app/components/send_/send-footer/index.js index cd1727330..58e91d622 100644 --- a/ui/app/components/send_/send-footer/index.js +++ b/ui/app/components/send_/send-footer/index.js @@ -1 +1 @@ -export { default } from './send-footer.container' \ No newline at end of file +export { default } from './send-footer.container' diff --git a/ui/app/components/send_/send-header/index.js b/ui/app/components/send_/send-header/index.js index b808eabbf..0b17f0b7d 100644 --- a/ui/app/components/send_/send-header/index.js +++ b/ui/app/components/send_/send-header/index.js @@ -1 +1 @@ -export { default } from './send-header.container' \ No newline at end of file +export { default } from './send-header.container' -- cgit