From cc95913dc188e161fb9230c62649c82aa67ecdfc Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 2 Aug 2021 13:56:00 +0200 Subject: [PATCH] [Fixes: #12393] Allow to enable transaction management Signed-off-by: Andrea Maria Piana --- src/status_im/multiaccounts/login/core.cljs | 13 +++++++ src/status_im/subs.cljs | 1 + .../ui/screens/advanced_settings/views.cljs | 38 ++++++++++++------- .../ui/screens/wallet/transactions/views.cljs | 22 ++++++----- src/status_im/wallet/core.cljs | 6 +++ translations/en.json | 1 + 6 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index 74c23ac1b4..0ce0bbbbfb 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -49,6 +49,14 @@ :communities-enabled? callback))))) +(re-frame/reg-fx + ::initialize-transactions-management-enabled + (fn [] + (let [callback #(re-frame/dispatch [:multiaccounts.ui/switch-transactions-management-enabled %])] + (async-storage/get-item + :transactions-management-enabled? + callback)))) + (re-frame/reg-fx ::login (fn [[key-uid account-data hashed-password]] @@ -253,6 +261,10 @@ [cofx] {::initialize-communities-enabled nil}) +(fx/defn initialize-transactions-management-enabled + [cofx] + {::initialize-transactions-management-enabled nil}) + (fx/defn get-node-config-callback {:events [::get-node-config-callback]} [{:keys [db] :as cofx} node-config] @@ -292,6 +304,7 @@ (initialize-appearance) (transport/start-messenger) (initialize-communities-enabled) + (initialize-transactions-management-enabled) (check-network-version network-id) (chat.loading/initialize-chats) (get-node-config) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 23645bb492..941a2b9f94 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -167,6 +167,7 @@ (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/latest-priority-fee :wallet/latest-priority-fee) +(reg-root-key-sub :wallet/transactions-management-enabled? :wallet/transactions-management-enabled?) ;;commands (reg-root-key-sub :commands/select-account :commands/select-account) diff --git a/src/status_im/ui/screens/advanced_settings/views.cljs b/src/status_im/ui/screens/advanced_settings/views.cljs index 875cfe284a..b25bc0d768 100644 --- a/src/status_im/ui/screens/advanced_settings/views.cljs +++ b/src/status_im/ui/screens/advanced_settings/views.cljs @@ -11,6 +11,7 @@ current-log-level waku-bloom-filter-mode communities-enabled? + transactions-management-enabled? current-fleet webview-debug]}] (keep @@ -78,6 +79,15 @@ [:multiaccounts.ui/switch-communities-enabled (not communities-enabled?)]) :accessory :switch :active communities-enabled?}) + {:size :small + :title (i18n/label :t/transactions-management-enabled) + :accessibility-label :transactions-management-enabled + :container-margin-bottom 8 + :on-press + #(re-frame/dispatch + [:multiaccounts.ui/switch-transactions-management-enabled (not transactions-management-enabled?)]) + :accessory :switch + :active transactions-management-enabled?} {:size :small :title "Webview debug" :accessibility-label :webview-debug-switch @@ -106,20 +116,22 @@ [quo/list-item props])) (views/defview advanced-settings [] - (views/letsubs [{:keys [webview-debug]} [:multiaccount] - network-name [:network-name] - waku-bloom-filter-mode [:waku/bloom-filter-mode] - communities-enabled? [:communities/enabled?] - current-log-level [:log-level/current-log-level] - current-fleet [:fleets/current-fleet]] + (views/letsubs [{:keys [webview-debug]} [:multiaccount] + network-name [:network-name] + waku-bloom-filter-mode [:waku/bloom-filter-mode] + communities-enabled? [:communities/enabled?] + transactions-management-enabled? [:wallet/transactions-management-enabled?] + current-log-level [:log-level/current-log-level] + current-fleet [:fleets/current-fleet]] [list/flat-list {:data (flat-list-data - {:network-name network-name - :current-log-level current-log-level - :communities-enabled? communities-enabled? - :current-fleet current-fleet - :dev-mode? false - :waku-bloom-filter-mode waku-bloom-filter-mode - :webview-debug webview-debug}) + {:network-name network-name + :current-log-level current-log-level + :communities-enabled? communities-enabled? + :transactions-management-enabled? transactions-management-enabled? + :current-fleet current-fleet + :dev-mode? false + :waku-bloom-filter-mode waku-bloom-filter-mode + :webview-debug webview-debug}) :key-fn (fn [_ i] (str i)) :render-fn render-item}])) diff --git a/src/status_im/ui/screens/wallet/transactions/views.cljs b/src/status_im/ui/screens/wallet/transactions/views.cljs index 261f70fa34..36a429d552 100644 --- a/src/status_im/ui/screens/wallet/transactions/views.cljs +++ b/src/status_im/ui/screens/wallet/transactions/views.cljs @@ -38,7 +38,7 @@ [{:keys [label contact address contact-accessibility-label address-accessibility-label currency-text amount-text time-formatted on-touch-fn type hash]} - _ _ {:keys [keycard-account?]}] + _ _ {:keys [keycard-account? transactions-management-enabled?]}] [react/view [list/touchable-item on-touch-fn [react/view {:accessibility-label :transaction-item} @@ -75,7 +75,7 @@ :style {:margin-top 10} :icon-opts (merge styles/forward {:accessibility-label :show-transaction-button})}]]]] - (when (and false ;;TODO temporary disable for 1.10 + (when (and transactions-management-enabled? (not keycard-account?) (= type :pending)) [react/view {:flex-direction :row :padding 16 :justify-content :space-between} @@ -132,13 +132,14 @@ (defn history-list [{:keys [transaction-history-sections total]} address] - (let [fetching-recent-history? @(re-frame/subscribe [:wallet/fetching-recent-tx-history? address]) - fetching-more-history? @(re-frame/subscribe [:wallet/fetching-tx-history? address]) - keycard-account? @(re-frame/subscribe [:multiaccounts/keycard-account?]) - custom-rpc-node? @(re-frame/subscribe [:custom-rpc-node]) - non-archival-rpc-node? @(re-frame/subscribe [:wallet/non-archival-node]) - all-fetched? @(re-frame/subscribe [:wallet/tx-history-fetched? address]) - syncing-allowed? @(re-frame/subscribe [:mobile-network/syncing-allowed?])] + (let [fetching-recent-history? @(re-frame/subscribe [:wallet/fetching-recent-tx-history? address]) + fetching-more-history? @(re-frame/subscribe [:wallet/fetching-tx-history? address]) + keycard-account? @(re-frame/subscribe [:multiaccounts/keycard-account?]) + transactions-management-enabled? @(re-frame/subscribe [:wallet/transactions-management-enabled?]) + custom-rpc-node? @(re-frame/subscribe [:custom-rpc-node]) + non-archival-rpc-node? @(re-frame/subscribe [:wallet/non-archival-node]) + all-fetched? @(re-frame/subscribe [:wallet/tx-history-fetched? address]) + syncing-allowed? @(re-frame/subscribe [:mobile-network/syncing-allowed?])] [react/view {:flex 1} [etherscan-link address] (cond non-archival-rpc-node? @@ -155,7 +156,8 @@ [list/section-list {:sections transaction-history-sections :key-fn :hash - :render-data {:keycard-account? keycard-account?} + :render-data {:keycard-account? keycard-account? + :transactions-management-enabled? transactions-management-enabled?} :render-fn render-transaction :empty-component [react/i18n-text {:style styles/empty-text diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index f6cc031d7d..a8c51f0ab1 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -962,3 +962,9 @@ {:method "wallet_deletePendingTransaction" :params [hash] :on-success #(log/info "[wallet] pending transaction deleted" hash)})))) + +(fx/defn switch-transactions-management-enabled + {:events [:multiaccounts.ui/switch-transactions-management-enabled]} + [{:keys [db]} enabled?] + {::async-storage/set! {:transactions-management-enabled? enabled?} + :db (assoc db :wallet/transactions-management-enabled? enabled?)}) diff --git a/translations/en.json b/translations/en.json index a0a1a03f17..eff5139fde 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1188,6 +1188,7 @@ "transaction": "Transaction", "transaction-data": "Transaction data", "transaction-declined": "Transaction declined", + "transactions-management-enabled": "Transaction management (alpha)", "transaction-description": "Consider it complete after 12 confirmations on the network.", "transaction-details": "Transaction details", "transaction-failed": "Transaction failed",