A Metamask fork with Infura removed and default networks editable
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
ciphermask/ui/selectors/metametrics.js

36 lines
1.1 KiB

import { createSelector } from 'reselect';
export const selectFragments = (state) => state.metamask.fragments;
export const selectFragmentBySuccessEvent = createSelector(
selectFragments,
(_, fragmentOptions) => fragmentOptions,
(fragments, fragmentOptions) => {
if (fragmentOptions.persist) {
return Object.values(fragments).find(
(fragment) => fragment.successEvent === fragmentOptions.successEvent,
);
}
return undefined;
},
);
export const selectFragmentById = createSelector(
selectFragments,
(_, fragmentId) => fragmentId,
(fragments, fragmentId) => {
// A valid existing fragment must exist in state.
// If these conditions are not meant we will create a new fragment.
if (fragmentId && fragments?.[fragmentId]) {
return fragments[fragmentId];
}
return undefined;
},
);
export const selectMatchingFragment = createSelector(
(state, params) =>
selectFragmentBySuccessEvent(state, params.fragmentOptions),
(state, params) => selectFragmentById(state, params.existingId),
(matchedBySuccessEvent, matchedById) => matchedById ?? matchedBySuccessEvent,
);