Skip to content

Commit

Permalink
chore: initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
zone-live committed Oct 30, 2024
1 parent 54b110a commit ba54e2e
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 0 deletions.
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.

3 changes: 3 additions & 0 deletions app/scripts/constants/sentry-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ export const SENTRY_UI_STATE = {
switchedNetworkNeverShowMessage: false,
newPrivacyPolicyToastClickedOrClosed: false,
newPrivacyPolicyToastShownDate: false,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
solanaSupportEnabled: false,
///: END:ONLY_INCLUDE_IF
},
unconnectedAccount: true,
};
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
59 changes: 59 additions & 0 deletions ui/pages/settings/experimental-tab/experimental-tab.component.tsx
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,56 @@ 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"
href={SurveyUrl.BtcSupport}
target="_blank"
rel="noopener noreferrer"
>
{t('form')}
</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 +452,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
13 changes: 13 additions & 0 deletions ui/pages/settings/experimental-tab/experimental-tab.container.ts
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,10 @@ 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
17 changes: 17 additions & 0 deletions ui/pages/settings/experimental-tab/experimental-tab.test.js
Original file line number Diff line number Diff line change
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

0 comments on commit ba54e2e

Please sign in to comment.