|
11 | 11 | [status-im.contexts.settings.wallet.effects] |
12 | 12 | [status-im.contexts.settings.wallet.events] |
13 | 13 | [status-im.contexts.wallet.common.activity-tab.events] |
| 14 | + [status-im.contexts.wallet.common.transaction-settings.core :as transaction-settings] |
14 | 15 | [status-im.contexts.wallet.common.utils :as utils] |
15 | 16 | [status-im.contexts.wallet.data-store :as data-store] |
16 | 17 | [status-im.contexts.wallet.db :as db] |
17 | 18 | [status-im.contexts.wallet.db-path :as db-path] |
18 | 19 | [status-im.contexts.wallet.item-types :as item-types] |
19 | 20 | [status-im.contexts.wallet.networks.db :as networks.db] |
20 | 21 | status-im.contexts.wallet.networks.events |
| 22 | + [status-im.contexts.wallet.send.utils :as send-utils] |
21 | 23 | [status-im.contexts.wallet.sheets.network-selection.view :as network-selection] |
22 | 24 | [status-im.contexts.wallet.tokens.events] |
23 | 25 | [status-im.feature-flags :as ff] |
|
784 | 786 | {:db (assoc-in db [:wallet :ui :show-new-chain-indicator?] false) |
785 | 787 | :fx [[:effects.wallet/set-base-chain-indicator-shown true]]})) |
786 | 788 |
|
| 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 | + |
0 commit comments