|
|
|
import assert from 'assert'
|
|
|
|
import proxyquire from 'proxyquire'
|
|
|
|
import sinon from 'sinon'
|
|
|
|
|
|
|
|
let mapDispatchToProps
|
|
|
|
|
|
|
|
const actionSpies = {
|
|
|
|
addToAddressBook: sinon.spy(),
|
|
|
|
clearSend: sinon.spy(),
|
|
|
|
signTokenTx: sinon.spy(),
|
|
|
|
signTx: sinon.spy(),
|
|
|
|
updateTransaction: sinon.spy(),
|
|
|
|
}
|
|
|
|
const utilsStubs = {
|
|
|
|
addressIsNew: sinon.stub().returns(true),
|
|
|
|
constructTxParams: sinon.stub().returns({
|
|
|
|
value: 'mockAmount',
|
|
|
|
}),
|
|
|
|
constructUpdatedTx: sinon.stub().returns('mockConstructedUpdatedTxParams'),
|
|
|
|
}
|
|
|
|
|
|
|
|
proxyquire('../send-footer.container.js', {
|
|
|
|
'react-redux': {
|
|
|
|
connect: (_, md) => {
|
|
|
|
mapDispatchToProps = md
|
|
|
|
return () => ({})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'../../../store/actions': actionSpies,
|
|
|
|
'../send.selectors': {
|
|
|
|
getGasLimit: (s) => `mockGasLimit:${s}`,
|
|
|
|
getGasPrice: (s) => `mockGasPrice:${s}`,
|
|
|
|
getGasTotal: (s) => `mockGasTotal:${s}`,
|
|
|
|
getSelectedToken: (s) => `mockSelectedToken:${s}`,
|
|
|
|
getSendAmount: (s) => `mockAmount:${s}`,
|
|
|
|
getSendEditingTransactionId: (s) => `mockEditingTransactionId:${s}`,
|
|
|
|
getSendFromObject: (s) => `mockFromObject:${s}`,
|
|
|
|
getSendTo: (s) => `mockTo:${s}`,
|
|
|
|
getSendToNickname: (s) => `mockToNickname:${s}`,
|
|
|
|
getSendToAccounts: (s) => `mockToAccounts:${s}`,
|
|
|
|
getTokenBalance: (s) => `mockTokenBalance:${s}`,
|
|
|
|
getSendHexData: (s) => `mockHexData:${s}`,
|
|
|
|
getUnapprovedTxs: (s) => `mockUnapprovedTxs:${s}`,
|
|
|
|
getSendErrors: (s) => `mockSendErrors:${s}`,
|
|
|
|
},
|
|
|
|
'./send-footer.selectors': { isSendFormInError: (s) => `mockInError:${s}` },
|
|
|
|
'./send-footer.utils': utilsStubs,
|
|
|
|
'../../../selectors/': {
|
Use `AdvancedGasInputs` in `AdvancedTabContent` (#7186)
* Use `AdvancedGasInputs` in `AdvancedTabContent`
The `AdvancedGasInputs` component was originally extracted from the
`AdvancedTabContent` component, duplicating much of the rendering
logic. They have since evolved separately, with bugs being fixed in one
place but not the other.
The inputs and outputs expected weren't exactly the same, as the
`AdvancedGasInputs` component converts the input custom gas price and
limit, and it converts them both in the setter methods as well.
The `GasModalPageContainer` had to be adjusted to avoid converting
these values multiple times.
Both components dealt with input debouncing separately, both in less
than ideal ways. `AdvancedTabContent` didn't debounce either field, but
it did debounce the check for whether the gas limit field was below the
minimum value. So if a less-than-minimum value was set, it would be
propogated upwards and could be saved if the user clicked 'Save'
quickly enough. After a second delay it would snap back to the minimum
value. The `AdvancedGasInputs` component debounced both fields, but
it would replace any gas limit below the minimum with the minimum
value. This led to a problem where a brief pause during typing would
reset the field to 21000.
The `AdvancedGasInputs` approach was chosen, except that it was
updated to no longer change the gas limit if it was below the minimum.
Instead it displays an error. Parent components were checked to ensure
they would detect the error case of the gas limit being set too low,
and prevent the form submission in those cases. Of the three parents,
one had already dealt with it correctly, one needed to convert the
gas limit from hex first, and another needed the gas limit check added.
Closes #6872
* Cleanup send components
Empty README files have been removed, and a mistake in the index file
for the send page has been corrected. The Gas Slider component class
name was updated as well; it looks like it was originally created from
`AdvancedTabContent`, so it still had that class name.
5 years ago
|
|
|
getRenderableEstimateDataForSmallButtonsFromGWEI: (s) => ([{ gasEstimateType: `mockGasEstimateType:${s}` }]),
|
|
|
|
getDefaultActiveButtonIndex: () => 0,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('send-footer container', function () {
|
|
|
|
|
|
|
|
describe('mapDispatchToProps()', function () {
|
|
|
|
let dispatchSpy
|
|
|
|
let mapDispatchToPropsObject
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
dispatchSpy = sinon.spy()
|
|
|
|
mapDispatchToPropsObject = mapDispatchToProps(dispatchSpy)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('clearSend()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
|
|
|
mapDispatchToPropsObject.clearSend()
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert(actionSpies.clearSend.calledOnce)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('sign()', function () {
|
|
|
|
it('should dispatch a signTokenTx action if selectedToken is defined', function () {
|
|
|
|
mapDispatchToPropsObject.sign({
|
|
|
|
selectedToken: {
|
|
|
|
address: '0xabc',
|
|
|
|
},
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
})
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsStubs.constructTxParams.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
selectedToken: {
|
|
|
|
address: '0xabc',
|
|
|
|
},
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.signTokenTx.getCall(0).args,
|
|
|
|
[ '0xabc', 'mockTo', 'mockAmount', { value: 'mockAmount' } ]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should dispatch a sign action if selectedToken is not defined', function () {
|
|
|
|
utilsStubs.constructTxParams.resetHistory()
|
|
|
|
mapDispatchToPropsObject.sign({
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
})
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsStubs.constructTxParams.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
selectedToken: undefined,
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.signTx.getCall(0).args,
|
|
|
|
[ { value: 'mockAmount' } ]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('update()', function () {
|
|
|
|
it('should dispatch an updateTransaction action', function () {
|
|
|
|
mapDispatchToPropsObject.update({
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
editingTransactionId: 'mockEditingTransactionId',
|
|
|
|
selectedToken: 'mockSelectedToken',
|
|
|
|
unapprovedTxs: 'mockUnapprovedTxs',
|
|
|
|
})
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.deepEqual(
|
|
|
|
utilsStubs.constructUpdatedTx.getCall(0).args[0],
|
|
|
|
{
|
|
|
|
data: undefined,
|
|
|
|
to: 'mockTo',
|
|
|
|
amount: 'mockAmount',
|
|
|
|
from: 'mockFrom',
|
|
|
|
gas: 'mockGas',
|
|
|
|
gasPrice: 'mockGasPrice',
|
|
|
|
editingTransactionId: 'mockEditingTransactionId',
|
|
|
|
selectedToken: 'mockSelectedToken',
|
|
|
|
unapprovedTxs: 'mockUnapprovedTxs',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert.equal(actionSpies.updateTransaction.getCall(0).args[0], 'mockConstructedUpdatedTxParams')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('addToAddressBookIfNew()', function () {
|
|
|
|
it('should dispatch an action', function () {
|
|
|
|
mapDispatchToPropsObject.addToAddressBookIfNew('mockNewAddress', 'mockToAccounts', 'mockNickname')
|
|
|
|
assert(dispatchSpy.calledOnce)
|
|
|
|
assert.equal(utilsStubs.addressIsNew.getCall(0).args[0], 'mockToAccounts')
|
|
|
|
assert.deepEqual(
|
|
|
|
actionSpies.addToAddressBook.getCall(0).args,
|
|
|
|
[ '0xmockNewAddress', 'mockNickname' ]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|