mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Fixing/extending type definitions for later usage (#17514)
This commit is contained in:
parent
c43b1b6191
commit
d9275bb1c1
@ -5,6 +5,10 @@ import { MINUTE } from '../../../shared/constants/time';
|
|||||||
import { AUTO_LOCK_TIMEOUT_ALARM } from '../../../shared/constants/alarms';
|
import { AUTO_LOCK_TIMEOUT_ALARM } from '../../../shared/constants/alarms';
|
||||||
import { isManifestV3 } from '../../../shared/modules/mv3.utils';
|
import { isManifestV3 } from '../../../shared/modules/mv3.utils';
|
||||||
import { isBeta } from '../../../ui/helpers/utils/build-types';
|
import { isBeta } from '../../../ui/helpers/utils/build-types';
|
||||||
|
import {
|
||||||
|
ENVIRONMENT_TYPE_BACKGROUND,
|
||||||
|
POLLING_TOKEN_ENVIRONMENT_TYPES,
|
||||||
|
} from '../../../shared/constants/app';
|
||||||
|
|
||||||
export default class AppStateController extends EventEmitter {
|
export default class AppStateController extends EventEmitter {
|
||||||
/**
|
/**
|
||||||
@ -236,11 +240,16 @@ export default class AppStateController extends EventEmitter {
|
|||||||
* @param pollingTokenType
|
* @param pollingTokenType
|
||||||
*/
|
*/
|
||||||
addPollingToken(pollingToken, pollingTokenType) {
|
addPollingToken(pollingToken, pollingTokenType) {
|
||||||
|
if (
|
||||||
|
pollingTokenType !==
|
||||||
|
POLLING_TOKEN_ENVIRONMENT_TYPES[ENVIRONMENT_TYPE_BACKGROUND]
|
||||||
|
) {
|
||||||
const prevState = this.store.getState()[pollingTokenType];
|
const prevState = this.store.getState()[pollingTokenType];
|
||||||
this.store.updateState({
|
this.store.updateState({
|
||||||
[pollingTokenType]: [...prevState, pollingToken],
|
[pollingTokenType]: [...prevState, pollingToken],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* removes a pollingToken for a given environmentType
|
* removes a pollingToken for a given environmentType
|
||||||
@ -249,11 +258,16 @@ export default class AppStateController extends EventEmitter {
|
|||||||
* @param pollingTokenType
|
* @param pollingTokenType
|
||||||
*/
|
*/
|
||||||
removePollingToken(pollingToken, pollingTokenType) {
|
removePollingToken(pollingToken, pollingTokenType) {
|
||||||
|
if (
|
||||||
|
pollingTokenType !==
|
||||||
|
POLLING_TOKEN_ENVIRONMENT_TYPES[ENVIRONMENT_TYPE_BACKGROUND]
|
||||||
|
) {
|
||||||
const prevState = this.store.getState()[pollingTokenType];
|
const prevState = this.store.getState()[pollingTokenType];
|
||||||
this.store.updateState({
|
this.store.updateState({
|
||||||
[pollingTokenType]: prevState.filter((token) => token !== pollingToken),
|
[pollingTokenType]: prevState.filter((token) => token !== pollingToken),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clears all pollingTokens
|
* clears all pollingTokens
|
||||||
|
@ -83,6 +83,7 @@ const VALID_UNAPPROVED_TRANSACTION_TYPES = [
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('../../../../shared/constants/transaction').TransactionMeta} TransactionMeta
|
* @typedef {import('../../../../shared/constants/transaction').TransactionMeta} TransactionMeta
|
||||||
|
* @typedef {import('../../../../shared/constants/gas').TxGasFees} TxGasFees
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const METRICS_STATUS_FAILED = 'failed on-chain';
|
const METRICS_STATUS_FAILED = 'failed on-chain';
|
||||||
@ -508,18 +509,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* updates the gas fees of the transaction with id if the transaction state is unapproved
|
* updates the gas fees of the transaction with id if the transaction state is unapproved
|
||||||
*
|
*
|
||||||
* @param {string} txId - transaction id
|
* @param {string} txId - transaction id
|
||||||
* @param {object} txGasFees - holds the gas fees parameters
|
* @param {TxGasFees} txGasFees - holds the gas fees parameters
|
||||||
* @param {string} txGasFees.gasLimit
|
|
||||||
* @param {string} txGasFees.gasPrice
|
|
||||||
* @param {string} txGasFees.maxPriorityFeePerGas
|
|
||||||
* @param {string} txGasFees.maxFeePerGas
|
|
||||||
* @param {string} txGasFees.estimateUsed
|
|
||||||
* @param {string} txGasFees.estimateSuggested
|
|
||||||
* @param {string} txGasFees.defaultGasEstimates
|
|
||||||
* @param {string} txGasFees.gas
|
|
||||||
* @param {string} txGasFees.originalGasEstimate
|
|
||||||
* @param {string} txGasFees.userEditedGasLimit
|
|
||||||
* @param {string} txGasFees.userFeeLevel
|
|
||||||
* @returns {TransactionMeta} the txMeta of the updated transaction
|
* @returns {TransactionMeta} the txMeta of the updated transaction
|
||||||
*/
|
*/
|
||||||
updateTransactionGasFees(
|
updateTransactionGasFees(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
|
||||||
|
import { isNullOrUndefined } from '@metamask/utils';
|
||||||
import { SWAPS_API_V2_BASE_URL } from '../../../shared/constants/swaps';
|
import { SWAPS_API_V2_BASE_URL } from '../../../shared/constants/swaps';
|
||||||
import {
|
import {
|
||||||
BUYABLE_CHAINS_MAP,
|
BUYABLE_CHAINS_MAP,
|
||||||
@ -29,7 +30,7 @@ const fetchWithTimeout = getFetchWithTimeout();
|
|||||||
const createWyrePurchaseUrl = async (
|
const createWyrePurchaseUrl = async (
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
||||||
symbol: CurrencySymbol,
|
symbol?: CurrencySymbol,
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const { wyre = {} as WyreChainSettings } = BUYABLE_CHAINS_MAP[chainId];
|
const { wyre = {} as WyreChainSettings } = BUYABLE_CHAINS_MAP[chainId];
|
||||||
const { srn, currencyCode } = wyre;
|
const { srn, currencyCode } = wyre;
|
||||||
@ -72,7 +73,7 @@ const createWyrePurchaseUrl = async (
|
|||||||
const createTransakUrl = (
|
const createTransakUrl = (
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
||||||
symbol: CurrencySymbol,
|
symbol?: CurrencySymbol,
|
||||||
): string => {
|
): string => {
|
||||||
const { nativeCurrency, network } = BUYABLE_CHAINS_MAP[chainId];
|
const { nativeCurrency, network } = BUYABLE_CHAINS_MAP[chainId];
|
||||||
|
|
||||||
@ -98,15 +99,16 @@ const createTransakUrl = (
|
|||||||
const createMoonPayUrl = async (
|
const createMoonPayUrl = async (
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
||||||
symbol: CurrencySymbol,
|
symbol?: CurrencySymbol,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const { moonPay: { defaultCurrencyCode, showOnlyCurrencies } = {} as any } =
|
const { moonPay: { defaultCurrencyCode, showOnlyCurrencies } = {} as any } =
|
||||||
BUYABLE_CHAINS_MAP[chainId];
|
BUYABLE_CHAINS_MAP[chainId];
|
||||||
const moonPayQueryParams = new URLSearchParams({
|
const moonPayQueryParams = new URLSearchParams({
|
||||||
apiKey: MOONPAY_API_KEY,
|
apiKey: MOONPAY_API_KEY,
|
||||||
walletAddress,
|
walletAddress,
|
||||||
defaultCurrencyCode:
|
defaultCurrencyCode: symbol
|
||||||
formatMoonpaySymbol(symbol, chainId) || defaultCurrencyCode,
|
? formatMoonpaySymbol(symbol, chainId)
|
||||||
|
: defaultCurrencyCode,
|
||||||
showOnlyCurrencies,
|
showOnlyCurrencies,
|
||||||
});
|
});
|
||||||
const queryParams = new URLSearchParams({
|
const queryParams = new URLSearchParams({
|
||||||
@ -144,7 +146,7 @@ const createMoonPayUrl = async (
|
|||||||
const createCoinbasePayUrl = (
|
const createCoinbasePayUrl = (
|
||||||
walletAddress: string,
|
walletAddress: string,
|
||||||
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
chainId: keyof typeof BUYABLE_CHAINS_MAP,
|
||||||
symbol: CurrencySymbol,
|
symbol?: CurrencySymbol,
|
||||||
): string => {
|
): string => {
|
||||||
// since coinbasePayCurrencies is going to be extended to include all tokens supported
|
// since coinbasePayCurrencies is going to be extended to include all tokens supported
|
||||||
// we now default to nativeCurrency instead of the 2 previous tokens + eth that we had before
|
// we now default to nativeCurrency instead of the 2 previous tokens + eth that we had before
|
||||||
@ -180,25 +182,40 @@ export default async function getBuyUrl({
|
|||||||
symbol,
|
symbol,
|
||||||
}: {
|
}: {
|
||||||
chainId: keyof typeof BUYABLE_CHAINS_MAP;
|
chainId: keyof typeof BUYABLE_CHAINS_MAP;
|
||||||
address: string;
|
address?: string;
|
||||||
service: string;
|
service?: string;
|
||||||
symbol: CurrencySymbol;
|
symbol?: CurrencySymbol;
|
||||||
}): Promise<string> {
|
}): Promise<string> {
|
||||||
|
let serviceToUse = service;
|
||||||
// default service by network if not specified
|
// default service by network if not specified
|
||||||
if (!service) {
|
if (isNullOrUndefined(service)) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
service = getDefaultServiceForChain(chainId);
|
serviceToUse = getDefaultServiceForChain(chainId);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (service) {
|
switch (serviceToUse) {
|
||||||
case 'wyre':
|
case 'wyre':
|
||||||
return await createWyrePurchaseUrl(address, chainId, symbol);
|
if (address) {
|
||||||
|
return await createWyrePurchaseUrl(address as string, chainId, symbol);
|
||||||
|
}
|
||||||
|
throw new Error('Address is required when requesting url for Wyre');
|
||||||
case 'transak':
|
case 'transak':
|
||||||
return createTransakUrl(address, chainId, symbol);
|
if (address) {
|
||||||
|
return createTransakUrl(address as string, chainId, symbol);
|
||||||
|
}
|
||||||
|
throw new Error('Address is required when requesting url for Transak');
|
||||||
case 'moonpay':
|
case 'moonpay':
|
||||||
return createMoonPayUrl(address, chainId, symbol);
|
if (address) {
|
||||||
|
return createMoonPayUrl(address as string, chainId, symbol);
|
||||||
|
}
|
||||||
|
throw new Error('Address is required when requesting url for Moonpay');
|
||||||
case 'coinbase':
|
case 'coinbase':
|
||||||
return createCoinbasePayUrl(address, chainId, symbol);
|
if (address) {
|
||||||
|
return createCoinbasePayUrl(address as string, chainId, symbol);
|
||||||
|
}
|
||||||
|
throw new Error(
|
||||||
|
'Address is required when requesting url for Coinbase Pay',
|
||||||
|
);
|
||||||
case 'metamask-faucet':
|
case 'metamask-faucet':
|
||||||
return 'https://faucet.metamask.io/';
|
return 'https://faucet.metamask.io/';
|
||||||
case 'goerli-faucet':
|
case 'goerli-faucet':
|
||||||
|
@ -82,6 +82,7 @@ export const POLLING_TOKEN_ENVIRONMENT_TYPES = {
|
|||||||
[ENVIRONMENT_TYPE_POPUP]: 'popupGasPollTokens',
|
[ENVIRONMENT_TYPE_POPUP]: 'popupGasPollTokens',
|
||||||
[ENVIRONMENT_TYPE_NOTIFICATION]: 'notificationGasPollTokens',
|
[ENVIRONMENT_TYPE_NOTIFICATION]: 'notificationGasPollTokens',
|
||||||
[ENVIRONMENT_TYPE_FULLSCREEN]: 'fullScreenGasPollTokens',
|
[ENVIRONMENT_TYPE_FULLSCREEN]: 'fullScreenGasPollTokens',
|
||||||
|
[ENVIRONMENT_TYPE_BACKGROUND]: 'none',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const ORIGIN_METAMASK = 'metamask';
|
export const ORIGIN_METAMASK = 'metamask';
|
||||||
|
@ -83,3 +83,31 @@ export enum NetworkCongestionThresholds {
|
|||||||
stable = 0.33,
|
stable = 0.33,
|
||||||
busy = 0.66,
|
busy = 0.66,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TxGasFees {
|
||||||
|
/** Maxmimum number of units of gas to use for this transaction. */
|
||||||
|
gasLimit: string;
|
||||||
|
/** Price per gas for legacy txs */
|
||||||
|
gasPrice: string;
|
||||||
|
/**
|
||||||
|
* Maximum amount per gas to pay for the transaction, including the priority
|
||||||
|
* fee.
|
||||||
|
*/
|
||||||
|
maxFeePerGas: string;
|
||||||
|
/** Maximum amount per gas to give to validator as incentive. */
|
||||||
|
maxPriorityFeePerGas: string;
|
||||||
|
/** Which estimate level was used */
|
||||||
|
estimateUsed: string;
|
||||||
|
/** Which estimate level that the API suggested. */
|
||||||
|
estimateSuggested: string;
|
||||||
|
/** The default estimate for gas. */
|
||||||
|
defaultGasEstimates: string;
|
||||||
|
/** same as gasLimit? */
|
||||||
|
gas: string;
|
||||||
|
/** Original estimate for gas. */
|
||||||
|
originalGasEstimate: string;
|
||||||
|
/** The gas limit supplied by user. */
|
||||||
|
userEditedGasLimit: string;
|
||||||
|
/** Estimate level user selected. */
|
||||||
|
userFeeLevel: string;
|
||||||
|
}
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
* @typedef {object} MetaMetricsEventPayload
|
* @typedef {object} MetaMetricsEventPayload
|
||||||
* @property {string} event - event name to track
|
* @property {string} event - event name to track
|
||||||
* @property {string} category - category to associate event to
|
* @property {string} category - category to associate event to
|
||||||
|
* @property {number} [actionId] - Action id to deduplicate event requests from
|
||||||
|
* the UI
|
||||||
* @property {string} [environmentType] - The type of environment this event
|
* @property {string} [environmentType] - The type of environment this event
|
||||||
* occurred in. Defaults to the background process type
|
* occurred in. Defaults to the background process type
|
||||||
* @property {object} [properties] - object of custom values to track, keys
|
* @property {object} [properties] - object of custom values to track, keys
|
||||||
|
Loading…
Reference in New Issue
Block a user