Skip to content

Commit

Permalink
resolve issue with missing template error (#10692)
Browse files Browse the repository at this point in the history
* resolve issue with missing template error

* also apply filtering to confirmation page

* rename variable
  • Loading branch information
brad-decker authored Mar 23, 2021
1 parent bfdc1e6 commit 255586a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions ui/app/helpers/constants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ const PATH_NAME_MAP = {
[CONNECTED_ACCOUNTS_ROUTE]: 'Accounts Connected To This Site Page',
[`${CONFIRM_TRANSACTION_ROUTE}/:id`]: 'Confirmation Root Page',
[CONFIRM_TRANSACTION_ROUTE]: 'Confirmation Root Page',
// TODO: rename when this is the only confirmation page
[CONFIRMATION_V_NEXT_ROUTE]: 'New Confirmation Page',
[`${CONFIRM_TRANSACTION_ROUTE}/:id${CONFIRM_TOKEN_METHOD_PATH}`]: 'Confirm Token Method Transaction Page',
[`${CONFIRM_TRANSACTION_ROUTE}/:id${CONFIRM_SEND_ETHER_PATH}`]: 'Confirm Send Ether Transaction Page',
[`${CONFIRM_TRANSACTION_ROUTE}/:id${CONFIRM_SEND_TOKEN_PATH}`]: 'Confirm Send Token Transaction Page',
Expand Down
7 changes: 5 additions & 2 deletions ui/app/pages/confirmation/confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { DEFAULT_ROUTE } from '../../helpers/constants/routes';
import { stripHttpsScheme } from '../../helpers/utils/util';
import { useI18nContext } from '../../hooks/useI18nContext';
import { useOriginMetadata } from '../../hooks/useOriginMetadata';
import { getUnapprovedConfirmations } from '../../selectors';
import { getUnapprovedTemplatedConfirmations } from '../../selectors';
import NetworkDisplay from '../../components/app/network-display/network-display';
import { COLORS, SIZES } from '../../helpers/constants/design-system';
import Callout from '../../components/ui/callout';
Expand Down Expand Up @@ -115,7 +115,10 @@ export default function ConfirmationPage() {
const t = useI18nContext();
const dispatch = useDispatch();
const history = useHistory();
const pendingConfirmations = useSelector(getUnapprovedConfirmations, isEqual);
const pendingConfirmations = useSelector(
getUnapprovedTemplatedConfirmations,
isEqual,
);
const [currentPendingConfirmation, setCurrentPendingConfirmation] = useState(
0,
);
Expand Down
4 changes: 4 additions & 0 deletions ui/app/pages/confirmation/templates/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const APPROVAL_TEMPLATES = {
[MESSAGE_TYPE.SWITCH_ETHEREUM_CHAIN]: switchEthereumChain,
};

export const TEMPLATED_CONFIRMATION_MESSAGE_TYPES = Object.keys(
APPROVAL_TEMPLATES,
);

const ALLOWED_TEMPLATE_KEYS = [
'content',
'approvalText',
Expand Down
6 changes: 3 additions & 3 deletions ui/app/pages/home/home.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Home extends PureComponent {
setWeb3ShimUsageAlertDismissed: PropTypes.func.isRequired,
originOfCurrentTab: PropTypes.string,
disableWeb3ShimUsageAlert: PropTypes.func.isRequired,
pendingApprovals: PropTypes.arrayOf(PropTypes.object).isRequired,
pendingConfirmations: PropTypes.arrayOf(PropTypes.object).isRequired,
};

state = {
Expand All @@ -91,7 +91,7 @@ export default class Home extends PureComponent {
haveSwapsQuotes,
showAwaitingSwapScreen,
swapsFetchParams,
pendingApprovals,
pendingConfirmations,
} = this.props;

this.setState({ mounted: true });
Expand All @@ -109,7 +109,7 @@ export default class Home extends PureComponent {
history.push(CONFIRM_TRANSACTION_ROUTE);
} else if (Object.keys(suggestedTokens).length > 0) {
history.push(CONFIRM_ADD_SUGGESTED_TOKEN_ROUTE);
} else if (pendingApprovals.length > 0) {
} else if (pendingConfirmations.length > 0) {
history.push(CONFIRMATION_V_NEXT_ROUTE);
}
}
Expand Down
5 changes: 3 additions & 2 deletions ui/app/pages/home/home.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getIsMainnet,
getOriginOfCurrentTab,
getTotalUnapprovedCount,
getUnapprovedTemplatedConfirmations,
getWeb3ShimUsageStateForOrigin,
unconfirmedTransactionsCountSelector,
} from '../../selectors';
Expand Down Expand Up @@ -52,12 +53,12 @@ const mapStateToProps = (state) => {
connectedStatusPopoverHasBeenShown,
defaultHomeActiveTabName,
swapsState,
pendingApprovals = {},
} = metamask;
const accountBalance = getCurrentEthBalance(state);
const { forgottenPassword, threeBoxLastUpdated } = appState;
const totalUnapprovedCount = getTotalUnapprovedCount(state);
const swapsEnabled = getSwapsFeatureLiveness(state);
const pendingConfirmations = getUnapprovedTemplatedConfirmations(state);

const envType = getEnvironmentType();
const isPopup = envType === ENVIRONMENT_TYPE_POPUP;
Expand Down Expand Up @@ -102,7 +103,7 @@ const mapStateToProps = (state) => {
isMainnet: getIsMainnet(state),
originOfCurrentTab,
shouldShowWeb3ShimUsageNotification,
pendingApprovals: Object.values(pendingApprovals),
pendingConfirmations,
};
};

Expand Down
8 changes: 8 additions & 0 deletions ui/app/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SWAPS_CHAINID_DEFAULT_TOKEN_MAP,
ALLOWED_SWAPS_CHAIN_IDS,
} from '../../../shared/constants/swaps';
import { TEMPLATED_CONFIRMATION_MESSAGE_TYPES } from '../pages/confirmation/templates';

/**
* One of the only remaining valid uses of selecting the network subkey of the
Expand Down Expand Up @@ -325,6 +326,13 @@ export function getUnapprovedConfirmations(state) {
return Object.values(pendingApprovals);
}

export function getUnapprovedTemplatedConfirmations(state) {
const unapprovedConfirmations = getUnapprovedConfirmations(state);
return unapprovedConfirmations.filter((approval) =>
TEMPLATED_CONFIRMATION_MESSAGE_TYPES.includes(approval.type),
);
}

function getSuggestedTokenCount(state) {
const { suggestedTokens = {} } = state.metamask;
return Object.keys(suggestedTokens).length;
Expand Down

0 comments on commit 255586a

Please sign in to comment.