2023-03-06 18:48:28 +01:00
|
|
|
import { ReactFragment } from 'react';
|
2021-02-04 19:15:23 +01:00
|
|
|
import log from 'loglevel';
|
2021-07-23 01:13:40 +02:00
|
|
|
import { captureException } from '@sentry/browser';
|
2021-06-23 23:35:25 +02:00
|
|
|
import { capitalize, isEqual } from 'lodash';
|
2023-02-03 18:56:44 +01:00
|
|
|
import { ThunkAction } from 'redux-thunk';
|
|
|
|
import { Action, AnyAction } from 'redux';
|
2023-06-20 15:37:09 +02:00
|
|
|
import { ethErrors, serializeError } from 'eth-rpc-errors';
|
2023-02-03 18:56:44 +01:00
|
|
|
import { Hex, Json } from '@metamask/utils';
|
|
|
|
import {
|
|
|
|
AssetsContractController,
|
|
|
|
BalanceMap,
|
|
|
|
Nft,
|
|
|
|
Token,
|
|
|
|
} from '@metamask/assets-controllers';
|
|
|
|
import { PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
import { GasFeeController } from '@metamask/gas-fee-controller';
|
|
|
|
import { PermissionsRequest } from '@metamask/permission-controller';
|
|
|
|
import { NonEmptyArray } from '@metamask/controller-utils';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { getMethodDataAsync } from '../helpers/utils/transactions.util';
|
2022-09-16 21:05:21 +02:00
|
|
|
import switchDirection from '../../shared/lib/switch-direction';
|
2021-08-04 23:53:13 +02:00
|
|
|
import {
|
|
|
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
2022-04-26 19:07:39 +02:00
|
|
|
ORIGIN_METAMASK,
|
2021-08-04 23:53:13 +02:00
|
|
|
POLLING_TOKEN_ENVIRONMENT_TYPES,
|
|
|
|
} from '../../shared/constants/app';
|
2021-04-28 21:53:59 +02:00
|
|
|
import { getEnvironmentType, addHexPrefix } from '../../app/scripts/lib/util';
|
2020-04-29 19:10:51 +02:00
|
|
|
import {
|
2021-06-23 23:35:25 +02:00
|
|
|
getMetaMaskAccounts,
|
2020-04-29 19:10:51 +02:00
|
|
|
getPermittedAccountsForCurrentTab,
|
|
|
|
getSelectedAddress,
|
2023-05-11 07:56:17 +02:00
|
|
|
hasTransactionPendingApprovals,
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-06-01 19:09:13 +02:00
|
|
|
getNotifications,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../selectors';
|
2022-07-01 15:58:35 +02:00
|
|
|
import {
|
|
|
|
computeEstimatedGasLimit,
|
|
|
|
initializeSendState,
|
|
|
|
resetSendState,
|
2023-02-03 18:56:44 +01:00
|
|
|
// NOTE: Until the send duck is typescript that this is importing a typedef
|
|
|
|
// that does not have an explicit export statement. lets see if it breaks the
|
|
|
|
// compiler
|
|
|
|
DraftTransaction,
|
2022-07-01 15:58:35 +02:00
|
|
|
} from '../ducks/send';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { switchedToUnconnectedAccount } from '../ducks/alerts/unconnected-account';
|
2023-05-02 14:36:24 +02:00
|
|
|
import {
|
|
|
|
getProviderConfig,
|
|
|
|
getUnconnectedAccountAlertEnabledness,
|
|
|
|
} from '../ducks/metamask/metamask';
|
2021-05-17 23:19:39 +02:00
|
|
|
import { toChecksumHexAddress } from '../../shared/modules/hexstring-utils';
|
2021-10-21 21:17:03 +02:00
|
|
|
import {
|
2023-01-20 16:14:40 +01:00
|
|
|
HardwareDeviceNames,
|
|
|
|
LedgerTransportTypes,
|
2021-10-21 21:17:03 +02:00
|
|
|
LEDGER_USB_VENDOR_ID,
|
|
|
|
} from '../../shared/constants/hardware-wallets';
|
2023-02-03 18:56:44 +01:00
|
|
|
import {
|
2023-04-03 17:31:04 +02:00
|
|
|
MetaMetricsEventCategory,
|
2023-02-03 18:56:44 +01:00
|
|
|
MetaMetricsEventFragment,
|
|
|
|
MetaMetricsEventOptions,
|
|
|
|
MetaMetricsEventPayload,
|
|
|
|
MetaMetricsPageObject,
|
|
|
|
MetaMetricsPageOptions,
|
|
|
|
MetaMetricsPagePayload,
|
|
|
|
MetaMetricsReferrerObject,
|
|
|
|
} from '../../shared/constants/metametrics';
|
2022-02-18 17:48:38 +01:00
|
|
|
import { parseSmartTransactionsError } from '../pages/swaps/swaps.util';
|
2022-03-07 19:54:36 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../shared/modules/string-utils';
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2022-06-01 19:09:13 +02:00
|
|
|
import { NOTIFICATIONS_EXPIRATION_DELAY } from '../helpers/constants/notifications';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2022-09-16 21:05:21 +02:00
|
|
|
import {
|
|
|
|
fetchLocale,
|
|
|
|
loadRelativeTimeFormatLocaleData,
|
2023-06-20 14:44:11 +02:00
|
|
|
} from '../../shared/modules/i18n';
|
2023-01-20 18:04:37 +01:00
|
|
|
import { decimalToHex } from '../../shared/modules/conversion.utils';
|
2023-02-03 18:56:44 +01:00
|
|
|
import { TxGasFees, PriorityLevels } from '../../shared/constants/gas';
|
|
|
|
import {
|
|
|
|
TransactionMetaMetricsEvent,
|
|
|
|
TransactionType,
|
|
|
|
} from '../../shared/constants/transaction';
|
2023-03-01 09:45:27 +01:00
|
|
|
import { NetworkType, RPCDefinition } from '../../shared/constants/network';
|
2023-02-03 18:56:44 +01:00
|
|
|
import { EtherDenomination } from '../../shared/constants/common';
|
|
|
|
import {
|
|
|
|
isErrorWithMessage,
|
|
|
|
logErrorWithMessage,
|
|
|
|
} from '../../shared/modules/error';
|
|
|
|
import { TransactionMeta } from '../../app/scripts/controllers/incoming-transactions';
|
|
|
|
import { TxParams } from '../../app/scripts/controllers/transactions/tx-state-manager';
|
|
|
|
import { CustomGasSettings } from '../../app/scripts/controllers/transactions';
|
|
|
|
import { ThemeType } from '../../shared/constants/preferences';
|
2021-02-04 19:15:23 +01:00
|
|
|
import * as actionConstants from './actionConstants';
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
2023-06-20 15:37:09 +02:00
|
|
|
import { updateCustodyState } from './institutional/institution-actions';
|
2023-03-14 11:57:05 +01:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
2022-09-05 16:55:34 +02:00
|
|
|
import {
|
2022-09-16 19:04:14 +02:00
|
|
|
generateActionId,
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod,
|
|
|
|
submitRequestToBackground,
|
|
|
|
} from './action-queue';
|
2023-02-03 18:56:44 +01:00
|
|
|
import {
|
|
|
|
MetaMaskReduxDispatch,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
TemporaryMessageDataType,
|
|
|
|
} from './store';
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function goHome() {
|
2016-04-25 21:20:33 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.GO_HOME,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-25 21:20:33 +02:00
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
// async actions
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function tryUnlockMetamask(
|
|
|
|
password: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
dispatch(unlockInProgress());
|
|
|
|
log.debug(`background.submitPassword`);
|
2018-03-03 22:08:10 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('submitPassword', [password], (error) => {
|
2018-03-08 16:29:29 +01:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2018-03-08 16:29:29 +01:00
|
|
|
}
|
2018-03-03 22:08:10 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
2018-03-08 16:29:29 +01:00
|
|
|
.then(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(unlockSucceeded());
|
|
|
|
return forceUpdateMetamaskState(dispatch);
|
2018-03-08 16:29:29 +01:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2018-03-08 16:29:29 +01:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(unlockFailed(err.message));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return Promise.reject(err);
|
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2021-07-30 23:37:40 +02:00
|
|
|
/**
|
|
|
|
* Adds a new account where all data is encrypted using the given password and
|
|
|
|
* where all addresses are generated from a given seed phrase.
|
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param password - The password.
|
|
|
|
* @param seedPhrase - The seed phrase.
|
|
|
|
* @returns The updated state of the keyring controller.
|
2021-07-30 23:37:40 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createNewVaultAndRestore(
|
|
|
|
password: string,
|
|
|
|
seedPhrase: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.createNewVaultAndRestore`);
|
2021-07-30 23:37:40 +02:00
|
|
|
|
|
|
|
// Encode the secret recovery phrase as an array of integers so that it is
|
|
|
|
// serialized as JSON properly.
|
|
|
|
const encodedSeedPhrase = Array.from(
|
|
|
|
Buffer.from(seedPhrase, 'utf8').values(),
|
|
|
|
);
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: Add types for vault
|
|
|
|
let vault: any;
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'createNewVaultAndRestore',
|
|
|
|
[password, encodedSeedPhrase],
|
2021-07-30 23:37:40 +02:00
|
|
|
(err, _vault) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vault = _vault;
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2016-11-01 19:25:38 +01:00
|
|
|
})
|
2020-01-09 04:34:58 +01:00
|
|
|
.then(() => dispatch(unMarkPasswordForgotten()))
|
2018-03-08 16:29:29 +01:00
|
|
|
.then(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showAccountsPage());
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return vault;
|
2018-03-08 16:29:29 +01:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return Promise.reject(err);
|
|
|
|
});
|
|
|
|
};
|
2016-11-01 19:25:38 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createNewVaultAndGetSeedPhrase(
|
|
|
|
password: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
await createNewVault(password);
|
2021-07-30 23:37:40 +02:00
|
|
|
const seedPhrase = await verifySeedPhrase();
|
|
|
|
return seedPhrase;
|
2019-01-23 16:25:34 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
|
|
|
if (isErrorWithMessage(error)) {
|
|
|
|
throw new Error(error.message);
|
|
|
|
} else {
|
|
|
|
throw error;
|
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function unlockAndGetSeedPhrase(
|
|
|
|
password: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2019-01-23 16:25:34 +01:00
|
|
|
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
await submitPassword(password);
|
2021-07-30 23:37:40 +02:00
|
|
|
const seedPhrase = await verifySeedPhrase();
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-07-30 23:37:40 +02:00
|
|
|
return seedPhrase;
|
2019-01-23 16:25:34 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
|
|
|
if (isErrorWithMessage(error)) {
|
|
|
|
throw new Error(error.message);
|
|
|
|
} else {
|
|
|
|
throw error;
|
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function submitPassword(password: string): Promise<void> {
|
2019-01-23 16:25:34 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('submitPassword', [password], (error) => {
|
2019-01-23 16:25:34 +01:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createNewVault(password: string): Promise<boolean> {
|
2019-01-23 16:25:34 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('createNewVaultAndKeychain', [password], (error) => {
|
2019-01-23 16:25:34 +01:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function verifyPassword(password: string): Promise<boolean> {
|
2018-05-14 15:30:50 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('verifyPassword', [password], (error) => {
|
2018-05-14 15:30:50 +02:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(true);
|
|
|
|
});
|
|
|
|
});
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
|
|
|
|
2021-07-30 23:37:40 +02:00
|
|
|
export async function verifySeedPhrase() {
|
2023-02-03 18:56:44 +01:00
|
|
|
const encodedSeedPhrase = await submitRequestToBackground<string>(
|
|
|
|
'verifySeedPhrase',
|
|
|
|
);
|
2021-07-30 23:37:40 +02:00
|
|
|
return Buffer.from(encodedSeedPhrase).toString('utf8');
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function requestRevealSeedWords(
|
|
|
|
password: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.verifyPassword`);
|
2018-05-14 15:30:50 +02:00
|
|
|
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
await verifyPassword(password);
|
2021-07-30 23:37:40 +02:00
|
|
|
const seedPhrase = await verifySeedPhrase();
|
|
|
|
return seedPhrase;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-11-02 06:19:04 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function tryReverseResolveAddress(
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2019-11-01 18:54:00 +01:00
|
|
|
return () => {
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<void>((resolve) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('tryReverseResolveAddress', [address], (err) => {
|
2019-11-01 18:54:00 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(err);
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-11-01 18:54:00 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function resetAccount(): ThunkAction<
|
|
|
|
Promise<string>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-01-31 09:33:15 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<string>((resolve, reject) => {
|
|
|
|
callBackgroundMethod<string>('resetAccount', [], (err, account) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2018-05-31 01:17:40 +02:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
if (isErrorWithMessage(err)) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2018-05-31 01:17:40 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info(`Transaction history reset for ${account}`);
|
|
|
|
dispatch(showAccountsPage());
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve(account as string);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2018-01-31 09:33:15 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removeAccount(
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-07-11 06:20:40 +02:00
|
|
|
|
2020-01-16 18:43:40 +01:00
|
|
|
try {
|
|
|
|
await new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('removeAccount', [address], (error, account) => {
|
2020-01-16 18:43:40 +01:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2020-01-16 18:43:40 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(account);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2020-01-16 18:43:40 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-01-16 18:43:40 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-01-16 18:43:40 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.info(`Account removed: ${address}`);
|
|
|
|
dispatch(showAccountsPage());
|
|
|
|
};
|
2018-07-11 06:20:40 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function importNewAccount(
|
|
|
|
strategy: string,
|
|
|
|
args: any[],
|
2023-03-06 18:48:28 +01:00
|
|
|
loadingMessage: ReactFragment,
|
2023-02-03 18:56:44 +01:00
|
|
|
): ThunkAction<
|
|
|
|
Promise<MetaMaskReduxState['metamask']>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2023-03-06 18:48:28 +01:00
|
|
|
|
|
|
|
dispatch(showLoadingIndication(loadingMessage));
|
|
|
|
|
2018-05-14 15:30:50 +02:00
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.importAccountWithStrategy`);
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('importAccountWithStrategy', [
|
|
|
|
strategy,
|
|
|
|
args,
|
|
|
|
]);
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.getState`);
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('getState');
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
return newState;
|
|
|
|
};
|
2017-01-19 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addNewAccount(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.addNewAccount`);
|
2020-04-27 21:03:25 +02:00
|
|
|
return async (dispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const oldIdentities = getState().metamask.identities;
|
|
|
|
dispatch(showLoadingIndication());
|
2017-09-22 08:59:27 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newIdentities;
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
const { identities } = await submitRequestToBackground('addNewAccount', [
|
2022-08-16 08:12:00 +02:00
|
|
|
Object.keys(oldIdentities).length,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-02-04 19:15:23 +01:00
|
|
|
newIdentities = identities;
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 21:03:25 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const newAccountAddress = Object.keys(newIdentities).find(
|
|
|
|
(address) => !oldIdentities[address],
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return newAccountAddress;
|
|
|
|
};
|
2016-10-28 21:10:35 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function checkHardwareStatus(
|
|
|
|
deviceName: HardwareDeviceNames,
|
|
|
|
hdPath: string,
|
|
|
|
): ThunkAction<Promise<boolean>, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.checkHardwareStatus`, deviceName, hdPath);
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-07-12 03:21:36 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
let unlocked = false;
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
unlocked = await submitRequestToBackground<boolean>(
|
|
|
|
'checkHardwareStatus',
|
|
|
|
[deviceName, hdPath],
|
|
|
|
);
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 21:03:25 +02:00
|
|
|
}
|
2018-07-12 03:21:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return unlocked;
|
|
|
|
};
|
2018-07-12 03:21:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function forgetDevice(
|
|
|
|
deviceName: HardwareDeviceNames,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.forgetDevice`, deviceName);
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('forgetDevice', [deviceName]);
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 21:03:25 +02:00
|
|
|
}
|
2018-07-12 03:21:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2018-07-12 03:21:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: Define an Account Type for the return type of this method and anywhere
|
|
|
|
// else dealing with accounts.
|
|
|
|
export function connectHardware(
|
|
|
|
deviceName: HardwareDeviceNames,
|
|
|
|
page: string,
|
|
|
|
hdPath: string,
|
|
|
|
t: (key: string) => string,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<{ address: string }[]>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.connectHardware`, deviceName, page, hdPath);
|
2021-10-21 21:17:03 +02:00
|
|
|
return async (dispatch, getState) => {
|
2021-11-05 21:32:53 +01:00
|
|
|
const { ledgerTransportType } = getState().metamask;
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
dispatch(
|
|
|
|
showLoadingIndication(`Looking for your ${capitalize(deviceName)}...`),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-06-10 09:52:32 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
let accounts: { address: string }[];
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2023-01-20 16:14:40 +01:00
|
|
|
if (deviceName === HardwareDeviceNames.ledger) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('establishLedgerTransportPreference');
|
2021-11-05 17:13:29 +01:00
|
|
|
}
|
2021-10-21 21:17:03 +02:00
|
|
|
if (
|
2023-01-20 16:14:40 +01:00
|
|
|
deviceName === HardwareDeviceNames.ledger &&
|
|
|
|
ledgerTransportType === LedgerTransportTypes.webhid
|
2021-10-21 21:17:03 +02:00
|
|
|
) {
|
|
|
|
const connectedDevices = await window.navigator.hid.requestDevice({
|
2023-02-03 18:56:44 +01:00
|
|
|
// The types for web hid were provided by @types/w3c-web-hid and may
|
|
|
|
// not be fully formed or correct, because LEDGER_USB_VENDOR_ID is a
|
|
|
|
// string and this integration with Navigator.hid works before
|
|
|
|
// TypeScript. As a note, on the next declaration we convert the
|
|
|
|
// LEDGER_USB_VENDOR_ID to a number for a different API so....
|
|
|
|
// TODO: Get David Walsh's opinion here
|
|
|
|
filters: [{ vendorId: LEDGER_USB_VENDOR_ID as unknown as number }],
|
2021-10-21 21:17:03 +02:00
|
|
|
});
|
|
|
|
const userApprovedWebHidConnection = connectedDevices.some(
|
|
|
|
(device) => device.vendorId === Number(LEDGER_USB_VENDOR_ID),
|
|
|
|
);
|
|
|
|
if (!userApprovedWebHidConnection) {
|
|
|
|
throw new Error(t('ledgerWebHIDNotConnectedErrorMessage'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
accounts = await submitRequestToBackground<{ address: string }[]>(
|
|
|
|
'connectHardware',
|
|
|
|
[deviceName, page, hdPath],
|
|
|
|
);
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-11-05 21:32:53 +01:00
|
|
|
if (
|
2023-01-20 16:14:40 +01:00
|
|
|
deviceName === HardwareDeviceNames.ledger &&
|
|
|
|
ledgerTransportType === LedgerTransportTypes.webhid &&
|
2023-02-03 18:56:44 +01:00
|
|
|
isErrorWithMessage(error) &&
|
2021-11-05 21:32:53 +01:00
|
|
|
error.message.match('Failed to open the device')
|
|
|
|
) {
|
|
|
|
dispatch(displayWarning(t('ledgerDeviceOpenFailureMessage')));
|
2021-11-08 01:37:15 +01:00
|
|
|
throw new Error(t('ledgerDeviceOpenFailureMessage'));
|
2021-11-05 21:32:53 +01:00
|
|
|
} else {
|
2023-01-20 16:14:40 +01:00
|
|
|
if (deviceName !== HardwareDeviceNames.qr) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2022-01-06 23:56:51 +01:00
|
|
|
}
|
2021-11-05 21:32:53 +01:00
|
|
|
throw error;
|
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 21:03:25 +02:00
|
|
|
}
|
2018-06-10 09:52:32 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return accounts;
|
|
|
|
};
|
2018-06-10 09:52:32 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
export function unlockHardwareWalletAccounts(
|
2023-02-03 18:56:44 +01:00
|
|
|
indexes: string[],
|
|
|
|
deviceName: HardwareDeviceNames,
|
|
|
|
hdPath: string,
|
|
|
|
hdPathDescription: string,
|
|
|
|
): ThunkAction<Promise<undefined>, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(
|
|
|
|
`background.unlockHardwareWalletAccount`,
|
2021-03-09 21:39:16 +01:00
|
|
|
indexes,
|
2021-02-04 19:15:23 +01:00
|
|
|
deviceName,
|
|
|
|
hdPath,
|
2021-03-09 21:39:16 +01:00
|
|
|
hdPathDescription,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-06-10 09:52:32 +02:00
|
|
|
|
2021-03-09 21:39:16 +01:00
|
|
|
for (const index of indexes) {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('unlockHardwareWalletAccount', [
|
2021-03-09 21:39:16 +01:00
|
|
|
index,
|
|
|
|
deviceName,
|
|
|
|
hdPath,
|
|
|
|
hdPathDescription,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
dispatch(displayWarning(err));
|
2021-03-09 21:39:16 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2023-02-03 18:56:44 +01:00
|
|
|
throw err;
|
2021-03-09 21:39:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return undefined;
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-10 09:52:32 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showQrScanner(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
dispatch(
|
|
|
|
showModal({
|
|
|
|
name: 'QR_SCANNER',
|
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2018-08-01 00:30:40 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setCurrentCurrency(
|
|
|
|
currencyCode: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setCurrentCurrency`);
|
2020-04-27 21:30:27 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setCurrentCurrency', [currencyCode]);
|
2021-05-07 16:02:22 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2020-04-27 21:30:27 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 21:30:27 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-07-21 18:30:58 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function decryptMsgInline(
|
|
|
|
decryptedMsgData: TemporaryMessageDataType['msgParams'],
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryMessageDataType>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - decryptMsgInline');
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`actions calling background.decryptMessageInline`);
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('decryptMessageInline', [decryptedMsgData]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-04-28 14:49:10 +02:00
|
|
|
}
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
return newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId];
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function decryptMsg(
|
|
|
|
decryptedMsgData: TemporaryMessageDataType['msgParams'],
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryMessageDataType['msgParams']>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - decryptMsg');
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.decryptMessage`);
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
let newState: MetaMaskReduxState['metamask'];
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('decryptMessage', [decryptedMsgData]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-28 14:49:10 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(completedTx(decryptedMsgData.metamaskId));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
return decryptedMsgData;
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function encryptionPublicKeyMsg(
|
|
|
|
msgData: TemporaryMessageDataType['msgParams'],
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryMessageDataType['msgParams']>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - encryptionPublicKeyMsg');
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.encryptionPublicKey`);
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
let newState: MetaMaskReduxState['metamask'];
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('encryptionPublicKey', [msgData]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-28 14:49:10 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(completedTx(msgData.metamaskId));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
return msgData;
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateCustomNonce(value: string) {
|
2019-09-27 06:30:36 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UPDATE_CUSTOM_NONCE,
|
2020-08-19 18:27:05 +02:00
|
|
|
value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
const updateMetamaskStateFromBackground = (): Promise<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
> => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.getState`);
|
2019-07-05 19:01:34 +02:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
callBackgroundMethod<MetaMaskReduxState['metamask']>(
|
|
|
|
'getState',
|
|
|
|
[],
|
|
|
|
(error, newState) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
2019-07-05 19:01:34 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve(newState as MetaMaskReduxState['metamask']);
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-07-05 19:01:34 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
/**
|
|
|
|
* TODO: update previousGasParams to use typed gas params object
|
|
|
|
* TODO: codeword: NOT_A_THUNK @brad-decker
|
|
|
|
*
|
|
|
|
* @param txId - MetaMask internal transaction id
|
|
|
|
* @param previousGasParams - Object of gas params to set as previous
|
|
|
|
*/
|
|
|
|
export function updatePreviousGasParams(
|
|
|
|
txId: number,
|
|
|
|
previousGasParams: Record<string, any>,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
|
|
|
return async () => {
|
|
|
|
let updatedTransaction: TransactionMeta;
|
2022-03-25 18:11:04 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updatePreviousGasParams',
|
|
|
|
[txId, previousGasParams],
|
2022-03-25 18:11:04 +01:00
|
|
|
);
|
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-03-25 18:11:04 +01:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return updatedTransaction;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateEditableParams(
|
|
|
|
txId: number,
|
|
|
|
editableParams: Partial<TxParams>,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
let updatedTransaction: TransactionMeta;
|
2022-03-07 20:14:48 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updateEditableParams',
|
|
|
|
[txId, editableParams],
|
2022-03-24 14:46:51 +01:00
|
|
|
);
|
2022-03-07 20:14:48 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-03-07 20:14:48 +01:00
|
|
|
throw error;
|
|
|
|
}
|
2022-07-21 01:03:23 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2022-03-24 14:46:51 +01:00
|
|
|
return updatedTransaction;
|
2022-03-07 20:14:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-04 18:54:46 +02:00
|
|
|
/**
|
|
|
|
* Appends new send flow history to a transaction
|
2023-02-03 18:56:44 +01:00
|
|
|
* TODO: codeword: NOT_A_THUNK @brad-decker
|
2022-05-04 18:54:46 +02:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param txId - the id of the transaction to update
|
|
|
|
* @param currentSendFlowHistoryLength - sendFlowHistory entries currently
|
|
|
|
* @param sendFlowHistory - the new send flow history to append to the
|
|
|
|
* transaction
|
|
|
|
* @returns
|
2022-05-04 18:54:46 +02:00
|
|
|
*/
|
2022-09-06 11:09:12 +02:00
|
|
|
export function updateTransactionSendFlowHistory(
|
2023-02-03 18:56:44 +01:00
|
|
|
txId: number,
|
|
|
|
currentSendFlowHistoryLength: number,
|
|
|
|
sendFlowHistory: DraftTransaction['history'],
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
|
|
|
return async () => {
|
|
|
|
let updatedTransaction: TransactionMeta;
|
2022-05-04 18:54:46 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updateTransactionSendFlowHistory',
|
2022-09-06 11:09:12 +02:00
|
|
|
[txId, currentSendFlowHistoryLength, sendFlowHistory],
|
2022-09-05 16:55:34 +02:00
|
|
|
);
|
2022-05-04 18:54:46 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-05-04 18:54:46 +02:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return updatedTransaction;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function backupUserData(): Promise<{
|
|
|
|
filename: string;
|
|
|
|
data: string;
|
|
|
|
}> {
|
2022-08-09 20:36:32 +02:00
|
|
|
let backedupData;
|
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
backedupData = await submitRequestToBackground<{
|
|
|
|
filename: string;
|
|
|
|
data: string;
|
|
|
|
}>('backupUserData');
|
2022-08-09 20:36:32 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-08-09 20:36:32 +02:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return backedupData;
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function restoreUserData(jsonString: Json): Promise<true> {
|
2022-08-09 20:36:32 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('restoreUserData', [jsonString]);
|
2022-08-09 20:36:32 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-08-09 20:36:32 +02:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: codeword: NOT_A_THUNK @brad-decker
|
|
|
|
export function updateTransactionGasFees(
|
|
|
|
txId: number,
|
|
|
|
txGasFees: Partial<TxGasFees>,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
|
|
|
return async () => {
|
|
|
|
let updatedTransaction: TransactionMeta;
|
2022-03-07 20:14:48 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updateTransactionGasFees',
|
|
|
|
[txId, txGasFees],
|
2022-03-24 14:46:51 +01:00
|
|
|
);
|
2022-03-07 20:14:48 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-03-07 20:14:48 +01:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2022-03-24 14:46:51 +01:00
|
|
|
return updatedTransaction;
|
2022-03-07 20:14:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateTransaction(
|
|
|
|
txMeta: TransactionMeta,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
!dontShowLoadingIndicator && dispatch(showLoadingIndication());
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-12-18 06:34:43 +01:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
await submitRequestToBackground('updateTransaction', [txMeta]);
|
2020-12-18 06:34:43 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(updateTransactionParams(txMeta.id, txMeta.txParams));
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(goHome());
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-12-18 06:34:43 +01:00
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2020-12-18 06:34:43 +01:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(updateTransactionParams(txMeta.id, txMeta.txParams));
|
2021-02-04 19:15:23 +01:00
|
|
|
const newState = await updateMetamaskStateFromBackground();
|
|
|
|
dispatch(updateMetamaskState(newState));
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(showConfTxPage({ id: txMeta.id }));
|
|
|
|
return txMeta;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-12-18 06:34:43 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2022-04-26 19:07:39 +02:00
|
|
|
/**
|
|
|
|
* Action to create a new transaction in the controller and route to the
|
|
|
|
* confirmation page. Returns the newly created txMeta in case additional logic
|
|
|
|
* should be applied to the transaction after creation.
|
|
|
|
*
|
2023-01-23 15:32:01 +01:00
|
|
|
* @param method
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param txParams - The transaction parameters
|
|
|
|
* @param type - The type of the transaction being added.
|
|
|
|
* @param sendFlowHistory - The history of the send flow at time of creation.
|
|
|
|
* @returns
|
2022-04-26 19:07:39 +02:00
|
|
|
*/
|
|
|
|
export function addUnapprovedTransactionAndRouteToConfirmationPage(
|
2023-02-03 18:56:44 +01:00
|
|
|
method: string,
|
|
|
|
txParams: TxParams,
|
|
|
|
type: TransactionType,
|
|
|
|
sendFlowHistory: DraftTransaction['history'],
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta | null>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2022-04-26 19:07:39 +02:00
|
|
|
try {
|
|
|
|
log.debug('background.addUnapprovedTransaction');
|
2023-02-03 18:56:44 +01:00
|
|
|
const txMeta = await submitRequestToBackground<TransactionMeta>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'addUnapprovedTransaction',
|
2023-01-23 15:32:01 +01:00
|
|
|
[method, txParams, ORIGIN_METAMASK, type, sendFlowHistory, actionId],
|
2022-09-06 11:08:32 +02:00
|
|
|
actionId,
|
2022-02-14 20:07:46 +01:00
|
|
|
);
|
2022-04-26 19:07:39 +02:00
|
|
|
dispatch(showConfTxPage());
|
|
|
|
return txMeta;
|
|
|
|
} catch (error) {
|
|
|
|
dispatch(hideLoadingIndication());
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2022-04-26 19:07:39 +02:00
|
|
|
}
|
|
|
|
return null;
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2022-04-26 19:07:39 +02:00
|
|
|
/**
|
|
|
|
* Wrapper around the promisifedBackground to create a new unapproved
|
|
|
|
* transaction in the background and return the newly created txMeta.
|
|
|
|
* This method does not show errors or route to a confirmation page and is
|
|
|
|
* used primarily for swaps functionality.
|
|
|
|
*
|
2023-01-23 15:32:01 +01:00
|
|
|
* @param method
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param txParams - the transaction parameters
|
|
|
|
* @param type - The type of the transaction being added.
|
2023-06-13 11:17:32 +02:00
|
|
|
* @param options - Additional options for the transaction.
|
|
|
|
* @param options.requireApproval - Whether the transaction requires approval.
|
|
|
|
* @param options.swaps - Options specific to swaps transactions.
|
|
|
|
* @param options.swaps.hasApproveTx - Whether the swap required an approval transaction.
|
|
|
|
* @param options.swaps.meta - Additional transaction metadata required by swaps.
|
2023-02-03 18:56:44 +01:00
|
|
|
* @returns
|
2022-04-26 19:07:39 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function addUnapprovedTransaction(
|
|
|
|
method: string,
|
|
|
|
txParams: TxParams,
|
|
|
|
type: TransactionType,
|
2023-06-13 11:17:32 +02:00
|
|
|
options?: {
|
|
|
|
requireApproval?: boolean;
|
|
|
|
swaps?: { hasApproveTx?: boolean; meta?: Record<string, unknown> };
|
|
|
|
},
|
2023-02-03 18:56:44 +01:00
|
|
|
): Promise<TransactionMeta> {
|
2022-04-26 19:07:39 +02:00
|
|
|
log.debug('background.addUnapprovedTransaction');
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2023-02-03 18:56:44 +01:00
|
|
|
const txMeta = await submitRequestToBackground<TransactionMeta>(
|
2022-09-06 11:08:32 +02:00
|
|
|
'addUnapprovedTransaction',
|
2023-06-13 11:17:32 +02:00
|
|
|
[method, txParams, ORIGIN_METAMASK, type, undefined, actionId, options],
|
2022-09-06 11:08:32 +02:00
|
|
|
actionId,
|
|
|
|
);
|
2022-04-26 19:07:39 +02:00
|
|
|
return txMeta;
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateAndApproveTx(
|
|
|
|
txMeta: TransactionMeta,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta | null>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
!dontShowLoadingIndicator && dispatch(showLoadingIndication());
|
2017-11-29 05:24:35 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
|
|
|
callBackgroundMethod(
|
2023-06-13 11:17:32 +02:00
|
|
|
'resolvePendingApproval',
|
|
|
|
[String(txMeta.id), { txMeta, actionId }, { waitForResult: true }],
|
2022-09-16 19:04:14 +02:00
|
|
|
(err) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(updateTransactionParams(txMeta.id, txMeta.txParams));
|
2022-09-16 19:04:14 +02:00
|
|
|
dispatch(resetSendState());
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2022-09-16 19:04:14 +02:00
|
|
|
if (err) {
|
|
|
|
dispatch(goHome());
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(err);
|
2022-09-16 19:04:14 +02:00
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
2017-11-29 05:24:35 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve(txMeta);
|
2022-09-16 19:04:14 +02:00
|
|
|
},
|
|
|
|
);
|
2016-04-14 00:28:44 +02:00
|
|
|
})
|
2018-06-23 08:52:45 +02:00
|
|
|
.then(() => updateMetamaskStateFromBackground())
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => dispatch(updateMetamaskState(newState)))
|
2018-06-23 08:52:45 +02:00
|
|
|
.then(() => {
|
2021-06-23 23:35:25 +02:00
|
|
|
dispatch(resetSendState());
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(completedTx(txMeta.id));
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(updateCustomNonce(''));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2018-07-24 05:25:04 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
return txMeta;
|
2018-06-23 08:52:45 +02:00
|
|
|
})
|
2018-08-28 21:18:57 +02:00
|
|
|
.catch((err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return Promise.reject(err);
|
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function getTransactions(
|
|
|
|
filters: {
|
|
|
|
filterToCurrentNetwork?: boolean;
|
|
|
|
searchCriteria?: Partial<TransactionMeta> & Partial<TxParams>;
|
|
|
|
} = {},
|
|
|
|
): Promise<TransactionMeta[]> {
|
|
|
|
return await submitRequestToBackground<TransactionMeta[]>('getTransactions', [
|
|
|
|
filters,
|
|
|
|
]);
|
2022-02-14 19:29:24 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function completedTx(
|
|
|
|
txId: number,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2020-02-06 17:38:14 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.COMPLETED_TX,
|
|
|
|
value: {
|
2023-02-03 18:56:44 +01:00
|
|
|
id: txId,
|
2020-02-06 17:38:14 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateTransactionParams(txId: number, txParams: TxParams) {
|
2017-11-08 17:44:48 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UPDATE_TRANSACTION_PARAMS,
|
2023-02-03 18:56:44 +01:00
|
|
|
id: txId,
|
2017-11-08 17:44:48 +01:00
|
|
|
value: txParams,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-08 17:44:48 +01:00
|
|
|
}
|
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2023-02-03 18:56:44 +01:00
|
|
|
export function disableSnap(
|
|
|
|
snapId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('disableSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function enableSnap(
|
|
|
|
snapId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('enableSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removeSnap(
|
|
|
|
snapId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('removeSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function removeSnapError(msgData: string): Promise<void> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('removeSnapError', [msgData]);
|
2022-02-15 01:02:51 +01:00
|
|
|
}
|
2022-06-01 19:09:13 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function handleSnapRequest(args: {
|
|
|
|
snapId: string;
|
|
|
|
origin: string;
|
|
|
|
handler: string;
|
|
|
|
request: {
|
|
|
|
jsonrpc: '2.0';
|
|
|
|
method: string;
|
|
|
|
params: Record<string, any>;
|
|
|
|
};
|
|
|
|
}): Promise<void> {
|
2022-09-20 19:00:07 +02:00
|
|
|
return submitRequestToBackground('handleSnapRequest', [args]);
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function dismissNotifications(
|
|
|
|
ids: string[],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('dismissNotifications', [ids]);
|
2022-06-01 19:09:13 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function deleteExpiredNotifications(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2022-06-01 19:09:13 +02:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const notifications = getNotifications(state);
|
|
|
|
|
|
|
|
const notificationIdsToDelete = notifications
|
|
|
|
.filter((notification) => {
|
|
|
|
const expirationTime = new Date(
|
|
|
|
Date.now() - NOTIFICATIONS_EXPIRATION_DELAY,
|
|
|
|
);
|
|
|
|
|
|
|
|
return Boolean(
|
|
|
|
notification.readDate &&
|
|
|
|
new Date(notification.readDate) < expirationTime,
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.map(({ id }) => id);
|
|
|
|
if (notificationIdsToDelete.length) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('dismissNotifications', [
|
|
|
|
notificationIdsToDelete,
|
|
|
|
]);
|
2022-06-01 19:09:13 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function markNotificationsAsRead(
|
|
|
|
ids: string[],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('markNotificationsAsRead', [ids]);
|
2022-06-01 19:09:13 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
2023-03-06 20:35:00 +01:00
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(desktop)
|
|
|
|
|
2023-03-06 20:35:00 +01:00
|
|
|
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');
|
|
|
|
}
|
2022-02-15 01:02:51 +01:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelDecryptMsg(
|
|
|
|
msgData: TemporaryMessageDataType,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryMessageDataType>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('cancelDecryptMessage', [msgData.id]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-28 14:49:10 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(completedTx(msgData.id));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
return msgData;
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelEncryptionPublicKeyMsg(
|
|
|
|
msgData: TemporaryMessageDataType,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryMessageDataType>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2020-02-19 19:24:16 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<
|
|
|
|
MetaMaskReduxState['metamask']
|
|
|
|
>('cancelEncryptionPublicKey', [msgData.id]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-28 14:49:10 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(completedTx(msgData.id));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
return msgData;
|
|
|
|
};
|
2020-02-19 19:24:16 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelTx(
|
|
|
|
txMeta: TransactionMeta,
|
|
|
|
_showLoadingIndication = true,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TransactionMeta>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
_showLoadingIndication && dispatch(showLoadingIndication());
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
callBackgroundMethod(
|
2023-06-13 11:17:32 +02:00
|
|
|
'rejectPendingApproval',
|
|
|
|
[
|
|
|
|
String(txMeta.id),
|
|
|
|
ethErrors.provider.userRejectedRequest().serialize(),
|
|
|
|
],
|
2022-09-16 19:04:14 +02:00
|
|
|
(error) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
2018-06-23 08:52:45 +02:00
|
|
|
|
2022-09-16 19:04:14 +02:00
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2018-06-23 08:52:45 +02:00
|
|
|
})
|
|
|
|
.then(() => updateMetamaskStateFromBackground())
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => dispatch(updateMetamaskState(newState)))
|
2018-06-23 08:52:45 +02:00
|
|
|
.then(() => {
|
2021-06-23 23:35:25 +02:00
|
|
|
dispatch(resetSendState());
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(completedTx(txMeta.id));
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2018-07-24 05:25:04 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
return txMeta;
|
2017-11-29 05:24:35 +01:00
|
|
|
})
|
2020-12-18 06:34:43 +01:00
|
|
|
.catch((error) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
throw error;
|
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2018-09-20 02:48:28 +02:00
|
|
|
/**
|
|
|
|
* Cancels all of the given transactions
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param txMetaList
|
|
|
|
* @returns
|
2018-09-20 02:48:28 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelTxs(
|
|
|
|
txMetaList: TransactionMeta[],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2020-12-18 06:34:43 +01:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
const txIds = txMetaList.map(({ id }) => id);
|
2020-12-18 06:34:43 +01:00
|
|
|
const cancellations = txIds.map(
|
|
|
|
(id) =>
|
2023-02-03 18:56:44 +01:00
|
|
|
new Promise<void>((resolve, reject) => {
|
2023-06-13 11:17:32 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'rejectPendingApproval',
|
|
|
|
[
|
|
|
|
String(id),
|
|
|
|
ethErrors.provider.userRejectedRequest().serialize(),
|
|
|
|
],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2020-12-18 06:34:43 +01:00
|
|
|
}),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
await Promise.all(cancellations);
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const newState = await updateMetamaskStateFromBackground();
|
|
|
|
dispatch(updateMetamaskState(newState));
|
2021-06-23 23:35:25 +02:00
|
|
|
dispatch(resetSendState());
|
2018-09-20 02:48:28 +02:00
|
|
|
|
2020-12-18 06:34:43 +01:00
|
|
|
txIds.forEach((id) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(completedTx(id));
|
|
|
|
});
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
2022-01-05 18:09:19 +01:00
|
|
|
closeNotificationPopup();
|
2020-12-18 06:34:43 +01:00
|
|
|
} else {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-12-18 06:34:43 +01:00
|
|
|
}
|
2018-09-20 02:48:28 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-20 02:48:28 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function markPasswordForgotten(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2020-04-22 21:15:22 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('markPasswordForgotten', [], (error) => {
|
2020-04-22 21:15:22 +02:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2020-04-22 21:15:22 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
2020-04-22 21:15:22 +02:00
|
|
|
} finally {
|
|
|
|
// TODO: handle errors
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2020-04-22 21:15:22 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-02-08 01:38:55 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function unMarkPasswordForgotten(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<void>((resolve) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('unMarkPasswordForgotten', [], () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}).then(() => forceUpdateMetamaskState(dispatch));
|
|
|
|
};
|
2018-02-08 01:38:55 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function closeWelcomeScreen() {
|
2018-03-08 18:31:21 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.CLOSE_WELCOME_SCREEN,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-08 18:31:21 +01:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
//
|
|
|
|
// unlock screen
|
|
|
|
//
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function unlockInProgress() {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UNLOCK_IN_PROGRESS,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function unlockFailed(message?: string) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UNLOCK_FAILED,
|
2016-11-02 01:00:17 +01:00
|
|
|
value: message,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function unlockSucceeded(message?: string) {
|
2018-01-30 03:44:43 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UNLOCK_SUCCEEDED,
|
2018-01-30 03:44:43 +01:00
|
|
|
value: message,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateMetamaskState(
|
|
|
|
newState: MetaMaskReduxState['metamask'],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2020-04-28 15:40:28 +02:00
|
|
|
return (dispatch, getState) => {
|
2023-05-02 14:36:24 +02:00
|
|
|
const state = getState();
|
|
|
|
const providerConfig = getProviderConfig(state);
|
|
|
|
const { metamask: currentState } = state;
|
2020-04-28 15:40:28 +02:00
|
|
|
|
2023-05-02 14:36:24 +02:00
|
|
|
const { currentLocale, selectedAddress } = currentState;
|
2020-04-29 19:10:51 +02:00
|
|
|
const {
|
|
|
|
currentLocale: newLocale,
|
|
|
|
selectedAddress: newSelectedAddress,
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: newProviderConfig,
|
2021-02-04 19:15:23 +01:00
|
|
|
} = newState;
|
2020-04-28 15:40:28 +02:00
|
|
|
|
|
|
|
if (currentLocale && newLocale && currentLocale !== newLocale) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateCurrentLocale(newLocale));
|
2020-04-28 15:40:28 +02:00
|
|
|
}
|
2021-06-23 23:35:25 +02:00
|
|
|
|
2020-04-29 19:10:51 +02:00
|
|
|
if (selectedAddress !== newSelectedAddress) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch({ type: actionConstants.SELECTED_ADDRESS_CHANGED });
|
2020-04-29 19:10:51 +02:00
|
|
|
}
|
2020-04-28 15:40:28 +02:00
|
|
|
|
2023-05-02 14:36:24 +02:00
|
|
|
const newAddressBook =
|
|
|
|
newState.addressBook?.[newProviderConfig?.chainId] ?? {};
|
|
|
|
const oldAddressBook =
|
|
|
|
currentState.addressBook?.[providerConfig?.chainId] ?? {};
|
2023-02-03 18:56:44 +01:00
|
|
|
const newAccounts: { [address: string]: Record<string, any> } =
|
|
|
|
getMetaMaskAccounts({ metamask: newState });
|
|
|
|
const oldAccounts: { [address: string]: Record<string, any> } =
|
|
|
|
getMetaMaskAccounts({ metamask: currentState });
|
2021-06-23 23:35:25 +02:00
|
|
|
const newSelectedAccount = newAccounts[newSelectedAddress];
|
|
|
|
const oldSelectedAccount = newAccounts[selectedAddress];
|
|
|
|
// dispatch an ACCOUNT_CHANGED for any account whose balance or other
|
|
|
|
// properties changed in this update
|
|
|
|
Object.entries(oldAccounts).forEach(([address, oldAccount]) => {
|
|
|
|
if (!isEqual(oldAccount, newAccounts[address])) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.ACCOUNT_CHANGED,
|
|
|
|
payload: { account: newAccounts[address] },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Also emit an event for the selected account changing, either due to a
|
|
|
|
// property update or if the entire account changes.
|
|
|
|
if (isEqual(oldSelectedAccount, newSelectedAccount) === false) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SELECTED_ACCOUNT_CHANGED,
|
|
|
|
payload: { account: newSelectedAccount },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// We need to keep track of changing address book entries
|
|
|
|
if (isEqual(oldAddressBook, newAddressBook) === false) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.ADDRESS_BOOK_UPDATED,
|
|
|
|
payload: { addressBook: newAddressBook },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-08 22:23:00 +02:00
|
|
|
// track when gasFeeEstimates change
|
|
|
|
if (
|
|
|
|
isEqual(currentState.gasFeeEstimates, newState.gasFeeEstimates) === false
|
|
|
|
) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.GAS_FEE_ESTIMATES_UPDATED,
|
|
|
|
payload: {
|
|
|
|
gasFeeEstimates: newState.gasFeeEstimates,
|
|
|
|
gasEstimateType: newState.gasEstimateType,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2022-08-03 18:54:35 +02:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.UPDATE_METAMASK_STATE,
|
|
|
|
value: newState,
|
|
|
|
});
|
2023-05-02 14:36:24 +02:00
|
|
|
if (providerConfig.chainId !== newProviderConfig.chainId) {
|
2021-06-23 23:35:25 +02:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.CHAIN_CHANGED,
|
2023-05-02 14:36:24 +02:00
|
|
|
payload: newProviderConfig.chainId,
|
2021-06-23 23:35:25 +02:00
|
|
|
});
|
2022-07-01 15:58:35 +02:00
|
|
|
// We dispatch this action to ensure that the send state stays up to date
|
|
|
|
// after the chain changes. This async thunk will fail gracefully in the
|
|
|
|
// event that we are not yet on the send flow with a draftTransaction in
|
|
|
|
// progress.
|
2023-02-03 18:56:44 +01:00
|
|
|
|
2022-07-01 15:58:35 +02:00
|
|
|
dispatch(initializeSendState({ chainHasChanged: true }));
|
2021-06-23 23:35:25 +02:00
|
|
|
}
|
2023-03-14 11:57:05 +01:00
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
2023-03-14 11:57:05 +01:00
|
|
|
updateCustodyState(dispatch, newState, getState());
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
const backgroundSetLocked = (): Promise<void> => {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setLocked', [], (error) => {
|
2017-10-27 08:02:56 +02:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2017-10-27 08:02:56 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-10-27 08:02:56 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function lockMetamask(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setLocked`);
|
2017-10-27 08:02:56 +02:00
|
|
|
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2017-10-27 08:02:56 +02:00
|
|
|
|
|
|
|
return backgroundSetLocked()
|
|
|
|
.then(() => updateMetamaskStateFromBackground())
|
2020-02-15 21:34:12 +01:00
|
|
|
.catch((error) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
return Promise.reject(error);
|
2017-10-27 08:02:56 +02:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch({ type: actionConstants.LOCK_METAMASK });
|
2018-01-12 00:49:10 +01:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch({ type: actionConstants.LOCK_METAMASK });
|
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
async function _setSelectedAddress(address: string): Promise<void> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setSelectedAddress`);
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSelectedAddress', [address]);
|
2020-05-01 18:56:46 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSelectedAddress(
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setSelectedAddress`);
|
2020-04-27 23:56:17 +02:00
|
|
|
try {
|
2021-09-10 19:37:19 +02:00
|
|
|
await _setSelectedAddress(address);
|
2020-04-27 23:56:17 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 23:56:17 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-10-12 19:29:03 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSelectedAccount(
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2020-04-29 19:10:51 +02:00
|
|
|
return async (dispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setSelectedAddress`);
|
2020-04-27 23:17:28 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const state = getState();
|
2022-07-31 20:26:40 +02:00
|
|
|
const unconnectedAccountAccountAlertIsEnabled =
|
|
|
|
getUnconnectedAccountAlertEnabledness(state);
|
2021-02-04 19:15:23 +01:00
|
|
|
const activeTabOrigin = state.activeTab.origin;
|
|
|
|
const selectedAddress = getSelectedAddress(state);
|
2022-07-31 20:26:40 +02:00
|
|
|
const permittedAccountsForCurrentTab =
|
|
|
|
getPermittedAccountsForCurrentTab(state);
|
2020-11-03 00:41:28 +01:00
|
|
|
const currentTabIsConnectedToPreviousAddress =
|
|
|
|
Boolean(activeTabOrigin) &&
|
2021-02-04 19:15:23 +01:00
|
|
|
permittedAccountsForCurrentTab.includes(selectedAddress);
|
2020-11-03 00:41:28 +01:00
|
|
|
const currentTabIsConnectedToNextAddress =
|
|
|
|
Boolean(activeTabOrigin) &&
|
2021-02-04 19:15:23 +01:00
|
|
|
permittedAccountsForCurrentTab.includes(address);
|
2020-11-03 00:41:28 +01:00
|
|
|
const switchingToUnconnectedAddress =
|
|
|
|
currentTabIsConnectedToPreviousAddress &&
|
2021-02-04 19:15:23 +01:00
|
|
|
!currentTabIsConnectedToNextAddress;
|
2020-04-29 19:10:51 +02:00
|
|
|
|
2020-04-27 23:17:28 +02:00
|
|
|
try {
|
2021-09-10 19:37:19 +02:00
|
|
|
await _setSelectedAddress(address);
|
2021-06-23 23:35:25 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2020-04-27 23:17:28 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-04-27 23:17:28 +02:00
|
|
|
}
|
2020-12-18 06:34:43 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
unconnectedAccountAccountAlertIsEnabled &&
|
|
|
|
switchingToUnconnectedAddress
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(switchedToUnconnectedAccount());
|
|
|
|
await setUnconnectedAccountAlertShown(activeTabOrigin);
|
2020-04-29 19:10:51 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addPermittedAccount(
|
|
|
|
origin: string,
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'addPermittedAccount',
|
|
|
|
[origin, address],
|
|
|
|
(error) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-04-17 00:23:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removePermittedAccount(
|
|
|
|
origin: string,
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
await new Promise<void>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'removePermittedAccount',
|
|
|
|
[origin, address],
|
|
|
|
(error) => {
|
|
|
|
if (error) {
|
|
|
|
reject(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-04-20 20:34:56 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showAccountsPage() {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_ACCOUNTS_PAGE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showConfTxPage({ id }: Partial<TransactionMeta> = {}) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_CONF_TX_PAGE,
|
2017-08-30 05:16:30 +02:00
|
|
|
id,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function addToken(
|
2023-02-03 18:56:44 +01:00
|
|
|
address?: string,
|
|
|
|
symbol?: string,
|
|
|
|
decimals?: number,
|
|
|
|
image?: string,
|
|
|
|
dontShowLoadingIndicator?: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-03-29 23:05:36 +02:00
|
|
|
if (!address) {
|
|
|
|
throw new Error('MetaMask - Cannot add token without address');
|
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
2021-09-10 19:37:19 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addToken', [
|
|
|
|
address,
|
|
|
|
symbol,
|
|
|
|
decimals,
|
|
|
|
image,
|
|
|
|
]);
|
2021-09-10 19:37:19 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-09-10 19:37:19 +02:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-11-19 17:16:41 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-04-13 18:23:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* To add the tokens user selected to state
|
|
|
|
*
|
|
|
|
* @param tokensToImport
|
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addImportedTokens(
|
|
|
|
tokensToImport: Token[],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-04-13 18:23:41 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addImportedTokens', [tokensToImport]);
|
2022-04-13 18:23:41 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-04-13 18:23:41 +02:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-18 16:43:30 +02:00
|
|
|
* To add ignored token addresses to state
|
2022-04-13 18:23:41 +02:00
|
|
|
*
|
2022-07-18 16:43:30 +02:00
|
|
|
* @param options
|
|
|
|
* @param options.tokensToIgnore
|
|
|
|
* @param options.dontShowLoadingIndicator
|
2022-04-13 18:23:41 +02:00
|
|
|
*/
|
2022-07-18 16:43:30 +02:00
|
|
|
export function ignoreTokens({
|
|
|
|
tokensToIgnore,
|
|
|
|
dontShowLoadingIndicator = false,
|
2023-02-03 18:56:44 +01:00
|
|
|
}: {
|
|
|
|
tokensToIgnore: string[];
|
|
|
|
dontShowLoadingIndicator: boolean;
|
|
|
|
}): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2022-07-18 16:43:30 +02:00
|
|
|
const _tokensToIgnore = Array.isArray(tokensToIgnore)
|
|
|
|
? tokensToIgnore
|
|
|
|
: [tokensToIgnore];
|
|
|
|
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-07-18 16:43:30 +02:00
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
2022-04-13 18:23:41 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('ignoreTokens', [_tokensToIgnore]);
|
2022-04-13 18:23:41 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2022-04-13 18:23:41 +02:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2022-07-18 16:43:30 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
2022-04-13 18:23:41 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To fetch the ERC20 tokens with non-zero balance in a single call
|
|
|
|
*
|
|
|
|
* @param tokens
|
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function getBalancesInSingleCall(
|
|
|
|
tokens: string[],
|
|
|
|
): Promise<BalanceMap> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return await submitRequestToBackground('getBalancesInSingleCall', [tokens]);
|
2022-04-13 18:23:41 +02:00
|
|
|
}
|
2021-11-19 17:16:41 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addNft(
|
|
|
|
address: string,
|
|
|
|
tokenID: string,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-19 17:16:41 +01:00
|
|
|
if (!address) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot add NFT without address');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!tokenID) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot add NFT without tokenID');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-11-15 19:49:42 +01:00
|
|
|
await submitRequestToBackground('addNft', [address, tokenID]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-11-19 17:16:41 +01:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-11-15 19:49:42 +01:00
|
|
|
export function addNftVerifyOwnership(
|
2023-02-03 18:56:44 +01:00
|
|
|
address: string,
|
|
|
|
tokenID: string,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-26 21:03:35 +01:00
|
|
|
if (!address) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot add NFT without address');
|
2021-11-26 21:03:35 +01:00
|
|
|
}
|
|
|
|
if (!tokenID) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot add NFT without tokenID');
|
2021-11-26 21:03:35 +01:00
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-11-15 19:49:42 +01:00
|
|
|
await submitRequestToBackground('addNftVerifyOwnership', [
|
2021-11-26 21:03:35 +01:00
|
|
|
address,
|
|
|
|
tokenID,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-11-26 21:03:35 +01:00
|
|
|
} catch (error) {
|
|
|
|
if (
|
2023-02-03 18:56:44 +01:00
|
|
|
isErrorWithMessage(error) &&
|
|
|
|
(error.message.includes('This NFT is not owned by the user') ||
|
|
|
|
error.message.includes('Unable to verify ownership'))
|
2021-11-26 21:03:35 +01:00
|
|
|
) {
|
|
|
|
throw error;
|
|
|
|
} else {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-11-26 21:03:35 +01:00
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removeAndIgnoreNft(
|
|
|
|
address: string,
|
|
|
|
tokenID: string,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-19 17:16:41 +01:00
|
|
|
if (!address) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot ignore NFT without address');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!tokenID) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot ignore NFT without tokenID');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-11-15 19:49:42 +01:00
|
|
|
await submitRequestToBackground('removeAndIgnoreNft', [address, tokenID]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-11-19 17:16:41 +01:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removeNft(
|
|
|
|
address: string,
|
|
|
|
tokenID: string,
|
|
|
|
dontShowLoadingIndicator: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-19 17:16:41 +01:00
|
|
|
if (!address) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot remove NFT without address');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!tokenID) {
|
2023-02-16 20:23:29 +01:00
|
|
|
throw new Error('MetaMask - Cannot remove NFT without tokenID');
|
2021-11-19 17:16:41 +01:00
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-11-15 19:49:42 +01:00
|
|
|
await submitRequestToBackground('removeNft', [address, tokenID]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
|
|
|
dispatch(displayWarning(error));
|
2021-11-19 17:16:41 +01:00
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-09-10 19:37:19 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-06-16 01:22:53 +02:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:49:42 +01:00
|
|
|
export async function checkAndUpdateAllNftsOwnershipStatus() {
|
|
|
|
await submitRequestToBackground('checkAndUpdateAllNftsOwnershipStatus');
|
2022-01-10 17:23:53 +01:00
|
|
|
}
|
|
|
|
|
2022-11-15 19:49:42 +01:00
|
|
|
export async function isNftOwner(
|
2023-02-03 18:56:44 +01:00
|
|
|
ownerAddress: string,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddress: string,
|
|
|
|
nftId: string,
|
2023-02-03 18:56:44 +01:00
|
|
|
): Promise<boolean> {
|
2022-11-15 19:49:42 +01:00
|
|
|
return await submitRequestToBackground('isNftOwner', [
|
2022-01-10 17:23:53 +01:00
|
|
|
ownerAddress,
|
2023-02-16 20:23:29 +01:00
|
|
|
nftAddress,
|
|
|
|
nftId,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-01-10 17:23:53 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function checkAndUpdateSingleNftOwnershipStatus(nft: Nft) {
|
2022-11-15 19:49:42 +01:00
|
|
|
await submitRequestToBackground('checkAndUpdateSingleNftOwnershipStatus', [
|
2023-02-03 18:56:44 +01:00
|
|
|
nft,
|
2022-11-15 19:49:42 +01:00
|
|
|
false,
|
|
|
|
]);
|
2022-01-03 21:39:41 +01:00
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
// When we upgrade to TypeScript 4.5 this is part of the language. It will get
|
|
|
|
// the underlying type of a Promise generic type. So Awaited<Promise<void>> is
|
|
|
|
// void.
|
|
|
|
type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
2022-01-03 21:39:41 +01:00
|
|
|
|
2022-01-19 15:38:33 +01:00
|
|
|
export async function getTokenStandardAndDetails(
|
2023-02-03 18:56:44 +01:00
|
|
|
address: string,
|
|
|
|
userAddress: string,
|
|
|
|
tokenId: string,
|
|
|
|
): Promise<
|
|
|
|
Awaited<
|
|
|
|
ReturnType<AssetsContractController['getTokenStandardAndDetails']>
|
|
|
|
> & { balance?: string }
|
|
|
|
> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return await submitRequestToBackground('getTokenStandardAndDetails', [
|
2022-01-19 15:38:33 +01:00
|
|
|
address,
|
|
|
|
userAddress,
|
|
|
|
tokenId,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-01-19 15:38:33 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addTokens(
|
|
|
|
tokens: Token[] | { [address: string]: Token },
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2017-09-22 03:44:52 +02:00
|
|
|
if (Array.isArray(tokens)) {
|
2020-11-03 00:41:28 +01:00
|
|
|
return Promise.all(
|
|
|
|
tokens.map(({ address, symbol, decimals }) =>
|
|
|
|
dispatch(addToken(address, symbol, decimals)),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2017-09-22 03:44:52 +02:00
|
|
|
}
|
2020-08-19 18:27:05 +02:00
|
|
|
return Promise.all(
|
2020-11-03 00:41:28 +01:00
|
|
|
Object.entries(tokens).map(([_, { address, symbol, decimals }]) =>
|
|
|
|
dispatch(addToken(address, symbol, decimals)),
|
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
};
|
2017-09-22 03:44:52 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function clearPendingTokens(): Action {
|
2017-10-03 19:25:52 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.CLEAR_PENDING_TOKENS,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-10-03 19:25:52 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createCancelTransaction(
|
|
|
|
txId: number,
|
|
|
|
customGasSettings: CustomGasSettings,
|
|
|
|
options: { estimatedBaseFee?: string } = {},
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('background.cancelTransaction');
|
2023-02-03 18:56:44 +01:00
|
|
|
let newTxId: number;
|
2018-09-09 19:07:23 +02:00
|
|
|
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<MetaMaskReduxState['metamask']>((resolve, reject) => {
|
|
|
|
callBackgroundMethod<MetaMaskReduxState['metamask']>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'createCancelTransaction',
|
2022-09-09 13:50:31 +02:00
|
|
|
[txId, customGasSettings, { ...options, actionId }],
|
2020-11-03 00:41:28 +01:00
|
|
|
(err, newState) => {
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
if (newState) {
|
|
|
|
const { currentNetworkTxList } = newState;
|
|
|
|
const { id } =
|
|
|
|
currentNetworkTxList[currentNetworkTxList.length - 1];
|
|
|
|
newTxId = id;
|
|
|
|
resolve(newState);
|
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2022-09-09 13:50:31 +02:00
|
|
|
actionId,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-09-09 19:07:23 +02:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => dispatch(updateMetamaskState(newState)))
|
2021-02-04 19:15:23 +01:00
|
|
|
.then(() => newTxId);
|
|
|
|
};
|
2018-09-09 19:07:23 +02:00
|
|
|
}
|
|
|
|
|
2022-12-08 19:37:06 +01:00
|
|
|
export function createSpeedUpTransaction(
|
2023-02-03 18:56:44 +01:00
|
|
|
txId: string,
|
|
|
|
customGasSettings: CustomGasSettings,
|
|
|
|
options: { estimatedBaseFee?: string } = {},
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('background.createSpeedUpTransaction');
|
2023-02-03 18:56:44 +01:00
|
|
|
let newTx: TransactionMeta;
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<MetaMaskReduxState['metamask']>((resolve, reject) => {
|
|
|
|
callBackgroundMethod<MetaMaskReduxState['metamask']>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'createSpeedUpTransaction',
|
2022-09-13 14:43:38 +02:00
|
|
|
[txId, customGasSettings, { ...options, actionId }],
|
2020-11-03 00:41:28 +01:00
|
|
|
(err, newState) => {
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2019-10-28 14:28:46 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
if (newState) {
|
|
|
|
const { currentNetworkTxList } = newState;
|
|
|
|
newTx = currentNetworkTxList[currentNetworkTxList.length - 1];
|
|
|
|
resolve(newState);
|
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2022-09-13 14:43:38 +02:00
|
|
|
actionId,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-10-28 14:28:46 +01:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => dispatch(updateMetamaskState(newState)))
|
2021-02-04 19:15:23 +01:00
|
|
|
.then(() => newTx);
|
|
|
|
};
|
2019-10-28 14:28:46 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createRetryTransaction(
|
|
|
|
txId: string,
|
|
|
|
customGasSettings: CustomGasSettings,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
|
|
|
let newTx: TransactionMeta;
|
2019-10-28 14:28:46 +01:00
|
|
|
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<MetaMaskReduxState['metamask']>((resolve, reject) => {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2023-02-03 18:56:44 +01:00
|
|
|
callBackgroundMethod<MetaMaskReduxState['metamask']>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'createSpeedUpTransaction',
|
2022-09-16 19:04:14 +02:00
|
|
|
[txId, customGasSettings, { actionId }],
|
2020-11-03 00:41:28 +01:00
|
|
|
(err, newState) => {
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
if (newState) {
|
|
|
|
const { currentNetworkTxList } = newState;
|
|
|
|
newTx = currentNetworkTxList[currentNetworkTxList.length - 1];
|
|
|
|
resolve(newState);
|
|
|
|
}
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2018-10-26 07:50:36 +02:00
|
|
|
})
|
2020-02-15 21:34:12 +01:00
|
|
|
.then((newState) => dispatch(updateMetamaskState(newState)))
|
2021-02-04 19:15:23 +01:00
|
|
|
.then(() => newTx);
|
|
|
|
};
|
2018-10-26 07:50:36 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:28:44 +02:00
|
|
|
//
|
|
|
|
// config
|
|
|
|
//
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setProviderType(
|
|
|
|
type: NetworkType,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setProviderType`, type);
|
2017-10-26 03:23:46 +02:00
|
|
|
|
2020-04-28 14:50:04 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setProviderType', [type]);
|
2020-04-28 14:50:04 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
2020-04-28 14:50:04 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-03-07 19:25:50 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function upsertNetworkConfiguration(
|
|
|
|
{
|
|
|
|
rpcUrl,
|
|
|
|
chainId,
|
|
|
|
nickname,
|
|
|
|
rpcPrefs,
|
|
|
|
ticker = EtherDenomination.ETH,
|
|
|
|
}: {
|
|
|
|
rpcUrl: string;
|
|
|
|
chainId: string;
|
|
|
|
nickname: string;
|
|
|
|
rpcPrefs: RPCDefinition['rpcPrefs'];
|
|
|
|
ticker: string;
|
|
|
|
},
|
|
|
|
{
|
|
|
|
setActive,
|
|
|
|
source,
|
|
|
|
}: {
|
|
|
|
setActive: boolean;
|
|
|
|
source: string;
|
|
|
|
},
|
2023-02-03 18:56:44 +01:00
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-09 22:00:28 +01:00
|
|
|
return async (dispatch) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug(
|
2023-03-09 22:00:28 +01:00
|
|
|
`background.upsertNetworkConfiguration: ${rpcUrl} ${chainId} ${ticker} ${nickname}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2023-03-09 22:00:28 +01:00
|
|
|
let networkConfigurationId;
|
2020-04-28 18:56:18 +02:00
|
|
|
try {
|
2023-03-09 22:00:28 +01:00
|
|
|
networkConfigurationId = await submitRequestToBackground(
|
|
|
|
'upsertNetworkConfiguration',
|
|
|
|
[
|
|
|
|
{ rpcUrl, chainId, ticker, nickname: nickname || rpcUrl, rpcPrefs },
|
|
|
|
{ setActive, source, referrer: ORIGIN_METAMASK },
|
|
|
|
],
|
|
|
|
);
|
2020-04-28 18:56:18 +02:00
|
|
|
} catch (error) {
|
2023-03-09 22:00:28 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem adding network!'));
|
2020-04-28 18:56:18 +02:00
|
|
|
}
|
2023-03-09 22:00:28 +01:00
|
|
|
return networkConfigurationId;
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-29 19:13:51 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function editAndSetNetworkConfiguration(
|
|
|
|
{
|
|
|
|
networkConfigurationId,
|
|
|
|
rpcUrl,
|
|
|
|
chainId,
|
|
|
|
nickname,
|
|
|
|
rpcPrefs,
|
|
|
|
ticker = EtherDenomination.ETH,
|
|
|
|
}: {
|
|
|
|
networkConfigurationId: string;
|
|
|
|
rpcUrl: string;
|
|
|
|
chainId: string;
|
|
|
|
nickname: string;
|
|
|
|
rpcPrefs: RPCDefinition['rpcPrefs'];
|
|
|
|
ticker: string;
|
|
|
|
},
|
|
|
|
{ source }: { source: string },
|
2023-02-03 18:56:44 +01:00
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-09 22:00:28 +01:00
|
|
|
return async (dispatch) => {
|
|
|
|
log.debug(
|
|
|
|
`background.removeNetworkConfiguration: ${networkConfigurationId}`,
|
|
|
|
);
|
2020-04-24 14:48:59 +02:00
|
|
|
try {
|
2023-03-09 22:00:28 +01:00
|
|
|
await submitRequestToBackground('removeNetworkConfiguration', [
|
|
|
|
networkConfigurationId,
|
|
|
|
]);
|
2020-04-24 14:48:59 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Had a problem removing network!'));
|
|
|
|
return;
|
2020-04-24 14:48:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-03-09 22:00:28 +01:00
|
|
|
await submitRequestToBackground('upsertNetworkConfiguration', [
|
|
|
|
{
|
|
|
|
rpcUrl,
|
|
|
|
chainId,
|
|
|
|
ticker,
|
|
|
|
nickname: nickname || rpcUrl,
|
|
|
|
rpcPrefs,
|
|
|
|
},
|
|
|
|
{ setActive: true, referrer: ORIGIN_METAMASK, source },
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-24 14:48:59 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
2020-04-24 14:48:59 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function setActiveNetwork(
|
|
|
|
networkConfigurationId: string,
|
2023-02-03 18:56:44 +01:00
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-09 22:00:28 +01:00
|
|
|
return async (dispatch) => {
|
|
|
|
log.debug(`background.setActiveNetwork: ${networkConfigurationId}`);
|
2020-04-24 14:59:13 +02:00
|
|
|
try {
|
2023-03-09 22:00:28 +01:00
|
|
|
await submitRequestToBackground('setActiveNetwork', [
|
|
|
|
networkConfigurationId,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-24 14:59:13 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
2020-04-24 14:59:13 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function rollbackToPreviousProvider(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-01-07 00:31:11 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('rollbackToPreviousProvider');
|
2021-01-07 00:31:11 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
2021-01-07 00:31:11 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2021-01-07 00:31:11 +01:00
|
|
|
}
|
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function removeNetworkConfiguration(
|
|
|
|
networkConfigurationId: string,
|
|
|
|
): ThunkAction<Promise<void>, MetaMaskReduxState, unknown, AnyAction> {
|
|
|
|
return (dispatch) => {
|
|
|
|
log.debug(
|
|
|
|
`background.removeNetworkConfiguration: ${networkConfigurationId}`,
|
|
|
|
);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
callBackgroundMethod(
|
|
|
|
'removeNetworkConfiguration',
|
|
|
|
[networkConfigurationId],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
dispatch(displayWarning('Had a problem removing network!'));
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2018-09-28 21:53:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-21 14:57:49 +01:00
|
|
|
// Calls the addressBookController to add a new address.
|
2023-02-03 18:56:44 +01:00
|
|
|
export function addToAddressBook(
|
|
|
|
recipient: string,
|
|
|
|
nickname = '',
|
|
|
|
memo = '',
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.addToAddressBook`);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-04-29 06:59:49 +02:00
|
|
|
return async (dispatch, getState) => {
|
2023-05-02 14:36:24 +02:00
|
|
|
const { chainId } = getProviderConfig(getState());
|
2019-08-14 01:13:05 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let set;
|
2020-04-29 06:59:49 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
set = await submitRequestToBackground('setAddressBook', [
|
2021-05-17 23:19:39 +02:00
|
|
|
toChecksumHexAddress(recipient),
|
2020-11-03 00:41:28 +01:00
|
|
|
nickname,
|
|
|
|
chainId,
|
|
|
|
memo,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-29 06:59:49 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Address book failed to update'));
|
|
|
|
throw error;
|
2020-04-29 06:59:49 +02:00
|
|
|
}
|
|
|
|
if (!set) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning('Address book failed to update'));
|
2020-04-29 06:59:49 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description Calls the addressBookController to remove an existing address.
|
2022-01-07 16:57:33 +01:00
|
|
|
* @param chainId
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param addressToRemove - Address of the entry to remove from the address book
|
2019-07-31 21:56:44 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removeFromAddressBook(
|
|
|
|
chainId: string,
|
|
|
|
addressToRemove: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.removeFromAddressBook`);
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-04-29 14:36:10 +02:00
|
|
|
return async () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('removeFromAddressBook', [
|
2020-11-03 00:41:28 +01:00
|
|
|
chainId,
|
2021-05-17 23:19:39 +02:00
|
|
|
toChecksumHexAddress(addressToRemove),
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-03-10 00:10:27 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showNetworkDropdown(): Action {
|
2017-08-13 22:15:21 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.NETWORK_DROPDOWN_OPEN,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-08-13 22:15:21 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function hideNetworkDropdown() {
|
2017-08-13 22:15:21 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.NETWORK_DROPDOWN_CLOSE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-08-13 22:15:21 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
type ModalPayload = { name: string } & Record<string, any>;
|
|
|
|
|
|
|
|
export function showModal(payload: ModalPayload): PayloadAction<ModalPayload> {
|
2017-08-08 22:37:16 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.MODAL_OPEN,
|
2017-08-21 03:32:58 +02:00
|
|
|
payload,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-08-08 22:37:16 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function hideModal(): Action {
|
2017-08-08 22:37:16 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.MODAL_CLOSE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-08-08 22:37:16 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function closeCurrentNotificationWindow(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-02-25 23:25:51 +01:00
|
|
|
return (_, getState) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION &&
|
2023-05-11 07:56:17 +02:00
|
|
|
!hasTransactionPendingApprovals(getState())
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2022-01-05 18:09:19 +01:00
|
|
|
closeNotificationPopup();
|
2019-07-16 10:55:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-07-16 10:55:52 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showAlert(msg: string): PayloadAction<string> {
|
2018-07-19 08:31:02 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.ALERT_OPEN,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: msg,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-19 08:31:02 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function hideAlert(): Action {
|
2018-07-19 08:31:02 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.ALERT_CLOSE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-19 08:31:02 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
/**
|
|
|
|
* TODO: this should be moved somewhere else when it makese sense to do so
|
|
|
|
*/
|
2023-02-16 20:23:29 +01:00
|
|
|
interface NftDropDownState {
|
2023-02-03 18:56:44 +01:00
|
|
|
[address: string]: {
|
|
|
|
[chainId: string]: {
|
2023-02-16 20:23:29 +01:00
|
|
|
[nftAddress: string]: boolean;
|
2023-02-03 18:56:44 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
export function updateNftDropDownState(
|
|
|
|
value: NftDropDownState,
|
2023-02-03 18:56:44 +01:00
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-16 20:23:29 +01:00
|
|
|
await submitRequestToBackground('updateNftDropDownState', [value]);
|
2022-01-27 18:26:33 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
interface QrCodeData {
|
|
|
|
// Address when a Ethereum Address has been detected
|
|
|
|
type?: 'address' | string;
|
|
|
|
// contains an address key when Ethereum Address detected
|
|
|
|
values?: { address?: string } & Json;
|
|
|
|
}
|
|
|
|
|
2018-08-08 21:42:25 +02:00
|
|
|
/**
|
|
|
|
* This action will receive two types of values via qrCodeData
|
|
|
|
* an object with the following structure {type, values}
|
|
|
|
* or null (used to clear the previous value)
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
|
|
|
* @param qrCodeData
|
2018-08-08 21:42:25 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function qrCodeDetected(
|
|
|
|
qrCodeData: QrCodeData,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-06-23 23:35:25 +02:00
|
|
|
await dispatch({
|
|
|
|
type: actionConstants.QR_CODE_DETECTED,
|
|
|
|
value: qrCodeData,
|
|
|
|
});
|
|
|
|
|
|
|
|
// If on the send page, the send slice will listen for the QR_CODE_DETECTED
|
|
|
|
// action and update its state. Address changes need to recompute gasLimit
|
|
|
|
// so we fire this method so that the send page gasLimit can be recomputed
|
|
|
|
dispatch(computeEstimatedGasLimit());
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-25 02:32:20 +02:00
|
|
|
}
|
2017-08-02 22:32:02 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showLoadingIndication(
|
2023-03-06 18:48:28 +01:00
|
|
|
message?: string | ReactFragment,
|
|
|
|
): PayloadAction<string | ReactFragment | undefined> {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_LOADING,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: message,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setHardwareWalletDefaultHdPath({
|
|
|
|
device,
|
|
|
|
path,
|
|
|
|
}: {
|
|
|
|
device: HardwareDeviceNames;
|
|
|
|
path: string;
|
|
|
|
}): PayloadAction<{ device: HardwareDeviceNames; path: string }> {
|
2019-07-31 22:17:11 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_HARDWARE_WALLET_DEFAULT_HD_PATH,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: { device, path },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-14 01:29:43 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function hideLoadingIndication(): Action {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.HIDE_LOADING,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function displayWarning(payload: unknown): PayloadAction<string> {
|
|
|
|
if (isErrorWithMessage(payload)) {
|
|
|
|
return {
|
|
|
|
type: actionConstants.DISPLAY_WARNING,
|
|
|
|
payload: payload.message,
|
|
|
|
};
|
|
|
|
} else if (typeof payload === 'string') {
|
|
|
|
return {
|
|
|
|
type: actionConstants.DISPLAY_WARNING,
|
|
|
|
payload,
|
|
|
|
};
|
|
|
|
}
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.DISPLAY_WARNING,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: `${payload}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function hideWarning() {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.HIDE_WARNING,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function exportAccount(
|
|
|
|
password: string,
|
|
|
|
address: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2016-06-21 22:18:32 +02:00
|
|
|
return function (dispatch) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2016-04-14 00:28:44 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.verifyPassword`);
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<string>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('verifyPassword', [password], function (err) {
|
2017-03-21 16:53:34 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error('Error in verifying password.');
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(displayWarning('Incorrect Password.'));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2017-03-21 16:53:34 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.exportAccount`);
|
2023-02-03 18:56:44 +01:00
|
|
|
callBackgroundMethod<string>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'exportAccount',
|
2023-01-17 16:01:12 +01:00
|
|
|
[address, password],
|
2022-09-05 16:55:34 +02:00
|
|
|
function (err2, result) {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
|
|
|
|
if (err2) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(err2);
|
2022-09-05 16:55:34 +02:00
|
|
|
dispatch(displayWarning('Had a problem exporting the account.'));
|
|
|
|
reject(err2);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-21 16:53:34 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(showPrivateKey(result as string));
|
|
|
|
resolve(result as string);
|
2022-09-05 16:55:34 +02:00
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function exportAccounts(
|
|
|
|
password: string,
|
|
|
|
addresses: string[],
|
|
|
|
): ThunkAction<Promise<string[]>, MetaMaskReduxState, unknown, AnyAction> {
|
2020-06-26 03:04:17 +02:00
|
|
|
return function (dispatch) {
|
2021-06-09 22:42:25 +02:00
|
|
|
log.debug(`background.verifyPassword`);
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<string[]>((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('verifyPassword', [password], function (err) {
|
2020-06-26 03:04:17 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error('Error in submitting password.');
|
|
|
|
reject(err);
|
|
|
|
return;
|
2020-06-26 03:04:17 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.exportAccounts`);
|
2020-11-03 00:41:28 +01:00
|
|
|
const accountPromises = addresses.map(
|
|
|
|
(address) =>
|
2023-02-03 18:56:44 +01:00
|
|
|
new Promise<string>((resolve2, reject2) =>
|
|
|
|
callBackgroundMethod<string>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'exportAccount',
|
2023-01-17 16:01:12 +01:00
|
|
|
[address, password],
|
2022-09-05 16:55:34 +02:00
|
|
|
function (err2, result) {
|
|
|
|
if (err2) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(err2);
|
2022-09-05 16:55:34 +02:00
|
|
|
dispatch(
|
|
|
|
displayWarning('Had a problem exporting the account.'),
|
|
|
|
);
|
|
|
|
reject2(err2);
|
|
|
|
return;
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve2(result as string);
|
2022-09-05 16:55:34 +02:00
|
|
|
},
|
|
|
|
),
|
2020-11-03 00:41:28 +01:00
|
|
|
),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
resolve(Promise.all(accountPromises));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2020-06-26 03:04:17 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showPrivateKey(key: string): PayloadAction<string> {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_PRIVATE_KEY,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: key,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setAccountLabel(
|
|
|
|
account: string,
|
|
|
|
label: string,
|
|
|
|
): ThunkAction<Promise<string>, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setAccountLabel`);
|
2017-10-26 03:23:46 +02:00
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setAccountLabel', [account, label], (err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2017-10-26 03:23:46 +02:00
|
|
|
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2017-10-26 03:23:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_ACCOUNT_LABEL,
|
2017-10-26 03:23:46 +02:00
|
|
|
value: { account, label },
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
resolve(account);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2016-05-21 01:18:54 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function clearAccountDetails(): Action {
|
2020-08-15 01:08:26 +02:00
|
|
|
return {
|
|
|
|
type: actionConstants.CLEAR_ACCOUNT_DETAILS,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-08-15 01:08:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function showSendTokenPage(): Action {
|
2017-09-07 13:24:03 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_SEND_TOKEN_PAGE,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-09-07 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: Lift to shared folder when it makes sense
|
|
|
|
interface TemporaryFeatureFlagDef {
|
|
|
|
[feature: string]: boolean;
|
|
|
|
}
|
|
|
|
interface TemporaryPreferenceFlagDef {
|
|
|
|
[preference: string]: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setFeatureFlag(
|
|
|
|
feature: string,
|
|
|
|
activated: boolean,
|
|
|
|
notificationType: string,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryFeatureFlagDef>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2017-11-14 17:04:55 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
callBackgroundMethod<TemporaryFeatureFlagDef>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'setFeatureFlag',
|
|
|
|
[feature, activated],
|
2020-11-03 00:41:28 +01:00
|
|
|
(err, updatedFeatureFlags) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-11-03 00:41:28 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
notificationType && dispatch(showModal({ name: notificationType }));
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve(updatedFeatureFlags as TemporaryFeatureFlagDef);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setPreference(
|
|
|
|
preference: string,
|
|
|
|
value: boolean | string,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<TemporaryPreferenceFlagDef>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2023-02-03 18:56:44 +01:00
|
|
|
return new Promise<TemporaryPreferenceFlagDef>((resolve, reject) => {
|
|
|
|
callBackgroundMethod<TemporaryPreferenceFlagDef>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'setPreference',
|
|
|
|
[preference, value],
|
|
|
|
(err, updatedPreferences) => {
|
|
|
|
dispatch(hideLoadingIndication());
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2022-09-05 16:55:34 +02:00
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
|
|
|
|
resolve(updatedPreferences as TemporaryPreferenceFlagDef);
|
2022-09-05 16:55:34 +02:00
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setDefaultHomeActiveTabName(
|
|
|
|
value: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setDefaultHomeActiveTabName', [value]);
|
2021-05-03 19:51:09 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2020-05-25 21:01:28 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseNativeCurrencyAsPrimaryCurrencyPreference(
|
|
|
|
value: boolean,
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('useNativeCurrencyAsPrimaryCurrency', value);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setHideZeroBalanceTokens(value: boolean) {
|
2021-03-09 20:35:55 +01:00
|
|
|
return setPreference('hideZeroBalanceTokens', value);
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setShowFiatConversionOnTestnetsPreference(value: boolean) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('showFiatInTestnets', value);
|
2019-02-26 19:30:41 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setShowTestNetworks(value: boolean) {
|
2021-10-28 21:31:05 +02:00
|
|
|
return setPreference('showTestNetworks', value);
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setAutoLockTimeLimit(value: boolean) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('autoLockTimeLimit', value);
|
2019-05-08 20:57:21 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setCompletedOnboarding(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2019-03-29 05:51:54 +01:00
|
|
|
|
2019-03-29 05:40:04 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('completeOnboarding');
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(completeOnboarding());
|
2019-03-29 05:40:04 +01:00
|
|
|
} catch (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw err;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2019-03-29 05:40:04 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function completeOnboarding() {
|
2019-01-23 16:25:34 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.COMPLETE_ONBOARDING,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-23 16:25:34 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setMouseUserState(
|
|
|
|
isMouseUser: boolean,
|
|
|
|
): PayloadAction<boolean> {
|
2018-02-12 18:45:53 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_MOUSE_USER_STATE,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: isMouseUser,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-02-12 18:45:53 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function forceUpdateMetamaskState(
|
|
|
|
dispatch: MetaMaskReduxDispatch,
|
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.getState`);
|
2018-03-08 16:29:29 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-27 23:21:17 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
newState = await submitRequestToBackground<MetaMaskReduxState['metamask']>(
|
|
|
|
'getState',
|
|
|
|
);
|
2020-04-27 23:21:17 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
throw error;
|
2020-04-27 23:21:17 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
return newState;
|
2017-02-04 05:45:20 +01:00
|
|
|
}
|
2017-10-16 07:28:25 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function toggleAccountMenu() {
|
2017-10-16 07:28:25 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.TOGGLE_ACCOUNT_MENU,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-10-16 07:28:25 +02:00
|
|
|
}
|
2017-11-24 02:33:44 +01:00
|
|
|
|
2023-04-13 18:54:03 +02:00
|
|
|
export function toggleNetworkMenu() {
|
|
|
|
return {
|
|
|
|
type: actionConstants.TOGGLE_NETWORK_MENU,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-03 19:09:13 +02:00
|
|
|
export function setAccountDetailsAddress(address: string) {
|
|
|
|
return {
|
|
|
|
type: actionConstants.SET_ACCOUNT_DETAILS_ADDRESS,
|
|
|
|
payload: address,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setParticipateInMetaMetrics(
|
|
|
|
participationPreference: boolean,
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<[boolean, string]>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setParticipateInMetaMetrics`);
|
2019-03-05 16:45:01 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
callBackgroundMethod<string>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'setParticipateInMetaMetrics',
|
2023-02-03 18:56:44 +01:00
|
|
|
[participationPreference],
|
2022-09-05 16:55:34 +02:00
|
|
|
(err, metaMetricsId) => {
|
|
|
|
log.debug(err);
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2022-09-05 16:55:34 +02:00
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-05 16:45:01 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_PARTICIPATE_IN_METAMETRICS,
|
2023-02-03 18:56:44 +01:00
|
|
|
value: participationPreference,
|
2022-09-05 16:55:34 +02:00
|
|
|
});
|
2023-02-03 18:56:44 +01:00
|
|
|
resolve([participationPreference, metaMetricsId as string]);
|
2022-09-05 16:55:34 +02:00
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseBlockie(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUseBlockie`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setUseBlockie', [val], (err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2017-11-24 18:35:17 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2017-11-24 18:35:17 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2017-11-25 23:47:34 +01:00
|
|
|
}
|
2017-12-22 19:43:02 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseNonceField(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUseNonceField`);
|
2021-12-01 19:46:10 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setUseNonceField', [val]);
|
2021-12-01 19:46:10 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-12-01 19:46:10 +01:00
|
|
|
}
|
|
|
|
dispatch(hideLoadingIndication());
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUsePhishDetect(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUsePhishDetect`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setUsePhishDetect', [val], (err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-02-27 07:29:41 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2020-02-27 07:29:41 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2020-02-27 07:29:41 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseMultiAccountBalanceChecker(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-12-01 22:16:04 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUseMultiAccountBalanceChecker`);
|
|
|
|
callBackgroundMethod('setUseMultiAccountBalanceChecker', [val], (err) => {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2022-12-01 22:16:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseTokenDetection(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-07-16 01:08:16 +02:00
|
|
|
dispatch(showLoadingIndication());
|
2021-09-09 22:56:27 +02:00
|
|
|
log.debug(`background.setUseTokenDetection`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setUseTokenDetection', [val], (err) => {
|
2021-07-16 01:08:16 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-07-16 01:08:16 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseNftDetection(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-26 19:54:57 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2022-11-15 19:49:42 +01:00
|
|
|
log.debug(`background.setUseNftDetection`);
|
|
|
|
callBackgroundMethod('setUseNftDetection', [val], (err) => {
|
2021-11-26 19:54:57 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-11-26 19:54:57 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setUseCurrencyRateCheck(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2023-01-17 16:23:04 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUseCurrencyRateCheck`);
|
|
|
|
callBackgroundMethod('setUseCurrencyRateCheck', [val], (err) => {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2023-01-17 16:23:04 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setOpenSeaEnabled(
|
|
|
|
val: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-12-01 05:12:27 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setOpenSeaEnabled`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setOpenSeaEnabled', [val], (err) => {
|
2021-12-01 05:12:27 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-12-01 05:12:27 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function detectNfts(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-12-14 00:41:10 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2022-11-15 19:49:42 +01:00
|
|
|
log.debug(`background.detectNfts`);
|
|
|
|
await submitRequestToBackground('detectNfts');
|
2021-12-14 00:41:10 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setAdvancedGasFee(
|
|
|
|
val: { maxBaseFee?: Hex; priorityFee?: Hex } | null,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-11 20:18:50 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setAdvancedGasFee`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setAdvancedGasFee', [val], (err) => {
|
2021-11-11 20:18:50 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-11-11 20:18:50 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setTheme(
|
|
|
|
val: ThemeType,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-03-07 19:53:19 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setTheme`);
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setTheme', [val]);
|
2022-03-07 19:53:19 +01:00
|
|
|
} finally {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setIpfsGateway(
|
|
|
|
val: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setIpfsGateway`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setIpfsGateway', [val], (err) => {
|
2019-12-12 20:28:07 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2019-12-12 20:28:07 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-12-12 20:28:07 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateCurrentLocale(
|
|
|
|
key: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2020-12-18 06:34:43 +01:00
|
|
|
|
|
|
|
try {
|
2021-02-04 19:15:23 +01:00
|
|
|
await loadRelativeTimeFormatLocaleData(key);
|
|
|
|
const localeMessages = await fetchLocale(key);
|
2023-02-03 18:56:44 +01:00
|
|
|
const textDirection = await submitRequestToBackground<
|
|
|
|
'rtl' | 'ltr' | 'auto'
|
|
|
|
>('setCurrentLocale', [key]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await switchDirection(textDirection);
|
|
|
|
dispatch(setCurrentLocale(key, localeMessages));
|
2020-12-18 06:34:43 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2020-12-18 06:34:43 +01:00
|
|
|
} finally {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2020-12-18 06:34:43 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-16 01:29:45 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setCurrentLocale(
|
|
|
|
locale: string,
|
|
|
|
messages: {
|
|
|
|
[translationKey: string]: { message: string; description?: string };
|
|
|
|
},
|
|
|
|
): PayloadAction<{
|
|
|
|
locale: string;
|
|
|
|
messages: {
|
|
|
|
[translationKey: string]: { message: string; description?: string };
|
|
|
|
};
|
|
|
|
}> {
|
2018-03-16 01:29:45 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_CURRENT_LOCALE,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: {
|
2019-09-06 15:47:07 +02:00
|
|
|
locale,
|
|
|
|
messages,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-16 01:29:45 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setPendingTokens(pendingTokens: {
|
|
|
|
customToken?: Token;
|
|
|
|
selectedTokens?: {
|
|
|
|
[address: string]: Token & { isCustom?: boolean; unlisted?: boolean };
|
|
|
|
};
|
|
|
|
tokenAddressList: string[];
|
|
|
|
}) {
|
2021-09-09 22:56:27 +02:00
|
|
|
const {
|
2023-02-03 18:56:44 +01:00
|
|
|
customToken,
|
2021-09-09 22:56:27 +02:00
|
|
|
selectedTokens = {},
|
|
|
|
tokenAddressList = [],
|
|
|
|
} = pendingTokens;
|
2020-11-03 00:41:28 +01:00
|
|
|
const tokens =
|
2023-02-03 18:56:44 +01:00
|
|
|
customToken?.address &&
|
|
|
|
customToken?.symbol &&
|
|
|
|
Boolean(customToken?.decimals >= 0 && customToken?.decimals <= 36)
|
2020-11-17 18:39:21 +01:00
|
|
|
? {
|
|
|
|
...selectedTokens,
|
2023-02-03 18:56:44 +01:00
|
|
|
[customToken.address]: {
|
2020-11-17 18:39:21 +01:00
|
|
|
...customToken,
|
|
|
|
isCustom: true,
|
|
|
|
},
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
: selectedTokens;
|
2018-05-20 08:04:19 +02:00
|
|
|
|
2020-11-17 18:39:21 +01:00
|
|
|
Object.keys(tokens).forEach((tokenAddress) => {
|
2021-09-09 22:56:27 +02:00
|
|
|
tokens[tokenAddress].unlisted = !tokenAddressList.find((addr) =>
|
|
|
|
isEqualCaseInsensitive(addr, tokenAddress),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
2020-11-17 18:39:21 +01:00
|
|
|
|
2018-05-20 08:04:19 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_PENDING_TOKENS,
|
2018-05-20 08:04:19 +02:00
|
|
|
payload: tokens,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-12-22 19:43:02 +01:00
|
|
|
}
|
2018-09-27 20:19:09 +02:00
|
|
|
|
2020-10-06 20:28:38 +02:00
|
|
|
// Swaps
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsLiveness(
|
|
|
|
swapsLiveness: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsLiveness', [swapsLiveness]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsFeatureFlags(
|
|
|
|
featureFlags: TemporaryFeatureFlagDef,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsFeatureFlags', [featureFlags]);
|
2022-02-18 17:48:38 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function fetchAndSetQuotes(
|
|
|
|
fetchParams: {
|
|
|
|
slippage: string;
|
|
|
|
sourceToken: string;
|
|
|
|
destinationToken: string;
|
|
|
|
value: string;
|
|
|
|
fromAddress: string;
|
|
|
|
balanceError: string;
|
|
|
|
sourceDecimals: number;
|
|
|
|
},
|
|
|
|
fetchParamsMetaData: {
|
|
|
|
sourceTokenInfo: Token;
|
|
|
|
destinationTokenInfo: Token;
|
|
|
|
accountBalance: string;
|
|
|
|
chainId: string;
|
|
|
|
},
|
|
|
|
): ThunkAction<
|
|
|
|
Promise<
|
|
|
|
[
|
|
|
|
{ destinationAmount: string; decimals: number; aggregator: string },
|
|
|
|
string,
|
|
|
|
]
|
|
|
|
>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
const [quotes, selectedAggId] = await submitRequestToBackground(
|
|
|
|
'fetchAndSetQuotes',
|
|
|
|
[fetchParams, fetchParamsMetaData],
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return [quotes, selectedAggId];
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSelectedQuoteAggId(
|
|
|
|
aggId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSelectedQuoteAggId', [aggId]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsTokens(
|
|
|
|
tokens: Token[],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsTokens', [tokens]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function clearSwapsQuotes(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('clearSwapsQuotes');
|
2021-09-15 15:13:18 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function resetBackgroundSwapsState(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
await submitRequestToBackground('resetSwapsState');
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setCustomApproveTxData(
|
|
|
|
data: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setCustomApproveTxData', [data]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsTxGasPrice(
|
|
|
|
gasPrice: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsTxGasPrice', [gasPrice]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsTxGasLimit(
|
|
|
|
gasLimit: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsTxGasLimit', [gasLimit, true]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2021-07-30 13:35:30 +02:00
|
|
|
export function updateCustomSwapsEIP1559GasParams({
|
|
|
|
gasLimit,
|
|
|
|
maxFeePerGas,
|
|
|
|
maxPriorityFeePerGas,
|
2023-02-03 18:56:44 +01:00
|
|
|
}: {
|
|
|
|
gasLimit: string;
|
|
|
|
maxFeePerGas: string;
|
|
|
|
maxPriorityFeePerGas: string;
|
|
|
|
}): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-07-30 13:35:30 +02:00
|
|
|
await Promise.all([
|
2022-09-05 16:55:34 +02:00
|
|
|
submitRequestToBackground('setSwapsTxGasLimit', [gasLimit]),
|
|
|
|
submitRequestToBackground('setSwapsTxMaxFeePerGas', [maxFeePerGas]),
|
|
|
|
submitRequestToBackground('setSwapsTxMaxFeePriorityPerGas', [
|
2021-07-30 13:35:30 +02:00
|
|
|
maxPriorityFeePerGas,
|
2022-09-05 16:55:34 +02:00
|
|
|
]),
|
2021-07-30 13:35:30 +02:00
|
|
|
]);
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// Note that the type widening happening below will resolve when we switch gas
|
|
|
|
// constants to TypeScript, at which point we'll get better type safety.
|
|
|
|
// TODO: Remove this comment when gas constants is typescript
|
|
|
|
export function updateSwapsUserFeeLevel(
|
|
|
|
swapsCustomUserFeeLevel: PriorityLevels,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsUserFeeLevel', [
|
|
|
|
swapsCustomUserFeeLevel,
|
|
|
|
]);
|
2021-08-06 21:31:30 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsQuotesPollingLimitEnabled(
|
|
|
|
quotesPollingLimitEnabled: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsQuotesPollingLimitEnabled', [
|
2021-09-15 15:13:18 +02:00
|
|
|
quotesPollingLimitEnabled,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-09-15 15:13:18 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function safeRefetchQuotes(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('safeRefetchQuotes');
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function stopPollingForQuotes(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('stopPollingForQuotes');
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setBackgroundSwapRouteState(
|
|
|
|
routeState: '' | 'loading' | 'awaiting' | 'smartTransactionStatus',
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setBackgroundSwapRouteState', [
|
|
|
|
routeState,
|
|
|
|
]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function resetSwapsPostFetchState(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('resetPostFetchState');
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSwapsErrorKey(
|
|
|
|
errorKey: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsErrorKey', [errorKey]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setInitialGasEstimate(
|
|
|
|
initialAggId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setInitialGasEstimate', [initialAggId]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
// Permissions
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function requestAccountsPermissionWithId(
|
|
|
|
origin: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
const id = await submitRequestToBackground(
|
|
|
|
'requestAccountsPermissionWithId',
|
|
|
|
[origin],
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return id;
|
|
|
|
};
|
2020-05-28 00:09:59 +02:00
|
|
|
}
|
|
|
|
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
/**
|
2019-12-04 03:52:14 +01:00
|
|
|
* Approves the permissions request.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param request - The permissions request to approve.
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function approvePermissionsRequest(
|
|
|
|
request: PermissionsRequest,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('approvePermissionsRequest', [request], (err) => {
|
2021-03-18 19:23:46 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-03-18 19:23:46 +01:00
|
|
|
}
|
2023-03-17 12:00:05 +01:00
|
|
|
forceUpdateMetamaskState(dispatch);
|
2021-03-18 19:23:46 +01:00
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-09-27 20:19:09 +02:00
|
|
|
}
|
|
|
|
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
/**
|
2019-12-04 03:52:14 +01:00
|
|
|
* Rejects the permissions request with the given ID.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param requestId - The id of the request to be rejected
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function rejectPermissionsRequest(
|
|
|
|
requestId: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2020-04-07 20:38:15 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('rejectPermissionsRequest', [requestId], (err) => {
|
2020-04-07 20:38:15 +02:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-04-07 20:38:15 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
forceUpdateMetamaskState(dispatch).then(resolve).catch(reject);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2018-09-27 20:19:09 +02:00
|
|
|
}
|
|
|
|
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
/**
|
|
|
|
* Clears the given permissions for the given origin.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
|
|
|
* @param subjects
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function removePermissionsFor(
|
|
|
|
subjects: Record<string, NonEmptyArray<string>>,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('removePermissionsFor', [subjects], (err) => {
|
2021-03-18 19:23:46 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2021-03-18 19:23:46 +01:00
|
|
|
}
|
|
|
|
});
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
}
|
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
2023-03-08 19:29:23 +01:00
|
|
|
/**
|
|
|
|
* Updates the caveat value for the specified origin, permission and caveat type.
|
|
|
|
*
|
|
|
|
* @param origin
|
|
|
|
* @param target
|
|
|
|
* @param caveatType
|
|
|
|
* @param caveatValue
|
|
|
|
*/
|
|
|
|
export function updateCaveat(
|
|
|
|
origin: string,
|
|
|
|
target: string,
|
|
|
|
caveatType: string,
|
|
|
|
caveatValue: Record<string, Json>,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
|
|
|
return (dispatch) => {
|
|
|
|
callBackgroundMethod(
|
|
|
|
'updateCaveat',
|
|
|
|
[origin, target, caveatType, caveatValue],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2021-02-22 17:20:42 +01:00
|
|
|
// Pending Approvals
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolves a pending approval and closes the current notification window if no
|
|
|
|
* further approvals are pending after the background state updates.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param id - The pending approval id
|
|
|
|
* @param [value] - The value required to confirm a pending approval
|
2021-02-22 17:20:42 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function resolvePendingApproval(
|
|
|
|
id: string,
|
|
|
|
value: unknown,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('resolvePendingApproval', [id, value]);
|
2021-02-22 17:20:42 +01:00
|
|
|
// Before closing the current window, check if any additional confirmations
|
|
|
|
// are added as a result of this confirmation being accepted
|
2021-02-25 23:25:51 +01:00
|
|
|
const { pendingApprovals } = await forceUpdateMetamaskState(dispatch);
|
2021-02-22 17:20:42 +01:00
|
|
|
if (Object.values(pendingApprovals).length === 0) {
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rejects a pending approval and closes the current notification window if no
|
|
|
|
* further approvals are pending after the background state updates.
|
2022-01-07 16:57:33 +01:00
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param id - The pending approval id
|
|
|
|
* @param [error] - The error to throw when rejecting the approval
|
2021-02-22 17:20:42 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function rejectPendingApproval(
|
|
|
|
id: string,
|
|
|
|
error: unknown,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('rejectPendingApproval', [id, error]);
|
2021-02-22 17:20:42 +01:00
|
|
|
// Before closing the current window, check if any additional confirmations
|
|
|
|
// are added as a result of this confirmation being rejected
|
2021-02-25 23:25:51 +01:00
|
|
|
const { pendingApprovals } = await forceUpdateMetamaskState(dispatch);
|
2021-02-22 17:20:42 +01:00
|
|
|
if (Object.values(pendingApprovals).length === 0) {
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-06-20 15:37:09 +02:00
|
|
|
/**
|
|
|
|
* Rejects all approvals for the given messages
|
|
|
|
*
|
|
|
|
* @param messageList - The list of messages to reject
|
|
|
|
*/
|
|
|
|
export function rejectAllMessages(
|
|
|
|
messageList: [],
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
|
|
|
const userRejectionError = serializeError(
|
|
|
|
ethErrors.provider.userRejectedRequest(),
|
|
|
|
);
|
|
|
|
await Promise.all(
|
|
|
|
messageList.map(
|
|
|
|
async ({ id }) =>
|
|
|
|
await submitRequestToBackground('rejectPendingApproval', [
|
|
|
|
id,
|
|
|
|
userRejectionError,
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
const { pendingApprovals } = await forceUpdateMetamaskState(dispatch);
|
|
|
|
if (Object.values(pendingApprovals).length === 0) {
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setFirstTimeFlowType(
|
|
|
|
type: 'create' | 'import',
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setFirstTimeFlowType`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setFirstTimeFlowType', [type], (err) => {
|
2019-03-05 16:45:01 +01:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-03-05 16:45:01 +01:00
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_FIRST_TIME_FLOW_TYPE,
|
2019-03-05 16:45:01 +01:00
|
|
|
value: type,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
2019-05-09 19:27:14 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function setSelectedNetworkConfigurationId(
|
|
|
|
networkConfigurationId: string,
|
2023-02-03 18:56:44 +01:00
|
|
|
): PayloadAction<string> {
|
2019-05-09 19:27:14 +02:00
|
|
|
return {
|
2023-03-09 22:00:28 +01:00
|
|
|
type: actionConstants.SET_SELECTED_NETWORK_CONFIGURATION_ID,
|
|
|
|
payload: networkConfigurationId,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function setNewNetworkAdded({
|
|
|
|
networkConfigurationId,
|
|
|
|
nickname,
|
|
|
|
}: {
|
|
|
|
networkConfigurationId: string;
|
|
|
|
nickname: string;
|
|
|
|
}): PayloadAction<object> {
|
2019-05-09 19:27:14 +02:00
|
|
|
return {
|
2021-10-25 22:38:43 +02:00
|
|
|
type: actionConstants.SET_NEW_NETWORK_ADDED,
|
2023-03-09 22:00:28 +01:00
|
|
|
payload: { networkConfigurationId, nickname },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
2019-05-13 18:16:09 +02:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
export function setNewNftAddedMessage(
|
2023-02-10 16:36:58 +01:00
|
|
|
newNftAddedMessage: string,
|
2023-02-03 18:56:44 +01:00
|
|
|
): PayloadAction<string> {
|
2021-11-26 21:03:35 +01:00
|
|
|
return {
|
2023-02-16 20:23:29 +01:00
|
|
|
type: actionConstants.SET_NEW_NFT_ADDED_MESSAGE,
|
2023-02-10 16:36:58 +01:00
|
|
|
payload: newNftAddedMessage,
|
2021-11-26 21:03:35 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
export function setRemoveNftMessage(
|
2023-02-10 16:36:58 +01:00
|
|
|
removeNftMessage: string,
|
2023-02-03 18:56:44 +01:00
|
|
|
): PayloadAction<string> {
|
2023-01-23 12:53:44 +01:00
|
|
|
return {
|
2023-02-16 20:23:29 +01:00
|
|
|
type: actionConstants.SET_REMOVE_NFT_MESSAGE,
|
2023-02-10 16:36:58 +01:00
|
|
|
payload: removeNftMessage,
|
2023-01-23 12:53:44 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setNewTokensImported(
|
|
|
|
newTokensImported: string,
|
|
|
|
): PayloadAction<string> {
|
2022-05-09 19:47:06 +02:00
|
|
|
return {
|
|
|
|
type: actionConstants.SET_NEW_TOKENS_IMPORTED,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: newTokensImported,
|
2022-05-09 19:47:06 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setLastActiveTime(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setLastActiveTime', [], (err) => {
|
2019-05-13 18:16:09 +02:00
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2019-05-13 18:16:09 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-05-13 18:16:09 +02:00
|
|
|
}
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setDismissSeedBackUpReminder(
|
|
|
|
value: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-05-05 15:58:29 +02:00
|
|
|
dispatch(showLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setDismissSeedBackUpReminder', [value]);
|
2021-05-05 15:58:29 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-06 17:47:50 +01:00
|
|
|
export function setDisabledRpcMethodPreference(
|
|
|
|
methodName: string,
|
|
|
|
value: number,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-06 17:47:50 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
await submitRequestToBackground('setDisabledRpcMethodPreference', [
|
|
|
|
methodName,
|
|
|
|
value,
|
|
|
|
]);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getRpcMethodPreferences(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-06 17:47:50 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
await submitRequestToBackground('getRpcMethodPreferences', []);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setConnectedStatusPopoverHasBeenShown(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2020-04-22 19:11:36 +02:00
|
|
|
return () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setConnectedStatusPopoverHasBeenShown', [], (err) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
if (isErrorWithMessage(err)) {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw new Error(err.message);
|
2020-04-22 19:11:36 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2020-04-22 19:11:36 +02:00
|
|
|
}
|
|
|
|
|
2021-06-05 08:33:58 +02:00
|
|
|
export function setRecoveryPhraseReminderHasBeenShown() {
|
|
|
|
return () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setRecoveryPhraseReminderHasBeenShown', [], (err) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
if (isErrorWithMessage(err)) {
|
2021-06-05 08:33:58 +02:00
|
|
|
throw new Error(err.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setRecoveryPhraseReminderLastShown(
|
|
|
|
lastShown: number,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-06-05 08:33:58 +02:00
|
|
|
return () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'setRecoveryPhraseReminderLastShown',
|
|
|
|
[lastShown],
|
|
|
|
(err) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
if (isErrorWithMessage(err)) {
|
2022-09-05 16:55:34 +02:00
|
|
|
throw new Error(err.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-06-05 08:33:58 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-04-14 18:51:13 +02:00
|
|
|
export function setTermsOfUseLastAgreed(lastAgreed: number) {
|
|
|
|
return async () => {
|
|
|
|
await submitRequestToBackground('setTermsOfUseLastAgreed', [lastAgreed]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setOutdatedBrowserWarningLastShown(lastShown: number) {
|
2023-02-02 19:56:41 +01:00
|
|
|
return async () => {
|
|
|
|
await submitRequestToBackground('setOutdatedBrowserWarningLastShown', [
|
|
|
|
lastShown,
|
|
|
|
]);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function getContractMethodData(
|
|
|
|
data = '',
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const prefixedData = addHexPrefix(data);
|
|
|
|
const fourBytePrefix = prefixedData.slice(0, 10);
|
2022-09-14 20:36:53 +02:00
|
|
|
if (fourBytePrefix.length < 10) {
|
2023-01-20 21:20:18 +01:00
|
|
|
return {};
|
2022-09-14 20:36:53 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
const { knownMethodData } = getState().metamask;
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
2023-02-03 18:56:44 +01:00
|
|
|
knownMethodData?.[fourBytePrefix] &&
|
2022-09-14 20:36:53 +02:00
|
|
|
Object.keys(knownMethodData[fourBytePrefix]).length !== 0
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2023-01-20 21:20:18 +01:00
|
|
|
return knownMethodData[fourBytePrefix];
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`loadingMethodData`);
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
const { name, params } = (await getMethodDataAsync(fourBytePrefix)) as {
|
|
|
|
name: string;
|
|
|
|
params: unknown;
|
|
|
|
};
|
2023-01-20 21:20:18 +01:00
|
|
|
|
|
|
|
callBackgroundMethod(
|
|
|
|
'addKnownMethodData',
|
|
|
|
[fourBytePrefix, { name, params }],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2023-01-20 21:20:18 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
return { name, params };
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSeedPhraseBackedUp(
|
|
|
|
seedPhraseBackupState: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return (dispatch: MetaMaskReduxDispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setSeedPhraseBackedUp`);
|
2019-08-02 05:57:26 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'setSeedPhraseBackedUp',
|
|
|
|
[seedPhraseBackupState],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(err));
|
2022-09-05 16:55:34 +02:00
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
forceUpdateMetamaskState(dispatch).then(resolve).catch(reject);
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-08-02 05:57:26 +02:00
|
|
|
}
|
2019-09-16 19:11:01 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setNextNonce(nextNonce: string): PayloadAction<string> {
|
2019-09-27 06:30:36 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_NEXT_NONCE,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: nextNonce,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
/**
|
|
|
|
* This function initiates the nonceLock in the background for the given
|
|
|
|
* address, and returns the next nonce to use. It then calls setNextNonce which
|
|
|
|
* sets the nonce in state on the nextNonce key. NOTE: The nextNonce key is
|
|
|
|
* actually ephemeral application state. It does not appear to be part of the
|
|
|
|
* background state.
|
|
|
|
*
|
|
|
|
* TODO: move this to a different slice, MetaMask slice will eventually be
|
|
|
|
* deprecated because it should not contain any ephemeral/app state but just
|
|
|
|
* background state. In addition we should key nextNonce by address to prevent
|
|
|
|
* accidental usage of a stale nonce as the call to getNextNonce only works for
|
|
|
|
* the currently selected address.
|
|
|
|
*
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export function getNextNonce(): ThunkAction<
|
|
|
|
Promise<string>,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2021-12-01 19:46:10 +01:00
|
|
|
return async (dispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const address = getState().metamask.selectedAddress;
|
2021-12-01 19:46:10 +01:00
|
|
|
let nextNonce;
|
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
nextNonce = await submitRequestToBackground<string>('getNextNonce', [
|
|
|
|
address,
|
|
|
|
]);
|
2021-12-01 19:46:10 +01:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
dispatch(displayWarning(error));
|
2021-12-01 19:46:10 +01:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
dispatch(setNextNonce(nextNonce));
|
|
|
|
return nextNonce;
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setRequestAccountTabIds(requestAccountTabIds: {
|
|
|
|
[origin: string]: string;
|
|
|
|
}): PayloadAction<{
|
|
|
|
[origin: string]: string;
|
|
|
|
}> {
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_REQUEST_ACCOUNT_TABS,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: requestAccountTabIds,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function getRequestAccountTabIds(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
const requestAccountTabIds = await submitRequestToBackground<{
|
|
|
|
[origin: string]: string;
|
|
|
|
}>('getRequestAccountTabIds');
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(setRequestAccountTabIds(requestAccountTabIds));
|
|
|
|
};
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setOpenMetamaskTabsIDs(openMetaMaskTabIDs: {
|
|
|
|
[tabId: string]: boolean;
|
|
|
|
}): PayloadAction<{ [tabId: string]: boolean }> {
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_OPEN_METAMASK_TAB_IDS,
|
2023-02-03 18:56:44 +01:00
|
|
|
payload: openMetaMaskTabIDs,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function getOpenMetamaskTabsIds(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2023-02-03 18:56:44 +01:00
|
|
|
const openMetaMaskTabIDs = await submitRequestToBackground<{
|
|
|
|
[tabId: string]: boolean;
|
|
|
|
}>('getOpenMetamaskTabsIds');
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(setOpenMetamaskTabsIDs(openMetaMaskTabIDs));
|
|
|
|
};
|
Connect distinct accounts per site (#7004)
* add PermissionsController
remove provider approval controller
integrate rpc-cap
create PermissionsController
move provider approval functionality to permissions controller
add permissions approval ui, settings page
add permissions activity and history
move some functionality to metamask-inpage-provider
rename siteMetadata -> domainMetadata
add accountsChange notification to inpage provider
move functionality to inpage provider
update inpage provider
Remove 'Connections' settings page (#7369)
add hooks for exposing accounts in settings
rename unused messages in non-English locales
Add external extension id to metadata (#7396)
update inpage provider, rpc-cap
add eth_requestAccounts handling to background
prevent notifying connections if extension is locked
update inpage provider
Fix lint errors
add migration
review fixes
transaction controller review updates
removed unused messages
* Login Per Site UI (#7368)
* LoginPerSite original UI changes to keep
* First commit
* Get necessary connected tab info for redirect and icon display for permissioned sites
* Fix up designs and add missing features
* Some lint fixes
* More lint fixes
* Ensures the tx controller + tx-state-manager orders transactions in the order they are received
* Code cleanup for LoginPerSite-ui
* Update e2e tests to use new connection flow
* Fix display of connect screen and app header after login when connect request present
* Update metamask-responsive-ui.spec for new item in accounts dropdown
* Fix approve container by replacing approvedOrigins with domainMetaData
* Adds test/e2e/permissions.spec.js
* Correctly handle cancellation of a permissions request
* Redirect to home after disconnecting all sites / cancelling all permissions
* Fix display of site icons in menu
* Fix height of permissions page container
* Remove unused locale messages
* Set default values for openExternalTabs and tabIdOrigins in account-menu.container
* More code cleanup for LoginPerSite-ui
* Use extensions api to close tab in permissions-connect
* Remove unnecessary change in domIsReady() in contentscript
* Remove unnecessary private function markers and class methods (for background tab info) in metamask-controller.
* Adds getOriginOfCurrentTab selector
* Adds IconWithFallback component and substitutes for appropriate cases
* Add and utilize font mixins
* Remove unused method in disconnect-all.container.js
* Simplify buttonSizeLarge code in page-container-footer.component.js
* Add and utilize getAccountsWithLabels selector
* Remove console.log in ui/app/store/actions.js
* Change last connected time format to yyyy-M-d
* Fix css associated with IconWithFallback change
* Ensure tracked openNonMetamaskTabsIDs are correctly set to inactive on tab changes
* Code cleanup for LoginPerSite-ui
* Use reusable function for modifying openNonMetamaskTabsIDs in background.js
* Enables automatic switching to connected account when connected domain is open
* Prevent exploit of tabIdOriginMap in background.js
* Remove unneeded code from contentscript.js
* Simplify current tab origin and window opener logic using remotePort listener tabs.queryTabs
* Design and styling fixes for LoginPerSite-ui
* Fix permissionHistory and permission logging for eth_requestAccounts and eth_accounts
* Front end changes to support display of lastConnected time in connected and permissions screens
* Fix lint errors
* Refactor structure of permissionsHistory
* Fix default values and object modifications for domain and permissionsHistory related data
* Fix connecting to new accounts from modal
* Replace retweet.svg with connect-white.svg
* Fix signature-request.spec
* Update metamask-inpage-provider version
* Fix permissions e2e tests
* Remove unneeded delay from test/e2e/signature-request.spec.js
* Add delay before attempting to retrieve network id in dapp in ethereum-on=.spec
* Use requestAccountTabIds strategy for determining tab id that opened a given window
* Improve default values for permissions requests
* Add some message descriptions to app/_locales/en/messages.json
* Code clean up in permission controller
* Stopped deep cloning object in mapObjectValues
* Bump metamask-inpage-provider version
* Add missing description in app/_locales/en/messages.json
* Return promises from queryTabs and switchToTab of extension.js
* Remove unused getAllPermissions function
* Use default props in icon-with-fallback.component.js
* Stop passing to permissions controller
* Delete no longer used clear-approved-origins modal code
* Remove duplicate imports in ui/app/components/app/index.scss
* Use URL instead of regex in getOriginFromUrl()
* Add runtime error checking to platform, promise based extension.tab methods
* Support permission requests from external extensions
* Improve font size and colour of the domain origin on the permission confirmation screen
* Add support for toggling permissions
* Ensure getRenderablePermissionsDomains only returns domains with exposedAccount caveat permissions
* Remove unused code from LoginPerSite-ui branch
* Ensure modal closes on Enter press for new-account-modal.component.js
* Lint fix
* fixup! Login Per Site UI (#7368)
* Some code cleanup for LoginPerSite
* Adds UX for connecting to dapps via the connected sites screen (#7593)
* Adds UX for connecting to dapps via the connected sites screen
* Use openMetaMaskTabIds from background.js to determine if current active tab is MetaMask
* Delete unused permissions controller methods
* Fixes two small bugs in the LoginPerSite ui (#7595)
* Restore `providerRequest` message translations (#7600)
This message was removed, but it was replaced with a very similar
message called `likeToConnect`. The only difference is that the new
message has "MetaMask" in it. Preserving these messages without
"MetaMask" is probably better than deleting them, so these messages
have all been restored and renamed to `likeToConnect`.
* Login per site no sitemetadata fix (#7610)
* Support connected sites for which we have no site metadata.
* Change property containing subtitle info often populated by origin to a more accurate of purpose name
* Lint fix
* Improve disconnection modal messages (#7612)
* Improve disconnectAccountModalDescription and disconnectAllModalDescription messages
* Update disconnectAccountModalDescription app/_locales/en/messages.json
Co-Authored-By: Mark Stacey <markjstacey@gmail.com>
* Improve disconnectAccount modal message clarity
* Adds cancel button to the account selection screen of the permissions request flow (#7613)
* Fix eth_accounts permission language & selectability (#7614)
* fix eth_accounts language & selectability
* fix MetaMask capitalization in all messages
* Close sidebar when opening connected sites (#7611)
The 'Connected Sites' button in the accounts details now closes the
sidebar, if it is open. This was accomplished by pulling the click
handler for that button up to the wallet view component, where another
button already followed a similar pattern of closing the sidebar.
It seemed confusing to me that one handler was in the `AccountsDetails`
container component, and one was handed down from above, so I added
PropTypes to the container component.
I'm not sure that the WalletView component is the best place for this
logic, but I've put it there for now to be consistent with the add
token button.
* Reject permissions request upon tab close (#7618)
Permissions requests are now rejected when the page is closed. This
only applies to the full-screen view, as that is the view permission
requests should be handled in. The case where the user deals with the
request through a different view is handled in #7617
* Handle tab update failure (#7619)
`extension.tabs.update` can sometimes fail if the user interacts with
the tabs directly around the same time. The redirect flow has been
updated to ensure that the permissions tab is still closed in that
case. The user is on their own to find the dapp tab again in that case.
* Login per site tab popup fixes (#7617)
* Handle redirect in response to state update in permissions-connect
* Ensure origin is available to permissions-connect subcomponents during redirect
* Hide app bar whenever on redirect route
* Improvements to handling of redirects in permissions-connect
* Ensure permission request id change handling only happens when page is not null
* Lint fix
* Decouple confirm transaction screen from the selected address (#7622)
* Avoid race condtion that could prevent contextual account switching (#7623)
There was a race condition in the logic responsible for switching the
selected account based upon the active tab. It was asynchronously
querying the active tab, then assuming it had been retrieved later.
The active tab info itself was already in the redux store in another
spot, one that is guaranteed to be set before the UI renders. The
race condition was avoided by deleting the duplicate state, and using
the other active tab state.
* Only redirect back to dapp if current tab is active (#7621)
The "redirect back to dapp" behaviour can be disruptive when the
permissions connect tab is not active. The purpose of the redirect was
to maintain context between the dapp and the permissions request, but
if the user has already moved to another tab, that no longer applies.
* Fix JSX style lint errors
* Remove unused state
2019-12-03 18:35:56 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setLedgerTransportPreference(
|
|
|
|
value: LedgerTransportTypes,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-04-26 20:05:48 +02:00
|
|
|
dispatch(showLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setLedgerTransportPreference', [value]);
|
2021-04-26 20:05:48 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-04 19:19:53 +01:00
|
|
|
export async function attemptLedgerTransportCreation() {
|
2022-09-05 16:55:34 +02:00
|
|
|
return await submitRequestToBackground('attemptLedgerTransportCreation');
|
2021-11-04 19:19:53 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
/**
|
|
|
|
* This method deduplicates error reports to sentry by maintaining a state
|
|
|
|
* object 'singleExceptions' in the app slice. The only place this state object
|
|
|
|
* is accessed from is within this method, to check if it has already seen and
|
|
|
|
* therefore tracked this error. This is to avoid overloading sentry with lots
|
|
|
|
* of duplicate errors.
|
|
|
|
*
|
|
|
|
* @param error
|
|
|
|
* @returns
|
|
|
|
*/
|
|
|
|
export function captureSingleException(
|
|
|
|
error: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2021-07-23 01:13:40 +02:00
|
|
|
return async (dispatch, getState) => {
|
|
|
|
const { singleExceptions } = getState().appState;
|
|
|
|
if (!(error in singleExceptions)) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.CAPTURE_SINGLE_EXCEPTION,
|
|
|
|
value: error,
|
|
|
|
});
|
|
|
|
captureException(Error(error));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-10 19:53:15 +02:00
|
|
|
// Wrappers around promisifedBackground
|
|
|
|
/**
|
|
|
|
* The "actions" below are not actions nor action creators. They cannot use
|
|
|
|
* dispatch nor should they be dispatched when used. Instead they can be
|
|
|
|
* called directly. These wrappers will be moved into their location at some
|
|
|
|
* point in the future.
|
|
|
|
*/
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function estimateGas(params: TxParams): Promise<Hex> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('estimateGas', [params]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function updateTokenType(
|
|
|
|
tokenAddress: string,
|
|
|
|
): Promise<Token | undefined> {
|
2021-06-23 23:35:25 +02:00
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
return await submitRequestToBackground('updateTokenType', [tokenAddress]);
|
2021-06-23 23:35:25 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2021-06-23 23:35:25 +02:00
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
return undefined;
|
2021-06-23 23:35:25 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 22:23:00 +02:00
|
|
|
/**
|
|
|
|
* initiates polling for gas fee estimates.
|
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @returns a unique identify of the polling request that can be used
|
|
|
|
* to remove that request from consideration of whether polling needs to
|
|
|
|
* continue.
|
2021-07-08 22:23:00 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function getGasFeeEstimatesAndStartPolling(): Promise<string> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('getGasFeeEstimatesAndStartPolling');
|
2021-07-08 22:23:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Informs the GasFeeController that a specific token is no longer requiring
|
|
|
|
* gas fee estimates. If all tokens unsubscribe the controller stops polling.
|
|
|
|
*
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param pollToken - Poll token received from calling
|
|
|
|
* `getGasFeeEstimatesAndStartPolling`.
|
2021-07-08 22:23:00 +02:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function disconnectGasFeeEstimatePoller(pollToken: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('disconnectGasFeeEstimatePoller', [
|
|
|
|
pollToken,
|
|
|
|
]);
|
2021-07-08 22:23:00 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function addPollingTokenToAppState(pollingToken: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('addPollingTokenToAppState', [
|
2021-08-04 23:53:13 +02:00
|
|
|
pollingToken,
|
|
|
|
POLLING_TOKEN_ENVIRONMENT_TYPES[getEnvironmentType()],
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-08-04 23:53:13 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function removePollingTokenFromAppState(pollingToken: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('removePollingTokenFromAppState', [
|
2021-08-04 23:53:13 +02:00
|
|
|
pollingToken,
|
|
|
|
POLLING_TOKEN_ENVIRONMENT_TYPES[getEnvironmentType()],
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-08-04 23:53:13 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function getGasFeeTimeEstimate(
|
|
|
|
maxPriorityFeePerGas: string,
|
|
|
|
maxFeePerGas: string,
|
|
|
|
): Promise<ReturnType<GasFeeController['getTimeEstimate']>> {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('getGasFeeTimeEstimate', [
|
2021-07-30 15:00:02 +02:00
|
|
|
maxPriorityFeePerGas,
|
|
|
|
maxFeePerGas,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-07-30 15:00:02 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 18:09:19 +01:00
|
|
|
export async function closeNotificationPopup() {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('markNotificationPopupAsAutomaticallyClosed');
|
2022-01-05 18:09:19 +01:00
|
|
|
global.platform.closeCurrentWindow();
|
|
|
|
}
|
|
|
|
|
2020-12-02 22:41:30 +01:00
|
|
|
/**
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param payload - details of the event to track
|
|
|
|
* @param options - options for routing/handling of event
|
|
|
|
* @returns
|
2020-12-02 22:41:30 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function trackMetaMetricsEvent(
|
|
|
|
payload: MetaMetricsEventPayload,
|
|
|
|
options?: MetaMetricsEventOptions,
|
|
|
|
) {
|
2022-11-08 19:08:08 +01:00
|
|
|
return submitRequestToBackground('trackMetaMetricsEvent', [
|
|
|
|
{ ...payload, actionId: generateActionId() },
|
|
|
|
options,
|
|
|
|
]);
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createEventFragment(
|
|
|
|
options: MetaMetricsEventFragment,
|
|
|
|
): Promise<string> {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
|
|
|
return submitRequestToBackground('createEventFragment', [
|
|
|
|
{ ...options, actionId },
|
|
|
|
]);
|
2022-01-12 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function createTransactionEventFragment(
|
|
|
|
transactionId: string,
|
|
|
|
event: TransactionMetaMetricsEvent,
|
|
|
|
): Promise<string> {
|
2022-09-16 19:04:14 +02:00
|
|
|
const actionId = generateActionId();
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('createTransactionEventFragment', [
|
2022-02-03 01:28:28 +01:00
|
|
|
transactionId,
|
|
|
|
event,
|
2022-09-16 19:04:14 +02:00
|
|
|
actionId,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-02-03 01:28:28 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateEventFragment(
|
|
|
|
id: string,
|
|
|
|
payload: MetaMetricsEventFragment,
|
|
|
|
) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('updateEventFragment', [id, payload]);
|
2022-01-12 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function finalizeEventFragment(
|
|
|
|
id: string,
|
|
|
|
options?: {
|
|
|
|
abandoned?: boolean;
|
|
|
|
page?: MetaMetricsPageObject;
|
|
|
|
referrer?: MetaMetricsReferrerObject;
|
|
|
|
},
|
|
|
|
) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('finalizeEventFragment', [id, options]);
|
2022-01-12 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
2020-12-02 22:41:30 +01:00
|
|
|
/**
|
2023-02-03 18:56:44 +01:00
|
|
|
* @param payload - details of the page viewed
|
|
|
|
* @param options - options for handling the page view
|
2020-12-02 22:41:30 +01:00
|
|
|
*/
|
2023-02-03 18:56:44 +01:00
|
|
|
export function trackMetaMetricsPage(
|
|
|
|
payload: MetaMetricsPagePayload,
|
|
|
|
options: MetaMetricsPageOptions,
|
|
|
|
) {
|
2022-11-08 19:08:08 +01:00
|
|
|
return submitRequestToBackground('trackMetaMetricsPage', [
|
|
|
|
{ ...payload, actionId: generateActionId() },
|
|
|
|
options,
|
|
|
|
]);
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
2021-04-28 18:51:41 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateViewedNotifications(notificationIdViewedStatusMap: {
|
|
|
|
[notificationId: string]: boolean;
|
|
|
|
}) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('updateViewedNotifications', [
|
2021-04-28 18:51:41 +02:00
|
|
|
notificationIdViewedStatusMap,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2021-04-28 18:51:41 +02:00
|
|
|
}
|
2021-06-10 19:53:15 +02:00
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function setAlertEnabledness(
|
|
|
|
alertId: string,
|
|
|
|
enabledness: boolean,
|
|
|
|
) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setAlertEnabledness', [
|
|
|
|
alertId,
|
|
|
|
enabledness,
|
|
|
|
]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function setUnconnectedAccountAlertShown(origin: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setUnconnectedAccountAlertShown', [origin]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function setWeb3ShimUsageAlertDismissed(origin: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setWeb3ShimUsageAlertDismissed', [origin]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
2021-09-10 20:03:42 +02:00
|
|
|
|
2022-02-18 17:48:38 +01:00
|
|
|
// Smart Transactions Controller
|
2022-03-23 20:28:26 +01:00
|
|
|
export async function setSmartTransactionsOptInStatus(
|
2023-02-03 18:56:44 +01:00
|
|
|
optInState: boolean,
|
|
|
|
prevOptInState: boolean,
|
2022-03-23 20:28:26 +01:00
|
|
|
) {
|
2022-02-18 17:48:38 +01:00
|
|
|
trackMetaMetricsEvent({
|
2022-11-08 19:08:08 +01:00
|
|
|
actionId: generateActionId(),
|
2022-02-18 17:48:38 +01:00
|
|
|
event: 'STX OptIn',
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Swaps,
|
2022-02-18 17:48:38 +01:00
|
|
|
sensitiveProperties: {
|
|
|
|
stx_enabled: true,
|
|
|
|
current_stx_enabled: true,
|
|
|
|
stx_user_opt_in: optInState,
|
2022-03-23 20:28:26 +01:00
|
|
|
stx_prev_user_opt_in: prevOptInState,
|
2022-02-18 17:48:38 +01:00
|
|
|
},
|
|
|
|
});
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSmartTransactionsOptInStatus', [
|
|
|
|
optInState,
|
|
|
|
]);
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
|
2022-08-09 19:56:52 +02:00
|
|
|
export function clearSmartTransactionFees() {
|
2022-09-05 16:55:34 +02:00
|
|
|
submitRequestToBackground('clearSmartTransactionFees');
|
2022-08-09 19:56:52 +02:00
|
|
|
}
|
|
|
|
|
2022-05-26 19:56:28 +02:00
|
|
|
export function fetchSmartTransactionFees(
|
2023-02-03 18:56:44 +01:00
|
|
|
unsignedTransaction: Partial<TxParams> & { chainId: string },
|
|
|
|
approveTxParams: TxParams,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-05-26 19:56:28 +02:00
|
|
|
if (approveTxParams) {
|
|
|
|
approveTxParams.value = '0x0';
|
|
|
|
}
|
2022-02-18 17:48:38 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
const smartTransactionFees = await await submitRequestToBackground(
|
|
|
|
'fetchSmartTransactionFees',
|
|
|
|
[unsignedTransaction, approveTxParams],
|
|
|
|
);
|
2022-08-09 19:56:52 +02:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
|
|
|
|
payload: null,
|
|
|
|
});
|
|
|
|
return smartTransactionFees;
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(err.message);
|
2022-02-18 17:48:38 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
|
2022-08-09 19:56:52 +02:00
|
|
|
payload: errorObj,
|
2022-02-18 17:48:38 +01:00
|
|
|
});
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
throw err;
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
interface TemporarySmartTransactionGasFees {
|
|
|
|
maxFeePerGas: string;
|
|
|
|
maxPriorityFeePerGas: string;
|
|
|
|
gas: string;
|
|
|
|
value: string;
|
|
|
|
}
|
|
|
|
|
2022-02-18 17:48:38 +01:00
|
|
|
const createSignedTransactions = async (
|
2023-02-03 18:56:44 +01:00
|
|
|
unsignedTransaction: Partial<TxParams> & { chainId: string },
|
|
|
|
fees: TemporarySmartTransactionGasFees[],
|
|
|
|
areCancelTransactions?: boolean,
|
|
|
|
): Promise<TxParams[]> => {
|
2022-02-18 17:48:38 +01:00
|
|
|
const unsignedTransactionsWithFees = fees.map((fee) => {
|
|
|
|
const unsignedTransactionWithFees = {
|
|
|
|
...unsignedTransaction,
|
|
|
|
maxFeePerGas: decimalToHex(fee.maxFeePerGas),
|
|
|
|
maxPriorityFeePerGas: decimalToHex(fee.maxPriorityFeePerGas),
|
|
|
|
gas: areCancelTransactions
|
|
|
|
? decimalToHex(21000) // It has to be 21000 for cancel transactions, otherwise the API would reject it.
|
|
|
|
: unsignedTransaction.gas,
|
|
|
|
value: unsignedTransaction.value,
|
|
|
|
};
|
|
|
|
if (areCancelTransactions) {
|
|
|
|
unsignedTransactionWithFees.to = unsignedTransactionWithFees.from;
|
|
|
|
unsignedTransactionWithFees.data = '0x';
|
|
|
|
}
|
|
|
|
return unsignedTransactionWithFees;
|
|
|
|
});
|
2023-02-03 18:56:44 +01:00
|
|
|
const signedTransactions = await submitRequestToBackground<TxParams[]>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'approveTransactionsWithSameNonce',
|
|
|
|
[unsignedTransactionsWithFees],
|
|
|
|
);
|
2022-02-18 17:48:38 +01:00
|
|
|
return signedTransactions;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function signAndSendSmartTransaction({
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees,
|
2023-02-03 18:56:44 +01:00
|
|
|
}: {
|
|
|
|
unsignedTransaction: Partial<TxParams> & { chainId: string };
|
|
|
|
smartTransactionFees: {
|
|
|
|
fees: TemporarySmartTransactionGasFees[];
|
|
|
|
cancelFees: TemporarySmartTransactionGasFees[];
|
|
|
|
};
|
|
|
|
}): ThunkAction<Promise<string>, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-02-18 17:48:38 +01:00
|
|
|
const signedTransactions = await createSignedTransactions(
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees.fees,
|
|
|
|
);
|
|
|
|
const signedCanceledTransactions = await createSignedTransactions(
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees.cancelFees,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
try {
|
2023-02-03 18:56:44 +01:00
|
|
|
const response = await submitRequestToBackground<{ uuid: string }>(
|
2022-09-05 16:55:34 +02:00
|
|
|
'submitSignedTransactions',
|
|
|
|
[
|
|
|
|
{
|
|
|
|
signedTransactions,
|
|
|
|
signedCanceledTransactions,
|
|
|
|
txParams: unsignedTransaction,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
); // Returns e.g.: { uuid: 'dP23W7c2kt4FK9TmXOkz1UM2F20' }
|
2022-02-18 17:48:38 +01:00
|
|
|
return response.uuid;
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(err.message);
|
2022-02-18 17:48:38 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
|
2022-08-09 19:56:52 +02:00
|
|
|
payload: errorObj,
|
2022-02-18 17:48:38 +01:00
|
|
|
});
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
throw err;
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function updateSmartTransaction(
|
|
|
|
uuid: string,
|
|
|
|
txMeta: TransactionMeta,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-02-18 17:48:38 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateSmartTransaction', [
|
|
|
|
{
|
|
|
|
uuid,
|
2023-02-03 18:56:44 +01:00
|
|
|
...txMeta,
|
2022-09-05 16:55:34 +02:00
|
|
|
},
|
|
|
|
]);
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(err.message);
|
2022-02-18 17:48:38 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
|
2022-08-09 19:56:52 +02:00
|
|
|
payload: errorObj,
|
2022-02-18 17:48:38 +01:00
|
|
|
});
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
throw err;
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setSmartTransactionsRefreshInterval(
|
|
|
|
refreshInterval: number,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2022-02-18 17:48:38 +01:00
|
|
|
return async () => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setStatusRefreshInterval', [
|
|
|
|
refreshInterval,
|
|
|
|
]);
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelSmartTransaction(
|
|
|
|
uuid: string,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-02-18 17:48:38 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('cancelSmartTransaction', [uuid]);
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
|
|
|
if (isErrorWithMessage(err) && err.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(err.message);
|
2022-02-18 17:48:38 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_SMART_TRANSACTIONS_ERROR,
|
2022-08-09 19:56:52 +02:00
|
|
|
payload: errorObj,
|
2022-02-18 17:48:38 +01:00
|
|
|
});
|
|
|
|
}
|
2023-02-03 18:56:44 +01:00
|
|
|
throw err;
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: codeword NOT_A_THUNK @brad-decker
|
2022-02-18 17:48:38 +01:00
|
|
|
export function fetchSmartTransactionsLiveness() {
|
|
|
|
return async () => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('fetchSmartTransactionsLiveness');
|
2023-02-03 18:56:44 +01:00
|
|
|
} catch (err) {
|
|
|
|
logErrorWithMessage(err);
|
2022-02-18 17:48:38 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function dismissSmartTransactionsErrorMessage(): Action {
|
2022-02-18 17:48:38 +01:00
|
|
|
return {
|
|
|
|
type: actionConstants.DISMISS_SMART_TRANSACTIONS_ERROR_MESSAGE,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-10 20:03:42 +02:00
|
|
|
// DetectTokenController
|
|
|
|
export async function detectNewTokens() {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('detectNewTokens');
|
2021-09-10 20:03:42 +02:00
|
|
|
}
|
2021-11-16 23:22:01 +01:00
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
// App state
|
2021-11-16 23:22:01 +01:00
|
|
|
export function hideTestNetMessage() {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('setShowTestnetMessageInDropdown', [false]);
|
2021-11-16 23:22:01 +01:00
|
|
|
}
|
2021-11-23 18:28:39 +01:00
|
|
|
|
2022-11-16 18:41:15 +01:00
|
|
|
export function hideBetaHeader() {
|
|
|
|
return submitRequestToBackground('setShowBetaHeader', [false]);
|
|
|
|
}
|
|
|
|
|
2023-04-21 17:28:18 +02:00
|
|
|
export function hideProductTour() {
|
|
|
|
return submitRequestToBackground('setShowProductTour', [false]);
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
// TODO: codeword NOT_A_THUNK @brad-decker
|
2022-11-17 15:13:02 +01:00
|
|
|
export function setTransactionSecurityCheckEnabled(
|
2023-02-03 18:56:44 +01:00
|
|
|
transactionSecurityCheckEnabled: boolean,
|
|
|
|
): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-22 17:51:37 +01:00
|
|
|
return async () => {
|
2022-11-17 15:13:02 +01:00
|
|
|
try {
|
|
|
|
await submitRequestToBackground('setTransactionSecurityCheckEnabled', [
|
|
|
|
transactionSecurityCheckEnabled,
|
|
|
|
]);
|
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2022-11-17 15:13:02 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function setFirstTimeUsedNetwork(chainId: string) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
|
2022-08-23 17:04:07 +02:00
|
|
|
}
|
|
|
|
|
2021-11-23 18:28:39 +01:00
|
|
|
// QR Hardware Wallets
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function submitQRHardwareCryptoHDKey(cbor: Hex) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareCryptoHDKey', [cbor]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function submitQRHardwareCryptoAccount(cbor: Hex) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareCryptoAccount', [cbor]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelSyncQRHardware(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-23 18:28:39 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('cancelSyncQRHardware');
|
2021-11-23 18:28:39 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export async function submitQRHardwareSignature(requestId: string, cbor: Hex) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareSignature', [
|
|
|
|
requestId,
|
|
|
|
cbor,
|
|
|
|
]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 18:56:44 +01:00
|
|
|
export function cancelQRHardwareSignRequest(): ThunkAction<
|
|
|
|
void,
|
|
|
|
MetaMaskReduxState,
|
|
|
|
unknown,
|
|
|
|
AnyAction
|
|
|
|
> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2021-11-23 18:28:39 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('cancelQRHardwareSignRequest');
|
2021-11-23 18:28:39 +01:00
|
|
|
};
|
|
|
|
}
|
2022-06-30 18:19:07 +02:00
|
|
|
|
2023-03-09 22:00:28 +01:00
|
|
|
export function requestUserApproval({
|
|
|
|
origin,
|
|
|
|
type,
|
|
|
|
requestData,
|
|
|
|
}: {
|
|
|
|
origin: string;
|
|
|
|
type: string;
|
|
|
|
requestData: object;
|
|
|
|
}): ThunkAction<void, MetaMaskReduxState, unknown, AnyAction> {
|
2023-03-06 18:48:28 +01:00
|
|
|
return async (dispatch: MetaMaskReduxDispatch) => {
|
2022-06-30 18:19:07 +02:00
|
|
|
try {
|
2023-03-09 22:00:28 +01:00
|
|
|
await submitRequestToBackground('requestUserApproval', [
|
|
|
|
{
|
|
|
|
origin,
|
|
|
|
type,
|
|
|
|
requestData,
|
|
|
|
},
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-06-30 18:19:07 +02:00
|
|
|
} catch (error) {
|
2023-02-03 18:56:44 +01:00
|
|
|
logErrorWithMessage(error);
|
2023-03-09 22:00:28 +01:00
|
|
|
dispatch(displayWarning('Had trouble requesting user approval'));
|
2022-06-30 18:19:07 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2023-04-27 06:46:36 +02:00
|
|
|
|
|
|
|
export async function getCurrentNetworkEIP1559Compatibility(): Promise<
|
|
|
|
boolean | undefined
|
|
|
|
> {
|
|
|
|
let networkEIP1559Compatibility;
|
|
|
|
try {
|
|
|
|
networkEIP1559Compatibility = await submitRequestToBackground<boolean>(
|
|
|
|
'getCurrentNetworkEIP1559Compatibility',
|
|
|
|
);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
return networkEIP1559Compatibility;
|
|
|
|
}
|
2023-05-31 14:43:39 +02:00
|
|
|
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(snaps)
|
|
|
|
/**
|
|
|
|
* Set status of popover warning for the first snap installation.
|
|
|
|
*
|
|
|
|
* @param shown - True if popover has been shown.
|
|
|
|
* @returns Promise Resolved on successfully submitted background request.
|
|
|
|
*/
|
|
|
|
export function setSnapsInstallPrivacyWarningShownStatus(shown: boolean) {
|
|
|
|
return async () => {
|
|
|
|
await submitRequestToBackground(
|
|
|
|
'setSnapsInstallPrivacyWarningShownStatus',
|
|
|
|
[shown],
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
///: END:ONLY_INCLUDE_IN
|