mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 12:29:06 +01:00
Adding estimate fields to updateTransaction, createCancelTransaction and createSpeedUpTransaction (#12398)
This commit is contained in:
parent
79b08fb803
commit
a4ddeed799
@ -649,6 +649,14 @@ export default class TransactionController extends EventEmitter {
|
||||
newGasParams.gas = customGasSettings?.gas ?? GAS_LIMITS.SIMPLE;
|
||||
}
|
||||
|
||||
if (customGasSettings.estimateSuggested) {
|
||||
newGasParams.estimateSuggested = customGasSettings.estimateSuggested;
|
||||
}
|
||||
|
||||
if (customGasSettings.estimateUsed) {
|
||||
newGasParams.estimateUsed = customGasSettings.estimateUsed;
|
||||
}
|
||||
|
||||
if (isEIP1559Transaction(originalTxMeta)) {
|
||||
previousGasParams.maxFeePerGas = txParams.maxFeePerGas;
|
||||
previousGasParams.maxPriorityFeePerGas = txParams.maxPriorityFeePerGas;
|
||||
@ -1393,7 +1401,14 @@ export default class TransactionController extends EventEmitter {
|
||||
status,
|
||||
chainId,
|
||||
origin: referrer,
|
||||
txParams: { gasPrice, gas: gasLimit, maxFeePerGas, maxPriorityFeePerGas },
|
||||
txParams: {
|
||||
gasPrice,
|
||||
gas: gasLimit,
|
||||
maxFeePerGas,
|
||||
maxPriorityFeePerGas,
|
||||
estimateSuggested,
|
||||
estimateUsed,
|
||||
},
|
||||
metamaskNetworkId: network,
|
||||
} = txMeta;
|
||||
const source = referrer === 'metamask' ? 'user' : 'dapp';
|
||||
@ -1407,6 +1422,14 @@ export default class TransactionController extends EventEmitter {
|
||||
gasParams.gas_price = gasPrice;
|
||||
}
|
||||
|
||||
if (estimateSuggested) {
|
||||
gasParams.estimate_suggested = estimateSuggested;
|
||||
}
|
||||
|
||||
if (estimateUsed) {
|
||||
gasParams.estimate_used = estimateUsed;
|
||||
}
|
||||
|
||||
const gasParamsInGwei = this._getGasValuesInGWEI(gasParams);
|
||||
|
||||
this._trackMetaMetricsEvent({
|
||||
@ -1441,6 +1464,8 @@ export default class TransactionController extends EventEmitter {
|
||||
for (const param in gasParams) {
|
||||
if (isHexString(gasParams[param])) {
|
||||
gasValuesInGwei[param] = hexWEIToDecGWEI(gasParams[param]);
|
||||
} else {
|
||||
gasValuesInGwei[param] = gasParams[param];
|
||||
}
|
||||
}
|
||||
return gasValuesInGwei;
|
||||
|
@ -999,6 +999,8 @@ describe('Transaction Controller', function () {
|
||||
to: '0xB09d8505E1F4EF1CeA089D47094f5DD3464083d4',
|
||||
gas: '0x5209',
|
||||
gasPrice: '0xa',
|
||||
estimateSuggested: 'medium',
|
||||
estimateUsed: 'high',
|
||||
};
|
||||
txController.txStateManager._addTransactionsToState([
|
||||
{
|
||||
@ -1698,6 +1700,8 @@ describe('Transaction Controller', function () {
|
||||
maxPriorityFeePerGas: '0x77359400',
|
||||
gas: '0x7b0d',
|
||||
nonce: '0x4b',
|
||||
estimateSuggested: 'medium',
|
||||
estimateUsed: 'high',
|
||||
},
|
||||
type: TRANSACTION_TYPES.SIMPLE_SEND,
|
||||
origin: 'other',
|
||||
@ -1724,6 +1728,8 @@ describe('Transaction Controller', function () {
|
||||
first_seen: 1624408066355,
|
||||
transaction_envelope_type: 'fee-market',
|
||||
status: 'unapproved',
|
||||
estimate_suggested: 'medium',
|
||||
estimate_used: 'high',
|
||||
},
|
||||
};
|
||||
|
||||
@ -1791,5 +1797,22 @@ describe('Transaction Controller', function () {
|
||||
const result = txController._getGasValuesInGWEI(params);
|
||||
assert.deepEqual(result, expectedParams);
|
||||
});
|
||||
|
||||
it('converts gas values in hex GWEi to dec GWEI, retains estimate fields', function () {
|
||||
const params = {
|
||||
max_fee_per_gas: '0x77359400',
|
||||
max_priority_fee_per_gas: '0x77359400',
|
||||
estimate_suggested: 'medium',
|
||||
estimate_used: 'high',
|
||||
};
|
||||
const expectedParams = {
|
||||
max_fee_per_gas: '2',
|
||||
max_priority_fee_per_gas: '2',
|
||||
estimate_suggested: 'medium',
|
||||
estimate_used: 'high',
|
||||
};
|
||||
const result = txController._getGasValuesInGWEI(params);
|
||||
assert.deepEqual(result, expectedParams);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -19,6 +19,8 @@ const normalizers = {
|
||||
maxFeePerGas: addHexPrefix,
|
||||
maxPriorityFeePerGas: addHexPrefix,
|
||||
type: addHexPrefix,
|
||||
estimateSuggested: (estimate) => estimate,
|
||||
estimateUsed: (estimate) => estimate,
|
||||
};
|
||||
|
||||
export function normalizeAndValidateTxParams(txParams, lowerCase = true) {
|
||||
|
@ -323,6 +323,8 @@ describe('txUtils', function () {
|
||||
gasPrice: '1',
|
||||
maxFeePerGas: '1',
|
||||
maxPriorityFeePerGas: '1',
|
||||
estimateSuggested: 'medium',
|
||||
estimateUsed: 'high',
|
||||
type: '1',
|
||||
};
|
||||
|
||||
@ -377,6 +379,17 @@ describe('txUtils', function () {
|
||||
'0x1',
|
||||
'type should be hex-prefixed',
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
normalizedTxParams.estimateSuggested,
|
||||
'medium',
|
||||
'estimateSuggested should be the string originally provided',
|
||||
);
|
||||
assert.equal(
|
||||
normalizedTxParams.estimateUsed,
|
||||
'high',
|
||||
'estimateSuggested should be the string originally provided',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -133,21 +133,22 @@ export default function EditGasPopover({
|
||||
closePopover();
|
||||
}
|
||||
|
||||
const newGasSettings = supportsEIP1559
|
||||
? {
|
||||
const newGasSettings = {
|
||||
gas: decimalToHex(gasLimit),
|
||||
gasLimit: decimalToHex(gasLimit),
|
||||
maxFeePerGas: decGWEIToHexWEI(maxFeePerGas ?? gasPrice),
|
||||
maxPriorityFeePerGas: decGWEIToHexWEI(
|
||||
maxPriorityFeePerGas ?? maxFeePerGas ?? gasPrice,
|
||||
),
|
||||
}
|
||||
: {
|
||||
gas: decimalToHex(gasLimit),
|
||||
gasLimit: decimalToHex(gasLimit),
|
||||
gasPrice: decGWEIToHexWEI(gasPrice),
|
||||
estimateSuggested: defaultEstimateToUse,
|
||||
estimateUsed: estimateToUse,
|
||||
};
|
||||
|
||||
if (supportsEIP1559) {
|
||||
newGasSettings.maxFeePerGas = decGWEIToHexWEI(maxFeePerGas ?? gasPrice);
|
||||
newGasSettings.maxPriorityFeePerGas = decGWEIToHexWEI(
|
||||
maxPriorityFeePerGas ?? maxFeePerGas ?? gasPrice,
|
||||
);
|
||||
} else {
|
||||
newGasSettings.gasPrice = decGWEIToHexWEI(gasPrice);
|
||||
}
|
||||
|
||||
const cleanTransactionParams = { ...updatedTransaction.txParams };
|
||||
|
||||
if (supportsEIP1559) {
|
||||
@ -205,6 +206,7 @@ export default function EditGasPopover({
|
||||
supportsEIP1559,
|
||||
estimateToUse,
|
||||
estimatedBaseFee,
|
||||
defaultEstimateToUse,
|
||||
]);
|
||||
|
||||
let title = t('editGasTitle');
|
||||
|
Loading…
Reference in New Issue
Block a user