mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Update amount error on update of send screen.
This commit is contained in:
parent
5347319dff
commit
6d8344d0d0
139
package-lock.json
generated
139
package-lock.json
generated
@ -1934,6 +1934,12 @@
|
|||||||
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz",
|
||||||
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw=="
|
"integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw=="
|
||||||
},
|
},
|
||||||
|
"arch": {
|
||||||
|
"version": "2.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/arch/-/arch-2.1.0.tgz",
|
||||||
|
"integrity": "sha1-NhOqRhSQZLPB8GB5Gb8dR4boKIk=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"archy": {
|
"archy": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz",
|
||||||
@ -3793,6 +3799,12 @@
|
|||||||
"integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=",
|
"integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"base64url": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/base64url/-/base64url-2.0.0.tgz",
|
||||||
|
"integrity": "sha1-6sFuA+oUOO/5Qj1puqNiYu0fcLs=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"bcrypt-pbkdf": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
|
||||||
@ -5141,6 +5153,33 @@
|
|||||||
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz",
|
||||||
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
|
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
|
||||||
},
|
},
|
||||||
|
"clipboardy": {
|
||||||
|
"version": "1.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/clipboardy/-/clipboardy-1.2.3.tgz",
|
||||||
|
"integrity": "sha512-2WNImOvCRe6r63Gk9pShfkwXsVtKCroMAevIbiae021mS850UkWPbevxsBz3tnvjZIEGvlwaqCPsw+4ulzNgJA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"arch": "2.1.0",
|
||||||
|
"execa": "0.8.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"execa": {
|
||||||
|
"version": "0.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/execa/-/execa-0.8.0.tgz",
|
||||||
|
"integrity": "sha1-2NdrvBtVIX7RkP1t1J08d07PyNo=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"cross-spawn": "5.1.0",
|
||||||
|
"get-stream": "3.0.0",
|
||||||
|
"is-stream": "1.1.0",
|
||||||
|
"npm-run-path": "2.0.2",
|
||||||
|
"p-finally": "1.0.0",
|
||||||
|
"signal-exit": "3.0.2",
|
||||||
|
"strip-eof": "1.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"cliui": {
|
"cliui": {
|
||||||
"version": "3.2.0",
|
"version": "3.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",
|
||||||
@ -9483,6 +9522,16 @@
|
|||||||
"integrity": "sha512-ZH7loueKBoDb7yG9esn1U+fgq7BzlzW6NRi5/rMdxIZ05dj7GFD/Xc5rq2CDt5Yq86CyfSYVyx4242QQNZbx1g==",
|
"integrity": "sha512-ZH7loueKBoDb7yG9esn1U+fgq7BzlzW6NRi5/rMdxIZ05dj7GFD/Xc5rq2CDt5Yq86CyfSYVyx4242QQNZbx1g==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"fill-keys": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-mo+jb06K1jTjv2tPPIiCVRRS6yA=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"is-object": "1.0.1",
|
||||||
|
"merge-descriptors": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"fill-range": {
|
"fill-range": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.3.tgz",
|
||||||
@ -11347,6 +11396,62 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"gh-pages": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/gh-pages/-/gh-pages-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-ZpDkeOVmIrN5mz+sBWDz5zmTqcbNJzI/updCwEv/7rrSdpTNlj1B5GhBqG7f4Q8p5sJOdnBV0SIqxJrxtZQ9FA==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"async": "2.6.0",
|
||||||
|
"base64url": "2.0.0",
|
||||||
|
"commander": "2.11.0",
|
||||||
|
"fs-extra": "4.0.3",
|
||||||
|
"globby": "6.1.0",
|
||||||
|
"graceful-fs": "4.1.11",
|
||||||
|
"rimraf": "2.6.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"fs-extra": {
|
||||||
|
"version": "4.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz",
|
||||||
|
"integrity": "sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"graceful-fs": "4.1.11",
|
||||||
|
"jsonfile": "4.0.0",
|
||||||
|
"universalify": "0.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"globby": {
|
||||||
|
"version": "6.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/globby/-/globby-6.1.0.tgz",
|
||||||
|
"integrity": "sha1-9abXDoOV4hyFj7BInWTfAkJNUGw=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"array-union": "1.0.2",
|
||||||
|
"glob": "7.1.2",
|
||||||
|
"object-assign": "4.1.1",
|
||||||
|
"pify": "2.3.0",
|
||||||
|
"pinkie-promise": "2.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"jsonfile": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
|
||||||
|
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"graceful-fs": "4.1.11"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pify": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz",
|
||||||
|
"integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"gifencoder": {
|
"gifencoder": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/gifencoder/-/gifencoder-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/gifencoder/-/gifencoder-1.1.0.tgz",
|
||||||
@ -18541,6 +18646,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"module-not-found-error": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-z4tP9PKWQGdNbN0CsOO8UjwrvcA=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"moment": {
|
"moment": {
|
||||||
"version": "2.22.1",
|
"version": "2.22.1",
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.1.tgz",
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.1.tgz",
|
||||||
@ -24330,6 +24441,28 @@
|
|||||||
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=",
|
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"proxyquire": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/proxyquire/-/proxyquire-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-fQr3VQrbdzHrdaDn3XuisVoJlJNDJizHAvUXw9IuXRR8BpV2x0N7LsCxrpJkeKfPbNjiNU/V5vc008cI0TmzzQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"fill-keys": "1.0.2",
|
||||||
|
"module-not-found-error": "1.0.1",
|
||||||
|
"resolve": "1.5.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"resolve": {
|
||||||
|
"version": "1.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.5.0.tgz",
|
||||||
|
"integrity": "sha512-hgoSGrc3pjzAPHNBg+KnFcK2HwlHTs/YrAGUr6qgTVUZmXv1UEXXl0bZNBKMA9fud6lRYFdPGz0xXxycPzmmiw==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"path-parse": "1.0.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"prr": {
|
"prr": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
|
||||||
@ -30195,6 +30328,12 @@
|
|||||||
"unist-util-is": "2.1.1"
|
"unist-util-is": "2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"universalify": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz",
|
||||||
|
"integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"unorm": {
|
"unorm": {
|
||||||
"version": "1.4.1",
|
"version": "1.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz",
|
||||||
|
@ -83,30 +83,31 @@ export default class SendTransactionScreen extends PersistentForm {
|
|||||||
|
|
||||||
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
const uninitialized = [prevBalance, prevGasTotal].every(n => n === null)
|
||||||
|
|
||||||
if (!uninitialized) {
|
const amountErrorRequiresUpdate = doesAmountErrorRequireUpdate({
|
||||||
const amountErrorRequiresUpdate = doesAmountErrorRequireUpdate({
|
balance,
|
||||||
|
gasTotal,
|
||||||
|
prevBalance,
|
||||||
|
prevGasTotal,
|
||||||
|
prevTokenBalance,
|
||||||
|
selectedToken,
|
||||||
|
tokenBalance,
|
||||||
|
})
|
||||||
|
|
||||||
|
if (amountErrorRequiresUpdate) {
|
||||||
|
const amountErrorObject = getAmountErrorObject({
|
||||||
|
amount,
|
||||||
|
amountConversionRate,
|
||||||
balance,
|
balance,
|
||||||
|
conversionRate,
|
||||||
gasTotal,
|
gasTotal,
|
||||||
prevBalance,
|
primaryCurrency,
|
||||||
prevGasTotal,
|
|
||||||
prevTokenBalance,
|
|
||||||
selectedToken,
|
selectedToken,
|
||||||
tokenBalance,
|
tokenBalance,
|
||||||
})
|
})
|
||||||
|
updateSendErrors(amountErrorObject)
|
||||||
|
}
|
||||||
|
|
||||||
if (amountErrorRequiresUpdate) {
|
if (!uninitialized) {
|
||||||
const amountErrorObject = getAmountErrorObject({
|
|
||||||
amount,
|
|
||||||
amountConversionRate,
|
|
||||||
balance,
|
|
||||||
conversionRate,
|
|
||||||
gasTotal,
|
|
||||||
primaryCurrency,
|
|
||||||
selectedToken,
|
|
||||||
tokenBalance,
|
|
||||||
})
|
|
||||||
updateSendErrors(amountErrorObject)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (network !== prevNetwork && network !== 'loading') {
|
if (network !== prevNetwork && network !== 'loading') {
|
||||||
updateSendTokenBalance({
|
updateSendTokenBalance({
|
||||||
|
@ -36,7 +36,7 @@ function calcGasTotal (gasLimit, gasPrice) {
|
|||||||
|
|
||||||
function isBalanceSufficient ({
|
function isBalanceSufficient ({
|
||||||
amount = '0x0',
|
amount = '0x0',
|
||||||
amountConversionRate,
|
amountConversionRate = 0,
|
||||||
balance,
|
balance,
|
||||||
conversionRate,
|
conversionRate,
|
||||||
gasTotal = '0x0',
|
gasTotal = '0x0',
|
||||||
@ -58,7 +58,7 @@ function isBalanceSufficient ({
|
|||||||
{
|
{
|
||||||
value: totalAmount,
|
value: totalAmount,
|
||||||
fromNumericBase: 'hex',
|
fromNumericBase: 'hex',
|
||||||
conversionRate: amountConversionRate || conversionRate,
|
conversionRate: Number(amountConversionRate) || conversionRate,
|
||||||
fromCurrency: primaryCurrency,
|
fromCurrency: primaryCurrency,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -25,7 +25,7 @@ const SendTransactionScreen = proxyquire('../send.component.js', {
|
|||||||
sinon.spy(SendTransactionScreen.prototype, 'componentDidMount')
|
sinon.spy(SendTransactionScreen.prototype, 'componentDidMount')
|
||||||
sinon.spy(SendTransactionScreen.prototype, 'updateGas')
|
sinon.spy(SendTransactionScreen.prototype, 'updateGas')
|
||||||
|
|
||||||
describe('Send Component', function () {
|
describe.only('Send Component', function () {
|
||||||
let wrapper
|
let wrapper
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -68,14 +68,17 @@ describe('Send Component', function () {
|
|||||||
|
|
||||||
describe('componentWillMount', () => {
|
describe('componentWillMount', () => {
|
||||||
it('should call this.updateGas', () => {
|
it('should call this.updateGas', () => {
|
||||||
assert(SendTransactionScreen.prototype.updateGas.calledOnce)
|
SendTransactionScreen.prototype.updateGas.resetHistory()
|
||||||
|
propsMethodSpies.updateSendErrors.resetHistory()
|
||||||
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 0)
|
||||||
wrapper.instance().componentWillMount()
|
wrapper.instance().componentWillMount()
|
||||||
assert(SendTransactionScreen.prototype.updateGas.calledTwice)
|
assert.equal(SendTransactionScreen.prototype.updateGas.callCount, 1)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('componentDidUpdate', () => {
|
describe('componentDidUpdate', () => {
|
||||||
it('should call doesAmountErrorRequireUpdate with the expected params', () => {
|
it('should call doesAmountErrorRequireUpdate with the expected params', () => {
|
||||||
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
||||||
wrapper.instance().componentDidUpdate({
|
wrapper.instance().componentDidUpdate({
|
||||||
from: {
|
from: {
|
||||||
balance: '',
|
balance: '',
|
||||||
@ -97,6 +100,7 @@ describe('Send Component', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should not call getAmountErrorObject if doesAmountErrorRequireUpdate returns false', () => {
|
it('should not call getAmountErrorObject if doesAmountErrorRequireUpdate returns false', () => {
|
||||||
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
||||||
wrapper.instance().componentDidUpdate({
|
wrapper.instance().componentDidUpdate({
|
||||||
from: {
|
from: {
|
||||||
balance: 'mockBalance',
|
balance: 'mockBalance',
|
||||||
@ -106,6 +110,7 @@ describe('Send Component', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should call getAmountErrorObject if doesAmountErrorRequireUpdate returns true', () => {
|
it('should call getAmountErrorObject if doesAmountErrorRequireUpdate returns true', () => {
|
||||||
|
utilsMethodStubs.getAmountErrorObject.resetHistory()
|
||||||
wrapper.instance().componentDidUpdate({
|
wrapper.instance().componentDidUpdate({
|
||||||
from: {
|
from: {
|
||||||
balance: 'balanceChanged',
|
balance: 'balanceChanged',
|
||||||
@ -128,6 +133,7 @@ describe('Send Component', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('should call updateSendErrors with the expected params', () => {
|
it('should call updateSendErrors with the expected params', () => {
|
||||||
|
propsMethodSpies.updateSendErrors.resetHistory()
|
||||||
wrapper.instance().componentDidUpdate({
|
wrapper.instance().componentDidUpdate({
|
||||||
from: {
|
from: {
|
||||||
balance: 'balanceChanged',
|
balance: 'balanceChanged',
|
||||||
|
Loading…
Reference in New Issue
Block a user