[#12666] Allow overriding nonce when sending transaction

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-10-04 12:44:41 +02:00
parent fe1cc2dc23
commit de373d0511
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
4 changed files with 47 additions and 3 deletions

View File

@ -93,7 +93,7 @@
{:events [:signing.ui/sign-is-pressed]}
[{{:signing/keys [sign tx] :as db} :db :as cofx}]
(let [{:keys [in-progress? password]} sign
{:keys [tx-obj gas gasPrice maxPriorityFeePerGas maxFeePerGas message]} tx
{:keys [tx-obj gas gasPrice maxPriorityFeePerGas maxFeePerGas message nonce]} tx
hashed-password (ethereum/sha3 (security/safe-unmask-data password))]
(if message
(sign-message cofx)
@ -102,6 +102,8 @@
{:gas (str "0x" (abi-spec/number-to-hex gas))})
(when gasPrice
{:gasPrice (str "0x" (abi-spec/number-to-hex gasPrice))})
(when nonce
{:nonce (str "0x" (abi-spec/number-to-hex nonce))})
(when maxPriorityFeePerGas
{:maxPriorityFeePerGas (str "0x" (abi-spec/number-to-hex
(js/parseInt maxPriorityFeePerGas)))})

View File

@ -275,6 +275,13 @@
:maxPriorityFeePerGas (money/->wei :gwei (:value-number maxPriorityFeePerGas)))}
(bottom-sheet/hide-bottom-sheet)))))
(fx/defn submit-nonce
{:events [:signing.nonce/submit]}
[{db :db :as cofx} nonce]
(fx/merge cofx
{:db (assoc-in db [:signing/tx :nonce] nonce)}
(bottom-sheet/hide-bottom-sheet)))
(re-frame/reg-fx
:signing/update-gas-price
(fn [{:keys [success-callback error-callback network-id] :as params}]

View File

@ -8,7 +8,8 @@
[status-im.utils.money :as money]
[status-im.ui.components.icons.icons :as icons]
[clojure.string :as clojure.string]
[status-im.signing.gas :as gas]))
[status-im.signing.gas :as gas]
[reagent.core :as reagent]))
(views/defview fee-bottom-sheet [fee-display-symbol]
(views/letsubs [{gas-edit :gas gas-price-edit :gasPrice max-fee :max-fee} [:signing/edit-fee]]
@ -377,3 +378,25 @@
:on-press #(do (re-frame/dispatch [:hide-popover])
(re-frame/dispatch [:signing.edit-fee.ui/submit true]))}
(i18n/label :t/continue-anyway)]]]))
(defn advanced []
(let [nonce (reagent/atom nil)
default-nonce (:nonce @(re-frame/subscribe [:signing/tx]))]
(fn []
[react/view {:padding 20}
[quo/text-input
{:label (i18n/label :t/nonce)
:accessibility-label :nonce
:keyboard-type :numeric
:default-value default-nonce
:on-change-text #(reset! nonce %)
:show-cancel false
:container-style {:margin-bottom 20}}]
[react/view {:align-items :flex-end}
[quo/button
{:type :primary
:accessibility-label :save-nonce
:theme :accent
:disabled (clojure.string/blank? @nonce)
:on-press #(re-frame/dispatch [:signing.nonce/submit @nonce])}
(i18n/label :t/save)]]])))

View File

@ -402,6 +402,15 @@
:accessory :text
:accessory-text network-name}]))
(defn advanced-item []
[:<>
[separator]
[quo/list-item
{:size :small
:title (i18n/label :t/advanced)
:chevron true
:on-press #(re-frame/dispatch [:bottom-sheet/show-sheet {:content sheets/advanced}])}]])
(views/defview sheet
[{:keys [from contact amount token cancel?] :as tx}]
(views/letsubs [fee [:signing/fee]
@ -413,7 +422,8 @@
prices [:prices]
wallet-currency [:wallet/currency]
mainnet? [:mainnet?]
prices-loading? [:prices-loading?]]
prices-loading? [:prices-loading?]
management-enabled? [:wallet/transactions-management-enabled?]]
(let [display-symbol (wallet.utils/display-symbol token)
fee-display-symbol (wallet.utils/display-symbol (tokens/native-currency chain))]
[react/view (styles/sheet)
@ -438,6 +448,8 @@
[amount-item prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?])
[separator]
[fee-item prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?]
(when management-enabled?
[advanced-item])
(when (= :gas-is-set gas-error-state)
[react/text {:style {:color colors/gray :margin-horizontal 32 :text-align :center}}
(i18n/label :t/tx-fail-description1)])