Skip to content

Commit

Permalink
Merge branch 'brian/token-balances-controller' of github.com:MetaMask…
Browse files Browse the repository at this point in the history
…/metamask-extension into brian/token-balances-controller
  • Loading branch information
bergeron committed Nov 4, 2024
2 parents bb1d6bf + 69404a5 commit f6e56b3
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 1 deletion.
9 changes: 9 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 @@ -853,4 +853,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 @@ -140,6 +140,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 @@ -184,6 +185,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 @@ -340,6 +344,10 @@ const controllerMetadata = {
persist: true,
anonymous: false,
},
solanaSupportEnabled: {
persist: true,
anonymous: false,
},
bitcoinSupportEnabled: {
persist: true,
anonymous: false,
Expand Down Expand Up @@ -669,6 +677,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 @@ -3342,6 +3342,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
4 changes: 4 additions & 0 deletions ui/components/multichain/network-list-item/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
&__delete {
visibility: hidden;
}

&__rpc-endpoint {
max-width: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export const NetworkListItem = ({
as="button"
variant={TextVariant.bodySmMedium}
color={TextColor.textAlternative}
ellipsis
>
{rpcEndpoint.name ?? new URL(rpcEndpoint.url).host}
</Text>
Expand Down
47 changes: 47 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,44 @@ 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'),
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 +440,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
12 changes: 12 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,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 @@ -2364,6 +2364,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 @@ -5022,6 +5022,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 f6e56b3

Please sign in to comment.