1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Move desktop code to flask build type (#17960)

This commit is contained in:
Matthew Walsh 2023-03-06 19:35:00 +00:00 committed by GitHub
parent e77e20d8c4
commit d0417da3d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 163 additions and 147 deletions

View File

@ -56,7 +56,7 @@ import { deferredPromise, getPlatform } from './lib/util';
/* eslint-enable import/first */
/* eslint-disable import/order */
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import {
CONNECTION_TYPE_EXTERNAL,
CONNECTION_TYPE_INTERNAL,
@ -107,7 +107,7 @@ const PHISHING_WARNING_PAGE_TIMEOUT = ONE_SECOND_IN_MILLISECONDS;
const ACK_KEEP_ALIVE_MESSAGE = 'ACK_KEEP_ALIVE_MESSAGE';
const WORKER_KEEP_ALIVE_MESSAGE = 'WORKER_KEEP_ALIVE_MESSAGE';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
const OVERRIDE_ORIGIN = {
EXTENSION: 'EXTENSION',
DESKTOP: 'DESKTOP_APP',
@ -263,7 +263,7 @@ async function initialize() {
const initState = await loadStateFromPersistence();
const initLangCode = await getFirstPreferredLangCode();
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
await DesktopManager.init(platform.getVersion());
///: END:ONLY_INCLUDE_IN
@ -503,7 +503,7 @@ export function setupController(initState, initLangCode, overrides) {
* @param {Port} remotePort - The port provided by a new context.
*/
connectRemote = async (remotePort) => {
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (
DesktopManager.isDesktopEnabled() &&
OVERRIDE_ORIGIN.DESKTOP !== overrides?.getOrigin?.()
@ -625,7 +625,7 @@ export function setupController(initState, initLangCode, overrides) {
// communication with page or other extension
connectExternal = (remotePort) => {
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (
DesktopManager.isDesktopEnabled() &&
OVERRIDE_ORIGIN.DESKTOP !== overrides?.getOrigin?.()
@ -814,7 +814,7 @@ export function setupController(initState, initLangCode, overrides) {
updateBadge();
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (OVERRIDE_ORIGIN.DESKTOP !== overrides?.getOrigin?.()) {
controller.store.subscribe((state) => {
DesktopManager.setState(state);

View File

@ -716,7 +716,7 @@ export default class MetaMetricsController {
[TRAITS.THREE_BOX_ENABLED]: false, // deprecated, hard-coded as false
[TRAITS.THEME]: metamaskState.theme || 'default',
[TRAITS.TOKEN_DETECTION_ENABLED]: metamaskState.useTokenDetection,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
[TRAITS.DESKTOP_ENABLED]: metamaskState.desktopEnabled || false,
///: END:ONLY_INCLUDE_IN
};

View File

@ -113,6 +113,8 @@ import { isManifestV3 } from '../../shared/modules/mv3.utils';
import { hexToDecimal } from '../../shared/modules/conversion.utils';
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { isMain, isFlask } from '../../shared/constants/environment';
// eslint-disable-next-line import/order
import { DesktopController } from '@metamask/desktop/dist/controllers/desktop';
///: END:ONLY_INCLUDE_IN
import {
onMessageReceived,
@ -175,16 +177,6 @@ import {
import createRPCMethodTrackingMiddleware from './lib/createRPCMethodTrackingMiddleware';
import { securityProviderCheck } from './lib/security-provider-helpers';
/* eslint-disable import/first */
/* eslint-disable import/order */
///: BEGIN:ONLY_INCLUDE_IN(desktop)
import { DesktopController } from '@metamask/desktop/dist/controllers/desktop';
///: END:ONLY_INCLUDE_IN
/* eslint-enable import/first */
/* eslint-enable import/order */
export const METAMASK_CONTROLLER_EVENTS = {
// Fired after state changes that impact the extension badge (unapproved msg count)
// The process of updating the badge happens in app/scripts/background.js.
@ -868,6 +860,10 @@ export default class MetamaskController extends EventEmitter {
state: initState.CronjobController,
messenger: cronjobControllerMessenger,
});
this.desktopController = new DesktopController({
initState: initState.DesktopController,
});
///: END:ONLY_INCLUDE_IN
this.detectTokensController = new DetectTokensController({
@ -1121,12 +1117,6 @@ export default class MetamaskController extends EventEmitter {
initState.SmartTransactionsController,
);
///: BEGIN:ONLY_INCLUDE_IN(desktop)
this.desktopController = new DesktopController({
initState: initState.DesktopController,
});
///: END:ONLY_INCLUDE_IN
// ensure accountTracker updates balances after network change
this.networkController.on(NETWORK_EVENTS.NETWORK_DID_CHANGE, () => {
this.accountTracker._updateAccounts();
@ -1233,8 +1223,6 @@ export default class MetamaskController extends EventEmitter {
SnapController: this.snapController,
CronjobController: this.cronjobController,
NotificationController: this.notificationController,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
DesktopController: this.desktopController.store,
///: END:ONLY_INCLUDE_IN
...resetOnRestartStore,
@ -1268,8 +1256,6 @@ export default class MetamaskController extends EventEmitter {
SnapController: this.snapController,
CronjobController: this.cronjobController,
NotificationController: this.notificationController,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
DesktopController: this.desktopController.store,
///: END:ONLY_INCLUDE_IN
...resetOnRestartStore,
@ -2038,6 +2024,22 @@ export default class MetamaskController extends EventEmitter {
),
dismissNotifications: this.dismissNotifications.bind(this),
markNotificationsAsRead: this.markNotificationsAsRead.bind(this),
// Desktop
getDesktopEnabled: this.desktopController.getDesktopEnabled.bind(
this.desktopController,
),
setDesktopEnabled: this.desktopController.setDesktopEnabled.bind(
this.desktopController,
),
generateDesktopOtp: this.desktopController.generateOtp.bind(
this.desktopController,
),
testDesktopConnection: this.desktopController.testDesktopConnection.bind(
this.desktopController,
),
disableDesktop: this.desktopController.disableDesktop.bind(
this.desktopController,
),
///: END:ONLY_INCLUDE_IN
// swaps
@ -2178,24 +2180,6 @@ export default class MetamaskController extends EventEmitter {
assetsContractController.getBalancesInSingleCall.bind(
assetsContractController,
),
///: BEGIN:ONLY_INCLUDE_IN(desktop)
getDesktopEnabled: this.desktopController.getDesktopEnabled.bind(
this.desktopController,
),
setDesktopEnabled: this.desktopController.setDesktopEnabled.bind(
this.desktopController,
),
generateOtp: this.desktopController.generateOtp.bind(
this.desktopController,
),
testDesktopConnection: this.desktopController.testDesktopConnection.bind(
this.desktopController,
),
disableDesktop: this.desktopController.disableDesktop.bind(
this.desktopController,
),
///: END:ONLY_INCLUDE_IN
};
}
@ -4035,11 +4019,6 @@ export default class MetamaskController extends EventEmitter {
this.alertController.setWeb3ShimUsageRecorded.bind(
this.alertController,
),
///: BEGIN:ONLY_INCLUDE_IN(desktop)
testDesktopConnection: this.desktopController.testDesktopConnection,
generateOtp: this.desktopController.generateOtp,
///: END:ONLY_INCLUDE_IN
}),
);

View File

@ -22,7 +22,7 @@ import { checkForLastErrorAndLog } from '../../shared/modules/browser-runtime.ut
import { SUPPORT_LINK } from '../../shared/lib/ui-utils';
import {
getErrorHtml,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
registerDesktopErrorActions,
///: END:ONLY_INCLUDE_IN
} from '../../shared/lib/error-utils';
@ -264,7 +264,7 @@ async function start() {
(
err,
store,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
backgroundConnection,
///: END:ONLY_INCLUDE_IN
) => {
@ -274,7 +274,7 @@ async function start() {
'troubleStarting',
err,
store,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
backgroundConnection,
///: END:ONLY_INCLUDE_IN
);
@ -302,7 +302,7 @@ async function start() {
displayCriticalError(
'troubleStarting',
err,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
undefined,
backgroundConnection,
///: END:ONLY_INCLUDE_IN
@ -345,7 +345,7 @@ function initializeUi(activeTab, connectionStream, cb) {
cb(
err,
null,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
backgroundConnection,
///: END:ONLY_INCLUDE_IN
);
@ -367,7 +367,7 @@ async function displayCriticalError(
errorKey,
err,
metamaskState,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
backgroundConnection,
///: END:ONLY_INCLUDE_IN
) {
@ -375,14 +375,14 @@ async function displayCriticalError(
errorKey,
SUPPORT_LINK,
metamaskState,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
err,
///: END:ONLY_INCLUDE_IN
);
container.innerHTML = html;
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
registerDesktopErrorActions(backgroundConnection, browser);
///: END:ONLY_INCLUDE_IN

View File

@ -814,6 +814,60 @@
"fetch": true
}
},
"@metamask/desktop": {
"globals": {
"TextDecoder": true,
"TextEncoder": true,
"WebSocket": true,
"clearInterval": true,
"clearTimeout": true,
"crypto.getRandomValues": true,
"crypto.subtle.decrypt": true,
"crypto.subtle.digest": true,
"crypto.subtle.encrypt": true,
"crypto.subtle.exportKey": true,
"crypto.subtle.generateKey": true,
"crypto.subtle.importKey": true,
"isDesktopApp": true,
"setInterval": true,
"setTimeout": true
},
"packages": {
"@metamask/desktop>eciesjs": true,
"@metamask/desktop>otpauth": true,
"@metamask/obs-store": true,
"browserify>buffer": true,
"browserify>events": true,
"browserify>process": true,
"browserify>stream-browserify": true,
"end-of-stream": true,
"extension-port-stream": true,
"loglevel": true,
"obj-multiplex": true,
"uuid": true,
"webextension-polyfill": true
}
},
"@metamask/desktop>eciesjs": {
"packages": {
"@metamask/desktop>eciesjs>futoin-hkdf": true,
"browserify>buffer": true,
"browserify>crypto-browserify": true,
"ethereumjs-util>ethereum-cryptography>secp256k1": true
}
},
"@metamask/desktop>eciesjs>futoin-hkdf": {
"packages": {
"browserify>buffer": true,
"browserify>crypto-browserify": true
}
},
"@metamask/desktop>otpauth": {
"globals": {
"__GLOBALTHIS__": true,
"define": true
}
},
"@metamask/eth-json-rpc-infura": {
"globals": {
"setTimeout": true

View File

@ -61,9 +61,6 @@ export const MESSAGE_TYPE = {
SNAP_DIALOG_CONFIRMATION: `${RestrictedMethods.snap_dialog}:confirmation`,
SNAP_DIALOG_PROMPT: `${RestrictedMethods.snap_dialog}:prompt`,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
ENABLE_DESKTOP: `metamask_enableDesktop`,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(mmi)
MMI_AUTHENTICATE: 'metamaskinstitutional_authenticate',
MMI_REAUTHENTICATE: 'metamaskinstitutional_reauthenticate',

View File

@ -1,4 +1,4 @@
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import browser from 'webextension-polyfill';
///: END:ONLY_INCLUDE_IN
import { memoize } from 'lodash';
@ -7,7 +7,7 @@ import {
fetchLocale,
loadRelativeTimeFormatLocaleData,
} from '../../ui/helpers/utils/i18n-helper';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { renderDesktopError } from '../../ui/pages/desktop-error/render-desktop-error';
import { EXTENSION_ERROR_PAGE_TYPES } from '../constants/desktop';
import { openCustomProtocol } from './deep-linking';
@ -44,7 +44,7 @@ export async function getErrorHtml(
errorKey,
supportLink,
metamaskState,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
err,
///: END:ONLY_INCLUDE_IN
) {
@ -65,7 +65,7 @@ export async function getErrorHtml(
const { currentLocaleMessages, enLocaleMessages } = response;
const t = getLocaleContext(currentLocaleMessages, enLocaleMessages);
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
const isDesktopEnabled = metamaskState?.desktopEnabled === true;
if (isDesktopEnabled) {
@ -120,7 +120,7 @@ export async function getErrorHtml(
`;
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
function disableDesktop(backgroundConnection) {
backgroundConnection.disableDesktopError();
}

View File

@ -26,14 +26,12 @@ export default class AppHeader extends PureComponent {
isAccountMenuOpen: PropTypes.bool,
///: BEGIN:ONLY_INCLUDE_IN(flask)
unreadNotificationsCount: PropTypes.number,
desktopEnabled: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
onClick: PropTypes.func,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
desktopEnabled: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
};
static contextTypes = {
@ -125,7 +123,7 @@ export default class AppHeader extends PureComponent {
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader,
///: END:ONLY_INCLUDE_IN(beta)
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
} = this.props;
@ -150,7 +148,7 @@ export default class AppHeader extends PureComponent {
}}
/>
{
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled && process.env.METAMASK_DEBUG && (
<div data-testid="app-header-desktop-dev-logo">
<MetaFoxLogo

View File

@ -20,7 +20,7 @@ const mapStateToProps = (state) => {
selectedAddress,
isUnlocked,
isAccountMenuOpen,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
} = metamask;
@ -40,13 +40,11 @@ const mapStateToProps = (state) => {
isAccountMenuOpen,
///: BEGIN:ONLY_INCLUDE_IN(flask)
unreadNotificationsCount,
desktopEnabled,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(beta)
showBetaHeader,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
};
};

View File

@ -8,7 +8,7 @@ export default class MetaFoxLogo extends PureComponent {
onClick: PropTypes.func,
unsetIconHeight: PropTypes.bool,
isOnboarding: PropTypes.bool,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
src: PropTypes.string,
///: END:ONLY_INCLUDE_IN
};
@ -22,7 +22,7 @@ export default class MetaFoxLogo extends PureComponent {
onClick,
unsetIconHeight,
isOnboarding,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
src,
///: END:ONLY_INCLUDE_IN
} = this.props;
@ -39,7 +39,7 @@ export default class MetaFoxLogo extends PureComponent {
let imageSrc = './images/logo/metamask-fox.svg';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (src) {
renderHorizontalLogo = () => (
<img

View File

@ -166,7 +166,7 @@ export default function reduceMetamask(state = initialState, action) {
};
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
case actionConstants.FORCE_DISABLE_DESKTOP: {
return {
...metamaskState,

View File

@ -70,6 +70,8 @@ const ONBOARDING_METAMETRICS = '/onboarding/metametrics';
///: BEGIN:ONLY_INCLUDE_IN(flask)
const INITIALIZE_EXPERIMENTAL_AREA = '/initialize/experimental-area';
const ONBOARDING_EXPERIMENTAL_AREA = '/onboarding/experimental-area';
const DESKTOP_ERROR_ROUTE = '/desktop/error';
const DESKTOP_PAIRING_ROUTE = '/desktop-pairing';
///: END:ONLY_INCLUDE_IN
const CONFIRM_TRANSACTION_ROUTE = '/confirm-transaction';
@ -85,10 +87,6 @@ const SIGNATURE_REQUEST_PATH = '/signature-request';
const DECRYPT_MESSAGE_REQUEST_PATH = '/decrypt-message-request';
const ENCRYPTION_PUBLIC_KEY_REQUEST_PATH = '/encryption-public-key-request';
const CONFIRMATION_V_NEXT_ROUTE = '/confirmation';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
const DESKTOP_ERROR_ROUTE = '/desktop/error';
const DESKTOP_PAIRING_ROUTE = '/desktop-pairing';
///: END:ONLY_INCLUDE_IN
// Used to pull a convenient name for analytics tracking events. The key must
// be react-router ready path, and can include params such as :id for popup windows
@ -245,8 +243,6 @@ export {
///: BEGIN:ONLY_INCLUDE_IN(flask)
INITIALIZE_EXPERIMENTAL_AREA,
ONBOARDING_EXPERIMENTAL_AREA,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
DESKTOP_ERROR_ROUTE,
DESKTOP_PAIRING_ROUTE,
///: END:ONLY_INCLUDE_IN

View File

@ -53,7 +53,7 @@ export const updateBackgroundConnection = (backgroundConnection) => {
export default function launchMetamaskUi(opts, cb) {
const { backgroundConnection } = opts;
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
let desktopEnabled = false;
backgroundConnection.getDesktopEnabled(function (err, result) {
@ -72,7 +72,7 @@ export default function launchMetamaskUi(opts, cb) {
err,
{
...metamaskState,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
},
@ -85,7 +85,7 @@ export default function launchMetamaskUi(opts, cb) {
cb(
null,
store,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
backgroundConnection,
///: END:ONLY_INCLUDE_IN
);

View File

@ -197,7 +197,7 @@ export function renderDesktopError({
);
break;
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
// This route only exists on the Desktop App
case EXTENSION_ERROR_PAGE_TYPES.ROUTE_NOT_FOUND:
content = (

View File

@ -18,7 +18,7 @@ import { useCopyToClipboard } from '../../hooks/useCopyToClipboard';
import Tooltip from '../../components/ui/tooltip';
export default function DesktopPairingPage({
generateOtp,
generateDesktopOtp,
mostRecentOverviewPage,
showLoadingIndication,
hideLoadingIndication,
@ -54,7 +54,7 @@ export default function DesktopPairingPage({
useEffect(() => {
const generate = async () => {
setLastOtpTime(new Date().getTime());
const OTP = await generateOtp();
const OTP = await generateDesktopOtp();
setOtp(OTP);
};
@ -71,7 +71,7 @@ export default function DesktopPairingPage({
clearInterval(generateIntervalRef.current);
clearInterval(refreshIntervalRef.current);
};
}, [OTP_DURATION, REFRESH_INTERVAL, generateOtp]);
}, [OTP_DURATION, REFRESH_INTERVAL, generateDesktopOtp]);
const renderIcon = () => {
return (
@ -186,5 +186,5 @@ DesktopPairingPage.propTypes = {
mostRecentOverviewPage: PropTypes.string,
showLoadingIndication: PropTypes.func,
hideLoadingIndication: PropTypes.func,
generateOtp: PropTypes.func,
generateDesktopOtp: PropTypes.func,
};

View File

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
generateOtp,
generateDesktopOtp,
hideLoadingIndication,
showLoadingIndication,
} from '../../store/actions';
@ -9,7 +9,7 @@ import DesktopPairingPage from './desktop-pairing.component';
const mapDispatchToProps = (dispatch) => {
return {
generateOtp: () => generateOtp(),
generateDesktopOtp: () => generateDesktopOtp(),
showLoadingIndication: () => dispatch(showLoadingIndication()),
hideLoadingIndication: () => dispatch(hideLoadingIndication()),
};

View File

@ -15,7 +15,7 @@ jest.mock('../../store/actions', () => {
return {
hideLoadingIndication: () => mockHideLoadingIndication,
showLoadingIndication: () => mockShowLoadingIndication,
generateOtp: jest.fn(),
generateDesktopOtp: jest.fn(),
};
});
@ -44,7 +44,7 @@ describe('Desktop Pairing page', () => {
it('should render otp component', async () => {
const otp = '123456';
mockedActions.generateOtp.mockResolvedValue(otp);
mockedActions.generateDesktopOtp.mockResolvedValue(otp);
const store = configureStore(mockState);
let container = null;
@ -65,7 +65,7 @@ describe('Desktop Pairing page', () => {
const otp = '123456';
const newOtp = '654321';
const neverGeneratedOTP = '111222';
mockedActions.generateOtp
mockedActions.generateDesktopOtp
.mockResolvedValueOnce(otp)
.mockResolvedValueOnce(newOtp)
.mockResolvedValueOnce(neverGeneratedOTP);
@ -81,7 +81,7 @@ describe('Desktop Pairing page', () => {
await flushPromises();
expect(screen.getByTestId('desktop-pairing-otp-content')).toBeDefined();
expect(screen.getByText(otp)).toBeDefined();
expect(mockedActions.generateOtp).toHaveBeenCalledTimes(1);
expect(mockedActions.generateDesktopOtp).toHaveBeenCalledTimes(1);
});
// Advance timers 30s to trigger next OTP
@ -91,7 +91,7 @@ describe('Desktop Pairing page', () => {
await flushPromises();
expect(screen.getByTestId('desktop-pairing-otp-content')).toBeDefined();
expect(screen.getByText(newOtp)).toBeDefined();
expect(mockedActions.generateOtp).toHaveBeenCalledTimes(2);
expect(mockedActions.generateDesktopOtp).toHaveBeenCalledTimes(2);
});
// Advance timers 10s to test that OTP is still the same
@ -101,7 +101,7 @@ describe('Desktop Pairing page', () => {
await flushPromises();
expect(screen.getByTestId('desktop-pairing-otp-content')).toBeDefined();
expect(screen.getByText(newOtp)).toBeDefined();
expect(mockedActions.generateOtp).toHaveBeenCalledTimes(2);
expect(mockedActions.generateDesktopOtp).toHaveBeenCalledTimes(2);
});
jest.clearAllTimers();

View File

@ -4,9 +4,9 @@ import React, { Component } from 'react';
import { matchPath, Route, Switch } from 'react-router-dom';
import IdleTimer from 'react-idle-timer';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import browserAPI from 'webextension-polyfill';
///: END:ONLY_INCLUDE_IN(desktop)
///: END:ONLY_INCLUDE_IN
import SendTransactionScreen from '../send';
import Swaps from '../swaps';
import ConfirmTransaction from '../confirm-transaction';
@ -38,12 +38,10 @@ import OnboardingAppHeader from '../onboarding-flow/onboarding-app-header/onboar
import TokenDetailsPage from '../token-details';
///: BEGIN:ONLY_INCLUDE_IN(flask)
import Notifications from '../notifications';
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
import { registerOnDesktopDisconnect } from '../../hooks/desktopHooks';
import DesktopErrorPage from '../desktop-error';
import DesktopPairingPage from '../desktop-pairing';
///: END:ONLY_INCLUDE_IN(desktop)
///: END:ONLY_INCLUDE_IN
import {
IMPORT_TOKEN_ROUTE,
@ -70,14 +68,12 @@ import {
TOKEN_DETAILS,
///: BEGIN:ONLY_INCLUDE_IN(flask)
NOTIFICATIONS_ROUTE,
///: END:ONLY_INCLUDE_IN
///: BEGIN:ONLY_INCLUDE_IN(desktop)
DESKTOP_PAIRING_ROUTE,
DESKTOP_ERROR_ROUTE,
///: END:ONLY_INCLUDE_IN
} from '../../helpers/constants/routes';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import { EXTENSION_ERROR_PAGE_TYPES } from '../../../shared/constants/desktop';
///: END:ONLY_INCLUDE_IN
@ -144,7 +140,7 @@ export default class Routes extends Component {
document.documentElement.setAttribute('data-theme', osTheme);
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
componentDidMount() {
const { history } = this.props;
browserAPI.runtime.onMessage.addListener(
@ -206,7 +202,7 @@ export default class Routes extends Component {
<Route path={ONBOARDING_ROUTE} component={OnboardingFlow} />
<Route path={LOCK_ROUTE} component={Lock} exact />
{
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
<Route
path={`${DESKTOP_ERROR_ROUTE}/:errorType`}
component={DesktopErrorPage}
@ -281,7 +277,7 @@ export default class Routes extends Component {
<Authenticated path={`${ASSET_ROUTE}/:asset/:id`} component={Asset} />
<Authenticated path={`${ASSET_ROUTE}/:asset/`} component={Asset} />
{
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
<Authenticated
path={DESKTOP_PAIRING_ROUTE}
component={DesktopPairingPage}
@ -345,7 +341,7 @@ export default class Routes extends Component {
hideAppHeader() {
const { location } = this.props;
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
const isDesktopConnectionLostScreen = Boolean(
matchPath(location.pathname, {
path: `${DESKTOP_ERROR_ROUTE}/${EXTENSION_ERROR_PAGE_TYPES.CONNECTION_LOST}`,

View File

@ -60,7 +60,7 @@ export default class AdvancedTab extends PureComponent {
disabledRpcMethodPreferences: PropTypes.shape({
eth_sign: PropTypes.bool.isRequired,
}),
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled: PropTypes.bool,
///: END:ONLY_INCLUDE_IN
};
@ -469,12 +469,12 @@ export default class AdvancedTab extends PureComponent {
ledgerTransportType,
setLedgerTransportPreference,
userHasALedgerAccount,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
} = this.props;
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
if (desktopEnabled) {
return null;
}

View File

@ -30,7 +30,7 @@ export const mapStateToProps = (state) => {
useNonceField,
ledgerTransportType,
dismissSeedBackUpReminder,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
} = metamask;
@ -54,7 +54,7 @@ export const mapStateToProps = (state) => {
dismissSeedBackUpReminder,
userHasALedgerAccount,
disabledRpcMethodPreferences,
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
desktopEnabled,
///: END:ONLY_INCLUDE_IN
};

View File

@ -13,7 +13,7 @@ import {
TextColor,
TypographyVariant,
} from '../../../helpers/constants/design-system';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
import DesktopEnableButton from '../../../components/app/desktop-enable-button';
///: END:ONLY_INCLUDE_IN
@ -226,7 +226,7 @@ export default class ExperimentalTab extends PureComponent {
);
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
renderDesktopEnableButton() {
const { t } = this.context;
@ -255,7 +255,7 @@ export default class ExperimentalTab extends PureComponent {
{this.renderTransactionSecurityCheckToggle()}
{process.env.NFTS_V1 && this.renderOpenSeaEnabledToggle()}
{
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
this.renderDesktopEnableButton()
///: END:ONLY_INCLUDE_IN
}

View File

@ -1357,7 +1357,7 @@ export function getUseCurrencyRateCheck(state) {
return Boolean(state.metamask.useCurrencyRateCheck);
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
/**
* To get the `desktopEnabled` value which determines whether we use the desktop app
*

View File

@ -103,6 +103,6 @@ export const SET_NEW_TOKENS_IMPORTED = 'SET_NEW_TOKENS_IMPORTED';
// Token allowance
export const SET_CUSTOM_TOKEN_AMOUNT = 'SET_CUSTOM_TOKEN_AMOUNT';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
///: BEGIN:ONLY_INCLUDE_IN(flask)
export const FORCE_DISABLE_DESKTOP = 'FORCE_DISABLE_DESKTOP';
///: END:ONLY_INCLUDE_IN

View File

@ -1350,6 +1350,28 @@ export function markNotificationsAsRead(
await forceUpdateMetamaskState(dispatch);
};
}
export function setDesktopEnabled(desktopEnabled: boolean) {
return async () => {
try {
await submitRequestToBackground('setDesktopEnabled', [desktopEnabled]);
} catch (error) {
log.error(error);
}
};
}
export async function generateDesktopOtp() {
return await submitRequestToBackground('generateDesktopOtp');
}
export async function testDesktopConnection() {
return await submitRequestToBackground('testDesktopConnection');
}
export async function disableDesktop() {
return await submitRequestToBackground('disableDesktop');
}
///: END:ONLY_INCLUDE_IN
export function cancelMsg(
@ -4574,27 +4596,3 @@ export function requestAddNetworkApproval(
}
};
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
export function setDesktopEnabled(desktopEnabled: boolean) {
return async () => {
try {
await submitRequestToBackground('setDesktopEnabled', [desktopEnabled]);
} catch (error) {
log.error(error);
}
};
}
export async function generateOtp() {
return await submitRequestToBackground('generateOtp');
}
export async function testDesktopConnection() {
return await submitRequestToBackground('testDesktopConnection');
}
export async function disableDesktop() {
return await submitRequestToBackground('disableDesktop');
}
///: END:ONLY_INCLUDE_IN