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

Use async/await instead of Promise.resolve (#16221)

This commit is contained in:
David Walsh 2023-01-20 14:20:18 -06:00 committed by GitHub
parent c5368c152b
commit cb6ee2b3fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 52 deletions

View File

@ -6,14 +6,10 @@ import { addHexPrefix } from '../lib/util';
import { stripHexPrefix } from '../../../shared/modules/hexstring-utils'; import { stripHexPrefix } from '../../../shared/modules/hexstring-utils';
const accountImporter = { const accountImporter = {
importAccount(strategy, args) { async importAccount(strategy, args) {
try { const importer = this.strategies[strategy];
const importer = this.strategies[strategy]; const privateKeyHex = importer(...args);
const privateKeyHex = importer(...args); return privateKeyHex;
return Promise.resolve(privateKeyHex);
} catch (e) {
return Promise.reject(e);
}
}, },
strategies: { strategies: {

View File

@ -46,11 +46,11 @@ export default class OnboardingController {
// * Sets the completedOnboarding state to true, indicating that the user has completed the // * Sets the completedOnboarding state to true, indicating that the user has completed the
// * onboarding process. // * onboarding process.
// */ // */
completeOnboarding() { async completeOnboarding() {
this.store.updateState({ this.store.updateState({
completedOnboarding: true, completedOnboarding: true,
}); });
return Promise.resolve(true); return true;
} }
/** /**

View File

@ -385,7 +385,7 @@ export default class PreferencesController {
* @param {string} label - the custom label for the account * @param {string} label - the custom label for the account
* @returns {Promise<string>} * @returns {Promise<string>}
*/ */
setAccountLabel(account, label) { async setAccountLabel(account, label) {
if (!account) { if (!account) {
throw new Error( throw new Error(
`setAccountLabel requires a valid address, got ${String(account)}`, `setAccountLabel requires a valid address, got ${String(account)}`,
@ -396,7 +396,7 @@ export default class PreferencesController {
identities[address] = identities[address] || {}; identities[address] = identities[address] || {};
identities[address].name = label; identities[address].name = label;
this.store.updateState({ identities }); this.store.updateState({ identities });
return Promise.resolve(label); return label;
} }
/** /**
@ -439,7 +439,7 @@ export default class PreferencesController {
* @param {string} url - The RPC url to remove from frequentRpcList. * @param {string} url - The RPC url to remove from frequentRpcList.
* @returns {Promise<Array>} Promise resolving to updated frequentRpcList. * @returns {Promise<Array>} Promise resolving to updated frequentRpcList.
*/ */
removeFromFrequentRpcList(url) { async removeFromFrequentRpcList(url) {
const rpcList = this.getFrequentRpcListDetail(); const rpcList = this.getFrequentRpcListDetail();
const index = rpcList.findIndex((element) => { const index = rpcList.findIndex((element) => {
return element.rpcUrl === url; return element.rpcUrl === url;
@ -448,7 +448,7 @@ export default class PreferencesController {
rpcList.splice(index, 1); rpcList.splice(index, 1);
} }
this.store.updateState({ frequentRpcListDetail: rpcList }); this.store.updateState({ frequentRpcListDetail: rpcList });
return Promise.resolve(rpcList); return rpcList;
} }
/** /**
@ -467,7 +467,7 @@ export default class PreferencesController {
* @param {boolean} activated - Indicates whether or not the UI feature should be displayed * @param {boolean} activated - Indicates whether or not the UI feature should be displayed
* @returns {Promise<object>} Promises a new object; the updated featureFlags object. * @returns {Promise<object>} Promises a new object; the updated featureFlags object.
*/ */
setFeatureFlag(feature, activated) { async setFeatureFlag(feature, activated) {
const currentFeatureFlags = this.store.getState().featureFlags; const currentFeatureFlags = this.store.getState().featureFlags;
const updatedFeatureFlags = { const updatedFeatureFlags = {
...currentFeatureFlags, ...currentFeatureFlags,
@ -476,7 +476,7 @@ export default class PreferencesController {
this.store.updateState({ featureFlags: updatedFeatureFlags }); this.store.updateState({ featureFlags: updatedFeatureFlags });
return Promise.resolve(updatedFeatureFlags); return updatedFeatureFlags;
} }
/** /**
@ -487,7 +487,7 @@ export default class PreferencesController {
* @param {boolean} value - Indicates whether or not the preference should be enabled or disabled. * @param {boolean} value - Indicates whether or not the preference should be enabled or disabled.
* @returns {Promise<object>} Promises a new object; the updated preferences object. * @returns {Promise<object>} Promises a new object; the updated preferences object.
*/ */
setPreference(preference, value) { async setPreference(preference, value) {
const currentPreferences = this.getPreferences(); const currentPreferences = this.getPreferences();
const updatedPreferences = { const updatedPreferences = {
...currentPreferences, ...currentPreferences,
@ -495,7 +495,7 @@ export default class PreferencesController {
}; };
this.store.updateState({ preferences: updatedPreferences }); this.store.updateState({ preferences: updatedPreferences });
return Promise.resolve(updatedPreferences); return updatedPreferences;
} }
/** /**
@ -522,9 +522,9 @@ export default class PreferencesController {
* @param {string} domain - The new IPFS gateway domain * @param {string} domain - The new IPFS gateway domain
* @returns {Promise<string>} A promise of the update IPFS gateway domain * @returns {Promise<string>} A promise of the update IPFS gateway domain
*/ */
setIpfsGateway(domain) { async setIpfsGateway(domain) {
this.store.updateState({ ipfsGateway: domain }); this.store.updateState({ ipfsGateway: domain });
return Promise.resolve(domain); return domain;
} }
/** /**

View File

@ -222,9 +222,9 @@ export default class DecryptMessageManager extends EventEmitter {
* @param {object} msgParams - The msgParams to modify * @param {object} msgParams - The msgParams to modify
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed * @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/ */
prepMsgForDecryption(msgParams) { async prepMsgForDecryption(msgParams) {
delete msgParams.metamaskId; delete msgParams.metamaskId;
return Promise.resolve(msgParams); return msgParams;
} }
/** /**

View File

@ -210,9 +210,9 @@ export default class EncryptionPublicKeyManager extends EventEmitter {
* @param {object} msgParams - The msgParams to modify * @param {object} msgParams - The msgParams to modify
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed * @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/ */
prepMsgForEncryptionPublicKey(msgParams) { async prepMsgForEncryptionPublicKey(msgParams) {
delete msgParams.metamaskId; delete msgParams.metamaskId;
return Promise.resolve(msgParams); return msgParams;
} }
/** /**

View File

@ -204,9 +204,9 @@ export default class MessageManager extends EventEmitter {
* @param {object} msgParams - The msgParams to modify * @param {object} msgParams - The msgParams to modify
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed * @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/ */
prepMsgForSigning(msgParams) { async prepMsgForSigning(msgParams) {
delete msgParams.metamaskId; delete msgParams.metamaskId;
return Promise.resolve(msgParams); return msgParams;
} }
/** /**

View File

@ -231,9 +231,9 @@ export default class PersonalMessageManager extends EventEmitter {
* @param {object} msgParams - The msgParams to modify * @param {object} msgParams - The msgParams to modify
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed * @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/ */
prepMsgForSigning(msgParams) { async prepMsgForSigning(msgParams) {
delete msgParams.metamaskId; delete msgParams.metamaskId;
return Promise.resolve(msgParams); return msgParams;
} }
/** /**

View File

@ -295,10 +295,10 @@ export default class TypedMessageManager extends EventEmitter {
* @param {object} msgParams - The msgParams to modify * @param {object} msgParams - The msgParams to modify
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed * @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/ */
prepMsgForSigning(msgParams) { async prepMsgForSigning(msgParams) {
delete msgParams.metamaskId; delete msgParams.metamaskId;
delete msgParams.version; delete msgParams.version;
return Promise.resolve(msgParams); return msgParams;
} }
/** /**

View File

@ -3,13 +3,13 @@ const mockKey = Buffer.alloc(32);
let cacheVal; let cacheVal;
const mockEncryptor = { const mockEncryptor = {
encrypt(_, dataObj) { async encrypt(_, dataObj) {
cacheVal = dataObj; cacheVal = dataObj;
return Promise.resolve(mockHex); return mockHex;
}, },
decrypt() { async decrypt() {
return Promise.resolve(cacheVal || {}); return cacheVal || {};
}, },
encryptWithDetail(_, dataObj) { encryptWithDetail(_, dataObj) {
@ -26,8 +26,8 @@ const mockEncryptor = {
return this.decrypt(key, text); return this.decrypt(key, text);
}, },
keyFromPassword() { async keyFromPassword() {
return Promise.resolve(mockKey); return mockKey;
}, },
generateSalt() { generateSalt() {

View File

@ -3276,11 +3276,11 @@ export function loadingMethodDataFinished() {
} }
export function getContractMethodData(data = '') { export function getContractMethodData(data = '') {
return (dispatch, getState) => { return async (dispatch, getState) => {
const prefixedData = addHexPrefix(data); const prefixedData = addHexPrefix(data);
const fourBytePrefix = prefixedData.slice(0, 10); const fourBytePrefix = prefixedData.slice(0, 10);
if (fourBytePrefix.length < 10) { if (fourBytePrefix.length < 10) {
return Promise.resolve({}); return {};
} }
const { knownMethodData } = getState().metamask; const { knownMethodData } = getState().metamask;
if ( if (
@ -3288,25 +3288,25 @@ export function getContractMethodData(data = '') {
knownMethodData[fourBytePrefix] && knownMethodData[fourBytePrefix] &&
Object.keys(knownMethodData[fourBytePrefix]).length !== 0 Object.keys(knownMethodData[fourBytePrefix]).length !== 0
) { ) {
return Promise.resolve(knownMethodData[fourBytePrefix]); return knownMethodData[fourBytePrefix];
} }
dispatch(loadingMethodDataStarted()); dispatch(loadingMethodDataStarted());
log.debug(`loadingMethodData`); log.debug(`loadingMethodData`);
return getMethodDataAsync(fourBytePrefix).then(({ name, params }) => { const { name, params } = await getMethodDataAsync(fourBytePrefix);
dispatch(loadingMethodDataFinished());
callBackgroundMethod( dispatch(loadingMethodDataFinished());
'addKnownMethodData', callBackgroundMethod(
[fourBytePrefix, { name, params }], 'addKnownMethodData',
(err) => { [fourBytePrefix, { name, params }],
if (err) { (err) => {
dispatch(displayWarning(err.message)); if (err) {
} dispatch(displayWarning(err.message));
}, }
); },
return { name, params }; );
}); return { name, params };
}; };
} }