Skip to content

Commit

Permalink
feat(27256): revert get remote feature flags by name
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDDDanica committed Nov 28, 2024
1 parent 91b2edb commit 6042c41
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 45 deletions.
3 changes: 0 additions & 3 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2361,9 +2361,6 @@ export default class MetamaskController extends EventEmitter {
previousValueComparator((prevState, currState) => {
const { useExternalServices: prevUseExternalServices } = prevState;
const { useExternalServices: currUseExternalServices } = currState;

console.log('-----------------');
console.log(this.remoteFeatureFlagController.updateRemoteFeatureFlags);
if (currUseExternalServices && !prevUseExternalServices) {
this.remoteFeatureFlagController.enable();
this.remoteFeatureFlagController.updateRemoteFeatureFlags();
Expand Down
8 changes: 5 additions & 3 deletions ui/pages/settings/info-tab/info-tab.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {

export default class InfoTab extends PureComponent {
static propTypes = {
tesRemoteFeatureFlag: PropTypes.bool,
remoteFeatureFlags: PropTypes.object,
};

state = {
Expand Down Expand Up @@ -57,9 +57,11 @@ export default class InfoTab extends PureComponent {
componentDidMount() {
const { t } = this.context;
handleSettingsRefs(t, t('about'), this.settingsRefs);
if (!this.props.tesRemoteFeatureFlag) {
if (Object.keys(this.props.remoteFeatureFlags).length > 0) {
// eslint-disable-next-line no-console
console.log('Feature flag for tesRemoteFeatureFlag fetched successfully');
console.log(
`Fetch remote feature flag success, eg: testBooleanFlag has value ${this.props.remoteFeatureFlags.testBooleanFlag}`,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/pages/settings/info-tab/info-tab.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export default {
title: 'Pages/Settings/InfoTab',
};

export const DefaultStory = () => <InfoTab tesRemoteFeatureFlag={false} />;
export const DefaultStory = () => <InfoTab remoteFeatureFlags={{}} />;

DefaultStory.storyName = 'Default';
2 changes: 1 addition & 1 deletion ui/pages/settings/info-tab/info-tab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('InfoTab', () => {

beforeEach(() => {
const renderResult = renderWithProvider(
<InfoTab tesRemoteFeatureFlag={false} />,
<InfoTab remoteFeatureFlags={{}} />,
);
getByText = renderResult.getByText;
});
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/settings/settings.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SettingsPage extends PureComponent {
isPopup: PropTypes.bool,
mostRecentOverviewPage: PropTypes.string.isRequired,
pathnameI18nKey: PropTypes.string,
tesRemoteFeatureFlag: PropTypes.bool,
remoteFeatureFlags: PropTypes.object,
toggleNetworkMenu: PropTypes.func.isRequired,
useExternalServices: PropTypes.bool,
};
Expand Down Expand Up @@ -387,7 +387,7 @@ class SettingsPage extends PureComponent {
exact
path={ABOUT_US_ROUTE}
render={() => (
<InfoTab tesRemoteFeatureFlag={this.props.tesRemoteFeatureFlag} />
<InfoTab remoteFeatureFlags={this.props.remoteFeatureFlags} />
)}
/>
<Route exact path={ADVANCED_ROUTE} component={AdvancedTab} />
Expand Down
4 changes: 2 additions & 2 deletions ui/pages/settings/settings.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import {
getAddressBookEntryOrAccountName,
getRemoteFeatureFlagsByName,
getRemoteFeatureFlags,
getUseExternalServices,
} from '../../selectors';
import { ENVIRONMENT_TYPE_POPUP } from '../../../shared/constants/app';
Expand Down Expand Up @@ -61,7 +61,7 @@ const mapStateToProps = (state, ownProps) => {
const {
metamask: { currencyRates },
} = state;
const remoteFeatureFlags = getRemoteFeatureFlagsByName(state);
const remoteFeatureFlags = getRemoteFeatureFlags(state);
const conversionDate = currencyRates[ticker]?.conversionDate;

const pathNameTail = pathname.match(/[^/]+$/u)[0];
Expand Down
7 changes: 2 additions & 5 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2911,11 +2911,8 @@ export function getMetaMetricsDataDeletionStatus(state) {
return state.metamask.metaMetricsDataDeletionStatus;
}

export function getRemoteFeatureFlagsByName(state, featureFlagName) {
if (featureFlagName && state.metamask.remoteFeatureFlags?.featureFlagName) {
return state.metamask.remoteFeatureFlags;
}
return null;
export function getRemoteFeatureFlags(state) {
return state.metamask.remoteFeatureFlags;
}

/**
Expand Down
32 changes: 4 additions & 28 deletions ui/selectors/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2164,14 +2164,7 @@ describe('#getConnectedSitesList', () => {
});
});

describe('#getRemoteFeatureFlagsByName', () => {
it('returns null when state.metamask.remoteFeatureFlags is undefined', () => {
const state = {
metamask: {},
};
expect(selectors.getRemoteFeatureFlagsByName(state, 'testFlag')).toBeNull();
});

describe('#getRemoteFeatureFlags', () => {
it('returns null when featureFlagName does not exist in remoteFeatureFlags', () => {
const state = {
metamask: {
Expand All @@ -2180,26 +2173,9 @@ describe('#getConnectedSitesList', () => {
},
},
};
expect(selectors.getRemoteFeatureFlagsByName(state, 'nonExistentFlag')).toBeNull();
});

it('returns remoteFeatureFlags object when featureFlagName exists', () => {
const remoteFeatureFlags = {
testFlag: true,
otherFlag: false,
};
const state = {
metamask: {
remoteFeatureFlags,
},
};
expect(selectors.getRemoteFeatureFlagsByName(state, 'testFlag')).toStrictEqual(remoteFeatureFlags);
});

it('returns null when state is undefined', () => {
expect(selectors.getRemoteFeatureFlagsByName(undefined, 'testFlag')).toBeNull();
expect(selectors.getRemoteFeatureFlags(state)).toStrictEqual({
existingFlag: true,
});
});
});
});


0 comments on commit 6042c41

Please sign in to comment.