Enable EIP 1559
This commit is contained in:
parent
f76b400a7d
commit
f5f47ae636
2
.env
2
.env
|
@ -29,4 +29,4 @@ APN_TOPIC=im.status.ethereum.pr
|
||||||
COMMUNITIES_ENABLED=1
|
COMMUNITIES_ENABLED=1
|
||||||
DATABASE_MANAGEMENT_ENABLED=1
|
DATABASE_MANAGEMENT_ENABLED=1
|
||||||
METRICS_ENABLED=0
|
METRICS_ENABLED=0
|
||||||
EIP1559_ENABLED=0
|
EIP1559_ENABLED=1
|
||||||
|
|
1
.env.e2e
1
.env.e2e
|
@ -30,3 +30,4 @@ DATABASE_MANAGEMENT_ENABLED=1
|
||||||
COMMUNITIES_ENABLED=1
|
COMMUNITIES_ENABLED=1
|
||||||
COMMUNITIES_MANAGEMENT_ENABLED=1
|
COMMUNITIES_MANAGEMENT_ENABLED=1
|
||||||
METRICS_ENABLED=0
|
METRICS_ENABLED=0
|
||||||
|
EIP1559_ENABLED=1
|
||||||
|
|
|
@ -30,3 +30,4 @@ DATABASE_MANAGEMENT_ENABLED=1
|
||||||
COMMUNITIES_ENABLED=1
|
COMMUNITIES_ENABLED=1
|
||||||
COMMUNITIES_MANAGEMENT_ENABLED=1
|
COMMUNITIES_MANAGEMENT_ENABLED=1
|
||||||
METRICS_ENABLED=0
|
METRICS_ENABLED=0
|
||||||
|
EIP1559_ENABLED=1
|
||||||
|
|
|
@ -23,3 +23,4 @@ BLANK_PREVIEW=0
|
||||||
COMMUNITIES_ENABLED=1
|
COMMUNITIES_ENABLED=1
|
||||||
DATABASE_MANAGEMENT_ENABLED=1
|
DATABASE_MANAGEMENT_ENABLED=1
|
||||||
METRICS_ENABLED=0
|
METRICS_ENABLED=0
|
||||||
|
EIP1559_ENABLED=1
|
||||||
|
|
|
@ -19,3 +19,4 @@ ENABLE_ROOT_ALERT=1
|
||||||
MAX_IMAGES_BATCH=1
|
MAX_IMAGES_BATCH=1
|
||||||
ENABLE_REFERRAL_INVITE=0
|
ENABLE_REFERRAL_INVITE=0
|
||||||
METRICS_ENABLED=0
|
METRICS_ENABLED=0
|
||||||
|
EIP1559_ENABLED=1
|
||||||
|
|
|
@ -406,7 +406,10 @@
|
||||||
:typed? typed?
|
:typed? typed?
|
||||||
:pinless? (= method constants/web3-keycard-sign-typed-data)
|
:pinless? (= method constants/web3-keycard-sign-typed-data)
|
||||||
:from dapps-address}}
|
:from dapps-address}}
|
||||||
{:tx-obj (update (first params) :from #(or % dapps-address))})
|
{:tx-obj (-> params
|
||||||
|
first
|
||||||
|
(update :from #(or % dapps-address))
|
||||||
|
(dissoc :gasPrice))})
|
||||||
{:on-result [:browser.dapp/transaction-on-result message-id id]
|
{:on-result [:browser.dapp/transaction-on-result message-id id]
|
||||||
:on-error [:browser.dapp/transaction-on-error message-id]}))))
|
:on-error [:browser.dapp/transaction-on-error message-id]}))))
|
||||||
(if (#{"eth_accounts" "eth_coinbase"} method)
|
(if (#{"eth_accounts" "eth_coinbase"} method)
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
"eth_newFilter" {:subscription? true}
|
"eth_newFilter" {:subscription? true}
|
||||||
"eth_getCode" {}
|
"eth_getCode" {}
|
||||||
"eth_syncing" {}
|
"eth_syncing" {}
|
||||||
|
"eth_feeHistory" {}
|
||||||
"net_version" {}
|
"net_version" {}
|
||||||
"web3_clientVersion" {}
|
"web3_clientVersion" {}
|
||||||
"shh_generateSymKeyFromPassword" {}
|
"shh_generateSymKeyFromPassword" {}
|
||||||
|
|
|
@ -50,7 +50,8 @@
|
||||||
(defn enrich-transfer
|
(defn enrich-transfer
|
||||||
[chain-tokens
|
[chain-tokens
|
||||||
{:keys [address blockNumber timestamp from txStatus txHash gasPrice
|
{:keys [address blockNumber timestamp from txStatus txHash gasPrice
|
||||||
gasUsed contract value gasLimit input nonce to type id]}]
|
gasUsed contract value gasLimit input nonce to type id
|
||||||
|
maxFeePerGas maxPriorityFeePerGas]}]
|
||||||
(let [erc20? (= type "erc20")
|
(let [erc20? (= type "erc20")
|
||||||
failed? (= txStatus "0x0")]
|
failed? (= txStatus "0x0")]
|
||||||
(merge {:address (eip55/address->checksum address)
|
(merge {:address (eip55/address->checksum address)
|
||||||
|
@ -59,6 +60,8 @@
|
||||||
:timestamp (* (decode/uint timestamp) 1000)
|
:timestamp (* (decode/uint timestamp) 1000)
|
||||||
:gas-used (str (decode/uint gasUsed))
|
:gas-used (str (decode/uint gasUsed))
|
||||||
:gas-price (str (decode/uint gasPrice))
|
:gas-price (str (decode/uint gasPrice))
|
||||||
|
:fee-cap (str (decode/uint maxFeePerGas))
|
||||||
|
:tip-cap (str (decode/uint maxPriorityFeePerGas))
|
||||||
:gas-limit (str (decode/uint gasLimit))
|
:gas-limit (str (decode/uint gasLimit))
|
||||||
:nonce (str (decode/uint nonce))
|
:nonce (str (decode/uint nonce))
|
||||||
:hash txHash
|
:hash txHash
|
||||||
|
|
|
@ -103,9 +103,11 @@
|
||||||
(when gasPrice
|
(when gasPrice
|
||||||
{:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))})
|
{:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))})
|
||||||
(when maxPriorityFeePerGas
|
(when maxPriorityFeePerGas
|
||||||
{:maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex (.decimalPlaces maxPriorityFeePerGas 0)))})
|
{:maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex
|
||||||
|
(js/parseInt maxPriorityFeePerGas)))})
|
||||||
(when maxFeePerGas
|
(when maxFeePerGas
|
||||||
{:maxFeePerGas (str "0x" (abi-spec/number-to-hex (.decimalPlaces maxFeePerGas 0)))}))]
|
{:maxFeePerGas (str "0x" (abi-spec/number-to-hex
|
||||||
|
(js/parseInt maxFeePerGas)))}))]
|
||||||
(when-not in-progress?
|
(when-not in-progress?
|
||||||
{:db (update db :signing/sign assoc :error nil :in-progress? true)
|
{:db (update db :signing/sign assoc :error nil :in-progress? true)
|
||||||
:signing/send-transaction-fx {:tx-obj tx-obj-to-send
|
:signing/send-transaction-fx {:tx-obj tx-obj-to-send
|
||||||
|
@ -113,7 +115,8 @@
|
||||||
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}})))))
|
:cb #(re-frame/dispatch [:signing/transaction-completed % tx-obj-to-send hashed-password])}})))))
|
||||||
|
|
||||||
(fx/defn prepare-unconfirmed-transaction
|
(fx/defn prepare-unconfirmed-transaction
|
||||||
[{:keys [db now]} new-tx-hash {:keys [value gasPrice gas data to from hash]} symbol amount]
|
[{:keys [db now]} new-tx-hash
|
||||||
|
{:keys [value gasPrice maxFeePerGas maxPriorityFeePerGas gas data to from hash]} symbol amount]
|
||||||
(let [token (tokens/symbol->token (:wallet/all-tokens db) symbol)
|
(let [token (tokens/symbol->token (:wallet/all-tokens db) symbol)
|
||||||
from (eip55/address->checksum from)
|
from (eip55/address->checksum from)
|
||||||
;;if there is a hash in the tx object that means we resending transaction
|
;;if there is a hash in the tx object that means we resending transaction
|
||||||
|
@ -132,6 +135,8 @@
|
||||||
(money/to-fixed (money/unit->token amount (:decimals token)))
|
(money/to-fixed (money/unit->token amount (:decimals token)))
|
||||||
(money/to-fixed (money/bignumber value)))
|
(money/to-fixed (money/bignumber value)))
|
||||||
:gas-price gas-price
|
:gas-price gas-price
|
||||||
|
:fee-cap maxFeePerGas
|
||||||
|
:tip-cap maxPriorityFeePerGas
|
||||||
:gas-limit gas-limit}]
|
:gas-limit gas-limit}]
|
||||||
(log/info "[signing] prepare-unconfirmed-transaction" tx)
|
(log/info "[signing] prepare-unconfirmed-transaction" tx)
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
|
@ -246,15 +251,25 @@
|
||||||
(prices/update-prices)
|
(prices/update-prices)
|
||||||
#(when-not gas
|
#(when-not gas
|
||||||
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
|
{:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
|
||||||
:signing/update-estimated-gas {:obj (dissoc tx-obj :gasPrice)
|
:signing/update-estimated-gas {:obj (-> tx-obj
|
||||||
|
(dissoc :gasPrice)
|
||||||
|
(update :maxFeePerGas
|
||||||
|
(fn [fee]
|
||||||
|
(some-> fee
|
||||||
|
money/bignumber
|
||||||
|
(money/mul 2)
|
||||||
|
money/to-hex))))
|
||||||
:success-event :signing/update-estimated-gas-success
|
:success-event :signing/update-estimated-gas-success
|
||||||
:error-event :signing/update-estimated-gas-error}})
|
:error-event :signing/update-estimated-gas-error}})
|
||||||
#(when-not (or maxFeePerGas gasPrice)
|
(fn [cofx]
|
||||||
{:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true)
|
(when-not (or maxFeePerGas gasPrice)
|
||||||
:signing/update-gas-price {:success-event :signing/update-gas-price-success
|
{:db (assoc-in (:db cofx) [:signing/edit-fee :gas-price-loading?] true)
|
||||||
:error-event :signing/update-gas-price-error
|
:signing/update-gas-price
|
||||||
|
{:success-callback #(re-frame/dispatch
|
||||||
|
[:wallet.send/update-gas-price-success :signing/tx %])
|
||||||
|
:error-callback #(re-frame/dispatch [:signing/update-gas-price-error %])
|
||||||
:network-id (get-in (ethereum/current-network db)
|
:network-id (get-in (ethereum/current-network db)
|
||||||
[:config :NetworkId])}})))))
|
[:config :NetworkId])}}))))))
|
||||||
|
|
||||||
(fx/defn check-queue [{:keys [db] :as cofx}]
|
(fx/defn check-queue [{:keys [db] :as cofx}]
|
||||||
(let [{:signing/keys [tx queue]} db]
|
(let [{:signing/keys [tx queue]} db]
|
||||||
|
@ -436,7 +451,7 @@
|
||||||
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
||||||
from-address (:address from)
|
from-address (:address from)
|
||||||
identity (:current-chat-id db)
|
identity (:current-chat-id db)
|
||||||
db (dissoc db :wallet/prepare-transaction)]
|
db (dissoc db :wallet/prepare-transaction :signing/edit-fee)]
|
||||||
(if to-norm
|
(if to-norm
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
|
@ -474,7 +489,7 @@
|
||||||
to-norm (:address request-parameters)
|
to-norm (:address request-parameters)
|
||||||
from-address (:address from)]
|
from-address (:address from)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (dissoc db :wallet/prepare-transaction)}
|
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
|
||||||
(fn [cofx]
|
(fn [cofx]
|
||||||
(sign
|
(sign
|
||||||
cofx
|
cofx
|
||||||
|
@ -502,7 +517,7 @@
|
||||||
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
to-norm (ethereum/normalized-hex (if (string? to) to (:address to)))
|
||||||
from-address (:address from)]
|
from-address (:address from)]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{:db (dissoc db :wallet/prepare-transaction)}
|
{:db (dissoc db :wallet/prepare-transaction :signing/edit-fee)}
|
||||||
(sign
|
(sign
|
||||||
{:tx-obj (merge (if (eip1559/sync-enabled?)
|
{:tx-obj (merge (if (eip1559/sync-enabled?)
|
||||||
{:from from-address
|
{:from from-address
|
||||||
|
|
|
@ -34,11 +34,10 @@
|
||||||
:on-error #(callback nil)}))
|
:on-error #(callback nil)}))
|
||||||
|
|
||||||
(defn sync-enabled? []
|
(defn sync-enabled? []
|
||||||
(and config/eip1559-enabled?
|
config/eip1559-enabled?)
|
||||||
@activated-on-current-network?))
|
|
||||||
|
|
||||||
(defn enabled? [network-id enabled-callback disabled-callback]
|
(defn enabled? [network-id enabled-callback disabled-callback]
|
||||||
(let [london-activated? (get @activated? network-id)]
|
(let [london-activated? true]
|
||||||
(cond
|
(cond
|
||||||
(not config/eip1559-enabled?)
|
(not config/eip1559-enabled?)
|
||||||
(disabled-callback)
|
(disabled-callback)
|
||||||
|
|
|
@ -62,17 +62,36 @@
|
||||||
(assoc key data)
|
(assoc key data)
|
||||||
edit-max-fee)))
|
edit-max-fee)))
|
||||||
|
|
||||||
(def minimum-priority-fee
|
;; TODO(rasom): this number is almost arbitrary, I was able to sent txs with
|
||||||
(money/wei-> :gwei (money/->wei :gwei 1)))
|
;; 0.2 gwei tip, so it should be revisited lately
|
||||||
|
(def minimum-priority-fee-gwei
|
||||||
|
(money/bignumber 0.3))
|
||||||
|
|
||||||
|
(defn get-suggested-tip [latest-priority-fee]
|
||||||
|
(money/bignumber latest-priority-fee))
|
||||||
|
|
||||||
|
(defn get-minimum-priority-fee [latest-priority-fee]
|
||||||
|
(let [latest-priority-fee-bn (money/bignumber latest-priority-fee)
|
||||||
|
suggested-tip-gwei (money/wei->gwei (get-suggested-tip latest-priority-fee-bn))]
|
||||||
|
(if (money/greater-than minimum-priority-fee-gwei suggested-tip-gwei)
|
||||||
|
(money/div suggested-tip-gwei 2)
|
||||||
|
minimum-priority-fee-gwei)))
|
||||||
|
|
||||||
|
(defn get-suggestions-range [latest-priority-fee]
|
||||||
|
(let [current-minimum-fee (get-minimum-priority-fee latest-priority-fee)]
|
||||||
|
[(if (money/greater-than minimum-priority-fee-gwei current-minimum-fee)
|
||||||
|
current-minimum-fee
|
||||||
|
minimum-priority-fee-gwei)
|
||||||
|
(money/wei->gwei (money/bignumber latest-priority-fee))]))
|
||||||
|
|
||||||
(def average-priority-fee
|
(def average-priority-fee
|
||||||
(money/wei-> :gwei (money/->wei :gwei 1.5)))
|
(money/wei->gwei (money/->wei :gwei 1.5)))
|
||||||
|
|
||||||
(defn validate-max-fee [db]
|
(defn validate-max-fee [db]
|
||||||
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]} (get db :signing/edit-fee)
|
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]} (get db :signing/edit-fee)
|
||||||
latest-base-fee (money/wei-> :gwei
|
latest-base-fee (money/wei->gwei
|
||||||
(money/bignumber
|
(money/bignumber
|
||||||
(get db :wallet/latest-base-fee)))
|
(get db :wallet/current-base-fee)))
|
||||||
fee-error (cond
|
fee-error (cond
|
||||||
(or (:error maxFeePerGas)
|
(or (:error maxFeePerGas)
|
||||||
(:error maxPriorityFeePerGas))
|
(:error maxPriorityFeePerGas))
|
||||||
|
@ -81,12 +100,6 @@
|
||||||
(money/greater-than latest-base-fee
|
(money/greater-than latest-base-fee
|
||||||
(:value-number maxFeePerGas))
|
(:value-number maxFeePerGas))
|
||||||
{:label (i18n/label :t/below-base-fee)
|
{:label (i18n/label :t/below-base-fee)
|
||||||
:severity :error}
|
|
||||||
|
|
||||||
(money/greater-than (:value-number maxPriorityFeePerGas)
|
|
||||||
(money/sub (:value-number maxFeePerGas)
|
|
||||||
latest-base-fee))
|
|
||||||
{:label (i18n/label :t/reduced-tip)
|
|
||||||
:severity :error})]
|
:severity :error})]
|
||||||
(if fee-error
|
(if fee-error
|
||||||
(assoc-in db [:signing/edit-fee :maxFeePerGas :fee-error] fee-error)
|
(assoc-in db [:signing/edit-fee :maxFeePerGas :fee-error] fee-error)
|
||||||
|
@ -94,18 +107,21 @@
|
||||||
|
|
||||||
(defn validate-max-priority-fee [db]
|
(defn validate-max-priority-fee [db]
|
||||||
(let [{:keys [maxPriorityFeePerGas]} (get db :signing/edit-fee)
|
(let [{:keys [maxPriorityFeePerGas]} (get db :signing/edit-fee)
|
||||||
|
latest-priority-fee (get db :wallet/current-priority-fee)
|
||||||
fee-error (cond
|
fee-error (cond
|
||||||
(:error maxPriorityFeePerGas)
|
(:error maxPriorityFeePerGas)
|
||||||
nil
|
nil
|
||||||
|
|
||||||
(money/greater-than minimum-priority-fee
|
(money/greater-than (get-minimum-priority-fee
|
||||||
|
(money/div
|
||||||
|
(money/wei->gwei (money/bignumber latest-priority-fee)) 2))
|
||||||
(:value-number maxPriorityFeePerGas))
|
(:value-number maxPriorityFeePerGas))
|
||||||
{:label (i18n/label :t/low-tip)
|
{:label (i18n/label :t/low-tip)
|
||||||
:severity :error}
|
:severity :error}
|
||||||
|
|
||||||
(money/greater-than average-priority-fee
|
#_(money/greater-than average-priority-fee
|
||||||
(:value-number maxPriorityFeePerGas))
|
(:value-number maxPriorityFeePerGas))
|
||||||
{:label (i18n/label :t/lower-than-average-tip)
|
#_{:label (i18n/label :t/lower-than-average-tip)
|
||||||
:severity :error})]
|
:severity :error})]
|
||||||
(if fee-error
|
(if fee-error
|
||||||
(assoc-in db [:signing/edit-fee :maxPriorityFeePerGas :fee-error] fee-error)
|
(assoc-in db [:signing/edit-fee :maxPriorityFeePerGas :fee-error] fee-error)
|
||||||
|
@ -125,20 +141,54 @@
|
||||||
{:events [:signing.edit-fee.ui/edit-value]}
|
{:events [:signing.edit-fee.ui/edit-value]}
|
||||||
[{:keys [db]} key value]
|
[{:keys [db]} key value]
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
|
(assoc-in [:signing/edit-fee :selected-fee-option] :custom)
|
||||||
(update :signing/edit-fee build-edit key value)
|
(update :signing/edit-fee build-edit key value)
|
||||||
validate-eip1559-fees)})
|
validate-eip1559-fees)})
|
||||||
|
|
||||||
|
(defn get-fee-options [tip slow normal fast]
|
||||||
|
(let [tip-bn (money/bignumber tip)
|
||||||
|
normal-bn (money/bignumber normal)
|
||||||
|
slow-bn (money/bignumber slow)
|
||||||
|
fast-bn (money/bignumber fast)]
|
||||||
|
{:normal
|
||||||
|
{:base-fee normal-bn
|
||||||
|
:tip tip-bn
|
||||||
|
:fee (money/add normal-bn tip-bn)}
|
||||||
|
:slow
|
||||||
|
{:base-fee slow-bn
|
||||||
|
:tip tip-bn
|
||||||
|
:fee (money/add slow-bn tip-bn)}
|
||||||
|
:fast
|
||||||
|
{:base-fee fast-bn
|
||||||
|
:tip tip-bn
|
||||||
|
:fee (money/add fast-bn tip-bn)}}))
|
||||||
|
|
||||||
|
(fx/defn set-fee-option
|
||||||
|
{:events [:signing.edit-fee.ui/set-option]}
|
||||||
|
[{:keys [db] :as cofx} option]
|
||||||
|
(let [tip (get db :wallet/current-priority-fee)
|
||||||
|
slow (get db :wallet/slow-base-fee)
|
||||||
|
normal (get db :wallet/normal-base-fee)
|
||||||
|
fast (get db :wallet/fast-base-fee)
|
||||||
|
{:keys [fee tip]} (get (get-fee-options tip slow normal fast) option)]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [:signing/edit-fee :selected-fee-option] option)
|
||||||
|
(update :signing/edit-fee
|
||||||
|
build-edit :maxFeePerGas (money/wei->gwei fee))
|
||||||
|
(update :signing/edit-fee
|
||||||
|
build-edit :maxPriorityFeePerGas (money/wei->gwei tip)))}))
|
||||||
|
|
||||||
(fx/defn set-priority-fee
|
(fx/defn set-priority-fee
|
||||||
{:events [:signing.edit-fee.ui/set-priority-fee]}
|
{:events [:signing.edit-fee.ui/set-priority-fee]}
|
||||||
[{:keys [db]} value]
|
[{:keys [db]} value]
|
||||||
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]}
|
(let [{:keys [maxFeePerGas maxPriorityFeePerGas]}
|
||||||
(get db :signing/edit-fee)
|
(get db :signing/edit-fee)
|
||||||
latest-base-fee (get db :wallet/latest-base-fee)
|
latest-base-fee (get db :wallet/current-base-fee)
|
||||||
max-fee-value (:value-number maxFeePerGas)
|
max-fee-value (:value-number maxFeePerGas)
|
||||||
max-priority-fee-value (:value-number maxPriorityFeePerGas)
|
max-priority-fee-value (:value-number maxPriorityFeePerGas)
|
||||||
new-value (money/bignumber value)
|
new-value (money/bignumber value)
|
||||||
fee-without-tip (money/sub max-fee-value max-priority-fee-value)
|
fee-without-tip (money/sub max-fee-value max-priority-fee-value)
|
||||||
base-fee (money/wei-> :gwei (money/bignumber latest-base-fee))
|
base-fee (money/wei->gwei (money/bignumber latest-base-fee))
|
||||||
new-max-fee-value
|
new-max-fee-value
|
||||||
(money/to-fixed
|
(money/to-fixed
|
||||||
(if (money/greater-than base-fee fee-without-tip)
|
(if (money/greater-than base-fee fee-without-tip)
|
||||||
|
@ -159,9 +209,21 @@
|
||||||
(fx/defn update-gas-price-success
|
(fx/defn update-gas-price-success
|
||||||
{:events [:signing/update-gas-price-success]}
|
{:events [:signing/update-gas-price-success]}
|
||||||
[{db :db} price]
|
[{db :db} price]
|
||||||
|
(if (eip1559/sync-enabled?)
|
||||||
|
(let [{:keys [normal-base-fee max-priority-fee]} price
|
||||||
|
max-priority-fee-bn (money/with-precision
|
||||||
|
(get-suggested-tip max-priority-fee)
|
||||||
|
0)]
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [:signing/tx :maxFeePerGas]
|
||||||
|
(money/to-hex (money/add max-priority-fee-bn
|
||||||
|
(money/bignumber normal-base-fee))))
|
||||||
|
(assoc-in [:signing/tx :maxPriorityFeePerGas]
|
||||||
|
(money/to-hex max-priority-fee-bn))
|
||||||
|
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-in [:signing/tx :gasPrice] price)
|
(assoc-in [:signing/tx :gasPrice] price)
|
||||||
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})
|
(assoc-in [:signing/edit-fee :gas-price-loading?] false))}))
|
||||||
|
|
||||||
(fx/defn update-estimated-gas-error
|
(fx/defn update-estimated-gas-error
|
||||||
{:events [:signing/update-estimated-gas-error]}
|
{:events [:signing/update-estimated-gas-error]}
|
||||||
|
@ -179,12 +241,12 @@
|
||||||
{:events [:signing.ui/open-fee-sheet]}
|
{:events [:signing.ui/open-fee-sheet]}
|
||||||
[{{:signing/keys [tx] :as db} :db :as cofx} sheet-opts]
|
[{{:signing/keys [tx] :as db} :db :as cofx} sheet-opts]
|
||||||
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} tx
|
(let [{:keys [gas gasPrice maxFeePerGas maxPriorityFeePerGas]} tx
|
||||||
max-fee (money/to-fixed (money/wei-> :gwei maxFeePerGas))
|
max-fee (money/to-fixed (money/wei->gwei maxFeePerGas))
|
||||||
max-priority-fee (money/to-fixed (money/wei-> :gwei maxPriorityFeePerGas))
|
max-priority-fee (money/to-fixed (money/wei->gwei maxPriorityFeePerGas))
|
||||||
edit-fee (reduce (partial apply build-edit)
|
edit-fee (reduce (partial apply build-edit)
|
||||||
{}
|
{:selected-fee-option (get-in db [:signing/edit-fee :selected-fee-option])}
|
||||||
{:gas (money/to-fixed gas)
|
{:gas (money/to-fixed gas)
|
||||||
:gasPrice (money/to-fixed (money/wei-> :gwei gasPrice))
|
:gasPrice (money/to-fixed (money/wei->gwei gasPrice))
|
||||||
:maxFeePerGas max-fee
|
:maxFeePerGas max-fee
|
||||||
:maxPriorityFeePerGas max-priority-fee})]
|
:maxPriorityFeePerGas max-priority-fee})]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
|
@ -214,57 +276,100 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:signing/update-gas-price
|
:signing/update-gas-price
|
||||||
(fn [{:keys [success-event error-event network-id] :as params}]
|
(fn [{:keys [success-callback error-callback network-id] :as params}]
|
||||||
(eip1559/enabled?
|
(eip1559/enabled?
|
||||||
network-id
|
network-id
|
||||||
(fn []
|
(fn []
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "eth_getBlockByNumber"
|
{:method "eth_feeHistory"
|
||||||
:params ["latest" false]
|
:params [101 "latest" nil]
|
||||||
:on-success #(re-frame/dispatch [::header-fetched
|
:on-success #(re-frame/dispatch [::header-fetched
|
||||||
(assoc params :header %)])
|
(assoc params :fee-history %)])}))
|
||||||
:on-error #(re-frame/dispatch [error-event %])}))
|
|
||||||
(fn []
|
(fn []
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "eth_gasPrice"
|
{:method "eth_gasPrice"
|
||||||
:on-success #(re-frame/dispatch [success-event %])
|
:on-success #(success-callback %)
|
||||||
:on-error #(re-frame/dispatch [error-event %])})))))
|
:on-error #(error-callback %)})))))
|
||||||
|
|
||||||
(fx/defn header-fetched
|
|
||||||
{:events [::header-fetched]}
|
|
||||||
[_ {:keys [error-event] :as params}]
|
|
||||||
{::json-rpc/call
|
|
||||||
[{:method "eth_maxPriorityFeePerGas"
|
|
||||||
:on-success #(re-frame/dispatch [::max-priority-fee-per-gas-fetched
|
|
||||||
(assoc params :max-priority-fee %)])
|
|
||||||
:on-error (if error-event
|
|
||||||
#(re-frame/dispatch [error-event %])
|
|
||||||
#(log/error "Can't fetch header" %))}]})
|
|
||||||
|
|
||||||
(def london-block-gas-limit (money/bignumber 30000000))
|
(def london-block-gas-limit (money/bignumber 30000000))
|
||||||
|
|
||||||
(defn check-base-fee [{:keys [gasUsed baseFeePerGas]}]
|
(defn calc-percentiles [v ps]
|
||||||
{:base-fee baseFeePerGas
|
(let [sorted-v (sort-by
|
||||||
:spike? (or (money/greater-than-or-equals
|
identity
|
||||||
(money/bignumber 0)
|
(fn [a b]
|
||||||
(money/bignumber gasUsed))
|
(status-im.utils.money/greater-than b a))
|
||||||
(money/greater-than-or-equals
|
v)]
|
||||||
(money/bignumber gasUsed)
|
(reduce
|
||||||
(money/bignumber london-block-gas-limit)))})
|
(fn [acc p]
|
||||||
|
(assoc acc p (nth sorted-v p)))
|
||||||
|
{}
|
||||||
|
ps)))
|
||||||
|
|
||||||
(fx/defn max-priority-fee-per-gas-fetched
|
;; It is very unlikely to be that small on mainnet, but on testnets current base
|
||||||
{:events [::max-priority-fee-per-gas-fetched]}
|
;; fee might be very small and using this value might slow transaction
|
||||||
[_ {:keys [success-event header max-priority-fee]}]
|
(def minimum-base-fee (money/->wei :gwei (money/bignumber 1)))
|
||||||
(let [{:keys [base-fee spike?]} (check-base-fee header)]
|
|
||||||
{:dispatch [success-event {:base-fee base-fee
|
(defn recommended-base-fee [current perc20 perc80]
|
||||||
:max-priority-fee max-priority-fee
|
(let [fee
|
||||||
:spike? spike?}]}))
|
(cond (and (money/greater-than-or-equals current perc20)
|
||||||
|
(money/greater-than-or-equals perc80 current))
|
||||||
|
current
|
||||||
|
|
||||||
|
(money/greater-than perc20 current)
|
||||||
|
perc20
|
||||||
|
|
||||||
|
:else
|
||||||
|
perc80)]
|
||||||
|
(if (money/greater-than minimum-base-fee fee)
|
||||||
|
minimum-base-fee
|
||||||
|
fee)))
|
||||||
|
|
||||||
|
(defn slow-base-fee [_ perc10] perc10)
|
||||||
|
|
||||||
|
(defn fast-base-fee [current _]
|
||||||
|
(let [fee (money/mul current 2)]
|
||||||
|
(if (money/greater-than minimum-base-fee fee)
|
||||||
|
(money/mul minimum-base-fee 2)
|
||||||
|
fee)))
|
||||||
|
|
||||||
|
(defn check-base-fee [{:keys [baseFeePerGas]}]
|
||||||
|
(let [all-base-fees (mapv money/bignumber baseFeePerGas)
|
||||||
|
current-base-fee (last all-base-fees)
|
||||||
|
previous-fees (subvec all-base-fees 0 101)
|
||||||
|
percentiles (calc-percentiles previous-fees [10 20 80])]
|
||||||
|
{:normal-base-fee (money/to-hex
|
||||||
|
(recommended-base-fee
|
||||||
|
current-base-fee
|
||||||
|
(get percentiles 20)
|
||||||
|
(get percentiles 80)))
|
||||||
|
:slow-base-fee (money/to-hex
|
||||||
|
(slow-base-fee
|
||||||
|
current-base-fee
|
||||||
|
(get percentiles 10)))
|
||||||
|
:fast-base-fee (money/to-hex
|
||||||
|
(fast-base-fee
|
||||||
|
current-base-fee
|
||||||
|
(get percentiles 80)))
|
||||||
|
:current-base-fee (money/to-hex current-base-fee)}))
|
||||||
|
|
||||||
|
(fx/defn header-fetched
|
||||||
|
{:events [::header-fetched]}
|
||||||
|
[_ {:keys [error-callback success-callback fee-history] :as params}]
|
||||||
|
{::json-rpc/call
|
||||||
|
[{:method "eth_maxPriorityFeePerGas"
|
||||||
|
:on-success #(success-callback (merge {:max-priority-fee %}
|
||||||
|
(check-base-fee fee-history)))
|
||||||
|
:on-error (if error-callback
|
||||||
|
#(error-callback %)
|
||||||
|
#(log/error "Can't fetch header" %))}]})
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:signing/update-estimated-gas
|
:signing/update-estimated-gas
|
||||||
(fn [{:keys [obj success-event error-event]}]
|
(fn [{:keys [obj success-event error-event]}]
|
||||||
|
(if (nil? (:data obj))
|
||||||
|
(re-frame/dispatch [success-event (money/bignumber 21000)])
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "eth_estimateGas"
|
{:method "eth_estimateGas"
|
||||||
:params [obj]
|
:params [obj]
|
||||||
:on-success #(re-frame/dispatch [success-event %])
|
:on-success #(re-frame/dispatch [success-event %])
|
||||||
:on-error #(re-frame/dispatch [error-event %])})))
|
:on-error #(re-frame/dispatch [error-event %])}))))
|
||||||
|
|
|
@ -25,16 +25,26 @@
|
||||||
(status/hash-typed-data data on-completed))))
|
(status/hash-typed-data data on-completed))))
|
||||||
|
|
||||||
(defn prepare-transaction
|
(defn prepare-transaction
|
||||||
[{:keys [gas gasPrice data nonce tx-obj]}]
|
[{:keys [gas gasPrice data nonce tx-obj] :as params}]
|
||||||
(let [{:keys [from to value chat-id message-id command?]} tx-obj]
|
(let [{:keys [from to value chat-id message-id command? maxPriorityFeePerGas maxFeePerGas]} tx-obj
|
||||||
|
maxPriorityFeePerGas (or maxPriorityFeePerGas (get params :maxPriorityFeePerGas))
|
||||||
|
maxFeePerGas (or maxFeePerGas (get params :maxFeePerGas))]
|
||||||
(cond-> {:from from
|
(cond-> {:from from
|
||||||
:to to
|
:to to
|
||||||
:value value
|
:value value
|
||||||
:gas (str "0x" (abi-spec/number-to-hex gas))
|
|
||||||
:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))
|
|
||||||
:chat-id chat-id
|
:chat-id chat-id
|
||||||
:message-id message-id
|
:message-id message-id
|
||||||
:command? command?}
|
:command? command?}
|
||||||
|
maxPriorityFeePerGas
|
||||||
|
(assoc :maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex
|
||||||
|
(js/parseInt maxPriorityFeePerGas))))
|
||||||
|
maxFeePerGas
|
||||||
|
(assoc :maxFeePerGas (str "0x" (abi-spec/number-to-hex
|
||||||
|
(js/parseInt maxFeePerGas))))
|
||||||
|
gas
|
||||||
|
(assoc :gas (str "0x" (abi-spec/number-to-hex gas)))
|
||||||
|
gasPrice
|
||||||
|
(assoc :gasPrice (str "0x" (abi-spec/number-to-hex gasPrice)))
|
||||||
data
|
data
|
||||||
(assoc :data data)
|
(assoc :data data)
|
||||||
nonce
|
nonce
|
||||||
|
@ -93,7 +103,7 @@
|
||||||
(fx/defn sign-with-keycard
|
(fx/defn sign-with-keycard
|
||||||
{:events [:signing.ui/sign-with-keycard-pressed]}
|
{:events [:signing.ui/sign-with-keycard-pressed]}
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [message (get-in db [:signing/tx :message])]
|
(let [{:keys [message maxPriorityFeePerGas maxFeePerGas]} (get db :signing/tx)]
|
||||||
(fx/merge
|
(fx/merge
|
||||||
cofx
|
cofx
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
|
|
|
@ -165,8 +165,11 @@
|
||||||
(reg-root-key-sub :wallet/refreshing-history? :wallet/refreshing-history?)
|
(reg-root-key-sub :wallet/refreshing-history? :wallet/refreshing-history?)
|
||||||
(reg-root-key-sub :wallet/fetching-error :wallet/fetching-error)
|
(reg-root-key-sub :wallet/fetching-error :wallet/fetching-error)
|
||||||
(reg-root-key-sub :wallet/non-archival-node :wallet/non-archival-node)
|
(reg-root-key-sub :wallet/non-archival-node :wallet/non-archival-node)
|
||||||
(reg-root-key-sub :wallet/latest-base-fee :wallet/latest-base-fee)
|
(reg-root-key-sub :wallet/current-base-fee :wallet/current-base-fee)
|
||||||
(reg-root-key-sub :wallet/latest-priority-fee :wallet/latest-priority-fee)
|
(reg-root-key-sub :wallet/slow-base-fee :wallet/slow-base-fee)
|
||||||
|
(reg-root-key-sub :wallet/normal-base-fee :wallet/normal-base-fee)
|
||||||
|
(reg-root-key-sub :wallet/fast-base-fee :wallet/fast-base-fee)
|
||||||
|
(reg-root-key-sub :wallet/current-priority-fee :wallet/current-priority-fee)
|
||||||
(reg-root-key-sub :wallet/transactions-management-enabled? :wallet/transactions-management-enabled?)
|
(reg-root-key-sub :wallet/transactions-management-enabled? :wallet/transactions-management-enabled?)
|
||||||
;;commands
|
;;commands
|
||||||
(reg-root-key-sub :commands/select-account :commands/select-account)
|
(reg-root-key-sub :commands/select-account :commands/select-account)
|
||||||
|
@ -2005,7 +2008,7 @@
|
||||||
(re-frame/subscribe [:ethereum/native-currency])
|
(re-frame/subscribe [:ethereum/native-currency])
|
||||||
(re-frame/subscribe [:ethereum/chain-keyword])])
|
(re-frame/subscribe [:ethereum/chain-keyword])])
|
||||||
(fn [[transactions native-currency chain-keyword] [_ hash _]]
|
(fn [[transactions native-currency chain-keyword] [_ hash _]]
|
||||||
(let [{:keys [gas-used gas-price hash timestamp type]
|
(let [{:keys [gas-used gas-price fee-cap tip-cap hash timestamp type]
|
||||||
:as transaction}
|
:as transaction}
|
||||||
(get transactions hash)
|
(get transactions hash)
|
||||||
native-currency-text (name (or (:symbol-display native-currency)
|
native-currency-text (name (or (:symbol-display native-currency)
|
||||||
|
@ -2021,6 +2024,14 @@
|
||||||
(money/wei->str :gwei
|
(money/wei->str :gwei
|
||||||
gas-price)
|
gas-price)
|
||||||
"-")
|
"-")
|
||||||
|
:fee-cap-gwei (if fee-cap
|
||||||
|
(money/wei->str :gwei
|
||||||
|
fee-cap)
|
||||||
|
"-")
|
||||||
|
:tip-cap-gwei (if tip-cap
|
||||||
|
(money/wei->str :gwei
|
||||||
|
tip-cap)
|
||||||
|
"-")
|
||||||
:date (datetime/timestamp->long-date timestamp)}
|
:date (datetime/timestamp->long-date timestamp)}
|
||||||
(if (= type :unsigned)
|
(if (= type :unsigned)
|
||||||
{:block (i18n/label :not-applicable)
|
{:block (i18n/label :not-applicable)
|
||||||
|
@ -2587,14 +2598,22 @@
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:signing/priority-fee-suggestions-range
|
:signing/priority-fee-suggestions-range
|
||||||
:<- [:wallet/latest-priority-fee]
|
:<- [:wallet/current-priority-fee]
|
||||||
(fn [latest-fee]
|
:<- [:wallet/slow-base-fee]
|
||||||
[0 (->> latest-fee
|
:<- [:wallet/normal-base-fee]
|
||||||
money/bignumber
|
:<- [:wallet/fast-base-fee]
|
||||||
(money/wei-> :gwei)
|
(fn [[latest-tip slow normal fast]]
|
||||||
(money/mul (money/bignumber 2))
|
(reduce
|
||||||
money/to-fixed
|
(fn [acc [k fees]]
|
||||||
js/parseFloat)]))
|
(assoc acc k (reduce
|
||||||
|
(fn [acc [k fee]]
|
||||||
|
(assoc acc k (-> fee
|
||||||
|
money/wei->gwei
|
||||||
|
(money/to-fixed 2))))
|
||||||
|
{}
|
||||||
|
fees)))
|
||||||
|
{}
|
||||||
|
(signing.gas/get-fee-options latest-tip slow normal fast))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:signing/phrase
|
:signing/phrase
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
[quo.core :as quo]
|
[quo.core :as quo]
|
||||||
[quo.design-system.colors :as quo-colors]
|
[quo.design-system.colors :as quo-colors]
|
||||||
[status-im.ui.components.colors :as colors]
|
[status-im.ui.components.colors :as colors]
|
||||||
[status-im.ui.components.slider :as slider]
|
|
||||||
[status-im.utils.money :as money]
|
[status-im.utils.money :as money]
|
||||||
[status-im.ui.components.icons.icons :as icons]
|
[status-im.ui.components.icons.icons :as icons]
|
||||||
[clojure.string :as clojure.string]
|
[clojure.string :as clojure.string]
|
||||||
|
@ -69,12 +68,15 @@
|
||||||
|
|
||||||
(declare fee-bottom-sheet-eip1559)
|
(declare fee-bottom-sheet-eip1559)
|
||||||
|
|
||||||
(defn fee-bottom-sheet-eip1559-custom [fee-display-symbol]
|
(defn fee-bottom-sheet-eip1559-custom [_ #_fee-display-symbol]
|
||||||
(let [{gas-edit :gas
|
(let [{gas-edit :gas
|
||||||
max-fee-per-gas-edit :maxFeePerGas
|
max-fee-per-gas-edit :maxFeePerGas
|
||||||
max-priority-fee-per-gas-edit :maxPriorityFeePerGas}
|
max-priority-fee-per-gas-edit :maxPriorityFeePerGas}
|
||||||
@(re-frame/subscribe [:signing/edit-fee])
|
@(re-frame/subscribe [:signing/edit-fee])
|
||||||
base-fee @(re-frame/subscribe [:wallet/latest-base-fee])
|
error? (some :error [gas-edit
|
||||||
|
max-fee-per-gas-edit
|
||||||
|
max-priority-fee-per-gas-edit])
|
||||||
|
base-fee @(re-frame/subscribe [:wallet/current-base-fee])
|
||||||
[fee-currency fiat-currency price]
|
[fee-currency fiat-currency price]
|
||||||
@(re-frame/subscribe [:signing/currencies])
|
@(re-frame/subscribe [:signing/currencies])
|
||||||
fee-eth
|
fee-eth
|
||||||
|
@ -123,7 +125,7 @@
|
||||||
{:label (i18n/label :t/per-gas-tip-limit)
|
{:label (i18n/label :t/per-gas-tip-limit)
|
||||||
:error (or (:error max-priority-fee-per-gas-edit)
|
:error (or (:error max-priority-fee-per-gas-edit)
|
||||||
(get-in max-priority-fee-per-gas-edit [:fee-error :label]))
|
(get-in max-priority-fee-per-gas-edit [:fee-error :label]))
|
||||||
:default-value (:value max-priority-fee-per-gas-edit)
|
:default-value (str (:value max-priority-fee-per-gas-edit))
|
||||||
:on-change-text #(re-frame/dispatch [:signing.edit-fee.ui/edit-value :maxPriorityFeePerGas %])
|
:on-change-text #(re-frame/dispatch [:signing.edit-fee.ui/edit-value :maxPriorityFeePerGas %])
|
||||||
:show-cancel false
|
:show-cancel false
|
||||||
:after {:component [quo/text
|
:after {:component [quo/text
|
||||||
|
@ -137,7 +139,7 @@
|
||||||
{:label (i18n/label :t/per-gas-price-limit)
|
{:label (i18n/label :t/per-gas-price-limit)
|
||||||
:error (or (:error max-fee-per-gas-edit)
|
:error (or (:error max-fee-per-gas-edit)
|
||||||
(get-in max-fee-per-gas-edit [:fee-error :label]))
|
(get-in max-fee-per-gas-edit [:fee-error :label]))
|
||||||
:default-value (:value max-fee-per-gas-edit)
|
:default-value (str (:value max-fee-per-gas-edit))
|
||||||
:on-change-text #(re-frame/dispatch [:signing.edit-fee.ui/edit-value :maxFeePerGas %])
|
:on-change-text #(re-frame/dispatch [:signing.edit-fee.ui/edit-value :maxFeePerGas %])
|
||||||
:show-cancel false
|
:show-cancel false
|
||||||
:after {:component [quo/text
|
:after {:component [quo/text
|
||||||
|
@ -176,66 +178,75 @@
|
||||||
:justify-content :space-between}}
|
:justify-content :space-between}}
|
||||||
[quo/button
|
[quo/button
|
||||||
{:type :secondary
|
{:type :secondary
|
||||||
:on-press #(re-frame/dispatch
|
:accessibility-label :see-fee-suggestions
|
||||||
|
;;:on-press
|
||||||
|
#_(re-frame/dispatch
|
||||||
[:bottom-sheet/show-sheet
|
[:bottom-sheet/show-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
[fee-bottom-sheet-eip1559 fee-display-symbol])
|
[fee-bottom-sheet-eip1559 fee-display-symbol])
|
||||||
:content-height 270}])}
|
:content-height 270}])}
|
||||||
(i18n/label :t/see-suggestions)]
|
"" #_(i18n/label :t/see-suggestions)]
|
||||||
[quo/button
|
[quo/button
|
||||||
{:type :primary
|
{:type :primary
|
||||||
|
:disabled error?
|
||||||
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/submit])
|
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/submit])
|
||||||
:theme :accent}
|
:theme :accent}
|
||||||
(i18n/label :t/save)]]]))
|
(i18n/label :t/save)]]]))
|
||||||
|
|
||||||
(defn fee-bottom-sheet-eip1559 [fee-display-symbol]
|
(defn fee-bottom-sheet-eip1559 [fee-display-symbol]
|
||||||
(let [{priority-fee-edit :maxPriorityFeePerGas
|
(let [{priority-fee-edit :maxPriorityFeePerGas
|
||||||
fee-edit :maxFeePerGas
|
option :selected-fee-option
|
||||||
gas :gas}
|
fee-edit :maxFeePerGas}
|
||||||
@(re-frame/subscribe [:signing/edit-fee])
|
@(re-frame/subscribe [:signing/edit-fee])
|
||||||
[min-value max-value]
|
{:keys [normal fast slow]}
|
||||||
@(re-frame/subscribe [:signing/priority-fee-suggestions-range])
|
@(re-frame/subscribe [:signing/priority-fee-suggestions-range])]
|
||||||
[fee-currency fiat-currency price] @(re-frame/subscribe [:signing/currencies])
|
|
||||||
fee-eth
|
|
||||||
(if (and (:value-number gas)
|
|
||||||
(:value-number fee-edit))
|
|
||||||
(money/mul
|
|
||||||
(money/wei->ether
|
|
||||||
(money/->wei :gwei (:value-number fee-edit)))
|
|
||||||
(:value-number gas))
|
|
||||||
(money/bignumber 0))]
|
|
||||||
[react/view
|
[react/view
|
||||||
[react/view {:style {:margin-horizontal 16 :margin-top 8}}
|
[react/view {:style {:margin-horizontal 16 :margin-top 8}}
|
||||||
[react/text {:style {:typography :title-bold}} (i18n/label :t/max-priority-fee)]
|
[react/text {:style {:typography :title-bold}} (i18n/label :t/fee-options)]
|
||||||
[react/text {:style {:color (quo-colors/get-color :text-02)
|
[react/text {:style {:margin-top 12}
|
||||||
:margin-top 12}}
|
:accessibility-label :slow-fee
|
||||||
(i18n/label :t/miners-higher-fee)]
|
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/set-option :slow])}
|
||||||
[quo/text {:style {:margin-horizontal 8
|
|
||||||
:margin-top 24}
|
|
||||||
:size :large}
|
|
||||||
(clojure.string/join
|
(clojure.string/join
|
||||||
" "
|
" "
|
||||||
[(money/to-fixed fee-eth 6)
|
[(str (i18n/label :t/slow) ":")
|
||||||
fee-currency
|
(str (:base-fee slow) " gwei")
|
||||||
"•"
|
(str (:tip slow) " gwei")
|
||||||
(money/to-fixed (money/mul fee-eth (money/bignumber (or price 0))) 2)
|
(when (= :slow option)
|
||||||
fiat-currency])]
|
"<- selected")])]
|
||||||
[slider/animated-slider
|
[react/text {:style {:margin-top 12}
|
||||||
{:style {:margin-horizontal 5
|
:accessibility-label :normal-fee
|
||||||
:margin-vertical 4}
|
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/set-option :normal])}
|
||||||
:minimumValue min-value
|
(clojure.string/join
|
||||||
:value (js/parseFloat (:value priority-fee-edit))
|
" "
|
||||||
:onValueChange #(re-frame/dispatch [:signing.edit-fee.ui/set-priority-fee (str %)])
|
[(str (i18n/label :t/normal) ":")
|
||||||
:maximumValue max-value
|
(str (:base-fee normal) " gwei")
|
||||||
:minimumTrackTintColor (quo-colors/get-color :icon-04)}]
|
(str (:tip normal) " gwei")
|
||||||
[react/view
|
(when (or (nil? option)
|
||||||
{:style {:margin-horizontal 8
|
(= :normal option))
|
||||||
:flex-direction :row
|
"<- selected")])]
|
||||||
:align-items :center
|
[react/text {:style {:margin-top 12}
|
||||||
:justify-content :space-between}}
|
:accessibility-label :fast-fee
|
||||||
[react/text {:style {:color (quo-colors/get-color :text-02)}} (i18n/label :t/slow)]
|
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/set-option :fast])}
|
||||||
[react/text {:style {:color (quo-colors/get-color :text-02)}} (i18n/label :t/optimal)]
|
(clojure.string/join
|
||||||
[react/text {:style {:color (quo-colors/get-color :text-02)}} (i18n/label :t/fast)]]]
|
" "
|
||||||
|
[(str (i18n/label :t/fast) ":")
|
||||||
|
(str (:base-fee fast) " gwei")
|
||||||
|
(str (:tip fast) " gwei")
|
||||||
|
(when (= :fast option)
|
||||||
|
"<- selected")])]
|
||||||
|
(when (= :custom option)
|
||||||
|
[react/text {:style {:margin-top 12}}
|
||||||
|
(clojure.string/join
|
||||||
|
" "
|
||||||
|
[(str (i18n/label :t/custom) ":")
|
||||||
|
(str (-> fee-edit
|
||||||
|
:value-number
|
||||||
|
(money/to-fixed 2)) " gwei")
|
||||||
|
(str (-> priority-fee-edit
|
||||||
|
:value-number
|
||||||
|
(money/to-fixed 2)) " gwei")
|
||||||
|
(when (= :custom option)
|
||||||
|
"<- selected")])])]
|
||||||
[react/view
|
[react/view
|
||||||
{:style {:margin-left 12
|
{:style {:margin-left 12
|
||||||
:margin-right 16
|
:margin-right 16
|
||||||
|
@ -245,6 +256,7 @@
|
||||||
:justify-content :space-between}
|
:justify-content :space-between}
|
||||||
[quo/button
|
[quo/button
|
||||||
{:type :secondary
|
{:type :secondary
|
||||||
|
:accessibility-label :set-custom-fee
|
||||||
:on-press #(re-frame/dispatch
|
:on-press #(re-frame/dispatch
|
||||||
[:bottom-sheet/show-sheet
|
[:bottom-sheet/show-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
|
@ -253,17 +265,18 @@
|
||||||
(i18n/label :t/set-custom-fee)]
|
(i18n/label :t/set-custom-fee)]
|
||||||
[quo/button
|
[quo/button
|
||||||
{:type :primary
|
{:type :primary
|
||||||
|
:accessibility-label :save-custom-fee
|
||||||
:theme :accent
|
:theme :accent
|
||||||
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/submit])}
|
:on-press #(re-frame/dispatch [:signing.edit-fee.ui/submit])}
|
||||||
(i18n/label :t/save)]]]))
|
(i18n/label :t/save)]]]))
|
||||||
|
|
||||||
(defn gwei [val]
|
(defn gwei [val]
|
||||||
(str val " " (i18n/label :t/gwei)))
|
(str (money/to-fixed val 2) " " (i18n/label :t/gwei)))
|
||||||
|
|
||||||
(defn fees-warning []
|
(defn fees-warning []
|
||||||
(let [base-fee @(re-frame/subscribe [:wallet/latest-base-fee])
|
(let [base-fee @(re-frame/subscribe [:wallet/current-base-fee])
|
||||||
base-fee-gwei (money/wei-> :gwei (money/bignumber base-fee))
|
base-fee-gwei (money/wei-> :gwei (money/bignumber base-fee))
|
||||||
priority-fee @(re-frame/subscribe [:wallet/latest-priority-fee])
|
priority-fee @(re-frame/subscribe [:wallet/current-priority-fee])
|
||||||
priority-fee-gwei (money/wei-> :gwei (money/bignumber priority-fee))
|
priority-fee-gwei (money/wei-> :gwei (money/bignumber priority-fee))
|
||||||
{priority-fee-edit :maxPriorityFeePerGas
|
{priority-fee-edit :maxPriorityFeePerGas
|
||||||
fee-edit :maxFeePerGas}
|
fee-edit :maxFeePerGas}
|
||||||
|
@ -293,14 +306,16 @@
|
||||||
:justify-content :space-between
|
:justify-content :space-between
|
||||||
:margin-horizontal 32}}
|
:margin-horizontal 32}}
|
||||||
[react/text (i18n/label :t/current-base-fee)]
|
[react/text (i18n/label :t/current-base-fee)]
|
||||||
[react/text (gwei (money/to-fixed base-fee-gwei 2))]]
|
[react/text (gwei base-fee-gwei)]]
|
||||||
[react/view
|
[react/view
|
||||||
{:style {:flex-direction :row
|
{:style {:flex-direction :row
|
||||||
:justify-content :space-between
|
:justify-content :space-between
|
||||||
:margin-horizontal 32}}
|
:margin-horizontal 32}}
|
||||||
[react/text (i18n/label :t/current-minimum-tip)]
|
[react/text (i18n/label :t/current-minimum-tip)]
|
||||||
[react/text (gwei gas/minimum-priority-fee)]]
|
[react/text (gwei (gas/get-minimum-priority-fee priority-fee))]]
|
||||||
[react/view
|
;;TODO(rasom): we can uncomment it once it will be clear which value can be
|
||||||
|
;;used as "average" here
|
||||||
|
#_[react/view
|
||||||
{:style {:flex-direction :row
|
{:style {:flex-direction :row
|
||||||
:justify-content :space-between
|
:justify-content :space-between
|
||||||
:margin-horizontal 32}}
|
:margin-horizontal 32}}
|
||||||
|
@ -317,7 +332,7 @@
|
||||||
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
||||||
(i18n/label :t/your-tip-limit)]
|
(i18n/label :t/your-tip-limit)]
|
||||||
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
||||||
(gwei (money/to-fixed (:value-number priority-fee-edit) 2))]]
|
(gwei (:value-number priority-fee-edit))]]
|
||||||
[react/view
|
[react/view
|
||||||
{:style {:flex-direction :row
|
{:style {:flex-direction :row
|
||||||
:justify-content :space-between
|
:justify-content :space-between
|
||||||
|
@ -325,7 +340,7 @@
|
||||||
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
||||||
(i18n/label :t/your-price-limit)]
|
(i18n/label :t/your-price-limit)]
|
||||||
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
[react/text {:style {:color (quo-colors/get-color :negative-01)}}
|
||||||
(gwei (money/to-fixed (:value-number fee-edit) 2))]]
|
(gwei (:value-number fee-edit))]]
|
||||||
[react/view {:style
|
[react/view {:style
|
||||||
{:background-color colors/gray-lighter
|
{:background-color colors/gray-lighter
|
||||||
:padding-horizontal 32
|
:padding-horizontal 32
|
||||||
|
@ -335,12 +350,12 @@
|
||||||
{:style {:flex-direction :row
|
{:style {:flex-direction :row
|
||||||
:justify-content :space-between}}
|
:justify-content :space-between}}
|
||||||
[react/text (i18n/label :t/suggested-min-tip)]
|
[react/text (i18n/label :t/suggested-min-tip)]
|
||||||
[react/text (gwei gas/minimum-priority-fee)]]
|
[react/text (gwei priority-fee-gwei)]]
|
||||||
[react/view
|
[react/view
|
||||||
{:style {:flex-direction :row
|
{:style {:flex-direction :row
|
||||||
:justify-content :space-between}}
|
:justify-content :space-between}}
|
||||||
[react/text (i18n/label :t/suggested-price-limit)]
|
[react/text (i18n/label :t/suggested-price-limit)]
|
||||||
[react/text (gwei (money/to-fixed (money/add base-fee-gwei priority-fee-gwei) 2))]]]
|
[react/text (gwei (money/add base-fee-gwei priority-fee-gwei))]]]
|
||||||
[react/view
|
[react/view
|
||||||
{:style {:align-items :center
|
{:style {:align-items :center
|
||||||
:justify-content :center
|
:justify-content :center
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
[status-im.ui.screens.keycard.pin.views :as pin.views]
|
[status-im.ui.screens.keycard.pin.views :as pin.views]
|
||||||
[status-im.ui.components.bottom-panel.views :as bottom-panel]
|
[status-im.ui.components.bottom-panel.views :as bottom-panel]
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]))
|
||||||
[status-im.signing.eip1559 :as eip1559]))
|
|
||||||
|
|
||||||
(defn separator []
|
(defn separator []
|
||||||
[react/view {:height 1 :background-color colors/gray-lighter}])
|
[react/view {:height 1 :background-color colors/gray-lighter}])
|
||||||
|
@ -383,6 +382,11 @@
|
||||||
(i18n/format-currency converted-fee-value (:code wallet-currency))])
|
(i18n/format-currency converted-fee-value (:code wallet-currency))])
|
||||||
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]))
|
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]))
|
||||||
:on-press #(re-frame/dispatch
|
:on-press #(re-frame/dispatch
|
||||||
|
[:signing.ui/open-fee-sheet
|
||||||
|
{:content (fn []
|
||||||
|
[sheets/fee-bottom-sheet-eip1559-custom fee-display-symbol])
|
||||||
|
:content-height 270}])
|
||||||
|
#_(re-frame/dispatch
|
||||||
[:signing.ui/open-fee-sheet
|
[:signing.ui/open-fee-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
(if (eip1559/sync-enabled?)
|
(if (eip1559/sync-enabled?)
|
||||||
|
|
|
@ -243,6 +243,7 @@
|
||||||
from from-wallet from-contact
|
from from-wallet from-contact
|
||||||
to to-wallet to-contact
|
to to-wallet to-contact
|
||||||
gas-limit gas-price-gwei gas-price-eth gas-used
|
gas-limit gas-price-gwei gas-price-eth gas-used
|
||||||
|
fee-cap-gwei tip-cap-gwei
|
||||||
cost nonce data]}]
|
cost nonce data]}]
|
||||||
[react/view {:style styles/details-block}
|
[react/view {:style styles/details-block}
|
||||||
[details-list-row :t/block block]
|
[details-list-row :t/block block]
|
||||||
|
@ -261,6 +262,8 @@
|
||||||
to])]
|
to])]
|
||||||
[details-list-row :t/gas-limit [{:monospace true} gas-limit]]
|
[details-list-row :t/gas-limit [{:monospace true} gas-limit]]
|
||||||
[details-list-row :t/gas-price gas-price-gwei [{:monospace false} gas-price-eth]]
|
[details-list-row :t/gas-price gas-price-gwei [{:monospace false} gas-price-eth]]
|
||||||
|
[details-list-row :t/fee-cap fee-cap-gwei]
|
||||||
|
[details-list-row :t/tip-cap tip-cap-gwei]
|
||||||
[details-list-row :t/gas-used gas-used]
|
[details-list-row :t/gas-used gas-used]
|
||||||
[details-list-row :t/cost-fee [{:monospace false} cost]]
|
[details-list-row :t/cost-fee [{:monospace false} cost]]
|
||||||
[details-list-row :t/nonce nonce]
|
[details-list-row :t/nonce nonce]
|
||||||
|
|
|
@ -39,10 +39,10 @@
|
||||||
|
|
||||||
(defn greater-than
|
(defn greater-than
|
||||||
[bn1 bn2]
|
[bn1 bn2]
|
||||||
(.greaterThan bn1 bn2))
|
(.greaterThan ^js bn1 bn2))
|
||||||
|
|
||||||
(defn sub [bn1 bn2]
|
(defn sub [bn1 bn2]
|
||||||
(.sub bn1 bn2))
|
(.sub ^js bn1 bn2))
|
||||||
|
|
||||||
(defn valid? [^js bn]
|
(defn valid? [^js bn]
|
||||||
(when bn
|
(when bn
|
||||||
|
@ -103,6 +103,9 @@
|
||||||
(defn wei->ether [n]
|
(defn wei->ether [n]
|
||||||
(wei-> :eth n))
|
(wei-> :eth n))
|
||||||
|
|
||||||
|
(defn wei->gwei [n]
|
||||||
|
(wei-> :gwei n))
|
||||||
|
|
||||||
(defn ether->wei [^js bn]
|
(defn ether->wei [^js bn]
|
||||||
(when bn
|
(when bn
|
||||||
(.times bn ^js (bignumber 1e18))))
|
(.times bn ^js (bignumber 1e18))))
|
||||||
|
@ -171,7 +174,16 @@
|
||||||
str))
|
str))
|
||||||
|
|
||||||
(defn add [bn1 n2]
|
(defn add [bn1 n2]
|
||||||
(.add bn1 n2))
|
(.add ^js bn1 n2))
|
||||||
|
|
||||||
(defn mul [bn1 bn2]
|
(defn mul [bn1 bn2]
|
||||||
(.mul bn1 bn2))
|
(.mul ^js bn1 bn2))
|
||||||
|
|
||||||
|
(defn mul-and-round [bn1 bn2]
|
||||||
|
(.round (.mul ^js bn1 bn2) 0))
|
||||||
|
|
||||||
|
(defn div [bn1 bn2]
|
||||||
|
(.dividedBy ^js bn1 bn2))
|
||||||
|
|
||||||
|
(defn div-and-round [bn1 bn2]
|
||||||
|
(.round (.dividedBy ^js bn1 bn2) 0))
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
[status-im.async-storage.core :as async-storage]
|
[status-im.async-storage.core :as async-storage]
|
||||||
[status-im.popover.core :as popover.core]
|
[status-im.popover.core :as popover.core]
|
||||||
[status-im.signing.eip1559 :as eip1559]
|
[status-im.signing.eip1559 :as eip1559]
|
||||||
|
[status-im.signing.gas :as signing.gas]
|
||||||
[clojure.set :as clojure.set]))
|
[clojure.set :as clojure.set]))
|
||||||
|
|
||||||
(defn get-balance
|
(defn get-balance
|
||||||
|
@ -380,23 +381,40 @@
|
||||||
|
|
||||||
(fx/defn wallet-send-gas-price-success
|
(fx/defn wallet-send-gas-price-success
|
||||||
{:events [:wallet.send/update-gas-price-success]}
|
{:events [:wallet.send/update-gas-price-success]}
|
||||||
[{db :db} price]
|
[{db :db} tx-entry price]
|
||||||
(if (eip1559/sync-enabled?)
|
(if (eip1559/sync-enabled?)
|
||||||
(let [{:keys [base-fee max-priority-fee]} price
|
(let [{:keys [slow-base-fee normal-base-fee fast-base-fee
|
||||||
max-priority-fee-bn (money/bignumber max-priority-fee)]
|
current-base-fee max-priority-fee]}
|
||||||
|
price
|
||||||
|
max-priority-fee-bn (money/with-precision
|
||||||
|
(signing.gas/get-suggested-tip max-priority-fee)
|
||||||
|
0)
|
||||||
|
fee-cap (-> normal-base-fee
|
||||||
|
money/bignumber
|
||||||
|
(money/add max-priority-fee-bn)
|
||||||
|
money/to-hex)
|
||||||
|
tip-cap (money/to-hex max-priority-fee-bn)]
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(update :wallet/prepare-transaction assoc
|
(update tx-entry assoc
|
||||||
:maxFeePerGas (money/to-hex (money/add max-priority-fee-bn base-fee))
|
:maxFeePerGas fee-cap
|
||||||
:maxPriorityFeePerGas max-priority-fee)
|
:maxPriorityFeePerGas tip-cap)
|
||||||
(assoc :wallet/latest-base-fee base-fee
|
(assoc :wallet/current-base-fee current-base-fee
|
||||||
:wallet/latest-priority-fee max-priority-fee))})
|
:wallet/normal-base-fee normal-base-fee
|
||||||
{:db (assoc-in db [:wallet/prepare-transaction :gasPrice] price)}))
|
:wallet/slow-base-fee slow-base-fee
|
||||||
|
:wallet/fast-base-fee fast-base-fee
|
||||||
|
:wallet/current-priority-fee max-priority-fee)
|
||||||
|
(assoc-in [:signing/edit-fee :gas-price-loading?] false))})
|
||||||
|
{:db (-> db
|
||||||
|
(assoc-in [:wallet/prepare-transaction :gasPrice] price)
|
||||||
|
(assoc-in [:signing/edit-fee :gas-price-loading?] false))}))
|
||||||
|
|
||||||
(fx/defn set-max-amount
|
(fx/defn set-max-amount
|
||||||
{:events [:wallet.send/set-max-amount]}
|
{:events [:wallet.send/set-max-amount]}
|
||||||
[{:keys [db]} {:keys [amount decimals symbol]}]
|
[{:keys [db]} {:keys [amount decimals symbol]}]
|
||||||
(let [^js gas (money/bignumber 21000)
|
(let [^js gas (money/bignumber 21000)
|
||||||
^js gasPrice (get-in db [:wallet/prepare-transaction :gasPrice])
|
^js gasPrice (or
|
||||||
|
(get-in db [:wallet/prepare-transaction :maxFeePerGas])
|
||||||
|
(get-in db [:wallet/prepare-transaction :gasPrice]))
|
||||||
^js fee (when gasPrice (.times gas gasPrice))
|
^js fee (when gasPrice (.times gas gasPrice))
|
||||||
amount-text (if (= :ETH symbol)
|
amount-text (if (= :ETH symbol)
|
||||||
(when (and fee (money/sufficient-funds? fee amount))
|
(when (and fee (money/sufficient-funds? fee amount))
|
||||||
|
@ -478,7 +496,9 @@
|
||||||
{:events [::recipient-address-resolved]}
|
{:events [::recipient-address-resolved]}
|
||||||
[{:keys [db]} address]
|
[{:keys [db]} address]
|
||||||
{:db (assoc-in db [:wallet/prepare-transaction :to :address] address)
|
{:db (assoc-in db [:wallet/prepare-transaction :to :address] address)
|
||||||
:signing/update-gas-price {:success-event :wallet.send/update-gas-price-success
|
:signing/update-gas-price {:success-callback
|
||||||
|
#(re-frame/dispatch
|
||||||
|
[:wallet.send/update-gas-price-success :wallet/prepare-transaction %])
|
||||||
:network-id (get-in (ethereum/current-network db)
|
:network-id (get-in (ethereum/current-network db)
|
||||||
[:config :NetworkId])}})
|
[:config :NetworkId])}})
|
||||||
|
|
||||||
|
@ -533,7 +553,9 @@
|
||||||
:symbol :ETH
|
:symbol :ETH
|
||||||
:from-chat? false})
|
:from-chat? false})
|
||||||
:dispatch [:open-modal :prepare-send-transaction]
|
:dispatch [:open-modal :prepare-send-transaction]
|
||||||
:signing/update-gas-price {:success-event :wallet.send/update-gas-price-success
|
:signing/update-gas-price {:success-callback
|
||||||
|
#(re-frame/dispatch
|
||||||
|
[:wallet.send/update-gas-price-success :wallet/prepare-transaction %])
|
||||||
:network-id (get-in (ethereum/current-network db)
|
:network-id (get-in (ethereum/current-network db)
|
||||||
[:config :NetworkId])}})
|
[:config :NetworkId])}})
|
||||||
|
|
||||||
|
|
|
@ -1648,5 +1648,9 @@
|
||||||
"category": "Category",
|
"category": "Category",
|
||||||
"edit-chats": "Edit chats",
|
"edit-chats": "Edit chats",
|
||||||
"hide": "Hide",
|
"hide": "Hide",
|
||||||
"account-is-used": "The account is being used with Dapps in the browser."
|
"account-is-used": "The account is being used with Dapps in the browser.",
|
||||||
|
"normal": "Normal",
|
||||||
|
"fee-options": "Suggested fee options",
|
||||||
|
"fee-cap": "Fee cap",
|
||||||
|
"tip-cap": "Tip cap"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue