Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ui/ducks/send/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ export const draftTransactionInitialState = {
status: SEND_STATUSES.VALID,
transactionType: TRANSACTION_ENVELOPE_TYPES.LEGACY,
userInputHexData: null,
contextEditingDisabled: true,
};

/**
Expand Down Expand Up @@ -842,6 +843,9 @@ const slice = createSlice({
// validate send state
slice.caseReducers.validateSendState(state);
},
disableContextEditing: (state) => {
state.contextEditingDisabled = true;
},
/**
* Clears all drafts from send state and drops the currentTransactionUUID.
* This is an important first step before adding a new draft transaction to
Expand Down Expand Up @@ -1548,6 +1552,7 @@ const slice = createSlice({
slice.caseReducers.validateAmountField(state);
slice.caseReducers.validateGasField(state);
slice.caseReducers.validateSendState(state);
state.contextEditingDisabled = false;
})
.addCase(SELECTED_ACCOUNT_CHANGED, (state, action) => {
// If we are on the edit flow the account we are keyed into will be the
Expand Down Expand Up @@ -1615,6 +1620,7 @@ const {
updateRecipientSearchMode,
addHistoryEntry,
acknowledgeRecipientWarning,
disableContextEditing,
} = actions;

export {
Expand All @@ -1623,6 +1629,7 @@ export {
updateGasLimit,
addHistoryEntry,
acknowledgeRecipientWarning,
disableContextEditing,
};

// Action Creators
Expand Down Expand Up @@ -1662,6 +1669,7 @@ const debouncedValidateRecipientUserInput = debounce(
*/
export function editExistingTransaction(assetType, transactionId) {
return async (dispatch, getState) => {
await dispatch(actions.disableContextEditing());
await dispatch(actions.clearPreviousDrafts());
const state = getState();
const unapprovedTransactions = getUnapprovedTxs(state);
Expand Down Expand Up @@ -2312,6 +2320,7 @@ export function toggleSendMaxMode() {
*/
export function startNewDraftTransaction(asset) {
return async (dispatch) => {
await dispatch(actions.disableContextEditing());
await dispatch(actions.clearPreviousDrafts());

await dispatch(
Expand Down
7 changes: 6 additions & 1 deletion ui/pages/routes/routes.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default class Routes extends Component {
browserEnvironmentBrowser: PropTypes.string,
theme: PropTypes.string,
sendStage: PropTypes.string,
disableContextEditing: PropTypes.bool,
};

static contextTypes = {
Expand Down Expand Up @@ -358,6 +359,7 @@ export default class Routes extends Component {
isMouseUser,
browserEnvironmentOs: os,
browserEnvironmentBrowser: browser,
disableContextEditing,
} = this.props;
const loadMessage =
loadingMessage || isNetworkLoading
Expand All @@ -384,9 +386,12 @@ export default class Routes extends Component {
{!this.hideAppHeader() && (
<AppHeader
hideNetworkIndicator={this.onInitializationUnlockPage()}
disableNetworkIndicator={this.onSwapsPage()}
disableNetworkIndicator={
disableContextEditing || this.onSwapsPage()
}
onClick={this.onAppHeaderClick}
disabled={
disableContextEditing ||
this.onConfirmPage() ||
this.onEditTransactionPage() ||
(this.onSwapsPage() && !this.onSwapsBuildQuotePage())
Expand Down
3 changes: 2 additions & 1 deletion ui/pages/routes/routes.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getSendStage } from '../../ducks/send';
import Routes from './routes.component';

function mapStateToProps(state) {
const { appState } = state;
const { appState, send } = state;
const { alertOpen, alertMessage, isLoading, loadingMessage } = appState;
const { autoLockTimeLimit = 0 } = getPreferences(state);

Expand All @@ -40,6 +40,7 @@ function mapStateToProps(state) {
providerType: state.metamask.provider?.type,
theme: getTheme(state),
sendStage: getSendStage(state),
disableSendContextEditing: send.disableContextEditing,
};
}

Expand Down
2 changes: 2 additions & 0 deletions ui/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
computeEstimatedGasLimit,
initializeSendState,
resetSendState,
disableContextEditing,
} from '../ducks/send';
import { switchedToUnconnectedAccount } from '../ducks/alerts/unconnected-account';
import { getUnconnectedAccountAlertEnabledness } from '../ducks/metamask/metamask';
Expand Down Expand Up @@ -1449,6 +1450,7 @@ export function updateMetamaskState(newState) {
type: actionConstants.CHAIN_CHANGED,
payload: newProvider.chainId,
});
dispatch(disableContextEditing());
// We dispatch this action to ensure that the send state stays up to date
// after the chain changes. This async thunk will fail gracefully in the
// event that we are not yet on the send flow with a draftTransaction in
Expand Down