From cd0892a3afe8a0d057f7f0760aecada0afb83dc9 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 10 Jan 2022 14:34:54 -0500 Subject: [PATCH] EIP-1559 V2: Use default gas preferences of user for all transactions (#13238) --- app/_locales/el/messages.json | 12 -- app/_locales/en/messages.json | 15 +-- app/_locales/fr/messages.json | 12 -- app/_locales/hi/messages.json | 12 -- app/_locales/id/messages.json | 12 -- app/_locales/ja/messages.json | 12 -- app/_locales/ko/messages.json | 12 -- app/_locales/ru/messages.json | 12 -- app/_locales/tl/messages.json | 12 -- app/_locales/tr/messages.json | 12 -- app/_locales/vi/messages.json | 12 -- app/_locales/zh_CN/messages.json | 12 -- app/scripts/controllers/transactions/index.js | 19 ++- test/data/mock-state.json | 2 +- .../advanced-gas-fee-defaults.js | 20 +-- .../advanced-gas-fee-defaults.test.js | 22 ++-- .../base-fee-input/base-fee-input.js | 123 +++--------------- .../base-fee-input/basefee-input.test.js | 66 +--------- .../priority-fee-input/priority-fee-input.js | 2 +- .../context/advancedGasFeePopover.js | 6 +- .../edit-gas-item/edit-gas-item.test.js | 4 +- .../edit-gas-item/useGasItemFeeDetails.js | 4 +- ui/selectors/selectors.test.js | 2 +- 23 files changed, 67 insertions(+), 350 deletions(-) diff --git a/app/_locales/el/messages.json b/app/_locales/el/messages.json index 02a658be4..53ebd0f4c 100644 --- a/app/_locales/el/messages.json +++ b/app/_locales/el/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Η μέγιστη βασική χρέωση τέλους είναι χαμηλή για τις τρέχουσες συνθήκες δικτύου" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Ο πολλαπλασιαστής είναι χαμηλός σε σχέση με το τέλος Προτεραιότητας" - }, "editGasMaxFeeHigh": { "message": "Η μέγιστη χρέωση είναι υψηλότερη από το απαραίτητο" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Αυτό μειώνει τη μέγιστη χρέωση αλλά αν η κίνηση δικτύου αυξήσει την συναλλαγή σας μπορεί να καθυστερήσει ή να αποτύχει." }, - "editInGwei": { - "message": "Επεξεργασία στο GWEI" - }, - "editInMultiplier": { - "message": "Επεξεργασία στον πολλαπλασιαστή" - }, "editNonceField": { "message": "Επεξεργασία Nonce" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "Η λειτουργία 'Συγχρονισμός με επέκταση' είναι προσωρινά απενεργοποιημένη. Αν θέλετε να χρησιμοποιήσετε το πορτοφόλι της επέκτασής σας στο MetaMask mobile, τότε στην εφαρμογή για το κινητό σας: επιστρέψτε στις επιλογές εγκατάστασης του πορτοφολιού και επιλέξτε την επιλογή 'Εισαγωγή με Μυστική Φράση Ανάκτησης'. Χρησιμοποιήστε τη μυστική φράση του πορτοφολιού της επέκτασής σας για να εισαγάγετε το πορτοφόλι σας στο κινητό." }, - "multiplier": { - "message": "πολλαπλασιαστής" - }, "mustSelectOne": { "message": "Πρέπει να επιλέξετε 1 τουλάχιστον διακριτικό." }, diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index a76db8eeb..08de0b075 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -857,9 +857,6 @@ "editGasMaxBaseFeeLow": { "message": "Max base fee is low for current network conditions" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Multiplier is low relative to Priority fee" - }, "editGasMaxFeeHigh": { "message": "Max fee is higher than necessary" }, @@ -921,12 +918,6 @@ "editGasTooLowWarningTooltip": { "message": "This lowers your maximum fee but if network traffic increases your transaction may be delayed or fail." }, - "editInGwei": { - "message": "Edit in GWEI" - }, - "editInMultiplier": { - "message": "Edit in multiplier" - }, "editNonceField": { "message": "Edit Nonce" }, @@ -1298,6 +1289,9 @@ "grantedToWithColon": { "message": "Granted to:" }, + "gwei": { + "message": "GWEI" + }, "happyToSeeYou": { "message": "We’re happy to see you." }, @@ -1752,9 +1746,6 @@ "mobileSyncWarning": { "message": "The 'Sync with extension' feature is temporarily disabled. If you want to use your extension wallet on MetaMask mobile, then on your mobile app: go back to the wallet setup options and select the 'Import with Secret Recovery Phrase' option. Use your extension wallet's secret phrase to then import your wallet into mobile." }, - "multiplier": { - "message": "multiplier" - }, "mustSelectOne": { "message": "Must select at least 1 token." }, diff --git a/app/_locales/fr/messages.json b/app/_locales/fr/messages.json index 7819973f6..22338bfe1 100644 --- a/app/_locales/fr/messages.json +++ b/app/_locales/fr/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Les frais de base maximaux sont faibles par rapport aux conditions actuelles du réseau" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Le multiplicateur est faible par rapport aux frais de priorité" - }, "editGasMaxFeeHigh": { "message": "Les frais maximaux sont plus élevés que nécessaire" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Cela réduit vos frais maximaux, mais si le trafic réseau augmente, votre transaction peut être retardée ou ne pas aboutir." }, - "editInGwei": { - "message": "Modifier dans GWEI" - }, - "editInMultiplier": { - "message": "Modifier le multiplicateur" - }, "editNonceField": { "message": "Modifier le nonce" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "La fonction « Synchronisation avec l’extension » est temporairement désactivée. Si vous souhaitez utiliser votre portefeuille d’extension sur MetaMask mobile : sur votre appli mobile, revenez aux options de configuration du portefeuille et sélectionnez l’option « Importation avec Phrase secrète de récupération ». Utilisez la phrase secrète de votre portefeuille d’extension pour importer celui-ci sur votre mobile." }, - "multiplier": { - "message": "multiplicateur" - }, "mustSelectOne": { "message": "Vous devez selectionner au moins 1 jeton." }, diff --git a/app/_locales/hi/messages.json b/app/_locales/hi/messages.json index 6e6f0718d..56ce5b71c 100644 --- a/app/_locales/hi/messages.json +++ b/app/_locales/hi/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "मौजूदा नेटवर्क स्थितियों के लिए अधिकतम आधार शुल्क कम है" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "प्राथमिकता शुल्क के सापेक्ष गुणक कम है" - }, "editGasMaxFeeHigh": { "message": "अधिकतम शुल्क आवश्यकता से अधिक है" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "यह आपके अधिकतम शुल्क को कम करता है लेकिन यदि नेटवर्क ट्रैफ़िक बढ़ता है तो आपके लेन-देन में देरी हो सकती है या लेन-देन विफल हो सकता है।" }, - "editInGwei": { - "message": "GWEI में संपादित करें" - }, - "editInMultiplier": { - "message": "गुणक में संपादित करें" - }, "editNonceField": { "message": "नॉन्स संपादित करें" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "'एक्सटेंशन के साथ सिंक' फीचर अस्थायी रूप से अक्षम है। यदि आप MetaMask मोबाइल पर अपने एक्सटेंशन वॉलेट का उपयोग करना चाहते हैं, तो अपने मोबाइल ऐप पर: वॉलेट सेटअप ऑप्शन पर वापस जाएं और 'सीक्रेट रिकवरी फ्रेज़ के साथ इम्पोर्ट करें' विकल्प चुनें। फिर अपने वॉलेट को मोबाइल में इम्पोर्ट करने के लिए अपने एक्सटेंशन वॉलेट के सीक्रेट फ्रेज़ का उपयोग करें।" }, - "multiplier": { - "message": "गुणक" - }, "mustSelectOne": { "message": "कम से कम 1 टोकन का चयन करना चाहिए।" }, diff --git a/app/_locales/id/messages.json b/app/_locales/id/messages.json index b0d882e54..ac6d2d019 100644 --- a/app/_locales/id/messages.json +++ b/app/_locales/id/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Biaya dasar maks rendah untuk kondisi jaringan saat ini" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Pengganda relatif rendah terhadap biaya Prioritas" - }, "editGasMaxFeeHigh": { "message": "Biaya maks lebih tinggi dari yang diperlukan" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Ini akan menurunkan biaya maks Anda, tetapi jika lalu lintas jaringan meningkat, transaksi Anda mungkin tertunda atau gagal." }, - "editInGwei": { - "message": "Edit dalam GWEI" - }, - "editInMultiplier": { - "message": "Edit dalam pengganda" - }, "editNonceField": { "message": "Edit Nonce" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "Fitur 'Sinkronkan dengan ekstensi' dinonaktifkan untuk sementara waktu. Jika Anda ingin menggunakan dompet ekstensi Anda di ponsel MetaMask, maka pada aplikasi seluler Anda: kembali ke opsi pengaturan dompet dan pilih opsi 'Impor dengan Frasa Pemulihan Rahasia'. Gunakan frasa rahasia dompet ekstensi Anda untuk mengimpor dompet Anda ke ponsel nantinya." }, - "multiplier": { - "message": "pengganda" - }, "mustSelectOne": { "message": "Harus memilih sekurangnya 1 token." }, diff --git a/app/_locales/ja/messages.json b/app/_locales/ja/messages.json index 4fab4987c..8a12c217b 100644 --- a/app/_locales/ja/messages.json +++ b/app/_locales/ja/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "現在のネットワーク状況に対して最大基本手数料が低いです" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "優先手数料に対して乗数が低いです" - }, "editGasMaxFeeHigh": { "message": "最大手数料が必要以上です" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "これにより最大手数料は下がりますが、ネットワークトラフィックが増加するとトランザクションが遅延または失敗する可能性があります。" }, - "editInGwei": { - "message": "GWEIで編集" - }, - "editInMultiplier": { - "message": "乗数で編集" - }, "editNonceField": { "message": "ナンスの編集" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "「拡張機能と同期」機能は一時的に無効になっています。拡張ウォレットをMetaMaskモバイルで使用する場合は、モバイルアプリでウォレットの設定オプションに戻り、「シークレットリカバリーフレーズでインポート」オプションを選択します。拡張ウォレットのシークレットフレーズを使用して、ウォレットをモバイルにインポートします。" }, - "multiplier": { - "message": "乗数" - }, "mustSelectOne": { "message": "トークンを 1 つ以上選択する必要があります。" }, diff --git a/app/_locales/ko/messages.json b/app/_locales/ko/messages.json index 6822ec382..f5e61e319 100644 --- a/app/_locales/ko/messages.json +++ b/app/_locales/ko/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "최대 기본 요금이 현재 네트워크 조건에 비해 낮습니다." }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "승수가 우선 요금에 비해 낮습니다." - }, "editGasMaxFeeHigh": { "message": "최대 요금이 필요 이상으로 높습니다." }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "이렇게 하면 최대 요금이 낮아지지만 네트워크 트래픽이 증가하여 거래가 지연되거나 실패할 수 있습니다." }, - "editInGwei": { - "message": "GWEI에서 편집" - }, - "editInMultiplier": { - "message": "승수에서 편집" - }, "editNonceField": { "message": "임시값 편집" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "'확장 프로그램과 동기화' 기능이 일시적으로 비활성화됩니다. 메타마스크 모바일에서 확장 지갑을 사용하려면 모바일 앱에서 지갑 설정 옵션으로 돌아가 '비밀 백업 문구 가져오기' 옵션을 선택하세요. 확장 지갑의 비밀 문구를 사용하여 지갑을 모바일로 가져올 수 있습니다." }, - "multiplier": { - "message": "승수" - }, "mustSelectOne": { "message": "토큰을 1개 이상 선택해야 합니다." }, diff --git a/app/_locales/ru/messages.json b/app/_locales/ru/messages.json index c0d3bb436..6ac373c49 100644 --- a/app/_locales/ru/messages.json +++ b/app/_locales/ru/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Максимальная базовая комиссия низкая для текущих условий сети" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Множитель низкий по сравнению с платой за приоритет" - }, "editGasMaxFeeHigh": { "message": "Максимальная комиссия выше, чем необходимо" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Это снижает вашу максимальную комиссию, но, если трафик в сети увеличивается, ваша транзакция может быть отложена или завершиться ошибкой." }, - "editInGwei": { - "message": "Изменить в GWEI" - }, - "editInMultiplier": { - "message": "Изменить в множителе" - }, "editNonceField": { "message": "Изменить одноразовый номер" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "Функция «Синхронизация с расширением» временно отключена. Если вы хотите использовать свой кошелек из расширения браузера в мобильной версии MetaMask, тогда в мобильном приложении вернитесь к параметрам настройки кошелька и выберите параметр «Импортировать с помощью секретной фразы для восстановления». Используйте секретную фразу своего кошелька из расширения, чтобы импортировать кошелек на мобильное устройство." }, - "multiplier": { - "message": "множитель" - }, "mustSelectOne": { "message": "Необходимо выбрать хотя бы 1 токен." }, diff --git a/app/_locales/tl/messages.json b/app/_locales/tl/messages.json index c77c81a67..e1c76e2b0 100644 --- a/app/_locales/tl/messages.json +++ b/app/_locales/tl/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Ang max base fee ay mababa para sa kasalukuyang mga kundisyon ng network" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Ang multiplier ay mababa may kaugnayan sa Priority fee" - }, "editGasMaxFeeHigh": { "message": "Ang max fee ay mas mataas kaysa kinakailangan" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Pinabababa nito ang iyong maximum fee ngunit kung network traffic ay maaaring maantala o mabigo ang iyong transaksyon." }, - "editInGwei": { - "message": "I-edit sa GWEI" - }, - "editInMultiplier": { - "message": "I-edit sa multiplier" - }, "editNonceField": { "message": "I-edit sa Nonce" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "Ang feature na 'I-sync gamit ang extension' ay pansamantalang hindi gumagana. Kung gusto mong gamitin ang iyong extension wallet sa MetaMask mobile, pagkatapos ay sa iyong mobile app: bumalik sa mga opsyon sa pag-setup ng wallet at piliin ang opsyong 'Mag-import gamit ang Secret Recovery Phrase'. Gamitin ang lihim na parirala ng iyong extension wallet upang pagkatapos ay i-import ang iyong wallet sa mobile." }, - "multiplier": { - "message": "multiplier" - }, "mustSelectOne": { "message": "Dapat pumili ng kahit 1 token lang." }, diff --git a/app/_locales/tr/messages.json b/app/_locales/tr/messages.json index 4fff783db..32efe261a 100644 --- a/app/_locales/tr/messages.json +++ b/app/_locales/tr/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Maks. baz ücreti mevcut ağ koşulları için düşük" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Öncelik ücretine göre çarpan düşük" - }, "editGasMaxFeeHigh": { "message": "Maks. ücret gerekenden daha yüksek" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Bu, maksimum ücretinizi düşürür ancak ağ trafiğiniz artarsa işleminiz gecikebilir ya da gerçekleşmeyebilir." }, - "editInGwei": { - "message": "GWEI'de düzenle" - }, - "editInMultiplier": { - "message": "Çarpanda düzenle" - }, "editNonceField": { "message": "Geçici anahtarı düzenle" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "\"Uzantı ile senkronize et\" özelliği geçici olarak devre dışı bırakılmış. MetaMask mobilde uzantı cüzdanınızı kullanmak istiyorsanız mobil uygulamaya gidin: cüzdan kurulum ayarlarına geri dönün ve \"Gizli Kurtarma İfadesi ile İçe Aktar\" seçeneğini seçin. Ardından cüzdanınızı mobil uygulamada içe aktarmak için uzantı cüzdanınızın gizli ifadesini kullanın." }, - "multiplier": { - "message": "çarpan" - }, "mustSelectOne": { "message": "En az bir jeton seçilmeli" }, diff --git a/app/_locales/vi/messages.json b/app/_locales/vi/messages.json index acadc18ff..a38e86a55 100644 --- a/app/_locales/vi/messages.json +++ b/app/_locales/vi/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "Phí cơ bản tối đa thấp so với tình trạng mạng hiện tại" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "Hệ số nhân thấp so với phí ưu tiên" - }, "editGasMaxFeeHigh": { "message": "Phí tối đa cao hơn cần thiết" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "Việc này sẽ giảm mức phí tối đa, nhưng nếu lưu lượng mạng tăng lên, giao dịch của bạn có thể bị trì hoãn hoặc thất bại." }, - "editInGwei": { - "message": "Chỉnh sửa GWEI" - }, - "editInMultiplier": { - "message": "Chỉnh sửa hệ số nhân" - }, "editNonceField": { "message": "Chỉnh sửa số chỉ dùng một lần" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "Tính năng 'Đồng bộ với tiện ích' tạm thời bị tắt. Nếu bạn muốn sử dụng ví tiện ích trên thiết bị di động MetaMask, thì trên ứng dụng di động: hãy quay lại các tùy chọn thiết lập ví và chọn phương án 'Nhập bằng Cụm Mật Khẩu Khôi Phục Bí Mật'. Sử dụng cụm mật khẩu bí mật của ví tiện ích để nhập ví của bạn vào thiết bị di động." }, - "multiplier": { - "message": "hệ số nhân" - }, "mustSelectOne": { "message": "Phải chọn ít nhất 1 token." }, diff --git a/app/_locales/zh_CN/messages.json b/app/_locales/zh_CN/messages.json index 317ff1dde..cec91fbfb 100644 --- a/app/_locales/zh_CN/messages.json +++ b/app/_locales/zh_CN/messages.json @@ -842,9 +842,6 @@ "editGasMaxBaseFeeLow": { "message": "当前网络条件的最高基本费用很低" }, - "editGasMaxBaseFeeMultiplierImbalance": { - "message": "乘数相对于优先级费用较低" - }, "editGasMaxFeeHigh": { "message": "最大费用高于必须" }, @@ -906,12 +903,6 @@ "editGasTooLowWarningTooltip": { "message": "这会降低您的最大费用,但如果网络流量增加,您的交易可能会被延迟或失败。" }, - "editInGwei": { - "message": "在 GWEI 编辑" - }, - "editInMultiplier": { - "message": "按乘数编辑" - }, "editNonceField": { "message": "编辑空格" }, @@ -1726,9 +1717,6 @@ "mobileSyncWarning": { "message": "“同步扩展”功能暂时被禁用。 如果您想要在MetaMask手机上使用您的扩展钱包,在您的手机应用上:返回钱包设置选项并选择“使用账户助记词导入”选项。 使用您的扩展钱包的助记词来导入您的钱包。" }, - "multiplier": { - "message": "倍数" - }, "mustSelectOne": { "message": "至少选择 1 种代币。" }, diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index f4e1dd33c..555d892e3 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -432,6 +432,7 @@ export default class TransactionController extends EventEmitter { gasLimit: defaultGasLimit, simulationFails, } = await this._getDefaultGasLimit(txMeta, getCodeResponse); + const advancedGasFeeDefaultValues = this.getAdvancedGasFee(); // eslint-disable-next-line no-param-reassign txMeta = this.txStateManager.getTransaction(txMeta.id); @@ -440,13 +441,21 @@ export default class TransactionController extends EventEmitter { } if (eip1559Compatibility) { - // If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas - // then we set maxFeePerGas and maxPriorityFeePerGas to the suggested gasPrice. - if ( + if (process.env.EIP_1559_V2 && Boolean(advancedGasFeeDefaultValues)) { + txMeta.userFeeLevel = CUSTOM_GAS_ESTIMATE; + txMeta.txParams.maxFeePerGas = decGWEIToHexWEI( + advancedGasFeeDefaultValues.maxBaseFee, + ); + txMeta.txParams.maxPriorityFeePerGas = decGWEIToHexWEI( + advancedGasFeeDefaultValues.priorityFee, + ); + } else if ( txMeta.txParams.gasPrice && !txMeta.txParams.maxFeePerGas && !txMeta.txParams.maxPriorityFeePerGas ) { + // If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas + // then we set maxFeePerGas and maxPriorityFeePerGas to the suggested gasPrice. txMeta.txParams.maxFeePerGas = txMeta.txParams.gasPrice; txMeta.txParams.maxPriorityFeePerGas = txMeta.txParams.gasPrice; if (process.env.EIP_1559_V2) { @@ -1142,6 +1151,10 @@ export default class TransactionController extends EventEmitter { * @param opts */ this.getTransactions = (opts) => this.txStateManager.getTransactions(opts); + + /** @returns {object} the saved default values for advancedGasFee */ + this.getAdvancedGasFee = () => + this.preferencesStore.getState().advancedGasFee; } // called once on startup diff --git a/test/data/mock-state.json b/test/data/mock-state.json index cc5bfc51b..d856bb3b6 100644 --- a/test/data/mock-state.json +++ b/test/data/mock-state.json @@ -162,7 +162,7 @@ }, "useTokenDetection": true, "advancedGasFee": { - "maxBaseFee": "1.5", + "maxBaseFee": "75", "priorityFee": "2" }, "tokenList": { diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.js index affe7a79a..05de4c655 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.js @@ -4,7 +4,6 @@ import { useSelector, useDispatch } from 'react-redux'; import Box from '../../../ui/box'; import Typography from '../../../ui/typography'; import CheckBox from '../../../ui/check-box'; -import I18nValue from '../../../ui/i18n-value'; import { COLORS, DISPLAY, @@ -23,7 +22,7 @@ const AdvancedGasFeeDefaults = () => { const { hasErrors, - baseFeeMultiplier, + maxBaseFee, maxPriorityFeePerGas, } = useAdvancedGasFeePopoverContext(); const advancedGasFeeValues = useSelector(getAdvancedGasFeeValues); @@ -32,7 +31,7 @@ const AdvancedGasFeeDefaults = () => { if (value) { dispatch( setAdvancedGasFee({ - maxBaseFee: baseFeeMultiplier, + maxBaseFee, priorityFee: maxPriorityFeePerGas, }), ); @@ -42,7 +41,7 @@ const AdvancedGasFeeDefaults = () => { }; const isDefaultSettingsSelected = Boolean(advancedGasFeeValues) && - advancedGasFeeValues.maxBaseFee === baseFeeMultiplier && + advancedGasFeeValues.maxBaseFee === maxBaseFee && advancedGasFeeValues.priorityFee === maxPriorityFeePerGas; const handleUpdateDefaultSettings = () => @@ -62,16 +61,11 @@ const AdvancedGasFeeDefaults = () => { disabled={hasErrors} /> - {!isDefaultSettingsSelected && Boolean(advancedGasFeeValues) ? ( - {t('newValues')}, - ]} - /> - ) : ( - - )} + ]) + : t('advancedGasFeeDefaultOptOut')} ); diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.test.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.test.js index 008565945..fd83dd1e6 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.test.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-defaults/advanced-gas-fee-defaults.test.js @@ -41,11 +41,7 @@ const render = (defaultGasParams) => { return renderWithProvider( @@ -67,7 +63,7 @@ describe('AdvancedGasFeeDefaults', () => { }); it('should renders correct message when the default values are set', () => { render({ - advancedGasFee: { maxBaseFee: 2, priorityFee: 2 }, + advancedGasFee: { maxBaseFee: 50, priorityFee: 2 }, }); expect( screen.queryByText( @@ -85,7 +81,7 @@ describe('AdvancedGasFeeDefaults', () => { ), ).toBeInTheDocument(); fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 3 }, + target: { value: 100 }, }); fireEvent.change(document.getElementsByTagName('input')[1], { target: { value: 4 }, @@ -93,7 +89,7 @@ describe('AdvancedGasFeeDefaults', () => { }); it('should renders correct message when the default values are set and the maxBaseFee values are updated', () => { render({ - advancedGasFee: { maxBaseFee: 2, priorityFee: 2 }, + advancedGasFee: { maxBaseFee: 50, priorityFee: 2 }, }); expect(document.getElementsByTagName('input')[2]).toBeChecked(); expect( @@ -102,9 +98,9 @@ describe('AdvancedGasFeeDefaults', () => { ), ).toBeInTheDocument(); fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 4 }, + target: { value: 75 }, }); - expect(document.getElementsByTagName('input')[0]).toHaveValue(4); + expect(document.getElementsByTagName('input')[0]).toHaveValue(75); expect(screen.queryByText('new values')).toBeInTheDocument(); expect( screen.queryByText('Save these as my default for "Advanced"'), @@ -112,7 +108,7 @@ describe('AdvancedGasFeeDefaults', () => { }); it('should renders correct message when the default values are set and the priorityFee values are updated', () => { render({ - advancedGasFee: { maxBaseFee: 2, priorityFee: 2 }, + advancedGasFee: { maxBaseFee: 50, priorityFee: 2 }, }); expect(document.getElementsByTagName('input')[2]).toBeChecked(); expect( @@ -121,9 +117,9 @@ describe('AdvancedGasFeeDefaults', () => { ), ).toBeInTheDocument(); fireEvent.change(document.getElementsByTagName('input')[1], { - target: { value: 4 }, + target: { value: 5 }, }); - expect(document.getElementsByTagName('input')[1]).toHaveValue(4); + expect(document.getElementsByTagName('input')[1]).toHaveValue(5); expect(screen.queryByText('new values')).toBeInTheDocument(); expect( screen.queryByText('Save these as my default for "Advanced"'), diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js index b1091a287..9693e238e 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/base-fee-input.js @@ -3,11 +3,7 @@ import { useSelector } from 'react-redux'; import { HIGH_FEE_WARNING_MULTIPLIER } from '../../../../../pages/send/send.constants'; import { PRIORITY_LEVELS } from '../../../../../../shared/constants/gas'; -import { - divideCurrencies, - multiplyCurrencies, -} from '../../../../../../shared/modules/conversion.utils'; -import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common'; +import { SECONDARY } from '../../../../../helpers/constants/common'; import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util'; import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util'; import { getAdvancedGasFeeValues } from '../../../../../selectors'; @@ -15,10 +11,8 @@ import { useGasFeeContext } from '../../../../../contexts/gasFee'; import { useI18nContext } from '../../../../../hooks/useI18nContext'; import { useUserPreferencedCurrency } from '../../../../../hooks/useUserPreferencedCurrency'; import { useCurrencyDisplay } from '../../../../../hooks/useCurrencyDisplay'; -import Button from '../../../../ui/button'; import Box from '../../../../ui/box'; import FormField from '../../../../ui/form-field'; -import I18nValue from '../../../../ui/i18n-value'; import { useAdvancedGasFeePopoverContext } from '../../context'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; @@ -27,34 +21,9 @@ import { renderFeeRange, } from '../utils'; -const divideCurrencyValues = (value, baseFee) => { - if (baseFee === 0) { - return 0; - } - return divideCurrencies(value, baseFee, { - numberOfDecimals: 2, - dividendBase: 10, - divisorBase: 10, - }).toNumber(); -}; - -const multiplyCurrencyValues = (baseFee, value, numberOfDecimals) => - multiplyCurrencies(baseFee, value, { - numberOfDecimals, - multiplicandBase: 10, - multiplierBase: 10, - }).toNumber(); - -const validateBaseFee = ( - editingInGwei, - value, - gasFeeEstimates, - maxPriorityFeePerGas, -) => { +const validateBaseFee = (value, gasFeeEstimates, maxPriorityFeePerGas) => { if (bnGreaterThan(maxPriorityFeePerGas, value)) { - return editingInGwei - ? 'editGasMaxBaseFeeGWEIImbalance' - : 'editGasMaxBaseFeeMultiplierImbalance'; + return 'editGasMaxBaseFeeGWEIImbalance'; } if ( gasFeeEstimates?.low && @@ -82,7 +51,7 @@ const BaseFeeInput = () => { maxPriorityFeePerGas, setErrorValue, setMaxFeePerGas, - setBaseFeeMultiplier, + setMaxBaseFee, } = useAdvancedGasFeePopoverContext(); const { @@ -91,9 +60,6 @@ const BaseFeeInput = () => { baseFeeTrend, } = gasFeeEstimates; const [baseFeeError, setBaseFeeError] = useState(); - const { - numberOfDecimals: numberOfDecimalsPrimary, - } = useUserPreferencedCurrency(PRIMARY); const { currency, numberOfDecimals: numberOfDecimalsFiat, @@ -101,90 +67,48 @@ const BaseFeeInput = () => { const advancedGasFeeValues = useSelector(getAdvancedGasFeeValues); - const [editingInGwei, setEditingInGwei] = useState(false); - - const [maxBaseFeeGWEI, setMaxBaseFeeGWEI] = useState(() => { - if ( - estimateUsed !== PRIORITY_LEVELS.CUSTOM && - advancedGasFeeValues?.maxBaseFee - ) { - return multiplyCurrencyValues( - estimatedBaseFee, - advancedGasFeeValues.maxBaseFee, - numberOfDecimalsPrimary, - ); - } - return maxFeePerGas; - }); - - const [maxBaseFeeMultiplier, setMaxBaseFeeMultiplier] = useState(() => { + const [baseFee, setBaseFee] = useState(() => { if ( estimateUsed !== PRIORITY_LEVELS.CUSTOM && advancedGasFeeValues?.maxBaseFee ) { return advancedGasFeeValues.maxBaseFee; } - return divideCurrencyValues(maxFeePerGas, estimatedBaseFee); + + return maxFeePerGas; }); const [, { value: baseFeeInFiat }] = useCurrencyDisplay( - decGWEIToHexWEI(maxBaseFeeGWEI), + decGWEIToHexWEI(baseFee), { currency, numberOfDecimalsFiat }, ); const updateBaseFee = useCallback( (value) => { - let baseFeeInGWEI; - let baseFeeMultiplierValue; - if (editingInGwei) { - baseFeeInGWEI = value; - baseFeeMultiplierValue = divideCurrencyValues(value, estimatedBaseFee); - } else { - baseFeeInGWEI = multiplyCurrencyValues( - estimatedBaseFee, - value, - numberOfDecimalsPrimary, - ); - baseFeeMultiplierValue = value; - } - setMaxBaseFeeGWEI(baseFeeInGWEI); - setMaxBaseFeeMultiplier(baseFeeMultiplierValue); + setBaseFee(value); }, - [ - editingInGwei, - estimatedBaseFee, - numberOfDecimalsPrimary, - setMaxBaseFeeGWEI, - setMaxBaseFeeMultiplier, - ], + [setBaseFee], ); useEffect(() => { - setMaxFeePerGas(maxBaseFeeGWEI); + setMaxFeePerGas(baseFee); const error = validateBaseFee( - editingInGwei, - maxBaseFeeGWEI, + baseFee, gasFeeEstimates, maxPriorityFeePerGas, ); setBaseFeeError(error); - setErrorValue( - 'maxFeePerGas', - error === 'editGasMaxBaseFeeGWEIImbalance' || - error === 'editGasMaxBaseFeeMultiplierImbalance', - ); - setBaseFeeMultiplier(maxBaseFeeMultiplier); + setErrorValue('maxFeePerGas', error === 'editGasMaxBaseFeeGWEIImbalance'); + setMaxBaseFee(baseFee); }, [ - editingInGwei, + baseFee, gasFeeEstimates, - maxBaseFeeGWEI, maxPriorityFeePerGas, - maxBaseFeeMultiplier, setBaseFeeError, setErrorValue, setMaxFeePerGas, - setBaseFeeMultiplier, + setMaxBaseFee, ]); return ( @@ -193,20 +117,9 @@ const BaseFeeInput = () => { error={baseFeeError ? t(baseFeeError) : ''} onChange={updateBaseFee} titleText={t('maxBaseFee')} - titleUnit={editingInGwei ? 'GWEI' : `(${t('multiplier')})`} + titleUnit={`(${t('gwei')})`} tooltipText={t('advancedBaseGasFeeToolTip')} - titleDetail={ - - } - value={editingInGwei ? maxBaseFeeGWEI : maxBaseFeeMultiplier} + value={baseFee} detailText={`≈ ${baseFeeInFiat}`} numeric /> diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/basefee-input.test.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/basefee-input.test.js index f34d8e2c5..9663f561e 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/basefee-input.test.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/base-fee-input/basefee-input.test.js @@ -30,7 +30,7 @@ const render = (txProps) => { balance: '0x1F4', }, }, - advancedGasFee: { maxBaseFee: 2 }, + advancedGasFee: { maxBaseFee: 100 }, featureFlags: { advancedInlineGas: true }, gasFeeEstimates: mockEstimates[GAS_ESTIMATE_TYPES.FEE_MARKET].gasFeeEstimates, @@ -57,7 +57,7 @@ describe('BaseFeeInput', () => { render({ userFeeLevel: 'high', }); - expect(document.getElementsByTagName('input')[0]).toHaveValue(2); + expect(document.getElementsByTagName('input')[0]).toHaveValue(100); }); it('should renders baseFee values from transaction if current estimate used is custom', () => { @@ -66,47 +66,8 @@ describe('BaseFeeInput', () => { maxFeePerGas: '0x174876E800', }, }); - expect(document.getElementsByTagName('input')[0]).toHaveValue(2); - }); - - it('should show GWEI value in input when Edit in GWEI link is clicked', () => { - render({ - txParams: { - maxFeePerGas: '0x174876E800', - }, - }); - fireEvent.click(screen.queryByText('Edit in GWEI')); expect(document.getElementsByTagName('input')[0]).toHaveValue(100); }); - - it('should correctly update GWEI value if multiplier is changed', () => { - render({ - txParams: { - maxFeePerGas: '0x174876E800', - }, - }); - fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 4 }, - }); - fireEvent.click(screen.queryByText('Edit in GWEI')); - expect(document.getElementsByTagName('input')[0]).toHaveValue(200); - }); - - it('should correctly update multiplier value if GWEI is changed', () => { - render({ - txParams: { - maxFeePerGas: '0x174876E800', - }, - }); - expect(document.getElementsByTagName('input')[0]).toHaveValue(2); - fireEvent.click(screen.queryByText('Edit in GWEI')); - fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 200 }, - }); - fireEvent.click(screen.queryByText('Edit in multiplier')); - expect(document.getElementsByTagName('input')[0]).toHaveValue(4); - }); - it('should show current value of estimatedBaseFee in subtext', () => { render({ txParams: { @@ -130,24 +91,14 @@ describe('BaseFeeInput', () => { }, }); fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 3 }, + target: { value: 55 }, }); expect( screen.queryByText('Max base fee is low for current network conditions'), ).not.toBeInTheDocument(); fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 0.01 }, + target: { value: 50 }, }); - expect( - screen.queryByText('Max base fee is low for current network conditions'), - ).toBeInTheDocument(); - fireEvent.click(screen.queryByText('Edit in GWEI')); - fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 10 }, - }); - expect( - screen.queryByText('Max base fee is low for current network conditions'), - ).toBeInTheDocument(); }); it('should show error if base if is more than suggested high value', () => { @@ -157,18 +108,11 @@ describe('BaseFeeInput', () => { }, }); fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 3 }, + target: { value: 75 }, }); expect( screen.queryByText('Max base fee is higher than necessary'), ).not.toBeInTheDocument(); - fireEvent.change(document.getElementsByTagName('input')[0], { - target: { value: 10 }, - }); - fireEvent.click(screen.queryByText('Edit in GWEI')); - expect( - screen.queryByText('Max base fee is higher than necessary'), - ).toBeInTheDocument(); fireEvent.change(document.getElementsByTagName('input')[0], { target: { value: 500 }, }); diff --git a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js index a0a3548d6..e617bc249 100644 --- a/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js +++ b/ui/components/app/advanced-gas-fee-popover/advanced-gas-fee-inputs/priority-fee-input/priority-fee-input.js @@ -103,7 +103,7 @@ const PriorityFeeInput = () => { error={priorityFeeError ? t(priorityFeeError) : ''} onChange={updatePriorityFee} titleText={t('priorityFeeProperCase')} - titleUnit="(GWEI)" + titleUnit={`(${t('gwei')})`} tooltipText={t('advancedPriorityFeeToolTip')} value={priorityFee} detailText={`≈ ${priorityFeeInFiat}`} diff --git a/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js b/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js index 74ff01272..55a6b49f1 100644 --- a/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js +++ b/ui/components/app/advanced-gas-fee-popover/context/advancedGasFeePopover.js @@ -20,7 +20,7 @@ export const AdvancedGasFeePopoverContextProvider = ({ children }) => { }, [errors, setErrors], ); - const [baseFeeMultiplier, setBaseFeeMultiplier] = useState(); + const [maxBaseFee, setMaxBaseFee] = useState(); return ( { maxFeePerGas, maxPriorityFeePerGas, setErrorValue, - baseFeeMultiplier, + maxBaseFee, setGasLimit, setMaxPriorityFeePerGas, setMaxFeePerGas, - setBaseFeeMultiplier, + setMaxBaseFee, }} > {children} diff --git a/ui/components/app/edit-gas-fee-popover/edit-gas-item/edit-gas-item.test.js b/ui/components/app/edit-gas-fee-popover/edit-gas-item/edit-gas-item.test.js index b9cb1c325..d3baf6a3b 100644 --- a/ui/components/app/edit-gas-fee-popover/edit-gas-item/edit-gas-item.test.js +++ b/ui/components/app/edit-gas-fee-popover/edit-gas-item/edit-gas-item.test.js @@ -68,7 +68,7 @@ const renderComponent = ({ gasEstimateType: 'fee-market', gasFeeEstimates: MOCK_FEE_ESTIMATE, advancedGasFee: { - maxBaseFee: '1.5', + maxBaseFee: '100', priorityFee: '2', }, }, @@ -161,7 +161,7 @@ describe('EditGasItem', () => { expect(screen.queryByText('⚙️')).toBeInTheDocument(); expect(screen.queryByText('Advanced')).toBeInTheDocument(); // below value of custom gas fee estimate is default obtained from state.metamask.advancedGasFee - expect(screen.queryByTitle('0.001575 ETH')).toBeInTheDocument(); + expect(screen.queryByTitle('0.0021 ETH')).toBeInTheDocument(); }); it('should renders +10% gas estimate option for priorityLevel minimum', () => { diff --git a/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js b/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js index 2f49fd18e..89491be86 100644 --- a/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js +++ b/ui/components/app/edit-gas-fee-popover/edit-gas-item/useGasItemFeeDetails.js @@ -59,9 +59,7 @@ export const useGasItemFeeDetails = (priorityLevel) => { maxFeePerGas = maxFeePerGasValue; maxPriorityFeePerGas = maxPriorityFeePerGasValue; } else if (advancedGasFeeValues) { - maxFeePerGas = - gasFeeEstimates.estimatedBaseFee * - parseFloat(advancedGasFeeValues.maxBaseFee); + maxFeePerGas = advancedGasFeeValues.maxBaseFee; maxPriorityFeePerGas = advancedGasFeeValues.priorityFee; } } else if ( diff --git a/ui/selectors/selectors.test.js b/ui/selectors/selectors.test.js index a596f91da..ca3f9c92f 100644 --- a/ui/selectors/selectors.test.js +++ b/ui/selectors/selectors.test.js @@ -230,7 +230,7 @@ describe('Selectors', () => { it('#getAdvancedGasFeeValues', () => { const advancedGasFee = selectors.getAdvancedGasFeeValues(mockState); expect(advancedGasFee).toStrictEqual({ - maxBaseFee: '1.5', + maxBaseFee: '75', priorityFee: '2', }); });