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';
|
2022-01-28 14:46:26 +01:00
|
|
|
import getBuyUrl from '../../app/scripts/lib/buy-url';
|
2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
fetchLocale,
|
|
|
|
loadRelativeTimeFormatLocaleData,
|
2021-02-04 19:15:23 +01:00
|
|
|
} from '../helpers/utils/i18n-helper';
|
|
|
|
import { getMethodDataAsync } from '../helpers/utils/transactions.util';
|
|
|
|
import switchDirection from '../helpers/utils/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,
|
2022-05-16 20:36:19 +02:00
|
|
|
MESSAGE_TYPE,
|
2021-08-04 23:53:13 +02:00
|
|
|
} from '../../shared/constants/app';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { hasUnconfirmedTransactions } from '../helpers/utils/confirm-tx.util';
|
2021-04-28 21:53:59 +02:00
|
|
|
import txHelper from '../helpers/utils/tx-helper';
|
|
|
|
import { getEnvironmentType, addHexPrefix } from '../../app/scripts/lib/util';
|
2022-02-18 17:48:38 +01:00
|
|
|
import { decimalToHex } from '../helpers/utils/conversions.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,
|
2022-06-01 19:09:13 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
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,
|
|
|
|
} from '../ducks/send';
|
2021-02-04 19:15:23 +01:00
|
|
|
import { switchedToUnconnectedAccount } from '../ducks/alerts/unconnected-account';
|
2021-08-03 00:52:18 +02:00
|
|
|
import { 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 {
|
2021-11-23 18:28:39 +01:00
|
|
|
DEVICE_NAMES,
|
2021-10-21 21:17:03 +02:00
|
|
|
LEDGER_TRANSPORT_TYPES,
|
|
|
|
LEDGER_USB_VENDOR_ID,
|
|
|
|
} from '../../shared/constants/hardware-wallets';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } 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';
|
2022-06-01 19:09:13 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
import { NOTIFICATIONS_EXPIRATION_DELAY } from '../helpers/constants/notifications';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2022-06-30 18:19:07 +02:00
|
|
|
import { setNewCustomNetworkAdded } from '../ducks/app/app';
|
2021-02-04 19:15:23 +01:00
|
|
|
import * as actionConstants from './actionConstants';
|
2022-09-05 16:55:34 +02:00
|
|
|
import {
|
|
|
|
callBackgroundMethod,
|
|
|
|
submitRequestToBackground,
|
|
|
|
} from './action-queue';
|
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
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function tryUnlockMetamask(password) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
dispatch(unlockInProgress());
|
|
|
|
log.debug(`background.submitPassword`);
|
2018-03-03 22:08:10 +01:00
|
|
|
|
2018-03-08 16:29:29 +01:00
|
|
|
return new Promise((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.
|
|
|
|
*
|
|
|
|
* @param {string} password - The password.
|
|
|
|
* @param {string} seedPhrase - The seed phrase.
|
2022-07-27 15:28:05 +02:00
|
|
|
* @returns {object} The updated state of the keyring controller.
|
2021-07-30 23:37:40 +02:00
|
|
|
*/
|
|
|
|
export function createNewVaultAndRestore(password, seedPhrase) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return (dispatch) => {
|
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(),
|
|
|
|
);
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let vault;
|
2017-10-21 07:31:59 +02:00
|
|
|
return new Promise((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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function createNewVaultAndGetSeedPhrase(password) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
throw new Error(error.message);
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function unlockAndGetSeedPhrase(password) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
throw new Error(error.message);
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function submitPassword(password) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function createNewVault(password) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function verifyPassword(password) {
|
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() {
|
2022-09-05 16:55:34 +02:00
|
|
|
const encodedSeedPhrase = await submitRequestToBackground('verifySeedPhrase');
|
2021-07-30 23:37:40 +02:00
|
|
|
return Buffer.from(encodedSeedPhrase).toString('utf8');
|
2018-05-14 15:30:50 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function requestRevealSeedWords(password) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return async (dispatch) => {
|
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;
|
2018-05-14 15:30:50 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
2021-07-30 23:37:40 +02:00
|
|
|
throw error;
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function tryReverseResolveAddress(address) {
|
2019-11-01 18:54:00 +01:00
|
|
|
return () => {
|
|
|
|
return new Promise((resolve) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('tryReverseResolveAddress', [address], (err) => {
|
2019-11-01 18:54:00 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function fetchInfoToSync() {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.fetchInfoToSync`);
|
2019-02-25 20:10:13 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('fetchInfoToSync', [], (err, result) => {
|
2019-02-25 20:10:13 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-02-25 20:10:13 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-02-25 20:10:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function resetAccount() {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-01-31 09:33:15 +01:00
|
|
|
|
2018-05-31 01:17:40 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('resetAccount', [], (err, account) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2018-05-31 01:17:40 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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());
|
|
|
|
resolve(account);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2018-01-31 09:33:15 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function removeAccount(address) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function importNewAccount(strategy, args) {
|
2018-05-14 15:30:50 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
|
|
|
dispatch(
|
|
|
|
showLoadingIndication('This may take a while, please be patient.'),
|
|
|
|
);
|
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`);
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('getState');
|
2018-05-14 15:30:50 +02:00
|
|
|
} catch (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
throw err;
|
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));
|
2018-05-30 21:13:45 +02:00
|
|
|
if (newState.selectedAddress) {
|
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_ACCOUNT_DETAIL,
|
2018-05-30 21:13:45 +02:00
|
|
|
value: newState.selectedAddress,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2018-05-30 21:13:45 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
return newState;
|
|
|
|
};
|
2017-01-19 00:17:08 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function addNewAccount() {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function checkHardwareStatus(deviceName, hdPath) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.checkHardwareStatus`, deviceName, hdPath);
|
2020-04-27 21:03:25 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-07-12 03:21:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let unlocked;
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
unlocked = await submitRequestToBackground('checkHardwareStatus', [
|
2020-11-03 00:41:28 +01:00
|
|
|
deviceName,
|
|
|
|
hdPath,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function forgetDevice(deviceName) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.forgetDevice`, deviceName);
|
2020-04-27 21:03:25 +02:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-10-21 21:17:03 +02:00
|
|
|
export function connectHardware(deviceName, page, hdPath, t) {
|
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
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let accounts;
|
2020-04-27 21:03:25 +02:00
|
|
|
try {
|
2022-02-16 21:54:30 +01:00
|
|
|
if (deviceName === DEVICE_NAMES.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 (
|
2021-11-23 18:28:39 +01:00
|
|
|
deviceName === DEVICE_NAMES.LEDGER &&
|
2021-10-21 21:17:03 +02:00
|
|
|
ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID
|
|
|
|
) {
|
|
|
|
const connectedDevices = await window.navigator.hid.requestDevice({
|
|
|
|
filters: [{ vendorId: LEDGER_USB_VENDOR_ID }],
|
|
|
|
});
|
|
|
|
const userApprovedWebHidConnection = connectedDevices.some(
|
|
|
|
(device) => device.vendorId === Number(LEDGER_USB_VENDOR_ID),
|
|
|
|
);
|
|
|
|
if (!userApprovedWebHidConnection) {
|
|
|
|
throw new Error(t('ledgerWebHIDNotConnectedErrorMessage'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
accounts = await submitRequestToBackground('connectHardware', [
|
2020-11-03 00:41:28 +01:00
|
|
|
deviceName,
|
|
|
|
page,
|
|
|
|
hdPath,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-27 21:03:25 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
2021-11-05 21:32:53 +01:00
|
|
|
if (
|
2022-02-16 21:54:30 +01:00
|
|
|
deviceName === DEVICE_NAMES.LEDGER &&
|
2021-11-05 21:32:53 +01:00
|
|
|
ledgerTransportType === LEDGER_TRANSPORT_TYPES.WEBHID &&
|
|
|
|
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 {
|
2022-01-06 23:56:51 +01:00
|
|
|
if (deviceName !== DEVICE_NAMES.QR) {
|
2021-11-23 18:28:39 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
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(
|
|
|
|
indexes,
|
|
|
|
deviceName,
|
|
|
|
hdPath,
|
|
|
|
hdPathDescription,
|
|
|
|
) {
|
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
|
|
|
);
|
2021-03-09 21:39:16 +01:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
]);
|
2021-03-09 21:39:16 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
dispatch(displayWarning(e.message));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
return undefined;
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-06-10 09:52:32 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showQrScanner() {
|
2019-05-08 21:51:33 +02:00
|
|
|
return (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCurrentCurrency(currencyCode) {
|
2020-04-27 21:30:27 +02:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-05-07 16:02:22 +02:00
|
|
|
log.error(error);
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function signMsg(msgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - signMsg');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.signMessage`);
|
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('signMessage', [msgData]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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;
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function signPersonalMsg(msgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - signPersonalMsg');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.signPersonalMessage`);
|
2017-02-23 01:23:13 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('signPersonalMessage', [
|
|
|
|
msgData,
|
|
|
|
]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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;
|
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function decryptMsgInline(decryptedMsgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - decryptMsgInline');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('decryptMessageInline', [
|
2020-11-03 00:41:28 +01:00
|
|
|
decryptedMsgData,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function decryptMsg(decryptedMsgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - decryptMsg');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.decryptMessage`);
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('decryptMessage', [
|
|
|
|
decryptedMsgData,
|
|
|
|
]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function encryptionPublicKeyMsg(msgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - encryptionPublicKeyMsg');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.encryptionPublicKey`);
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('encryptionPublicKey', [
|
|
|
|
msgData,
|
|
|
|
]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function signTypedMsg(msgData) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('action - signTypedMsg');
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`actions calling background.signTypedMessage`);
|
2017-09-29 18:24:08 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('signTypedMessage', [msgData]);
|
2020-04-28 14:49:10 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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;
|
|
|
|
};
|
2017-09-29 18:24:08 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateCustomNonce(value) {
|
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
|
|
|
}
|
|
|
|
|
2019-07-05 19:01:34 +02:00
|
|
|
const updateMetamaskStateFromBackground = () => {
|
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) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('getState', [], (error, newState) => {
|
2019-07-05 19:01:34 +02:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2019-07-05 19:01:34 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(newState);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-07-05 19:01:34 +02:00
|
|
|
|
2022-03-25 18:11:04 +01:00
|
|
|
export function updatePreviousGasParams(txId, previousGasParams) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
let updatedTransaction;
|
|
|
|
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) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return updatedTransaction;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-10 03:31:04 +01:00
|
|
|
export function updateSwapApprovalTransaction(txId, txSwapApproval) {
|
|
|
|
return async (dispatch) => {
|
2022-03-24 14:46:51 +01:00
|
|
|
let updatedTransaction;
|
2022-03-10 03:31:04 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updateSwapApprovalTransaction',
|
|
|
|
[txId, txSwapApproval],
|
|
|
|
);
|
2022-03-10 03:31:04 +01:00
|
|
|
} catch (error) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2022-03-24 14:46:51 +01:00
|
|
|
return updatedTransaction;
|
2022-03-10 03:31:04 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-07 20:14:48 +01:00
|
|
|
export function updateEditableParams(txId, editableParams) {
|
|
|
|
return async (dispatch) => {
|
2022-03-24 14:46:51 +01:00
|
|
|
let updatedTransaction;
|
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) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
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
|
|
|
|
*
|
|
|
|
* @param {string} txId - the id of the transaction to update
|
2022-09-06 11:09:12 +02:00
|
|
|
* @param {number} currentSendFlowHistoryLength - sendFlowHistory entries currently
|
2022-05-04 18:54:46 +02:00
|
|
|
* @param {Array<{event: string, timestamp: number}>} sendFlowHistory - the new send flow history to append to the
|
|
|
|
* transaction
|
|
|
|
* @returns {import('../../shared/constants/transaction').TransactionMeta}
|
|
|
|
*/
|
2022-09-06 11:09:12 +02:00
|
|
|
export function updateTransactionSendFlowHistory(
|
|
|
|
txId,
|
|
|
|
currentSendFlowHistoryLength,
|
|
|
|
sendFlowHistory,
|
|
|
|
) {
|
2022-05-04 18:54:46 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
let updatedTransaction;
|
|
|
|
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) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return updatedTransaction;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-09 20:36:32 +02:00
|
|
|
export async function backupUserData() {
|
|
|
|
let backedupData;
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
backedupData = await submitRequestToBackground('backupUserData');
|
2022-08-09 20:36:32 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return backedupData;
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function restoreUserData(jsonString) {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('restoreUserData', [jsonString]);
|
2022-08-09 20:36:32 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-03-07 20:14:48 +01:00
|
|
|
export function updateTransactionGasFees(txId, txGasFees) {
|
|
|
|
return async (dispatch) => {
|
2022-03-24 14:46:51 +01:00
|
|
|
let updatedTransaction;
|
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) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2022-03-24 14:46:51 +01:00
|
|
|
return updatedTransaction;
|
2022-03-07 20:14:48 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-10 03:31:04 +01:00
|
|
|
export function updateSwapTransaction(txId, txSwap) {
|
|
|
|
return async (dispatch) => {
|
2022-03-24 14:46:51 +01:00
|
|
|
let updatedTransaction;
|
2022-03-10 03:31:04 +01:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
updatedTransaction = await submitRequestToBackground(
|
|
|
|
'updateSwapTransaction',
|
|
|
|
[txId, txSwap],
|
2022-03-24 14:46:51 +01:00
|
|
|
);
|
2022-03-10 03:31:04 +01:00
|
|
|
} catch (error) {
|
|
|
|
dispatch(txError(error));
|
|
|
|
log.error(error.message);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2022-03-24 14:46:51 +01:00
|
|
|
return updatedTransaction;
|
2022-03-10 03:31:04 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateTransaction(txData, dontShowLoadingIndicator) {
|
2020-12-18 06:34:43 +01:00
|
|
|
return async (dispatch) => {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateTransaction', [txData]);
|
2020-12-18 06:34:43 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateTransactionParams(txData.id, txData.txParams));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(txError(error));
|
|
|
|
dispatch(goHome());
|
|
|
|
log.error(error.message);
|
|
|
|
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 {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateTransactionParams(txData.id, txData.txParams));
|
|
|
|
const newState = await updateMetamaskStateFromBackground();
|
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
dispatch(showConfTxPage({ id: txData.id }));
|
|
|
|
return txData;
|
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.
|
|
|
|
*
|
|
|
|
* @param {import('../../shared/constants/transaction').TxParams} txParams -
|
|
|
|
* The transaction parameters
|
|
|
|
* @param {import(
|
|
|
|
* '../../shared/constants/transaction'
|
|
|
|
* ).TransactionTypeString} type - The type of the transaction being added.
|
2022-05-04 18:54:46 +02:00
|
|
|
* @param {Array<{event: string, timestamp: number}>} sendFlowHistory - The
|
|
|
|
* history of the send flow at time of creation.
|
2022-04-26 19:07:39 +02:00
|
|
|
* @returns {import('../../shared/constants/transaction').TransactionMeta}
|
|
|
|
*/
|
|
|
|
export function addUnapprovedTransactionAndRouteToConfirmationPage(
|
|
|
|
txParams,
|
|
|
|
type,
|
2022-05-04 18:54:46 +02:00
|
|
|
sendFlowHistory,
|
2022-04-26 19:07:39 +02:00
|
|
|
) {
|
|
|
|
return async (dispatch) => {
|
2022-09-06 11:08:32 +02:00
|
|
|
const actionId = Date.now() + Math.random();
|
2022-04-26 19:07:39 +02:00
|
|
|
try {
|
|
|
|
log.debug('background.addUnapprovedTransaction');
|
2022-09-05 16:55:34 +02:00
|
|
|
const txMeta = await submitRequestToBackground(
|
|
|
|
'addUnapprovedTransaction',
|
2022-09-06 11:08:32 +02:00
|
|
|
[txParams, ORIGIN_METAMASK, type, sendFlowHistory, actionId],
|
|
|
|
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());
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @param {import('../../shared/constants/transaction').TxParams} txParams -
|
|
|
|
* The transaction parameters
|
|
|
|
* @param {import(
|
|
|
|
* '../../shared/constants/transaction'
|
|
|
|
* ).TransactionTypeString} type - The type of the transaction being added.
|
|
|
|
* @returns {import('../../shared/constants/transaction').TransactionMeta}
|
|
|
|
*/
|
|
|
|
export async function addUnapprovedTransaction(txParams, type) {
|
|
|
|
log.debug('background.addUnapprovedTransaction');
|
2022-09-06 11:08:32 +02:00
|
|
|
const actionId = Date.now() + Math.random();
|
|
|
|
const txMeta = await submitRequestToBackground(
|
|
|
|
'addUnapprovedTransaction',
|
|
|
|
[txParams, ORIGIN_METAMASK, type, undefined, actionId],
|
|
|
|
actionId,
|
|
|
|
);
|
2022-04-26 19:07:39 +02:00
|
|
|
return txMeta;
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateAndApproveTx(txData, dontShowLoadingIndicator) {
|
2019-07-16 10:55:52 +02:00
|
|
|
return (dispatch) => {
|
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-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('updateAndApproveTransaction', [txData], (err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateTransactionParams(txData.id, txData.txParams));
|
2021-06-23 23:35:25 +02:00
|
|
|
dispatch(resetSendState());
|
2017-11-29 05:24:35 +01:00
|
|
|
|
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(txError(err));
|
|
|
|
dispatch(goHome());
|
|
|
|
log.error(err.message);
|
|
|
|
reject(err);
|
|
|
|
return;
|
2017-11-29 05:24:35 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(txData);
|
|
|
|
});
|
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());
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(completedTx(txData.id));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(updateCustomNonce(''));
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2018-07-24 05:25:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return txData;
|
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
|
|
|
}
|
|
|
|
|
2022-02-14 19:29:24 +01:00
|
|
|
export async function getTransactions(filters = {}) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return await submitRequestToBackground('getTransactions', [filters]);
|
2022-02-14 19:29:24 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function completedTx(id) {
|
2020-02-06 17:38:14 +01:00
|
|
|
return (dispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const state = getState();
|
2020-02-06 17:38:14 +01:00
|
|
|
const {
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedTypedMessages,
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
provider: { chainId },
|
2021-02-04 19:15:23 +01:00
|
|
|
} = state.metamask;
|
2020-11-03 00:41:28 +01:00
|
|
|
const unconfirmedActions = txHelper(
|
|
|
|
unapprovedTxs,
|
|
|
|
unapprovedMsgs,
|
|
|
|
unapprovedPersonalMsgs,
|
|
|
|
unapprovedTypedMessages,
|
|
|
|
network,
|
2021-03-01 16:15:42 +01:00
|
|
|
chainId,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-11-03 00:41:28 +01:00
|
|
|
const otherUnconfirmedActions = unconfirmedActions.filter(
|
|
|
|
(tx) => tx.id !== id,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-02-06 17:38:14 +01:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.COMPLETED_TX,
|
|
|
|
value: {
|
|
|
|
id,
|
|
|
|
unconfirmedActionsCount: otherUnconfirmedActions.length,
|
|
|
|
},
|
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 updateTransactionParams(id, txParams) {
|
2017-11-08 17:44:48 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UPDATE_TRANSACTION_PARAMS,
|
2017-11-08 17:44:48 +01:00
|
|
|
id,
|
|
|
|
value: txParams,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-08 17:44:48 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function txError(err) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.TRANSACTION_ERROR,
|
2016-04-14 00:28:44 +02:00
|
|
|
message: err.message,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2022-02-15 01:02:51 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
export function disableSnap(snapId) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('disableSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function enableSnap(snapId) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('enableSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-09 18:19:34 +02:00
|
|
|
export function removeSnap(snapId) {
|
2022-02-15 01:02:51 +01:00
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('removeSnap', [snapId]);
|
2022-02-15 01:02:51 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function removeSnapError(msgData) {
|
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
|
|
|
|
|
|
|
export function dismissNotifications(ids) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('dismissNotifications', [ids]);
|
2022-06-01 19:09:13 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteExpiredNotifications() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function markNotificationsAsRead(ids) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('markNotificationsAsRead', [ids]);
|
2022-06-01 19:09:13 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
2022-02-15 01:02:51 +01:00
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelMsg(msgData) {
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2017-12-05 04:27:42 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('cancelMessage', [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;
|
|
|
|
};
|
2016-05-03 23:32:22 +02:00
|
|
|
}
|
|
|
|
|
2022-05-16 20:36:19 +02:00
|
|
|
/**
|
|
|
|
* Cancels all of the given messages
|
|
|
|
*
|
|
|
|
* @param {Array<object>} msgDataList - a list of msg data objects
|
|
|
|
* @returns {function(*): Promise<void>}
|
|
|
|
*/
|
|
|
|
export function cancelMsgs(msgDataList) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
|
|
|
|
try {
|
|
|
|
const msgIds = msgDataList.map((id) => id);
|
|
|
|
const cancellations = msgDataList.map(
|
|
|
|
({ id, type }) =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
switch (type) {
|
|
|
|
case MESSAGE_TYPE.ETH_SIGN_TYPED_DATA:
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelTypedMessage', [id], (err) => {
|
2022-05-16 20:36:19 +02:00
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
case MESSAGE_TYPE.PERSONAL_SIGN:
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelPersonalMessage', [id], (err) => {
|
2022-05-16 20:36:19 +02:00
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
case MESSAGE_TYPE.ETH_DECRYPT:
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelDecryptMessage', [id], (err) => {
|
2022-05-16 20:36:19 +02:00
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
case MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY:
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'cancelEncryptionPublicKey',
|
|
|
|
[id],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2022-05-16 20:36:19 +02:00
|
|
|
return;
|
|
|
|
case MESSAGE_TYPE.ETH_SIGN:
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelMessage', [id], (err) => {
|
2022-05-16 20:36:19 +02:00
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
reject(
|
|
|
|
new Error(
|
|
|
|
`MetaMask Message Signature: Unknown message type: ${id}`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
await Promise.all(cancellations);
|
|
|
|
const newState = await updateMetamaskStateFromBackground();
|
|
|
|
dispatch(updateMetamaskState(newState));
|
|
|
|
|
|
|
|
msgIds.forEach((id) => {
|
|
|
|
dispatch(completedTx(id));
|
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
log.error(err);
|
|
|
|
} finally {
|
|
|
|
if (getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION) {
|
|
|
|
closeNotificationPopup();
|
|
|
|
} else {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelPersonalMsg(msgData) {
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-07-24 05:25:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('cancelPersonalMessage', [
|
|
|
|
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;
|
|
|
|
};
|
2017-02-23 01:23:13 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelDecryptMsg(msgData) {
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelEncryptionPublicKeyMsg(msgData) {
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('cancelEncryptionPublicKey', [
|
2020-11-03 00:41:28 +01:00
|
|
|
msgData.id,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelTypedMsg(msgData) {
|
2020-04-28 14:49:10 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2017-12-05 04:27:42 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
let newState;
|
2020-04-28 14:49:10 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('cancelTypedMessage', [
|
|
|
|
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;
|
|
|
|
};
|
2017-09-29 18:24:08 +02:00
|
|
|
}
|
|
|
|
|
2021-01-26 21:31:25 +01:00
|
|
|
export function cancelTx(txData, _showLoadingIndication = true) {
|
2019-07-16 10:55:52 +02:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
_showLoadingIndication && dispatch(showLoadingIndication());
|
2017-11-29 05:24:35 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelTransaction', [txData.id], (error) => {
|
2020-12-18 06:34:43 +01:00
|
|
|
if (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(error);
|
|
|
|
return;
|
2018-06-23 08:52:45 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01: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());
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(completedTx(txData.id));
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2018-07-24 05:25:04 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
return txData;
|
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
|
|
|
*
|
2020-01-13 19:36:36 +01:00
|
|
|
* @param {Array<object>} txDataList - a list of tx data objects
|
|
|
|
* @returns {function(*): Promise<void>}
|
2018-09-20 02:48:28 +02:00
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export function cancelTxs(txDataList) {
|
2019-05-08 21:51:33 +02:00
|
|
|
return async (dispatch) => {
|
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 {
|
2021-02-04 19:15:23 +01:00
|
|
|
const txIds = txDataList.map(({ id }) => id);
|
2020-12-18 06:34:43 +01:00
|
|
|
const cancellations = txIds.map(
|
|
|
|
(id) =>
|
|
|
|
new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('cancelTransaction', [id], (err) => {
|
2020-12-18 06:34:43 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
reject(err);
|
|
|
|
return;
|
2020-12-18 06:34:43 +01:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function markPasswordForgotten() {
|
2020-04-22 21:15:22 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
|
|
|
await new Promise((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());
|
|
|
|
dispatch(forgotPassword());
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function unMarkPasswordForgotten() {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('unMarkPasswordForgotten', [], () => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(forgotPassword(false));
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}).then(() => forceUpdateMetamaskState(dispatch));
|
|
|
|
};
|
2018-02-08 01:38:55 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function forgotPassword(forgotPasswordState = true) {
|
2016-12-20 00:46:09 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.FORGOT_PASSWORD,
|
2018-03-03 03:14:05 +01:00
|
|
|
value: forgotPasswordState,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-12-20 00:46:09 +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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function unlockFailed(message) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function unlockSucceeded(message) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateMetamaskState(newState) {
|
2020-04-28 15:40:28 +02:00
|
|
|
return (dispatch, getState) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { metamask: currentState } = getState();
|
2020-04-28 15:40:28 +02:00
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
const { currentLocale, selectedAddress, provider } = currentState;
|
2020-04-29 19:10:51 +02:00
|
|
|
const {
|
|
|
|
currentLocale: newLocale,
|
|
|
|
selectedAddress: newSelectedAddress,
|
2021-06-23 23:35:25 +02:00
|
|
|
provider: newProvider,
|
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
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
const newAddressBook = newState.addressBook?.[newProvider?.chainId] ?? {};
|
|
|
|
const oldAddressBook = currentState.addressBook?.[provider?.chainId] ?? {};
|
|
|
|
const newAccounts = getMetaMaskAccounts({ metamask: newState });
|
|
|
|
const oldAccounts = getMetaMaskAccounts({ metamask: currentState });
|
|
|
|
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,
|
|
|
|
});
|
2021-06-23 23:35:25 +02:00
|
|
|
if (provider.chainId !== newProvider.chainId) {
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.CHAIN_CHANGED,
|
|
|
|
payload: newProvider.chainId,
|
|
|
|
});
|
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.
|
|
|
|
dispatch(initializeSendState({ chainHasChanged: true }));
|
2021-06-23 23:35:25 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-04-14 00:28:44 +02:00
|
|
|
}
|
|
|
|
|
2017-10-27 08:02:56 +02:00
|
|
|
const backgroundSetLocked = () => {
|
|
|
|
return new Promise((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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function lockMetamask() {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.setLocked`);
|
2017-10-27 08:02:56 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2021-09-10 19:37:19 +02:00
|
|
|
async function _setSelectedAddress(address) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSelectedAddress(address) {
|
2020-04-27 23:56:17 +02:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showAccountDetail(address) {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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-04-27 23:17:28 +02:00
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SHOW_ACCOUNT_DETAIL,
|
|
|
|
value: address,
|
2021-02-04 19:15:23 +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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function addPermittedAccount(origin, address) {
|
2020-04-17 00:23:36 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
await new Promise((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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function removePermittedAccount(origin, address) {
|
2020-04-20 20:34:56 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
await new Promise((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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showConfTxPage({ id } = {}) {
|
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(
|
|
|
|
address,
|
|
|
|
symbol,
|
|
|
|
decimals,
|
|
|
|
image,
|
|
|
|
dontShowLoadingIndicator,
|
|
|
|
) {
|
2021-09-10 19:37:19 +02:00
|
|
|
return async (dispatch) => {
|
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) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-11-19 17:16:41 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2022-04-13 18:23:41 +02:00
|
|
|
/**
|
|
|
|
* To add detected tokens to state
|
|
|
|
*
|
|
|
|
* @param newDetectedTokens
|
|
|
|
*/
|
|
|
|
export function addDetectedTokens(newDetectedTokens) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addDetectedTokens', [newDetectedTokens]);
|
2022-04-13 18:23:41 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To add the tokens user selected to state
|
|
|
|
*
|
|
|
|
* @param tokensToImport
|
|
|
|
*/
|
2022-07-18 16:43:30 +02:00
|
|
|
export function addImportedTokens(tokensToImport) {
|
2022-04-13 18:23:41 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addImportedTokens', [tokensToImport]);
|
2022-04-13 18:23:41 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
} 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,
|
|
|
|
}) {
|
|
|
|
const _tokensToIgnore = Array.isArray(tokensToIgnore)
|
|
|
|
? tokensToIgnore
|
|
|
|
: [tokensToIgnore];
|
|
|
|
|
2022-04-13 18:23:41 +02:00
|
|
|
return async (dispatch) => {
|
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) {
|
|
|
|
log.error(error);
|
2022-07-18 16:43:30 +02:00
|
|
|
dispatch(displayWarning(error.message));
|
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
|
|
|
|
*/
|
|
|
|
export async function getBalancesInSingleCall(tokens) {
|
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
|
|
|
|
|
|
|
export function addCollectible(address, tokenID, dontShowLoadingIndicator) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
if (!address) {
|
|
|
|
throw new Error('MetaMask - Cannot add collectible without address');
|
|
|
|
}
|
|
|
|
if (!tokenID) {
|
|
|
|
throw new Error('MetaMask - Cannot add collectible without tokenID');
|
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addCollectible', [address, tokenID]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-26 21:03:35 +01:00
|
|
|
export function addCollectibleVerifyOwnership(
|
|
|
|
address,
|
|
|
|
tokenID,
|
|
|
|
dontShowLoadingIndicator,
|
|
|
|
) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
if (!address) {
|
|
|
|
throw new Error('MetaMask - Cannot add collectible without address');
|
|
|
|
}
|
|
|
|
if (!tokenID) {
|
|
|
|
throw new Error('MetaMask - Cannot add collectible without tokenID');
|
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addCollectibleVerifyOwnership', [
|
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 (
|
|
|
|
error.message.includes('This collectible is not owned by the user') ||
|
|
|
|
error.message.includes('Unable to verify ownership.')
|
|
|
|
) {
|
|
|
|
throw error;
|
|
|
|
} else {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-19 17:16:41 +01:00
|
|
|
export function removeAndIgnoreCollectible(
|
|
|
|
address,
|
|
|
|
tokenID,
|
|
|
|
dontShowLoadingIndicator,
|
|
|
|
) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
if (!address) {
|
|
|
|
throw new Error('MetaMask - Cannot ignore collectible without address');
|
|
|
|
}
|
|
|
|
if (!tokenID) {
|
|
|
|
throw new Error('MetaMask - Cannot ignore collectible without tokenID');
|
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('removeAndIgnoreCollectible', [
|
|
|
|
address,
|
|
|
|
tokenID,
|
|
|
|
]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
} finally {
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function removeCollectible(address, tokenID, dontShowLoadingIndicator) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
if (!address) {
|
|
|
|
throw new Error('MetaMask - Cannot remove collectible without address');
|
|
|
|
}
|
|
|
|
if (!tokenID) {
|
|
|
|
throw new Error('MetaMask - Cannot remove collectible without tokenID');
|
|
|
|
}
|
|
|
|
if (!dontShowLoadingIndicator) {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
}
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('removeCollectible', [address, tokenID]);
|
2021-11-19 17:16:41 +01:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
} 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-01-10 17:23:53 +01:00
|
|
|
export async function checkAndUpdateAllCollectiblesOwnershipStatus() {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground(
|
|
|
|
'checkAndUpdateAllCollectiblesOwnershipStatus',
|
|
|
|
);
|
2022-01-10 17:23:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function isCollectibleOwner(
|
|
|
|
ownerAddress,
|
|
|
|
collectibleAddress,
|
|
|
|
collectibleId,
|
|
|
|
) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return await submitRequestToBackground('isCollectibleOwner', [
|
2022-01-10 17:23:53 +01:00
|
|
|
ownerAddress,
|
|
|
|
collectibleAddress,
|
|
|
|
collectibleId,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-01-10 17:23:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function checkAndUpdateSingleCollectibleOwnershipStatus(
|
|
|
|
collectible,
|
|
|
|
) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground(
|
|
|
|
'checkAndUpdateSingleCollectibleOwnershipStatus',
|
|
|
|
[collectible, false],
|
2022-01-10 17:23:53 +01:00
|
|
|
);
|
2022-01-03 21:39:41 +01:00
|
|
|
}
|
|
|
|
|
2022-01-19 15:38:33 +01:00
|
|
|
export async function getTokenStandardAndDetails(
|
|
|
|
address,
|
|
|
|
userAddress,
|
|
|
|
tokenId,
|
|
|
|
) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function addTokens(tokens) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2021-09-10 19:37:19 +02:00
|
|
|
export function rejectWatchAsset(suggestedAssetID) {
|
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2021-09-10 19:37:19 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('rejectWatchAsset', [suggestedAssetID]);
|
2022-03-24 17:26:38 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-09-10 19:37:19 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-04 01:24:12 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 19:37:19 +02:00
|
|
|
export function acceptWatchAsset(suggestedAssetID) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('acceptWatchAsset', [suggestedAssetID]);
|
2022-03-24 17:26:38 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
2021-09-10 19:37:19 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
return;
|
|
|
|
} finally {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
dispatch(closeCurrentNotificationWindow());
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-01-22 19:22:56 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function clearPendingTokens() {
|
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
|
|
|
}
|
|
|
|
|
2022-09-09 13:50:31 +02:00
|
|
|
export function createCancelTransaction(txId, customGasSettings, options) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('background.cancelTransaction');
|
|
|
|
let newTxId;
|
2018-09-09 19:07:23 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2022-09-09 13:50:31 +02:00
|
|
|
const actionId = Date.now() + Math.random();
|
2018-09-09 19:07:23 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2018-09-09 19:07:23 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
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-09-13 14:43:38 +02:00
|
|
|
export function createSpeedUpTransaction(txId, customGasSettings, options) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug('background.createSpeedUpTransaction');
|
|
|
|
let newTx;
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2022-09-13 14:43:38 +02:00
|
|
|
const actionId = Date.now() + Math.random();
|
2019-10-28 14:28:46 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2019-10-28 14:28:46 +01:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-07-08 20:48:23 +02:00
|
|
|
export function createRetryTransaction(txId, customGasSettings) {
|
2021-02-04 19:15:23 +01:00
|
|
|
let newTx;
|
2019-10-28 14:28:46 +01:00
|
|
|
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2018-10-26 07:50:36 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'createSpeedUpTransaction',
|
|
|
|
[txId, customGasSettings],
|
2020-11-03 00:41:28 +01:00
|
|
|
(err, newState) => {
|
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2018-10-26 07:50:36 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
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
|
|
|
|
//
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setProviderType(type) {
|
2021-01-07 00:31:11 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
|
|
|
return;
|
2020-04-28 14:50:04 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateProviderType(type));
|
|
|
|
};
|
2017-10-05 01:12:07 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateProviderType(type) {
|
2017-10-05 01:12:07 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_PROVIDER_TYPE,
|
2017-10-05 01:12:07 +02:00
|
|
|
value: type,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-03-07 19:25:50 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateAndSetCustomRpc(
|
|
|
|
newRpc,
|
|
|
|
chainId,
|
|
|
|
ticker = 'ETH',
|
|
|
|
nickname,
|
|
|
|
rpcPrefs,
|
|
|
|
) {
|
2020-04-28 18:56:18 +02:00
|
|
|
return async (dispatch) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug(
|
|
|
|
`background.updateAndSetCustomRpc: ${newRpc} ${chainId} ${ticker} ${nickname}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-04-28 18:56:18 +02:00
|
|
|
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateAndSetCustomRpc', [
|
2020-11-03 00:41:28 +01:00
|
|
|
newRpc,
|
|
|
|
chainId,
|
|
|
|
ticker,
|
|
|
|
nickname || newRpc,
|
|
|
|
rpcPrefs,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-28 18:56:18 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
|
|
|
return;
|
2020-04-28 18:56:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_RPC_TARGET,
|
|
|
|
value: newRpc,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-01-29 19:13:51 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function editRpc(
|
|
|
|
oldRpc,
|
|
|
|
newRpc,
|
|
|
|
chainId,
|
|
|
|
ticker = 'ETH',
|
|
|
|
nickname,
|
|
|
|
rpcPrefs,
|
|
|
|
) {
|
2020-04-24 14:48:59 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.delRpcTarget: ${oldRpc}`);
|
2020-04-24 14:48:59 +02:00
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
submitRequestToBackground('delCustomRpc', [oldRpc]);
|
2020-04-24 14:48:59 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem removing network!'));
|
|
|
|
return;
|
2020-04-24 14:48:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateAndSetCustomRpc', [
|
2020-11-03 00:41:28 +01:00
|
|
|
newRpc,
|
|
|
|
chainId,
|
|
|
|
ticker,
|
|
|
|
nickname || newRpc,
|
|
|
|
rpcPrefs,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-24 14:48:59 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
|
|
|
return;
|
2020-04-24 14:48:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.SET_RPC_TARGET,
|
|
|
|
value: newRpc,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setRpcTarget(newRpc, chainId, ticker = 'ETH', nickname) {
|
2020-04-24 14:59:13 +02:00
|
|
|
return async (dispatch) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
log.debug(
|
|
|
|
`background.setRpcTarget: ${newRpc} ${chainId} ${ticker} ${nickname}`,
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2020-04-24 14:59:13 +02:00
|
|
|
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setCustomRpc', [
|
2020-11-03 00:41:28 +01:00
|
|
|
newRpc,
|
|
|
|
chainId,
|
|
|
|
ticker,
|
|
|
|
nickname || newRpc,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2020-04-24 14:59:13 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-07 00:31:11 +01:00
|
|
|
export function rollbackToPreviousProvider() {
|
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('rollbackToPreviousProvider');
|
2021-01-07 00:31:11 +01:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function delRpcTarget(oldRpc) {
|
2018-09-28 21:53:58 +02:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.debug(`background.delRpcTarget: ${oldRpc}`);
|
2019-07-02 14:13:02 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('delCustomRpc', [oldRpc], (err) => {
|
2019-07-02 14:13:02 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(err);
|
|
|
|
dispatch(displayWarning('Had a problem removing network!'));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-07-02 14:13:02 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2018-09-28 21:53:58 +02:00
|
|
|
}
|
|
|
|
|
2017-03-21 14:57:49 +01:00
|
|
|
// Calls the addressBookController to add a new address.
|
2020-11-03 00:41:28 +01:00
|
|
|
export function addToAddressBook(recipient, nickname = '', memo = '') {
|
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) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const { chainId } = getState().metamask.provider;
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
log.error(error);
|
|
|
|
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
|
2020-01-13 19:36:36 +01:00
|
|
|
* @param {string} addressToRemove - Address of the entry to remove from the address book
|
2019-07-31 21:56:44 +02:00
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export function removeFromAddressBook(chainId, addressToRemove) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showNetworkDropdown() {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showModal(payload) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function hideModal(payload) {
|
2017-08-08 22:37:16 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.MODAL_CLOSE,
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function closeCurrentNotificationWindow() {
|
2021-02-25 23:25:51 +01:00
|
|
|
return (_, getState) => {
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
|
|
|
getEnvironmentType() === ENVIRONMENT_TYPE_NOTIFICATION &&
|
|
|
|
!hasUnconfirmedTransactions(getState())
|
|
|
|
) {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showAlert(msg) {
|
2018-07-19 08:31:02 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.ALERT_OPEN,
|
2018-07-19 08:31:02 +02:00
|
|
|
value: msg,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-07-19 08:31:02 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function hideAlert() {
|
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
|
|
|
}
|
|
|
|
|
2022-01-27 18:26:33 +01:00
|
|
|
export function updateCollectibleDropDownState(value) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateCollectibleDropDownState', [value]);
|
2022-01-27 18:26:33 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export function qrCodeDetected(qrCodeData) {
|
2021-06-23 23:35:25 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showLoadingIndication(message) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_LOADING,
|
2017-01-19 01:45:39 +01:00
|
|
|
value: message,
|
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 setHardwareWalletDefaultHdPath({ device, path }) {
|
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,
|
2019-12-03 21:50:55 +01:00
|
|
|
value: { device, path },
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-08-14 01:29:43 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function hideLoadingIndication() {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function displayWarning(text) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.DISPLAY_WARNING,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: text,
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function exportAccount(password, address) {
|
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`);
|
2017-09-27 01:03:33 +02:00
|
|
|
return new Promise((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`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'exportAccount',
|
|
|
|
[address],
|
|
|
|
function (err2, result) {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
|
|
|
|
if (err2) {
|
|
|
|
log.error(err2);
|
|
|
|
dispatch(displayWarning('Had a problem exporting the account.'));
|
|
|
|
reject(err2);
|
|
|
|
return;
|
|
|
|
}
|
2017-03-21 16:53:34 +01:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
dispatch(showPrivateKey(result));
|
|
|
|
resolve(result);
|
|
|
|
},
|
|
|
|
);
|
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 exportAccounts(password, addresses) {
|
2020-06-26 03:04:17 +02:00
|
|
|
return function (dispatch) {
|
2021-06-09 22:42:25 +02:00
|
|
|
log.debug(`background.verifyPassword`);
|
2020-06-26 03:04:17 +02:00
|
|
|
return new Promise((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) =>
|
|
|
|
new Promise((resolve2, reject2) =>
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'exportAccount',
|
|
|
|
[address],
|
|
|
|
function (err2, result) {
|
|
|
|
if (err2) {
|
|
|
|
log.error(err2);
|
|
|
|
dispatch(
|
|
|
|
displayWarning('Had a problem exporting the account.'),
|
|
|
|
);
|
|
|
|
reject2(err2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve2(result);
|
|
|
|
},
|
|
|
|
),
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showPrivateKey(key) {
|
2016-04-14 00:28:44 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SHOW_PRIVATE_KEY,
|
2016-04-14 00:28:44 +02:00
|
|
|
value: key,
|
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 setAccountLabel(account, label) {
|
2016-05-21 01:18:54 +02:00
|
|
|
return (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function clearAccountDetails() {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function showSendTokenPage() {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function buyEth(opts) {
|
2021-06-25 16:52:29 +02:00
|
|
|
return async (dispatch) => {
|
2022-01-28 14:46:26 +01:00
|
|
|
const url = await getBuyUrl(opts);
|
2022-03-21 10:26:52 +01:00
|
|
|
if (url) {
|
|
|
|
global.platform.openTab({ url });
|
|
|
|
dispatch({
|
|
|
|
type: actionConstants.BUY_ETH,
|
|
|
|
});
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2016-08-10 22:43:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setFeatureFlag(feature, activated, notificationType) {
|
2017-11-14 17:04:55 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2017-11-14 17:04:55 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2020-11-03 00:41:28 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(updateFeatureFlags(updatedFeatureFlags));
|
|
|
|
notificationType && dispatch(showModal({ name: notificationType }));
|
|
|
|
resolve(updatedFeatureFlags);
|
2020-11-03 00:41:28 +01:00
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
};
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateFeatureFlags(updatedFeatureFlags) {
|
2017-11-14 17:04:55 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UPDATE_FEATURE_FLAGS,
|
2017-11-14 17:04:55 +01:00
|
|
|
value: updatedFeatureFlags,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2017-11-14 17:04:55 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setPreference(preference, value) {
|
2020-02-15 21:34:12 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
2018-10-17 01:03:29 +02:00
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'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) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
2018-10-17 01:03:29 +02:00
|
|
|
|
2022-09-05 16:55:34 +02:00
|
|
|
dispatch(updatePreferences(updatedPreferences));
|
|
|
|
resolve(updatedPreferences);
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updatePreferences(value) {
|
2018-10-17 01:03:29 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.UPDATE_PREFERENCES,
|
2018-10-17 01:03:29 +02:00
|
|
|
value,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setDefaultHomeActiveTabName(value) {
|
2021-05-03 19:51:09 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setUseNativeCurrencyAsPrimaryCurrencyPreference(value) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('useNativeCurrencyAsPrimaryCurrency', value);
|
2018-10-17 01:03:29 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 20:35:55 +01:00
|
|
|
export function setHideZeroBalanceTokens(value) {
|
|
|
|
return setPreference('hideZeroBalanceTokens', value);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setShowFiatConversionOnTestnetsPreference(value) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('showFiatInTestnets', value);
|
2019-02-26 19:30:41 +01:00
|
|
|
}
|
|
|
|
|
2021-10-28 21:31:05 +02:00
|
|
|
export function setShowTestNetworks(value) {
|
|
|
|
return setPreference('showTestNetworks', value);
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setAutoLockTimeLimit(value) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return setPreference('autoLockTimeLimit', value);
|
2019-05-08 20:57:21 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCompletedOnboarding() {
|
2020-02-15 21:34:12 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setMouseUserState(isMouseUser) {
|
2018-02-12 18:45:53 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_MOUSE_USER_STATE,
|
2018-02-12 18:45:53 +01:00
|
|
|
value: isMouseUser,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-02-12 18:45:53 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export async function forceUpdateMetamaskState(dispatch) {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
newState = await submitRequestToBackground('getState');
|
2020-04-27 23:21:17 +02:00
|
|
|
} catch (error) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setParticipateInMetaMetrics(val) {
|
2019-03-05 16:45:01 +01:00
|
|
|
return (dispatch) => {
|
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) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'setParticipateInMetaMetrics',
|
|
|
|
[val],
|
|
|
|
(err, metaMetricsId) => {
|
|
|
|
log.debug(err);
|
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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,
|
|
|
|
value: val,
|
|
|
|
});
|
|
|
|
resolve([val, metaMetricsId]);
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-03-05 16:45:01 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setUseBlockie(val) {
|
2017-11-24 18:35:17 +01:00
|
|
|
return (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
2017-11-24 18:35:17 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2017-11-24 18:35:17 +01:00
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_USE_BLOCKIE,
|
2017-11-25 23:47:34 +01:00
|
|
|
value: val,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2017-11-25 23:47:34 +01:00
|
|
|
}
|
2017-12-22 19:43:02 +01:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setUseNonceField(val) {
|
2021-12-01 19:46:10 +01:00
|
|
|
return async (dispatch) => {
|
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) {
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
}
|
|
|
|
dispatch(hideLoadingIndication());
|
2019-09-27 06:30:36 +02:00
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_USE_NONCEFIELD,
|
2019-09-27 06:30:36 +02:00
|
|
|
value: val,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setUsePhishDetect(val) {
|
2020-02-27 07:29:41 +01:00
|
|
|
return (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
2020-02-27 07:29:41 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2020-02-27 07:29:41 +01:00
|
|
|
}
|
|
|
|
|
2021-09-09 22:56:27 +02:00
|
|
|
export function setUseTokenDetection(val) {
|
2021-07-16 01:08:16 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
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) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-26 19:54:57 +01:00
|
|
|
export function setUseCollectibleDetection(val) {
|
|
|
|
return (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setUseCollectibleDetection`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setUseCollectibleDetection', [val], (err) => {
|
2021-11-26 19:54:57 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-01 05:12:27 +01:00
|
|
|
export function setOpenSeaEnabled(val) {
|
|
|
|
return (dispatch) => {
|
|
|
|
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) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
export function detectCollectibles() {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.detectCollectibles`);
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('detectCollectibles');
|
2021-12-14 00:41:10 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-11-11 20:18:50 +01:00
|
|
|
export function setAdvancedGasFee(val) {
|
|
|
|
return (dispatch) => {
|
|
|
|
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) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-11 20:17:56 +01:00
|
|
|
export function setEIP1559V2Enabled(val) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setEIP1559V2Enabled`);
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setEIP1559V2Enabled', [val]);
|
2022-01-11 20:17:56 +01:00
|
|
|
} finally {
|
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-07 19:53:19 +01:00
|
|
|
export function setTheme(val) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setIpfsGateway(val) {
|
2019-12-12 20:28:07 +01:00
|
|
|
return (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(showLoadingIndication());
|
|
|
|
log.debug(`background.setIpfsGateway`);
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setIpfsGateway', [val], (err) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(hideLoadingIndication());
|
2019-12-12 20:28:07 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
2019-12-12 20:28:07 +01:00
|
|
|
} else {
|
|
|
|
dispatch({
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_IPFS_GATEWAY,
|
2019-12-12 20:28:07 +01:00
|
|
|
value: val,
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
2019-12-12 20:28:07 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-12-12 20:28:07 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function updateCurrentLocale(key) {
|
2020-07-03 02:34:48 +02:00
|
|
|
return async (dispatch) => {
|
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);
|
2022-09-05 16:55:34 +02:00
|
|
|
const textDirection = await submitRequestToBackground(
|
|
|
|
'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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCurrentLocale(locale, messages) {
|
2018-03-16 01:29:45 +01:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_CURRENT_LOCALE,
|
2019-09-06 15:47:07 +02:00
|
|
|
value: {
|
|
|
|
locale,
|
|
|
|
messages,
|
|
|
|
},
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2018-03-16 01:29:45 +01:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setPendingTokens(pendingTokens) {
|
2021-09-09 22:56:27 +02:00
|
|
|
const {
|
|
|
|
customToken = {},
|
|
|
|
selectedTokens = {},
|
|
|
|
tokenAddressList = [],
|
|
|
|
} = pendingTokens;
|
2021-02-04 19:15:23 +01:00
|
|
|
const { address, symbol, decimals } = customToken;
|
2020-11-03 00:41:28 +01:00
|
|
|
const tokens =
|
2021-05-18 19:23:54 +02:00
|
|
|
address && symbol && decimals >= 0 <= 36
|
2020-11-17 18:39:21 +01:00
|
|
|
? {
|
|
|
|
...selectedTokens,
|
|
|
|
[address]: {
|
|
|
|
...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
|
|
|
|
|
2021-07-09 17:24:00 +02:00
|
|
|
export function setSwapsLiveness(swapsLiveness) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2022-02-18 17:48:38 +01:00
|
|
|
export function setSwapsFeatureFlags(featureFlags) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsFeatureFlags', [featureFlags]);
|
2022-02-18 17:48:38 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function fetchAndSetQuotes(fetchParams, fetchParamsMetaData) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSelectedQuoteAggId(aggId) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSwapsTokens(tokens) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2021-09-15 15:13:18 +02:00
|
|
|
export function clearSwapsQuotes() {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('clearSwapsQuotes');
|
2021-09-15 15:13:18 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function resetBackgroundSwapsState() {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
const id = await submitRequestToBackground('resetSwapsState');
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
return id;
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCustomApproveTxData(data) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSwapsTxGasPrice(gasPrice) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSwapsTxGasLimit(gasLimit) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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,
|
|
|
|
}) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-06 21:31:30 +02:00
|
|
|
export function updateSwapsUserFeeLevel(swapsCustomUserFeeLevel) {
|
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsUserFeeLevel', [
|
|
|
|
swapsCustomUserFeeLevel,
|
|
|
|
]);
|
2021-08-06 21:31:30 +02:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-09-15 15:13:18 +02:00
|
|
|
export function setSwapsQuotesPollingLimitEnabled(quotesPollingLimitEnabled) {
|
|
|
|
return async (dispatch) => {
|
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);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:14:08 +01:00
|
|
|
export function customSwapsGasParamsUpdated(gasLimit, gasPrice) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setSwapsTxGasPrice', [gasPrice]);
|
|
|
|
await submitRequestToBackground('setSwapsTxGasLimit', [gasLimit, true]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setTradeTxId(tradeTxId) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setTradeTxId', [tradeTxId]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setApproveTxId(approveTxId) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setApproveTxId', [approveTxId]);
|
2021-02-04 19:15:23 +01:00
|
|
|
await forceUpdateMetamaskState(dispatch);
|
|
|
|
};
|
2020-10-06 20:28:38 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function safeRefetchQuotes() {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function stopPollingForQuotes() {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setBackgroundSwapRouteState(routeState) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function resetSwapsPostFetchState() {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSwapsErrorKey(errorKey) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setInitialGasEstimate(initialAggId) {
|
2020-10-06 20:28:38 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function requestAccountsPermissionWithId(origin) {
|
2020-05-28 00:09:59 +02:00
|
|
|
return async (dispatch) => {
|
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
|
|
|
*
|
2022-07-27 15:28:05 +02:00
|
|
|
* @param {object} 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
|
|
|
*/
|
Permission System 2.0 (#12243)
# Permission System 2.0
## Background
This PR migrates the extension permission system to [the new `PermissionController`](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions).
The original permission system, based on [`rpc-cap`](https://github.com/MetaMask/rpc-cap), introduced [`ZCAP-LD`](https://w3c-ccg.github.io/zcap-ld/)-like permissions to our JSON-RPC stack.
We used it to [implement](https://github.com/MetaMask/metamask-extension/pull/7004) what we called "LoginPerSite" in [version 7.7.0](https://github.com/MetaMask/metamask-extension/releases/tag/v7.7.0) of the extension, which enabled the user to choose which accounts, if any, should be exposed to each dapp.
While that was a worthwhile feature in and of itself, we wanted a permission _system_ in order to enable everything we are going to with Snaps.
Unfortunately, the original permission system was difficult to use, and necessitated the creation of the original `PermissionsController` (note the "s"), which was more or less a wrapper for `rpc-cap`.
With this PR, we shake off the yoke of the original permission system, in favor of the modular, self-contained, ergonomic, and more mature permission system 2.0.
Note that [the `PermissionController` readme](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions/README.md) explains how the new permission system works.
The `PermissionController` and `SubjectMetadataController` are currently shipped via `@metamask/snap-controllers`. This is a temporary state of affairs, and we'll move them to `@metamask/controllers` once they've landed in prod.
## Changes in Detail
First, the changes in this PR are not as big as they seem. Roughly half of the additions in this PR are fixtures in the test for the new migration (number 68), and a significant portion of the remaining ~2500 lines are due to find-and-replace changes in other test fixtures and UI files.
- The extension `PermissionsController` has been deleted, and completely replaced with the new `PermissionController` from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The original `PermissionsController` "domain metadata" functionality is now managed by the new `SubjectMetadataController`, also from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The permission activity and history log controller has been renamed `PermissionLogController` and has its own top-level state key, but is otherwise functionally equivalent to the existing implementation.
- Migration number 68 has been added to account for the new state changes.
- The tests in `app/scripts/controllers/permissions` have been migrated from `mocha` to `jest`.
Reviewers should focus their attention on the following files:
- `app/scripts/`
- `metamask-controller.js`
- This is where most of the integration work for the new `PermissionController` occurs.
Some functions that were internal to the original controller were moved here.
- `controllers/permissions/`
- `selectors.js`
- These selectors are for `ControllerMessenger` selector subscriptions. The actual subscriptions occur in `metamask-controller.js`. See the `ControllerMessenger` implementation for details.
- `specifications.js`
- The caveat and permission specifications are required by the new `PermissionController`, and are used to specify the `eth_accounts` permission and its JSON-RPC method implementation.
See the `PermissionController` readme for details.
- `migrations/068.js`
- The new state should be cross-referenced with the controllers that manage it.
The accompanying tests should also be thoroughly reviewed.
Some files may appear new but have just moved and/or been renamed:
- `app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js`
- This was previously implemented in `controllers/permissions/permissionsMethodMiddleware.js`.
- `test/mocks/permissions.js`
- A truncated version of `test/mocks/permission-controller.js`.
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-12-07 04:16:49 +01:00
|
|
|
export function approvePermissionsRequest(request) {
|
2021-03-18 19:23:46 +01:00
|
|
|
return (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('approvePermissionsRequest', [request], (err) => {
|
2021-03-18 19:23:46 +01:00
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
*
|
2019-12-04 03:52:14 +01:00
|
|
|
* @param {string} 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
|
|
|
*/
|
2020-11-03 00:41:28 +01:00
|
|
|
export function rejectPermissionsRequest(requestId) {
|
2020-04-07 20:38:15 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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
|
|
|
*/
|
Permission System 2.0 (#12243)
# Permission System 2.0
## Background
This PR migrates the extension permission system to [the new `PermissionController`](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions).
The original permission system, based on [`rpc-cap`](https://github.com/MetaMask/rpc-cap), introduced [`ZCAP-LD`](https://w3c-ccg.github.io/zcap-ld/)-like permissions to our JSON-RPC stack.
We used it to [implement](https://github.com/MetaMask/metamask-extension/pull/7004) what we called "LoginPerSite" in [version 7.7.0](https://github.com/MetaMask/metamask-extension/releases/tag/v7.7.0) of the extension, which enabled the user to choose which accounts, if any, should be exposed to each dapp.
While that was a worthwhile feature in and of itself, we wanted a permission _system_ in order to enable everything we are going to with Snaps.
Unfortunately, the original permission system was difficult to use, and necessitated the creation of the original `PermissionsController` (note the "s"), which was more or less a wrapper for `rpc-cap`.
With this PR, we shake off the yoke of the original permission system, in favor of the modular, self-contained, ergonomic, and more mature permission system 2.0.
Note that [the `PermissionController` readme](https://github.com/MetaMask/snaps-skunkworks/tree/main/packages/controllers/src/permissions/README.md) explains how the new permission system works.
The `PermissionController` and `SubjectMetadataController` are currently shipped via `@metamask/snap-controllers`. This is a temporary state of affairs, and we'll move them to `@metamask/controllers` once they've landed in prod.
## Changes in Detail
First, the changes in this PR are not as big as they seem. Roughly half of the additions in this PR are fixtures in the test for the new migration (number 68), and a significant portion of the remaining ~2500 lines are due to find-and-replace changes in other test fixtures and UI files.
- The extension `PermissionsController` has been deleted, and completely replaced with the new `PermissionController` from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The original `PermissionsController` "domain metadata" functionality is now managed by the new `SubjectMetadataController`, also from [`@metamask/snap-controllers`](https://www.npmjs.com/package/@metamask/snap-controllers).
- The permission activity and history log controller has been renamed `PermissionLogController` and has its own top-level state key, but is otherwise functionally equivalent to the existing implementation.
- Migration number 68 has been added to account for the new state changes.
- The tests in `app/scripts/controllers/permissions` have been migrated from `mocha` to `jest`.
Reviewers should focus their attention on the following files:
- `app/scripts/`
- `metamask-controller.js`
- This is where most of the integration work for the new `PermissionController` occurs.
Some functions that were internal to the original controller were moved here.
- `controllers/permissions/`
- `selectors.js`
- These selectors are for `ControllerMessenger` selector subscriptions. The actual subscriptions occur in `metamask-controller.js`. See the `ControllerMessenger` implementation for details.
- `specifications.js`
- The caveat and permission specifications are required by the new `PermissionController`, and are used to specify the `eth_accounts` permission and its JSON-RPC method implementation.
See the `PermissionController` readme for details.
- `migrations/068.js`
- The new state should be cross-referenced with the controllers that manage it.
The accompanying tests should also be thoroughly reviewed.
Some files may appear new but have just moved and/or been renamed:
- `app/scripts/lib/rpc-method-middleware/handlers/request-accounts.js`
- This was previously implemented in `controllers/permissions/permissionsMethodMiddleware.js`.
- `test/mocks/permissions.js`
- A truncated version of `test/mocks/permission-controller.js`.
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-12-07 04:16:49 +01:00
|
|
|
export function removePermissionsFor(subjects) {
|
2021-03-18 19:23:46 +01:00
|
|
|
return (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('removePermissionsFor', [subjects], (err) => {
|
2021-03-18 19:23:46 +01:00
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
*
|
2021-02-22 17:20:42 +01:00
|
|
|
* @param {string} id - The pending approval id
|
|
|
|
* @param {any} [value] - The value required to confirm a pending approval
|
|
|
|
*/
|
|
|
|
export function resolvePendingApproval(id, value) {
|
|
|
|
return async (dispatch) => {
|
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
|
|
|
*
|
2021-02-22 17:20:42 +01:00
|
|
|
* @param {string} id - The pending approval id
|
|
|
|
* @param {Error} [error] - The error to throw when rejecting the approval
|
|
|
|
*/
|
|
|
|
export function rejectPendingApproval(id, error) {
|
|
|
|
return async (dispatch) => {
|
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());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setFirstTimeFlowType(type) {
|
2019-03-05 16:45:01 +01:00
|
|
|
return (dispatch) => {
|
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) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSelectedSettingsRpcUrl(newRpcUrl) {
|
2019-05-09 19:27:14 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_SELECTED_SETTINGS_RPC_URL,
|
2019-05-09 19:27:14 +02:00
|
|
|
value: newRpcUrl,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-25 22:38:43 +02:00
|
|
|
export function setNewNetworkAdded(newNetworkAdded) {
|
2019-05-09 19:27:14 +02:00
|
|
|
return {
|
2021-10-25 22:38:43 +02:00
|
|
|
type: actionConstants.SET_NEW_NETWORK_ADDED,
|
|
|
|
value: newNetworkAdded,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-05-09 19:27:14 +02:00
|
|
|
}
|
2019-05-13 18:16:09 +02:00
|
|
|
|
2021-11-26 21:03:35 +01:00
|
|
|
export function setNewCollectibleAddedMessage(newCollectibleAddedMessage) {
|
|
|
|
return {
|
|
|
|
type: actionConstants.SET_NEW_COLLECTIBLE_ADDED_MESSAGE,
|
|
|
|
value: newCollectibleAddedMessage,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-09 19:47:06 +02:00
|
|
|
export function setNewTokensImported(newTokensImported) {
|
|
|
|
return {
|
|
|
|
type: actionConstants.SET_NEW_TOKENS_IMPORTED,
|
|
|
|
value: newTokensImported,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setLastActiveTime() {
|
2019-05-13 18:16:09 +02:00
|
|
|
return (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setLastActiveTime', [], (err) => {
|
2019-05-13 18:16:09 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
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
|
|
|
|
2021-05-05 15:58:29 +02:00
|
|
|
export function setDismissSeedBackUpReminder(value) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(showLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setDismissSeedBackUpReminder', [value]);
|
2021-05-05 15:58:29 +02:00
|
|
|
dispatch(hideLoadingIndication());
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setConnectedStatusPopoverHasBeenShown() {
|
2020-04-22 19:11:36 +02:00
|
|
|
return () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setConnectedStatusPopoverHasBeenShown', [], (err) => {
|
2020-04-22 19:11:36 +02:00
|
|
|
if (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) => {
|
2021-06-05 08:33:58 +02:00
|
|
|
if (err) {
|
|
|
|
throw new Error(err.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setRecoveryPhraseReminderLastShown(lastShown) {
|
|
|
|
return () => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'setRecoveryPhraseReminderLastShown',
|
|
|
|
[lastShown],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
throw new Error(err.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-06-05 08:33:58 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function loadingMethodDataStarted() {
|
2019-06-18 14:17:14 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.LOADING_METHOD_DATA_STARTED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function loadingMethodDataFinished() {
|
2019-06-18 14:17:14 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.LOADING_METHOD_DATA_FINISHED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getContractMethodData(data = '') {
|
2019-06-18 14:17:14 +02:00
|
|
|
return (dispatch, 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) {
|
|
|
|
return Promise.resolve({});
|
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
const { knownMethodData } = getState().metamask;
|
2020-11-03 00:41:28 +01:00
|
|
|
if (
|
2022-09-14 20:36:53 +02:00
|
|
|
knownMethodData &&
|
|
|
|
knownMethodData[fourBytePrefix] &&
|
|
|
|
Object.keys(knownMethodData[fourBytePrefix]).length !== 0
|
2020-11-03 00:41:28 +01:00
|
|
|
) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return Promise.resolve(knownMethodData[fourBytePrefix]);
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(loadingMethodDataStarted());
|
|
|
|
log.debug(`loadingMethodData`);
|
2019-06-18 14:17:14 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
return getMethodDataAsync(fourBytePrefix).then(({ name, params }) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(loadingMethodDataFinished());
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'addKnownMethodData',
|
|
|
|
[fourBytePrefix, { name, params }],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
return { name, params };
|
|
|
|
});
|
|
|
|
};
|
2019-06-18 14:17:14 +02:00
|
|
|
}
|
2019-06-28 05:53:12 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function loadingTokenParamsStarted() {
|
2019-06-28 05:53:12 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.LOADING_TOKEN_PARAMS_STARTED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-28 05:53:12 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function loadingTokenParamsFinished() {
|
2019-06-28 05:53:12 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.LOADING_TOKEN_PARAMS_FINISHED,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-06-28 05:53:12 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setSeedPhraseBackedUp(seedPhraseBackupState) {
|
2019-08-02 05:57:26 +02:00
|
|
|
return (dispatch) => {
|
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) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function initializeThreeBox() {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('initializeThreeBox', [], (err) => {
|
2019-09-26 09:24:52 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setShowRestorePromptToFalse() {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('setShowRestorePromptToFalse', [], (err) => {
|
2019-09-26 09:24:52 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function turnThreeBoxSyncingOn() {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('turnThreeBoxSyncingOn', [], (err) => {
|
2019-09-26 09:24:52 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function restoreFromThreeBox(accountAddress) {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('restoreFromThreeBox', [accountAddress], (err) => {
|
2019-09-26 09:24:52 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getThreeBoxLastUpdated() {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod('getThreeBoxLastUpdated', [], (err, lastUpdated) => {
|
2019-09-26 09:24:52 +02:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
resolve(lastUpdated);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setThreeBoxSyncingPermission(threeBoxSyncingAllowed) {
|
2019-09-26 09:24:52 +02:00
|
|
|
return (dispatch) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
callBackgroundMethod(
|
|
|
|
'setThreeBoxSyncingPermission',
|
|
|
|
[threeBoxSyncingAllowed],
|
|
|
|
(err) => {
|
|
|
|
if (err) {
|
|
|
|
dispatch(displayWarning(err.message));
|
|
|
|
reject(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
resolve();
|
|
|
|
},
|
|
|
|
);
|
2021-02-04 19:15:23 +01:00
|
|
|
});
|
|
|
|
};
|
2019-09-26 09:24:52 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function turnThreeBoxSyncingOnAndInitialize() {
|
2019-09-26 09:24:52 +02:00
|
|
|
return async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
await dispatch(setThreeBoxSyncingPermission(true));
|
|
|
|
await dispatch(turnThreeBoxSyncingOn());
|
|
|
|
await dispatch(initializeThreeBox(true));
|
|
|
|
};
|
2019-09-16 19:11:01 +02:00
|
|
|
}
|
2019-09-27 06:30:36 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setNextNonce(nextNonce) {
|
2019-09-27 06:30:36 +02:00
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_NEXT_NONCE,
|
2019-09-27 06:30:36 +02:00
|
|
|
value: nextNonce,
|
2021-02-04 19:15:23 +01:00
|
|
|
};
|
2019-09-27 06:30:36 +02:00
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getNextNonce() {
|
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 {
|
2022-09-05 16:55:34 +02:00
|
|
|
nextNonce = await submitRequestToBackground('getNextNonce', [address]);
|
2021-12-01 19:46:10 +01:00
|
|
|
} catch (error) {
|
|
|
|
dispatch(displayWarning(error.message));
|
|
|
|
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
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function 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
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_REQUEST_ACCOUNT_TABS,
|
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
|
|
|
value: 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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getRequestAccountTabIds() {
|
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 async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
const requestAccountTabIds = await submitRequestToBackground(
|
|
|
|
'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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function 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
|
|
|
return {
|
2020-01-09 04:34:58 +01:00
|
|
|
type: actionConstants.SET_OPEN_METAMASK_TAB_IDS,
|
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
|
|
|
value: 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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getOpenMetamaskTabsIds() {
|
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 async (dispatch) => {
|
2022-09-05 16:55:34 +02:00
|
|
|
const openMetaMaskTabIDs = await submitRequestToBackground(
|
|
|
|
'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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function setCurrentWindowTab(currentWindowTab) {
|
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_CURRENT_WINDOW_TAB,
|
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
|
|
|
value: currentWindowTab,
|
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
|
|
|
}
|
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function getCurrentWindowTab() {
|
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 async (dispatch) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const currentWindowTab = await global.platform.currentTab();
|
|
|
|
dispatch(setCurrentWindowTab(currentWindowTab));
|
|
|
|
};
|
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
|
|
|
}
|
2020-12-02 22:41:30 +01:00
|
|
|
|
2021-11-08 16:28:40 +01:00
|
|
|
export function setLedgerTransportPreference(value) {
|
2021-04-26 20:05:48 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-07-23 01:13:40 +02:00
|
|
|
export function captureSingleException(error) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
export function estimateGas(params) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('estimateGas', [params]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 23:35:25 +02:00
|
|
|
export async function updateTokenType(tokenAddress) {
|
|
|
|
let token = {};
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
token = await submitRequestToBackground('updateTokenType', [tokenAddress]);
|
2021-06-23 23:35:25 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
2021-07-08 22:23:00 +02:00
|
|
|
/**
|
|
|
|
* initiates polling for gas fee estimates.
|
|
|
|
*
|
|
|
|
* @returns {string} a unique identify of the polling request that can be used
|
|
|
|
* to remove that request from consideration of whether polling needs to
|
|
|
|
* continue.
|
|
|
|
*/
|
|
|
|
export function getGasFeeEstimatesAndStartPolling() {
|
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.
|
|
|
|
*
|
|
|
|
* @param {string} pollToken - Poll token received from calling
|
|
|
|
* `getGasFeeEstimatesAndStartPolling`.
|
|
|
|
*/
|
|
|
|
export function disconnectGasFeeEstimatePoller(pollToken) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('disconnectGasFeeEstimatePoller', [
|
|
|
|
pollToken,
|
|
|
|
]);
|
2021-07-08 22:23:00 +02:00
|
|
|
}
|
|
|
|
|
2021-08-04 23:53:13 +02:00
|
|
|
export async function addPollingTokenToAppState(pollingToken) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
export async function removePollingTokenFromAppState(pollingToken) {
|
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
|
|
|
}
|
|
|
|
|
2021-07-30 19:40:41 +02:00
|
|
|
export function getGasFeeTimeEstimate(maxPriorityFeePerGas, maxFeePerGas) {
|
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
|
|
|
// MetaMetrics
|
|
|
|
/**
|
2021-04-28 21:53:59 +02:00
|
|
|
* @typedef {import('../../shared/constants/metametrics').MetaMetricsEventPayload} MetaMetricsEventPayload
|
|
|
|
* @typedef {import('../../shared/constants/metametrics').MetaMetricsEventOptions} MetaMetricsEventOptions
|
|
|
|
* @typedef {import('../../shared/constants/metametrics').MetaMetricsPagePayload} MetaMetricsPagePayload
|
|
|
|
* @typedef {import('../../shared/constants/metametrics').MetaMetricsPageOptions} MetaMetricsPageOptions
|
2020-12-02 22:41:30 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {MetaMetricsEventPayload} payload - details of the event to track
|
|
|
|
* @param {MetaMetricsEventOptions} options - options for routing/handling of event
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
export function trackMetaMetricsEvent(payload, options) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('trackMetaMetricsEvent', [payload, options]);
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 20:31:54 +01:00
|
|
|
export function createEventFragment(options) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('createEventFragment', [options]);
|
2022-01-12 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
2022-02-03 01:28:28 +01:00
|
|
|
export function createTransactionEventFragment(transactionId, event) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('createTransactionEventFragment', [
|
2022-02-03 01:28:28 +01:00
|
|
|
transactionId,
|
|
|
|
event,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-02-03 01:28:28 +01:00
|
|
|
}
|
|
|
|
|
2022-01-12 20:31:54 +01:00
|
|
|
export function updateEventFragment(id, payload) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('updateEventFragment', [id, payload]);
|
2022-01-12 20:31:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function finalizeEventFragment(id, options) {
|
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
|
|
|
/**
|
|
|
|
* @param {MetaMetricsPagePayload} payload - details of the page viewed
|
|
|
|
* @param {MetaMetricsPageOptions} options - options for handling the page view
|
|
|
|
*/
|
|
|
|
export function trackMetaMetricsPage(payload, options) {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('trackMetaMetricsPage', [payload, options]);
|
2020-12-02 22:41:30 +01:00
|
|
|
}
|
2021-04-28 18:51:41 +02:00
|
|
|
|
|
|
|
export function updateViewedNotifications(notificationIdViewedStatusMap) {
|
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
|
|
|
|
|
|
|
export async function setAlertEnabledness(alertId, enabledness) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setAlertEnabledness', [
|
|
|
|
alertId,
|
|
|
|
enabledness,
|
|
|
|
]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function setUnconnectedAccountAlertShown(origin) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setUnconnectedAccountAlertShown', [origin]);
|
2021-06-10 19:53:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function setWeb3ShimUsageAlertDismissed(origin) {
|
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(
|
|
|
|
optInState,
|
|
|
|
prevOptInState,
|
|
|
|
) {
|
2022-02-18 17:48:38 +01:00
|
|
|
trackMetaMetricsEvent({
|
|
|
|
event: 'STX OptIn',
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.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(
|
2022-02-18 17:48:38 +01:00
|
|
|
unsignedTransaction,
|
|
|
|
approveTxParams,
|
|
|
|
) {
|
|
|
|
return async (dispatch) => {
|
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;
|
2022-02-18 17:48:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
if (e.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(e.message);
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const createSignedTransactions = async (
|
|
|
|
unsignedTransaction,
|
|
|
|
fees,
|
|
|
|
areCancelTransactions,
|
|
|
|
) => {
|
|
|
|
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;
|
|
|
|
});
|
2022-09-05 16:55:34 +02:00
|
|
|
const signedTransactions = await submitRequestToBackground(
|
|
|
|
'approveTransactionsWithSameNonce',
|
|
|
|
[unsignedTransactionsWithFees],
|
|
|
|
);
|
2022-02-18 17:48:38 +01:00
|
|
|
return signedTransactions;
|
|
|
|
};
|
|
|
|
|
|
|
|
export function signAndSendSmartTransaction({
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees,
|
|
|
|
}) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
const signedTransactions = await createSignedTransactions(
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees.fees,
|
|
|
|
);
|
|
|
|
const signedCanceledTransactions = await createSignedTransactions(
|
|
|
|
unsignedTransaction,
|
|
|
|
smartTransactionFees.cancelFees,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
const response = await submitRequestToBackground(
|
|
|
|
'submitSignedTransactions',
|
|
|
|
[
|
|
|
|
{
|
|
|
|
signedTransactions,
|
|
|
|
signedCanceledTransactions,
|
|
|
|
txParams: unsignedTransaction,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
); // Returns e.g.: { uuid: 'dP23W7c2kt4FK9TmXOkz1UM2F20' }
|
2022-02-18 17:48:38 +01:00
|
|
|
return response.uuid;
|
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
if (e.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(e.message);
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateSmartTransaction(uuid, txData) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('updateSmartTransaction', [
|
|
|
|
{
|
|
|
|
uuid,
|
|
|
|
...txData,
|
|
|
|
},
|
|
|
|
]);
|
2022-02-18 17:48:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
if (e.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(e.message);
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setSmartTransactionsRefreshInterval(refreshInterval) {
|
|
|
|
return async () => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setStatusRefreshInterval', [
|
|
|
|
refreshInterval,
|
|
|
|
]);
|
2022-02-18 17:48:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cancelSmartTransaction(uuid) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('cancelSmartTransaction', [uuid]);
|
2022-02-18 17:48:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
if (e.message.startsWith('Fetch error:')) {
|
|
|
|
const errorObj = parseSmartTransactionsError(e.message);
|
|
|
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchSmartTransactionsLiveness() {
|
|
|
|
return async () => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('fetchSmartTransactionsLiveness');
|
2022-02-18 17:48:38 +01:00
|
|
|
} catch (e) {
|
|
|
|
log.error(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function dismissSmartTransactionsErrorMessage() {
|
|
|
|
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-09-13 15:41:58 +02:00
|
|
|
export function hidePortfolioTooltip() {
|
|
|
|
return submitRequestToBackground('setShowPortfolioTooltip', [false]);
|
|
|
|
}
|
|
|
|
|
2021-12-14 00:41:10 +01:00
|
|
|
export function setCollectiblesDetectionNoticeDismissed() {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('setCollectiblesDetectionNoticeDismissed', [
|
|
|
|
true,
|
|
|
|
]);
|
2021-12-14 00:41:10 +01:00
|
|
|
}
|
|
|
|
|
2022-01-11 20:17:56 +01:00
|
|
|
export function setEnableEIP1559V2NoticeDismissed() {
|
2022-09-05 16:55:34 +02:00
|
|
|
return submitRequestToBackground('setEnableEIP1559V2NoticeDismissed', [true]);
|
2022-01-11 20:17:56 +01:00
|
|
|
}
|
|
|
|
|
2022-06-30 18:19:07 +02:00
|
|
|
export function setCustomNetworkListEnabled(customNetworkListEnabled) {
|
|
|
|
return async () => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('setCustomNetworkListEnabled', [
|
2022-06-30 18:19:07 +02:00
|
|
|
customNetworkListEnabled,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-06-30 18:19:07 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-08-23 17:04:07 +02:00
|
|
|
export function setFirstTimeUsedNetwork(chainId) {
|
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
|
|
|
|
export async function submitQRHardwareCryptoHDKey(cbor) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareCryptoHDKey', [cbor]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function submitQRHardwareCryptoAccount(cbor) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareCryptoAccount', [cbor]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function cancelSyncQRHardware() {
|
|
|
|
return async (dispatch) => {
|
|
|
|
dispatch(hideLoadingIndication());
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('cancelSyncQRHardware');
|
2021-11-23 18:28:39 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function submitQRHardwareSignature(requestId, cbor) {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('submitQRHardwareSignature', [
|
|
|
|
requestId,
|
|
|
|
cbor,
|
|
|
|
]);
|
2021-11-23 18:28:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function cancelQRHardwareSignRequest() {
|
|
|
|
return async (dispatch) => {
|
|
|
|
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
|
|
|
|
|
|
|
export function addCustomNetwork(customRpc) {
|
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
|
|
|
dispatch(setNewCustomNetworkAdded(customRpc));
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('addCustomNetwork', [customRpc]);
|
2022-06-30 18:19:07 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-07-27 22:19:05 +02:00
|
|
|
export function requestAddNetworkApproval(customRpc, originIsMetaMask) {
|
2022-06-30 18:19:07 +02:00
|
|
|
return async (dispatch) => {
|
|
|
|
try {
|
2022-09-05 16:55:34 +02:00
|
|
|
await submitRequestToBackground('requestAddNetworkApproval', [
|
2022-06-30 18:19:07 +02:00
|
|
|
customRpc,
|
|
|
|
originIsMetaMask,
|
2022-09-05 16:55:34 +02:00
|
|
|
]);
|
2022-06-30 18:19:07 +02:00
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
dispatch(displayWarning('Had a problem changing networks!'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|