Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds the experimental toggle for Solana #28190

Merged
merged 5 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions app/scripts/controllers/preferences-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,4 +849,19 @@ describe('preferences controller', () => {
);
});
});

describe('setSolanaSupportEnabled', () => {
const { controller } = setupController({});
it('has the default value as false', () => {
expect(controller.state.solanaSupportEnabled).toStrictEqual(false);
});

it('sets the solanaSupportEnabled property in state to true and then false', () => {
controller.setSolanaSupportEnabled(true);
expect(controller.state.solanaSupportEnabled).toStrictEqual(true);

controller.setSolanaSupportEnabled(false);
expect(controller.state.solanaSupportEnabled).toStrictEqual(false);
});
});
});
20 changes: 20 additions & 0 deletions app/scripts/controllers/preferences-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export type PreferencesControllerState = Omit<
useRequestQueue: boolean;
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
watchEthereumAccountEnabled: boolean;
solanaSupportEnabled: boolean;
///: END:ONLY_INCLUDE_IF
bitcoinSupportEnabled: boolean;
bitcoinTestnetSupportEnabled: boolean;
Expand Down Expand Up @@ -182,6 +183,9 @@ export const getDefaultPreferencesControllerState =
openSeaEnabled: true,
securityAlertsEnabled: true,
watchEthereumAccountEnabled: false,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
solanaSupportEnabled: false,
///: END:ONLY_INCLUDE_IF
bitcoinSupportEnabled: false,
bitcoinTestnetSupportEnabled: false,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
Expand Down Expand Up @@ -336,6 +340,10 @@ const controllerMetadata = {
persist: true,
anonymous: false,
},
solanaSupportEnabled: {
persist: true,
anonymous: false,
},
bitcoinSupportEnabled: {
persist: true,
anonymous: false,
Expand Down Expand Up @@ -665,6 +673,18 @@ export class PreferencesController extends BaseController<
state.watchEthereumAccountEnabled = watchEthereumAccountEnabled;
});
}

/**
* Setter for the `solanaSupportEnabled` property.
*
* @param solanaSupportEnabled - Whether or not the user wants to
* enable the "Add a new Solana account" button.
*/
setSolanaSupportEnabled(solanaSupportEnabled: boolean): void {
this.update((state) => {
state.solanaSupportEnabled = solanaSupportEnabled;
});
}
///: END:ONLY_INCLUDE_IF

/**
Expand Down
4 changes: 4 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,10 @@ export default class MetamaskController extends EventEmitter {
preferencesController.setWatchEthereumAccountEnabled.bind(
preferencesController,
),
setSolanaSupportEnabled:
preferencesController.setSolanaSupportEnabled.bind(
preferencesController,
),
///: END:ONLY_INCLUDE_IF
setBitcoinSupportEnabled:
preferencesController.setBitcoinSupportEnabled.bind(
Expand Down
1 change: 1 addition & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,7 @@ export enum MetaMetricsEventName {
BridgeLinkClicked = 'Bridge Link Clicked',
BitcoinSupportToggled = 'Bitcoin Support Toggled',
BitcoinTestnetSupportToggled = 'Bitcoin Testnet Support Toggled',
SolanaSupportToggled = 'Solana Support Toggled',
CurrentCurrency = 'Current Currency',
DappViewed = 'Dapp Viewed',
DecryptionApproved = 'Decryption Approved',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ import { SurveyUrl } from '../../../../shared/constants/urls';
type ExperimentalTabProps = {
watchAccountEnabled: boolean;
setWatchAccountEnabled: (value: boolean) => void;
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
solanaSupportEnabled: boolean;
setSolanaSupportEnabled: (value: boolean) => void;
///: END:ONLY_INCLUDE_IF
bitcoinSupportEnabled: boolean;
setBitcoinSupportEnabled: (value: boolean) => void;
bitcoinTestnetSupportEnabled: boolean;
Expand Down Expand Up @@ -369,6 +373,53 @@ export default class ExperimentalTab extends PureComponent<ExperimentalTabProps>
</>
);
}

renderSolanaSupport() {
const { t, trackEvent } = this.context;
const { solanaSupportEnabled, setSolanaSupportEnabled } = this.props;

return (
<>
<Text
variant={TextVariant.headingSm}
as="h4"
color={TextColor.textAlternative}
marginBottom={2}
fontWeight={FontWeight.Bold}
>
{t('solanaSupportSectionTitle')}
</Text>
{this.renderToggleSection({
title: t('solanaSupportToggleTitle'),
description: t('solanaSupportToggleDescription', [
<a
key="btc-account-feedback-form__link-text"
zone-live marked this conversation as resolved.
Show resolved Hide resolved
href={SurveyUrl.BtcSupport}
target="_blank"
rel="noopener noreferrer"
>
{t('form')}
zone-live marked this conversation as resolved.
Show resolved Hide resolved
</a>,
]),
toggleValue: solanaSupportEnabled,
toggleCallback: (value) => {
trackEvent({
event: MetaMetricsEventName.SolanaSupportToggled,
category: MetaMetricsEventCategory.Settings,
properties: {
enabled: !value,
},
});
setSolanaSupportEnabled(!value);
},
toggleContainerDataTestId: 'solana-support-toggle-div',
toggleDataTestId: 'solana-support-toggle',
toggleOffLabel: t('off'),
toggleOnLabel: t('on'),
})}
</>
);
}
///: END:ONLY_INCLUDE_IF

render() {
Expand Down Expand Up @@ -398,6 +449,11 @@ export default class ExperimentalTab extends PureComponent<ExperimentalTabProps>
this.renderBitcoinSupport()
///: END:ONLY_INCLUDE_IF
}
{
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
this.renderSolanaSupport()
///: END:ONLY_INCLUDE_IF
}
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ import {
setRedesignedConfirmationsEnabled,
setRedesignedTransactionsEnabled,
setWatchEthereumAccountEnabled,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
setSolanaSupportEnabled,
///: END:ONLY_INCLUDE_IF
} from '../../../store/actions';
import {
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
getIsSolanaSupportEnabled,
///: END:ONLY_INCLUDE_IF
getIsBitcoinSupportEnabled,
getIsBitcoinTestnetSupportEnabled,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
Expand All @@ -37,6 +43,9 @@ const mapStateToProps = (state: MetaMaskReduxState) => {
const petnamesEnabled = getPetnamesEnabled(state);
const featureNotificationsEnabled = getFeatureNotificationsEnabled(state);
return {
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
solanaSupportEnabled: getIsSolanaSupportEnabled(state),
///: END:ONLY_INCLUDE_IF
watchAccountEnabled: getIsWatchEthereumAccountEnabled(state),
bitcoinSupportEnabled: getIsBitcoinSupportEnabled(state),
bitcoinTestnetSupportEnabled: getIsBitcoinTestnetSupportEnabled(state),
Expand All @@ -55,6 +64,9 @@ const mapDispatchToProps = (dispatch: MetaMaskReduxDispatch) => {
return {
setWatchAccountEnabled: (value: boolean) =>
setWatchEthereumAccountEnabled(value),
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
setSolanaSupportEnabled: (value: boolean) => setSolanaSupportEnabled(value),
///: END:ONLY_INCLUDE_IF
setBitcoinSupportEnabled: (value: boolean) =>
setBitcoinSupportEnabled(value),
setBitcoinTestnetSupportEnabled: (value: boolean) =>
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
Expand Up @@ -30,7 +30,7 @@ describe('ExperimentalTab', () => {
const { getAllByRole } = render();
const toggle = getAllByRole('checkbox');

expect(toggle).toHaveLength(8);
expect(toggle).toHaveLength(9);
});

it('enables add account snap', async () => {
Expand Down Expand Up @@ -108,4 +108,21 @@ describe('ExperimentalTab', () => {
expect(setBitcoinSupportEnabled).toHaveBeenNthCalledWith(1, true);
});
});

it('enables the experimental solana account feature', async () => {
const setSolanaSupportEnabled = jest.fn();
const { getByTestId } = render(
{},
{
setSolanaSupportEnabled,
solanaSupportEnabled: false,
},
);
const toggle = getByTestId('solana-support-toggle');

fireEvent.click(toggle);
await waitFor(() => {
expect(setSolanaSupportEnabled).toHaveBeenNthCalledWith(1, true);
});
});
});
12 changes: 12 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2334,6 +2334,18 @@ export function getIsBitcoinSupportEnabled(state) {
return state.metamask.bitcoinSupportEnabled;
}

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
/**
* Get the state of the `solanaSupportEnabled` flag.
*
* @param {*} state
* @returns The state of the `solanaSupportEnabled` flag.
*/
export function getIsSolanaSupportEnabled(state) {
return state.metamask.solanaSupportEnabled;
}
///: END:ONLY_INCLUDE_IF

/**
* Get the state of the `bitcoinTestnetSupportEnabled` flag.
*
Expand Down
10 changes: 10 additions & 0 deletions ui/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4963,6 +4963,16 @@ export async function setBitcoinTestnetSupportEnabled(value: boolean) {
}
}

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
export async function setSolanaSupportEnabled(value: boolean) {
try {
await submitRequestToBackground('setSolanaSupportEnabled', [value]);
} catch (error) {
logErrorWithMessage(error);
}
}
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
export async function setAddSnapAccountEnabled(value: boolean): Promise<void> {
try {
Expand Down