1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 03:20:23 +01: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';
const accountImporter = {
importAccount(strategy, args) {
try {
async importAccount(strategy, args) {
const importer = this.strategies[strategy];
const privateKeyHex = importer(...args);
return Promise.resolve(privateKeyHex);
} catch (e) {
return Promise.reject(e);
}
return privateKeyHex;
},
strategies: {

View File

@ -46,11 +46,11 @@ export default class OnboardingController {
// * Sets the completedOnboarding state to true, indicating that the user has completed the
// * onboarding process.
// */
completeOnboarding() {
async completeOnboarding() {
this.store.updateState({
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
* @returns {Promise<string>}
*/
setAccountLabel(account, label) {
async setAccountLabel(account, label) {
if (!account) {
throw new Error(
`setAccountLabel requires a valid address, got ${String(account)}`,
@ -396,7 +396,7 @@ export default class PreferencesController {
identities[address] = identities[address] || {};
identities[address].name = label;
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.
* @returns {Promise<Array>} Promise resolving to updated frequentRpcList.
*/
removeFromFrequentRpcList(url) {
async removeFromFrequentRpcList(url) {
const rpcList = this.getFrequentRpcListDetail();
const index = rpcList.findIndex((element) => {
return element.rpcUrl === url;
@ -448,7 +448,7 @@ export default class PreferencesController {
rpcList.splice(index, 1);
}
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
* @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 updatedFeatureFlags = {
...currentFeatureFlags,
@ -476,7 +476,7 @@ export default class PreferencesController {
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.
* @returns {Promise<object>} Promises a new object; the updated preferences object.
*/
setPreference(preference, value) {
async setPreference(preference, value) {
const currentPreferences = this.getPreferences();
const updatedPreferences = {
...currentPreferences,
@ -495,7 +495,7 @@ export default class PreferencesController {
};
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
* @returns {Promise<string>} A promise of the update IPFS gateway domain
*/
setIpfsGateway(domain) {
async setIpfsGateway(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
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/
prepMsgForDecryption(msgParams) {
async prepMsgForDecryption(msgParams) {
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
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/
prepMsgForEncryptionPublicKey(msgParams) {
async prepMsgForEncryptionPublicKey(msgParams) {
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
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/
prepMsgForSigning(msgParams) {
async prepMsgForSigning(msgParams) {
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
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/
prepMsgForSigning(msgParams) {
async prepMsgForSigning(msgParams) {
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
* @returns {Promise<object>} Promises the msgParams with the metamaskId property removed
*/
prepMsgForSigning(msgParams) {
async prepMsgForSigning(msgParams) {
delete msgParams.metamaskId;
delete msgParams.version;
return Promise.resolve(msgParams);
return msgParams;
}
/**

View File

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

View File

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