Skip to content

Commit

Permalink
Revert "Revert "feat: codefence Account Watcher for flask (#27543)""
Browse files Browse the repository at this point in the history
This reverts commit 7c6fc74.
  • Loading branch information
MajorLift committed Oct 28, 2024
1 parent 06880d7 commit bae0053
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 28 deletions.
4 changes: 4 additions & 0 deletions app/scripts/controllers/preferences-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ export type PreferencesControllerState = Omit<
use4ByteResolution: boolean;
useCurrencyRateCheck: boolean;
useRequestQueue: boolean;
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
watchEthereumAccountEnabled: boolean;
///: END:ONLY_INCLUDE_IF
bitcoinSupportEnabled: boolean;
bitcoinTestnetSupportEnabled: boolean;
addSnapAccountEnabled?: boolean;
Expand Down Expand Up @@ -651,6 +653,7 @@ export class PreferencesController extends BaseController<
}
///: END:ONLY_INCLUDE_IF

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
/**
* Setter for the `watchEthereumAccountEnabled` property.
*
Expand All @@ -662,6 +665,7 @@ export class PreferencesController extends BaseController<
state.watchEthereumAccountEnabled = watchEthereumAccountEnabled;
});
}
///: END:ONLY_INCLUDE_IF

/**
* Setter for the `bitcoinSupportEnabled` property.
Expand Down
2 changes: 2 additions & 0 deletions app/scripts/lib/snap-keyring/account-watcher-snap.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// BEGIN:ONLY_INCLUDE_IF(build-flask)
import { SnapId } from '@metamask/snaps-sdk';
import AccountWatcherSnap from '@metamask/account-watcher/dist/preinstalled-snap.json';

Expand All @@ -6,3 +7,4 @@ export const ACCOUNT_WATCHER_SNAP_ID: SnapId =

export const ACCOUNT_WATCHER_NAME: string =
AccountWatcherSnap.manifest.proposedName;
// END:ONLY_INCLUDE_IF
2 changes: 2 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3313,10 +3313,12 @@ export default class MetamaskController extends EventEmitter {
preferencesController,
),
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
setWatchEthereumAccountEnabled:
preferencesController.setWatchEthereumAccountEnabled.bind(
preferencesController,
),
///: END:ONLY_INCLUDE_IF
setBitcoinSupportEnabled:
preferencesController.setBitcoinSupportEnabled.bind(
preferencesController,
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/snaps/preinstalled-snaps.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PreinstalledSnap } from '@metamask/snaps-controllers';
import MessageSigningSnap from '@metamask/message-signing-snap/dist/preinstalled-snap.json';
import EnsResolverSnap from '@metamask/ens-resolver-snap/dist/preinstalled-snap.json';
import AccountWatcherSnap from '@metamask/account-watcher/dist/preinstalled-snap.json';
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
import AccountWatcherSnap from '@metamask/account-watcher/dist/preinstalled-snap.json';
import BitcoinWalletSnap from '@metamask/bitcoin-wallet-snap/dist/preinstalled-snap.json';
import PreinstalledExampleSnap from '@metamask/preinstalled-example-snap/dist/preinstalled-snap.json';
///: END:ONLY_INCLUDE_IF
Expand All @@ -11,8 +11,8 @@ import PreinstalledExampleSnap from '@metamask/preinstalled-example-snap/dist/pr
const PREINSTALLED_SNAPS = Object.freeze<PreinstalledSnap[]>([
MessageSigningSnap as unknown as PreinstalledSnap,
EnsResolverSnap as PreinstalledSnap,
AccountWatcherSnap as PreinstalledSnap,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
AccountWatcherSnap as PreinstalledSnap,
BitcoinWalletSnap as unknown as PreinstalledSnap,
PreinstalledExampleSnap as unknown as PreinstalledSnap,
///: END:ONLY_INCLUDE_IF
Expand Down
2 changes: 2 additions & 0 deletions shared/constants/metametrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,9 @@ export enum MetaMetricsEventName {
WalletSetupCanceled = 'Wallet Setup Canceled',
WalletSetupFailed = 'Wallet Setup Failed',
WalletCreated = 'Wallet Created',
// BEGIN:ONLY_INCLUDE_IF(build-flask)
WatchEthereumAccountsToggled = 'Watch Ethereum Accounts Toggled',
// END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
DeeplinkClicked = 'Deeplink Clicked',
ConnectCustodialAccountClicked = 'Connect Custodial Account Clicked',
Expand Down
File renamed without changes.
51 changes: 28 additions & 23 deletions ui/components/multichain/account-list-menu/account-list-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ import {
getIsAddSnapAccountEnabled,
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
getIsWatchEthereumAccountEnabled,
getIsBitcoinSupportEnabled,
getIsBitcoinTestnetSupportEnabled,
///: END:ONLY_INCLUDE_IF
getMetaMaskAccountsOrdered,
getOriginOfCurrentTab,
getSelectedInternalAccount,
getUpdatedAndSortedAccounts,
getIsWatchEthereumAccountEnabled,
} from '../../../selectors';
import { setSelectedAccount } from '../../../store/actions';
import {
Expand All @@ -87,6 +87,12 @@ import { getEnvironmentType } from '../../../../app/scripts/lib/util';
import { ENVIRONMENT_TYPE_POPUP } from '../../../../shared/constants/app';
import { getAccountLabel } from '../../../helpers/utils/accounts';
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
import {
ACCOUNT_WATCHER_NAME,
ACCOUNT_WATCHER_SNAP_ID,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../../app/scripts/lib/snap-keyring/account-watcher-snap';
import {
hasCreatedBtcMainnetAccount,
hasCreatedBtcTestnetAccount,
Expand All @@ -100,12 +106,6 @@ import {
MergedInternalAccount,
} from '../../../selectors/selectors.types';
import { trace, endTrace, TraceName } from '../../../../shared/lib/trace';
import {
ACCOUNT_WATCHER_NAME,
ACCOUNT_WATCHER_SNAP_ID,
// TODO: Remove restricted import
// eslint-disable-next-line import/no-restricted-paths
} from '../../../../app/scripts/lib/snap-keyring/account-watcher-snap';
import { HiddenAccountList } from './hidden-account-list';

const ACTION_MODES = {
Expand All @@ -115,9 +115,9 @@ const ACTION_MODES = {
MENU: 'menu',
// Displays the add account form controls
ADD: 'add',
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
// Displays the add account form controls (for watch-only account)
ADD_WATCH_ONLY: 'add-watch-only',
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
// Displays the add account form controls (for bitcoin account)
ADD_BITCOIN: 'add-bitcoin',
// Same but for testnet
Expand All @@ -141,9 +141,9 @@ export const getActionTitle = (
switch (actionMode) {
case ACTION_MODES.ADD:
case ACTION_MODES.MENU:
case ACTION_MODES.ADD_WATCH_ONLY:
return t('addAccount');
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
case ACTION_MODES.ADD_WATCH_ONLY:
case ACTION_MODES.ADD_BITCOIN:
return t('addAccount');
case ACTION_MODES.ADD_BITCOIN_TESTNET:
Expand Down Expand Up @@ -237,6 +237,7 @@ export const AccountListMenu = ({
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
const addSnapAccountEnabled = useSelector(getIsAddSnapAccountEnabled);
///: END:ONLY_INCLUDE_IF
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
const isAddWatchEthereumAccountEnabled = useSelector(
getIsWatchEthereumAccountEnabled,
);
Expand All @@ -254,7 +255,7 @@ export const AccountListMenu = ({
onClose();
history.push(`/snaps/view/${encodeURIComponent(ACCOUNT_WATCHER_SNAP_ID)}`);
}, [trackEvent, onClose, history]);
///: BEGIN:ONLY_INCLUDE_IF(build-flask)

const bitcoinSupportEnabled = useSelector(getIsBitcoinSupportEnabled);
const bitcoinTestnetSupportEnabled = useSelector(
getIsBitcoinTestnetSupportEnabled,
Expand Down Expand Up @@ -554,19 +555,23 @@ export const AccountListMenu = ({
</Box>
///: END:ONLY_INCLUDE_IF
}
{isAddWatchEthereumAccountEnabled && (
<Box marginTop={4}>
<ButtonLink
disabled={!isAddWatchEthereumAccountEnabled}
size={ButtonLinkSize.Sm}
startIconName={IconName.Eye}
onClick={handleAddWatchAccount}
data-testid="multichain-account-menu-popover-add-watch-only-account"
>
{t('addEthereumWatchOnlyAccount')}
</ButtonLink>
</Box>
)}
{
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
isAddWatchEthereumAccountEnabled && (
<Box marginTop={4}>
<ButtonLink
disabled={!isAddWatchEthereumAccountEnabled}
size={ButtonLinkSize.Sm}
startIconName={IconName.Eye}
onClick={handleAddWatchAccount}
data-testid="multichain-account-menu-popover-add-watch-only-account"
>
{t('addEthereumWatchOnlyAccount')}
</ButtonLink>
</Box>
)
///: END:ONLY_INCLUDE_IF
}
</Box>
) : null}
{actionMode === ACTION_MODES.LIST ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export default class ExperimentalTab extends PureComponent<ExperimentalTabProps>
});
}

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
renderWatchAccountToggle() {
const { t, trackEvent } = this.context;
const { watchAccountEnabled, setWatchAccountEnabled } = this.props;
Expand Down Expand Up @@ -297,7 +298,6 @@ export default class ExperimentalTab extends PureComponent<ExperimentalTabProps>
});
}

///: BEGIN:ONLY_INCLUDE_IF(build-flask)
// We're only setting the code fences here since
// we should remove it for the feature release
renderBitcoinSupport() {
Expand Down Expand Up @@ -385,12 +385,15 @@ export default class ExperimentalTab extends PureComponent<ExperimentalTabProps>
this.renderKeyringSnapsToggle()
///: END:ONLY_INCLUDE_IF
}
{this.renderWatchAccountToggle()}
{
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
this.renderWatchAccountToggle()
///: END:ONLY_INCLUDE_IF
}
{
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
// We're only setting the code fences here since
// we should remove it for the feature release

/* Section: Bitcoin Accounts */
this.renderBitcoinSupport()
///: END:ONLY_INCLUDE_IF
Expand Down

0 comments on commit bae0053

Please sign in to comment.