Skip to content

Commit

Permalink
Merge branch 'develop' into MMI-update-metamask-keyring-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat authored Oct 13, 2023
2 parents ec5c921 + 69316d2 commit 74a9a5d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 51 deletions.
17 changes: 16 additions & 1 deletion ui/components/ui/toggle-button/toggle-button.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ const colors = {
};

const ToggleButton = (props) => {
const { value, onToggle, offLabel, onLabel, disabled, className } = props;
const {
value,
onToggle,
offLabel,
onLabel,
disabled,
className,
dataTestId,
} = props;

const modifier = value ? 'on' : 'off';

Expand Down Expand Up @@ -77,6 +85,9 @@ const ToggleButton = (props) => {
thumbStyle={thumbStyle}
thumbAnimateRange={[3, 18]}
colors={colors}
passThroughInputProps={{
'data-testId': dataTestId,
}}
/>
<div className="toggle-button__status">
<span className="toggle-button__label-off">{offLabel}</span>
Expand Down Expand Up @@ -111,6 +122,10 @@ ToggleButton.propTypes = {
* Additional className to add to the ToggleButton
*/
className: PropTypes.string,
/**
* A test id for the toggle button
*/
dataTestId: PropTypes.string,
};

export default ToggleButton;
Original file line number Diff line number Diff line change
Expand Up @@ -208,52 +208,48 @@ exports[`ExperimentalTab with desktop enabled renders ExperimentalTab component
>
Enable "Add account Snap (Beta)"
</h5>
<div
class="mm-box"
data-testid="add-snap-account-toggle"
<label
class="toggle-button toggle-button--off"
tabindex="0"
>
<label
class="toggle-button toggle-button--off"
tabindex="0"
<div
style="display: flex; width: 52px; align-items: center; justify-content: flex-start; position: relative; cursor: pointer; background-color: transparent; border: 0px; padding: 0px; user-select: none;"
>
<div
style="display: flex; width: 52px; align-items: center; justify-content: flex-start; position: relative; cursor: pointer; background-color: transparent; border: 0px; padding: 0px; user-select: none;"
style="width: 40px; height: 24px; padding: 0px; border-radius: 26px; display: flex; align-items: center; justify-content: center; background-color: rgb(242, 244, 246);"
>
<div
style="width: 40px; height: 24px; padding: 0px; border-radius: 26px; display: flex; align-items: center; justify-content: center; background-color: rgb(242, 244, 246);"
>
<div
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgb(250, 250, 250); margin-top: auto; margin-bottom: auto; line-height: 0; opacity: 0; width: 26px; height: 20px; left: 4px;"
/>
<div
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgba(255, 255, 255, 0.6); bottom: 0px; margin-top: auto; margin-bottom: auto; padding-right: 5px; line-height: 0; width: 26px; height: 20px; opacity: 1;"
/>
</div>
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgb(250, 250, 250); margin-top: auto; margin-bottom: auto; line-height: 0; opacity: 0; width: 26px; height: 20px; left: 4px;"
/>
<div
style="position: absolute; height: 100%; top: 0px; left: 0px; display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-start;"
>
<div
style="width: 18px; height: 18px; display: flex; align-self: center; box-shadow: none; border-radius: 50%; box-sizing: border-box; position: relative; background-color: rgb(106, 115, 125); left: 3px;"
/>
</div>
<input
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px;"
type="checkbox"
value="false"
style="font-size: 11px; display: flex; align-items: center; justify-content: center; font-family: 'Helvetica Neue', Helvetica, sans-serif; position: relative; color: rgba(255, 255, 255, 0.6); bottom: 0px; margin-top: auto; margin-bottom: auto; padding-right: 5px; line-height: 0; width: 26px; height: 20px; opacity: 1;"
/>
</div>
<div
class="toggle-button__status"
style="position: absolute; height: 100%; top: 0px; left: 0px; display: flex; flex: 1; align-self: stretch; align-items: center; justify-content: flex-start;"
>
<span
class="toggle-button__label-off"
/>
<span
class="toggle-button__label-on"
<div
style="width: 18px; height: 18px; display: flex; align-self: center; box-shadow: none; border-radius: 50%; box-sizing: border-box; position: relative; background-color: rgb(106, 115, 125); left: 3px;"
/>
</div>
</label>
</div>
<input
data-testid="add-snap-account-toggle"
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px;"
type="checkbox"
value="false"
/>
</div>
<div
class="toggle-button__status"
>
<span
class="toggle-button__label-off"
/>
<span
class="toggle-button__label-on"
/>
</div>
</label>
</div>
<h6
class="mm-box mm-text mm-text--body-sm mm-box--margin-top-0 mm-box--color-text-alternative"
Expand Down
29 changes: 14 additions & 15 deletions ui/pages/settings/experimental-tab/experimental-tab.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,20 @@ export default class ExperimentalTab extends PureComponent {
>
{t('addSnapAccountToggle')}
</Text>
<Box data-testid="add-snap-account-toggle">
<ToggleButton
value={addSnapAccountEnabled}
onToggle={(value) => {
trackEvent({
event: MetaMetricsEventName.AddSnapAccountEnabled,
category: MetaMetricsEventCategory.Settings,
properties: {
enabled: !value,
},
});
setAddSnapAccountEnabled(!value);
}}
/>
</Box>
<ToggleButton
dataTestId="add-snap-account-toggle"
value={addSnapAccountEnabled}
onToggle={(value) => {
trackEvent({
event: MetaMetricsEventName.AddSnapAccountEnabled,
category: MetaMetricsEventCategory.Settings,
properties: {
enabled: !value,
},
});
setAddSnapAccountEnabled(!value);
}}
/>
</div>
<Text
variant={TextVariant.bodySm}
Expand Down
19 changes: 18 additions & 1 deletion ui/pages/settings/experimental-tab/experimental-tab.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { fireEvent, renderWithProvider } from '../../../../test/jest';
import { fireEvent, renderWithProvider, waitFor } from '../../../../test/jest';
import configureStore from '../../../store/store';
import mockState from '../../../../test/data/mock-state.json';
import { LegacyMetaMetricsProvider } from '../../../contexts/metametrics';
Expand Down Expand Up @@ -86,4 +86,21 @@ describe('ExperimentalTab', () => {
expect(setTransactionSecurityCheckEnabled).toHaveBeenCalledWith(true);
expect(setSecurityAlertsEnabled).toHaveBeenCalledWith(false);
});

it('should enable add account snap', async () => {
const setAddSnapAccountEnabled = jest.fn();
const { getByTestId } = render(
{ desktopEnabled: true },
{
setAddSnapAccountEnabled,
},
);

const toggle = getByTestId('add-snap-account-toggle');
fireEvent.click(toggle);

await waitFor(() => {
expect(setAddSnapAccountEnabled).toHaveBeenCalledWith(true);
});
});
});

0 comments on commit 74a9a5d

Please sign in to comment.