-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display a warning and gas fee component for token allowance and NFT flow when transaction is expected to fail #17437
Merged
brad-decker
merged 8 commits into
develop
from
display-gas-fee-and-warning-for-failing-transactions
Feb 1, 2023
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
15458af
Display a warning and gas fee component for token allowance and NFT f…
VSaric 9554af7
Fixing test-storybook and test-unit-jest-main
VSaric b351f59
Fixing failing e2e tests
VSaric cabe23b
Added small component for simulation error, re-usable hook and more u…
VSaric 2bfc2ca
Merge branch 'develop' into display-gas-fee-and-warning-for-failing-t…
VSaric 044131f
Merge branch 'develop' into display-gas-fee-and-warning-for-failing-t…
pedronfigueiredo 0526f9a
Merge branch 'develop' into display-gas-fee-and-warning-for-failing-t…
danjm 7e71360
Merge branch 'develop' into display-gas-fee-and-warning-for-failing-t…
brad-decker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './simulation-error-message'; | ||
33 changes: 33 additions & 0 deletions
33
ui/components/ui/simulation-error-message/simulation-error-message.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { useContext } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ActionableMessage from '../actionable-message'; | ||
import { I18nContext } from '../../../../.storybook/i18n'; | ||
|
||
export default function SimulationErrorMessage({ | ||
userAcknowledgedGasMissing = false, | ||
setUserAcknowledgedGasMissing, | ||
}) { | ||
const t = useContext(I18nContext); | ||
|
||
return ( | ||
<ActionableMessage | ||
message={t('simulationErrorMessageV2')} | ||
useIcon | ||
iconFillColor="var(--color-error-default)" | ||
type="danger" | ||
primaryActionV2={ | ||
userAcknowledgedGasMissing === true | ||
? undefined | ||
: { | ||
label: t('proceedWithTransaction'), | ||
onClick: setUserAcknowledgedGasMissing, | ||
} | ||
} | ||
/> | ||
); | ||
} | ||
|
||
SimulationErrorMessage.propTypes = { | ||
userAcknowledgedGasMissing: PropTypes.bool, | ||
setUserAcknowledgedGasMissing: PropTypes.func, | ||
}; |
65 changes: 65 additions & 0 deletions
65
ui/components/ui/simulation-error-message/simulation-error-message.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import configureMockStore from 'redux-mock-store'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { renderWithProvider } from '../../../../test/lib/render-helpers'; | ||
import SimulationErrorMessage from './simulation-error-message'; | ||
|
||
describe('Simulation Error Message', () => { | ||
const store = configureMockStore()({}); | ||
let props = {}; | ||
|
||
beforeEach(() => { | ||
props = { | ||
userAcknowledgedGasMissing: false, | ||
setUserAcknowledgedGasMissing: jest.fn(), | ||
}; | ||
}); | ||
|
||
it('should render SimulationErrorMessage component with I want to procced anyway link', () => { | ||
const { queryByText } = renderWithProvider( | ||
<SimulationErrorMessage {...props} />, | ||
store, | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.', | ||
), | ||
).toBeInTheDocument(); | ||
expect(queryByText('I want to proceed anyway')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render SimulationErrorMessage component without I want to procced anyway link', () => { | ||
props.userAcknowledgedGasMissing = true; | ||
const { queryByText } = renderWithProvider( | ||
<SimulationErrorMessage {...props} />, | ||
store, | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.', | ||
), | ||
).toBeInTheDocument(); | ||
expect(queryByText('I want to proceed anyway')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should render SimulationErrorMessage component with I want to proceed anyway and fire that event', () => { | ||
props.userAcknowledgedGasMissing = false; | ||
const { queryByText, getByText } = renderWithProvider( | ||
<SimulationErrorMessage {...props} />, | ||
store, | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We were not able to estimate gas. There might be an error in the contract and this transaction may fail.', | ||
), | ||
).toBeInTheDocument(); | ||
expect(queryByText('I want to proceed anyway')).toBeInTheDocument(); | ||
|
||
const proceedAnywayLink = getByText('I want to proceed anyway'); | ||
fireEvent.click(proceedAnywayLink); | ||
expect(props.setUserAcknowledgedGasMissing).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { txDataSelector } from '../selectors'; | ||
|
||
/** | ||
* Returns the simulation failure warning if a simulaiton error | ||
* is present and user didn't acknowledge gas missing | ||
* | ||
* @param {boolean} userAcknowledgedGasMissing - Whether the user acknowledge gas missing | ||
* @returns {boolean} simulation failure warning | ||
*/ | ||
|
||
export function useSimulationFailureWarning(userAcknowledgedGasMissing) { | ||
const txData = useSelector(txDataSelector) || {}; | ||
const hasSimulationError = Boolean(txData.simulationFails); | ||
const renderSimulationFailureWarning = | ||
hasSimulationError && !userAcknowledgedGasMissing; | ||
return renderSimulationFailureWarning; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better place for this will be
ui/components/app