Skip to content

Commit e847a58

Browse files
[#22234] feat: add tx params settings for swap (#22327)
1 parent e42194e commit e847a58

File tree

19 files changed

+303
-283
lines changed

19 files changed

+303
-283
lines changed

src/status_im/contexts/wallet/send/transaction_settings/core.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.core
1+
(ns status-im.contexts.wallet.common.transaction-settings.core
22
(:require
33
[status-im.constants :as constants]))
44

src/status_im/contexts/wallet/send/transaction_settings/gas_amount/view.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/gas_amount/view.cljs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.gas-amount.view
1+
(ns status-im.contexts.wallet.common.transaction-settings.gas-amount.view
22
(:require
33
[quo.context]
4-
[status-im.contexts.wallet.send.transaction-settings.view :as transaction-settings]
4+
[status-im.contexts.wallet.common.transaction-settings.view :as transaction-settings]
55
[utils.i18n :as i18n]
66
[utils.re-frame :as rf]))
77

@@ -32,8 +32,8 @@
3232
[]
3333
(let [spectrum {:low 21000
3434
:high 7920027}
35-
gas-amount (rf/sub [:wallet.send/tx-settings-gas-amount])
36-
suggested-gas-amount (rf/sub [:wallet.send/tx-settings-suggested-tx-gas-amount])
35+
gas-amount (rf/sub [:wallet/tx-settings-gas-amount])
36+
suggested-gas-amount (rf/sub [:wallet/tx-settings-suggested-tx-gas-amount])
3737
conditions (partial hint-and-status suggested-gas-amount spectrum)]
3838
[transaction-settings/custom-setting-screen
3939
{:screen-title (i18n/label :t/max-gas-amount)
@@ -43,7 +43,7 @@
4343
:info-title (i18n/label :t/gas-amount)
4444
:info-content (i18n/label :t/about-gas-amount)
4545
:on-save (fn [new-val]
46-
(rf/dispatch [:wallet.send/set-max-gas-amount new-val])
46+
(rf/dispatch [:wallet/set-max-gas-amount new-val])
4747
(rf/dispatch [:navigate-back])
4848
(rf/dispatch [:show-bottom-sheet
4949
{:content transaction-settings/custom-settings-sheet}]))

src/status_im/contexts/wallet/send/transaction_settings/max_fee/view.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/max_fee/view.cljs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.max-fee.view
1+
(ns status-im.contexts.wallet.common.transaction-settings.max-fee.view
22
(:require
33
[quo.context]
4-
[status-im.contexts.wallet.send.transaction-settings.view :as transaction-settings]
4+
[status-im.contexts.wallet.common.transaction-settings.view :as transaction-settings]
55
[utils.i18n :as i18n]
66
[utils.re-frame :as rf]))
77

@@ -27,9 +27,9 @@
2727

2828
(defn view
2929
[]
30-
(let [network-base-fee (rf/sub [:wallet.send/tx-settings-network-base-fee-route])
31-
max-base-fee (rf/sub [:wallet.send/tx-settings-max-base-fee])
32-
priority-fee (rf/sub [:wallet.send/tx-settings-priority-fee])
30+
(let [network-base-fee (rf/sub [:wallet/tx-settings-network-base-fee-route])
31+
max-base-fee (rf/sub [:wallet/tx-settings-max-base-fee])
32+
priority-fee (rf/sub [:wallet/tx-settings-priority-fee])
3333
conditions (partial hint-and-status network-base-fee priority-fee)]
3434
[transaction-settings/custom-setting-screen
3535
{:screen-title (i18n/label :t/max-base-fee)
@@ -39,7 +39,7 @@
3939
:info-title (i18n/label :t/max-base-fee)
4040
:info-content (i18n/label :t/about-max-base-fee)
4141
:on-save (fn [new-val]
42-
(rf/dispatch [:wallet.send/set-max-base-fee new-val])
42+
(rf/dispatch [:wallet/set-max-base-fee new-val])
4343
(rf/dispatch [:navigate-back])
4444
(rf/dispatch [:show-bottom-sheet
4545
{:content transaction-settings/custom-settings-sheet}]))}]))

src/status_im/contexts/wallet/send/transaction_settings/nonce/view.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/nonce/view.cljs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.nonce.view
1+
(ns status-im.contexts.wallet.common.transaction-settings.nonce.view
22
(:require
33
[quo.core :as quo]
44
[quo.foundations.colors :as colors]
55
[react-native.core :as rn]
66
[react-native.safe-area :as safe-area]
77
[status-im.common.controlled-input.utils :as controlled-input]
8-
[status-im.contexts.wallet.send.transaction-settings.view :as transaction-settings]
8+
[status-im.contexts.wallet.common.transaction-settings.view :as transaction-settings]
99
[utils.i18n :as i18n]
1010
[utils.re-frame :as rf]))
1111

1212
(defn view
1313
[]
14-
(let [current (rf/sub [:wallet.send/tx-settings-nonce])
15-
suggested-nonce (rf/sub [:wallet.send/tx-settings-suggested-nonce])
14+
(let [current (rf/sub [:wallet/tx-settings-nonce])
15+
suggested-nonce (rf/sub [:wallet/tx-settings-suggested-nonce])
1616
last-tx-nonce (dec suggested-nonce)
1717
[input-state set-input-state] (rn/use-state (controlled-input/set-value-numeric
1818
controlled-input/init-state
@@ -64,7 +64,7 @@
6464
:button-one-label (i18n/label :t/save-changes)
6565
:button-one-props {:disabled? (controlled-input/empty-value? input-state)
6666
:on-press (fn []
67-
(rf/dispatch [:wallet.send/set-nonce
67+
(rf/dispatch [:wallet/set-nonce
6868
(controlled-input/value-numeric input-state)])
6969
(rf/dispatch [:navigate-back])
7070
(rf/dispatch [:show-bottom-sheet

src/status_im/contexts/wallet/send/transaction_settings/priority_fee/view.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/priority_fee/view.cljs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.priority-fee.view
1+
(ns status-im.contexts.wallet.common.transaction-settings.priority-fee.view
22
(:require
33
[quo.context]
4-
[status-im.contexts.wallet.send.transaction-settings.view :as transaction-settings]
4+
[status-im.contexts.wallet.common.transaction-settings.view :as transaction-settings]
55
[utils.i18n :as i18n]
66
[utils.re-frame :as rf]))
77

@@ -25,10 +25,10 @@
2525

2626
(defn view
2727
[]
28-
(let [priority-fee (rf/sub [:wallet.send/tx-settings-priority-fee])
29-
max-base-fee (rf/sub [:wallet.send/tx-settings-max-base-fee])
30-
spectrum {:low (rf/sub [:wallet.send/tx-settings-suggested-min-priority-fee])
31-
:high (rf/sub [:wallet.send/tx-settings-suggested-max-priority-fee])}
28+
(let [priority-fee (rf/sub [:wallet/tx-settings-priority-fee])
29+
max-base-fee (rf/sub [:wallet/tx-settings-max-base-fee])
30+
spectrum {:low (rf/sub [:wallet/tx-settings-suggested-min-priority-fee])
31+
:high (rf/sub [:wallet/tx-settings-suggested-max-priority-fee])}
3232
conditions (partial hint-and-status priority-fee spectrum max-base-fee)]
3333
[transaction-settings/custom-setting-screen
3434
{:screen-title (i18n/label :t/priority-fee)
@@ -38,7 +38,7 @@
3838
:info-title (i18n/label :t/priority-fee)
3939
:info-content (i18n/label :t/about-priority-fee)
4040
:on-save (fn [new-val]
41-
(rf/dispatch [:wallet.send/set-priority-fee new-val])
41+
(rf/dispatch [:wallet/set-priority-fee new-val])
4242
(rf/dispatch [:navigate-back])
4343
(rf/dispatch [:show-bottom-sheet
4444
{:content transaction-settings/custom-settings-sheet}]))}]))

src/status_im/contexts/wallet/send/transaction_settings/view.cljs renamed to src/status_im/contexts/wallet/common/transaction_settings/view.cljs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns status-im.contexts.wallet.send.transaction-settings.view
1+
(ns status-im.contexts.wallet.common.transaction-settings.view
22
(:require
33
[quo.core :as quo]
44
[react-native.core :as rn]
@@ -11,11 +11,12 @@
1111

1212
(defn custom-settings-sheet
1313
[_]
14-
(let [max-base-fee (rf/sub [:wallet.send/tx-settings-max-base-fee])
15-
priority-fee (rf/sub [:wallet.send/tx-settings-priority-fee])
16-
max-gas-amount (rf/sub [:wallet.send/tx-settings-gas-amount])
17-
nonce (rf/sub [:wallet.send/tx-settings-nonce])
18-
account-color (rf/sub [:wallet/current-viewing-account-color])]
14+
(let [max-base-fee (rf/sub [:wallet/tx-settings-max-base-fee])
15+
priority-fee (rf/sub [:wallet/tx-settings-priority-fee])
16+
max-gas-amount (rf/sub [:wallet/tx-settings-gas-amount])
17+
nonce (rf/sub [:wallet/tx-settings-nonce])
18+
account-color (rf/sub [:wallet/current-viewing-account-color])
19+
current-screen (rf/sub [:view-id])]
1920
[rn/view
2021
[quo/drawer-top
2122
{:title (i18n/label :t/custom)}]
@@ -28,7 +29,7 @@
2829
:action :arrow
2930
:on-press #(rf/dispatch [:navigate-to-within-stack
3031
[:screen/wallet.tx-settings-max-fee
31-
:screen/wallet.transaction-confirmation]])
32+
current-screen]])
3233
:label :text
3334
:preview-size :size-32}
3435
{:title (i18n/label :t/priority-fee)
@@ -38,7 +39,7 @@
3839
:action :arrow
3940
:on-press #(rf/dispatch [:navigate-to-within-stack
4041
[:screen/wallet.tx-settings-priority-fee
41-
:screen/wallet.transaction-confirmation]])
42+
current-screen]])
4243
:label :text
4344
:preview-size :size-32}
4445
{:title (i18n/label :t/max-gas-amount)
@@ -48,7 +49,7 @@
4849
:action :arrow
4950
:on-press #(rf/dispatch [:navigate-to-within-stack
5051
[:screen/wallet.tx-settings-gas-amount
51-
:screen/wallet.transaction-confirmation]])
52+
current-screen]])
5253
:label :text
5354
:preview-size :size-32}
5455
{:title (i18n/label :t/nonce)
@@ -58,14 +59,14 @@
5859
:action :arrow
5960
:on-press #(rf/dispatch [:navigate-to-within-stack
6061
[:screen/wallet.tx-settings-nonce
61-
:screen/wallet.transaction-confirmation]])
62+
current-screen]])
6263
:label :text
6364
:preview-size :size-32}]}]
6465
[quo/bottom-actions
6566
{:actions :one-action
6667
:button-one-props {:on-press (fn []
6768
(rf/dispatch
68-
[:wallet.send/custom-transaction-settings-confirmed])
69+
[:wallet/custom-transaction-settings-confirmed])
6970
(rf/dispatch [:hide-bottom-sheet]))
7071
:customization-color account-color}
7172
:button-one-label (i18n/label :t/confirm)}]]))
@@ -94,7 +95,7 @@
9495

9596
(defn settings-sheet
9697
[]
97-
(let [current-transaction-setting (rf/sub [:wallet.send/tx-settings-fee-mode])
98+
(let [current-transaction-setting (rf/sub [:wallet/tx-settings-fee-mode])
9899
fees-by-mode (rf/sub [:wallet/suggested-gas-fees-for-setting])
99100
account-color (rf/sub [:wallet/current-viewing-account-color])
100101
[transaction-setting set-transaction-setting] (rn/use-state current-transaction-setting)
@@ -117,7 +118,7 @@
117118
:data
118119
[{:title (title :tx-fee-mode/normal)
119120
:image-props "🍿"
120-
:description-props {:text (rf/sub [:wallet/wallet-send-transaction-setting-fiat-formatted
121+
:description-props {:text (rf/sub [:wallet/wallet-transaction-setting-fiat-formatted
121122
:tx-fee-mode/normal])}
122123
:image :emoji
123124
:description :text
@@ -137,7 +138,7 @@
137138
:preview-size :size-32}
138139
{:title (title :tx-fee-mode/fast)
139140
:image-props "🚗"
140-
:description-props {:text (rf/sub [:wallet/wallet-send-transaction-setting-fiat-formatted
141+
:description-props {:text (rf/sub [:wallet/wallet-transaction-setting-fiat-formatted
141142
:tx-fee-mode/fast])}
142143
:image :emoji
143144
:description :text
@@ -151,7 +152,7 @@
151152
:preview-size :size-32}
152153
{:title (title :tx-fee-mode/urgent)
153154
:image-props "🚀"
154-
:description-props {:text (rf/sub [:wallet/wallet-send-transaction-setting-fiat-formatted
155+
:description-props {:text (rf/sub [:wallet/wallet-transaction-setting-fiat-formatted
155156
:tx-fee-mode/urgent])}
156157
:image :emoji
157158
:description :text
@@ -179,7 +180,7 @@
179180
[quo/bottom-actions
180181
{:actions :one-action
181182
:button-one-props {:on-press (fn []
182-
(rf/dispatch [:wallet.send/quick-fee-mode-confirmed
183+
(rf/dispatch [:wallet/quick-fee-mode-confirmed
183184
transaction-setting])
184185
(rf/dispatch [:hide-bottom-sheet]))
185186
:customization-color account-color}

src/status_im/contexts/wallet/data_store.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@
223223
:bonder-fees (to-bignumber :tx-bonder-fees)
224224
:token-fees (to-bignumber :tx-token-fees)
225225
:from (:from-chain new-path)
226-
:amount-in-locked (:amount-in-locked new-path)
227226
:amount-in (:amount-in new-path)
228227
:bridge-name (:processor-name new-path)
229228
:amount-out (:amount-out new-path)

src/status_im/contexts/wallet/events.cljs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111
[status-im.contexts.settings.wallet.effects]
1212
[status-im.contexts.settings.wallet.events]
1313
[status-im.contexts.wallet.common.activity-tab.events]
14+
[status-im.contexts.wallet.common.transaction-settings.core :as transaction-settings]
1415
[status-im.contexts.wallet.common.utils :as utils]
1516
[status-im.contexts.wallet.data-store :as data-store]
1617
[status-im.contexts.wallet.db :as db]
1718
[status-im.contexts.wallet.db-path :as db-path]
1819
[status-im.contexts.wallet.item-types :as item-types]
1920
[status-im.contexts.wallet.networks.db :as networks.db]
2021
status-im.contexts.wallet.networks.events
22+
[status-im.contexts.wallet.send.utils :as send-utils]
2123
[status-im.contexts.wallet.sheets.network-selection.view :as network-selection]
2224
[status-im.contexts.wallet.tokens.events]
2325
[status-im.feature-flags :as ff]
@@ -784,3 +786,94 @@
784786
{:db (assoc-in db [:wallet :ui :show-new-chain-indicator?] false)
785787
:fx [[:effects.wallet/set-base-chain-indicator-shown true]]}))
786788

789+
(rf/reg-event-fx
790+
:wallet/set-max-base-fee
791+
(fn [{db :db} [value]]
792+
{:db (assoc-in db [:wallet :ui :user-tx-settings :max-base-fee] value)}))
793+
794+
(rf/reg-event-fx
795+
:wallet/set-priority-fee
796+
(fn [{db :db} [value]]
797+
{:db (assoc-in db [:wallet :ui :user-tx-settings :priority-fee] value)}))
798+
799+
(rf/reg-event-fx
800+
:wallet/set-max-gas-amount
801+
(fn [{db :db} [value]]
802+
{:db (assoc-in db [:wallet :ui :user-tx-settings :gas-amount] value)}))
803+
804+
(rf/reg-event-fx
805+
:wallet/set-nonce
806+
(fn [{db :db} [value]]
807+
{:db (assoc-in db [:wallet :ui :user-tx-settings :nonce] value)}))
808+
809+
(defn set-fee-mode-effect
810+
[path-tx-identity gas-rate]
811+
(let [params [path-tx-identity gas-rate]]
812+
[:json-rpc/call
813+
[{:method "wallet_setFeeMode"
814+
:params params
815+
:on-error (fn [error]
816+
(log/error "failed to set quick transaction settings"
817+
{:event :wallet/quick-fee-mode-confirmed
818+
:error (:message error)
819+
:params params}))}]]))
820+
821+
(rf/reg-event-fx :wallet/quick-fee-mode-confirmed
822+
(fn [{db :db} [fee-mode]]
823+
(let [gas-rate (transaction-settings/tx-fee-mode->gas-rate fee-mode)
824+
tx-type (get-in db [:wallet :ui :send :tx-type])
825+
route (if tx-type
826+
(first (get-in db [:wallet :ui :send :route]))
827+
(get-in db [:wallet :ui :swap :swap-proposal]))
828+
;; bridge consist from 2 transactions - approval and send, so we need to apply
829+
;; setting to both of them by making 2 calls
830+
set-fee-effects (if (= tx-type :tx/bridge)
831+
[(set-fee-mode-effect (send-utils/path-identity route true) gas-rate)
832+
(set-fee-mode-effect (send-utils/path-identity route false) gas-rate)]
833+
[(set-fee-mode-effect (send-utils/path-identity route) gas-rate)])]
834+
{:db (assoc-in db [:wallet :ui :user-fee-mode] fee-mode)
835+
:fx (conj set-fee-effects
836+
[:dispatch [:wallet/mark-user-tx-settings-for-deletion]])})))
837+
838+
(defn set-custom-tx-effect
839+
[path-tx-identity custom-tx-params]
840+
(let [params [path-tx-identity custom-tx-params]]
841+
[:json-rpc/call
842+
[{:method "wallet_setCustomTxDetails"
843+
:params params
844+
:on-error (fn [error]
845+
(log/error "failed to set custom tx settings"
846+
{:event :wallet/custom-transaction-settings-confirmed
847+
:error (:message error)
848+
:params params}))}]]))
849+
850+
(rf/reg-event-fx :wallet/custom-transaction-settings-confirmed
851+
(fn [{db :db}]
852+
(let [tx-type (get-in db [:wallet :ui :send :tx-type])
853+
route (if tx-type
854+
(first (get-in db [:wallet :ui :send :route]))
855+
(get-in db [:wallet :ui :swap :swap-proposal]))
856+
user-tx-settings (get-in db [:wallet :ui :user-tx-settings])
857+
custom-tx-params (send-utils/path-tx-custom-params user-tx-settings route)
858+
;; bridge consist from 2 transactions - approval and send, so we need to apply
859+
;; setting to both of them by making 2 calls
860+
custom-tx-details-effects (if (= tx-type :tx/bridge)
861+
[(set-custom-tx-effect (send-utils/path-identity route true)
862+
custom-tx-params)
863+
(set-custom-tx-effect (send-utils/path-identity route false)
864+
custom-tx-params)]
865+
[(set-custom-tx-effect (send-utils/path-identity route)
866+
custom-tx-params)])]
867+
{:db (assoc-in db [:wallet :ui :user-fee-mode] :tx-fee-mode/custom)
868+
:fx (conj custom-tx-details-effects
869+
[:dispatch [:wallet/mark-user-tx-settings-for-deletion]])})))
870+
871+
;; There is a delay between the moment when user selected
872+
;; custom settings and the moment when new route arrived
873+
;; with those settings applied. During this delay
874+
;; we should keep user settings for ui. After new route
875+
;; arrived we should clean the settings.
876+
(rf/reg-event-fx :wallet/mark-user-tx-settings-for-deletion
877+
(fn [{db :db}]
878+
{:db (assoc-in db [:wallet :ui :user-tx-settings :delete-on-routes-update?] true)}))
879+

src/status_im/contexts/wallet/router/core.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(ns status-im.contexts.wallet.router.core
22
(:require [schema.core :as schema]
33
[status-im.constants :as constants]
4+
[status-im.contexts.wallet.common.transaction-settings.core :as transaction-settings]
45
[status-im.contexts.wallet.router.schema :as router.schema]
5-
[status-im.contexts.wallet.send.transaction-settings.core :as transaction-settings]
66
[utils.money :as money]))
77

88
(defn- to-gwei

src/status_im/contexts/wallet/router/schema.cljs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
;; Amounts
4343
[:amount-in :schema.common/hex]
4444
[:amount-out :schema.common/hex]
45-
[:amount-in-locked :boolean]
4645
[:required-native-balance nat-int?]
4746
[:required-token-balance nat-int?]
4847

0 commit comments

Comments
 (0)