diff --git a/src/status_im/accounts/update/core.cljs b/src/status_im/accounts/update/core.cljs index d7c1e38555..c583899d20 100644 --- a/src/status_im/accounts/update/core.cljs +++ b/src/status_im/accounts/update/core.cljs @@ -6,18 +6,16 @@ (defn account-update "Takes effects (containing :db) + new account fields, adds all effects necessary for account update. - Optionally, one can specify event to be dispatched after fields are persisted." + Optionally, one can specify a success-event to be dispatched after fields are persisted." ([new-account-fields cofx] (account-update new-account-fields nil cofx)) - ([new-account-fields after-update-event {:keys [db] :as cofx}] + ([new-account-fields success-event {:keys [db] :as cofx}] (let [current-account (:account/account db) new-account (merge current-account new-account-fields) fcm-token (get-in db [:notifications :fcm-token]) fx {:db (assoc db :account/account new-account) - :data-store/base-tx [(accounts-store/save-account-tx - (assoc new-account - :after-update-event - after-update-event))]} + :data-store/base-tx [{:transaction (accounts-store/save-account-tx new-account) + :success-event success-event}]} {:keys [name photo-path address]} new-account] (if (or (:name new-account-fields) (:photo-path new-account-fields)) (handlers-macro/merge-fx diff --git a/src/status_im/bootnodes/core.cljs b/src/status_im/bootnodes/core.cljs index bf3f690f8b..33e4e0904a 100644 --- a/src/status_im/bootnodes/core.cljs +++ b/src/status_im/bootnodes/core.cljs @@ -6,7 +6,7 @@ [status-im.ui.screens.navigation :as navigation] [status-im.utils.handlers-macro :as handlers-macro])) -(def address-regex #"enode://[a-zA-Z0-9]+\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})") +(def address-regex #"enode://[a-zA-Z0-9]+:?(.*)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})") (defn valid-address? [address] (re-matches address-regex address)) @@ -51,7 +51,8 @@ (defn delete [id {{:account/keys [account] :as db} :db :as cofx}] (let [network (:network db) new-account (update-in account [:bootnodes network] dissoc id)] - (handlers-macro/merge-fx {:db (assoc db :account/account new-account)} + (handlers-macro/merge-fx cofx + {:db (assoc db :account/account new-account)} (accounts.update/account-update (select-keys new-account [:bootnodes]) (when (custom-bootnodes-in-use? cofx) diff --git a/src/status_im/data_store/accounts.cljs b/src/status_im/data_store/accounts.cljs index 4b17f38d8c..1a2fb2939a 100644 --- a/src/status_im/data_store/accounts.cljs +++ b/src/status_im/data_store/accounts.cljs @@ -50,10 +50,6 @@ (defn save-account-tx "Returns tx function for saving account" - [{:keys [after-update-event] :as account}] + [account] (fn [realm] - (let [account-to-save (-> (serialize-account account) - (dissoc :after-update-event))] - (core/create realm :account account-to-save true) - (when after-update-event - (re-frame/dispatch after-update-event))))) + (core/create realm :account (serialize-account account) true))) diff --git a/src/status_im/network/core.cljs b/src/status_im/network/core.cljs index 85c87c609b..2073c3d09b 100644 --- a/src/status_im/network/core.cljs +++ b/src/status_im/network/core.cljs @@ -72,16 +72,22 @@ (save cofx nil)) ([{{:network/keys [manage] :account/keys [account] :as db} :db :as cofx} - {:keys [data on-success on-failure]}] - (let [data (or data manage)] + {:keys [data success-event on-success on-failure]}] + (let [data (or data manage)] (if (valid-manage? data) (let [{:keys [name url chain network-id]} data - network (new-network (:random-id cofx) (:value name) (:value url) (:value chain) (:value network-id)) + network (new-network (:random-id cofx) + (:value name) + (:value url) + (:value chain) + (:value network-id)) new-networks (merge {(:id network) network} (:networks account))] (handlers-macro/merge-fx cofx {:db (dissoc db :networks/manage)} (action-handler on-success (:id network)) - (accounts.update/account-update {:networks new-networks}))) + (accounts.update/account-update + {:networks new-networks} + success-event))) (action-handler on-failure))))) ;; No edit functionality actually implemented @@ -95,10 +101,12 @@ (if (ethereum/network-with-upstream-rpc? current-network) (handlers-macro/merge-fx cofx (action-handler on-success network) - (accounts.update/account-update {:network network - :last-updated now} - [:accounts.update.callback/save-settings-success])) - (handlers-macro/merge-fx {:ui/show-confirmation {:title (i18n/label :t/close-app-title) + (accounts.update/account-update + {:network network + :last-updated now} + [:accounts.update.callback/save-settings-success])) + (handlers-macro/merge-fx cofx + {:ui/show-confirmation {:title (i18n/label :t/close-app-title) :content (i18n/label :t/close-app-content) :confirm-button-text (i18n/label :t/close-app-button) :on-accept #(re-frame/dispatch [:network.ui/save-non-rpc-network-pressed network]) @@ -106,13 +114,15 @@ (action-handler on-success network)))) (action-handler on-failure))) -(defn delete [{{:account/keys [account]} :db} {:keys [network on-success on-failure]}] +(defn delete [{{:account/keys [account]} :db :as cofx} {:keys [network on-success on-failure]}] (let [current-network? (= (:network account) network)] (if (or current-network? (not (get-in account [:networks network]))) - (handlers-macro/merge-fx {:ui/show-error (i18n/label :t/delete-network-error)} + (handlers-macro/merge-fx cofx + {:ui/show-error (i18n/label :t/delete-network-error)} (action-handler on-failure network)) - (handlers-macro/merge-fx {:ui/show-confirmation {:title (i18n/label :t/delete-network-title) + (handlers-macro/merge-fx cofx + {:ui/show-confirmation {:title (i18n/label :t/delete-network-title) :content (i18n/label :t/delete-network-confirmation) :confirm-button-text (i18n/label :t/delete) :on-accept #(re-frame/dispatch [:network.ui/remove-network-confirmed network]) @@ -122,24 +132,25 @@ (defn save-non-rpc-network [network {:keys [db now] :as cofx}] (handlers-macro/merge-fx cofx - (accounts.update/account-update {:network network - :last-updated now} - [:network.callback/non-rpc-network-saved]))) + (accounts.update/account-update + {:network network + :last-updated now} + [:network.callback/non-rpc-network-saved]))) (defn remove-network [network {:keys [db now] :as cofx}] (let [networks (dissoc (get-in db [:account/account :networks]) network)] (handlers-macro/merge-fx cofx - {:dispatch [:navigate-back]} - (accounts.update-update {:networks networks - :last-updated now})))) + (accounts.update/account-update + {:networks networks + :last-updated now} + [:navigate-back])))) (defn save-network [cofx] (save cofx - {:data (get-in cofx [:db :network/manage]) - :on-success (fn [] - {:dispatch [:navigate-back]})})) + {:data (get-in cofx [:db :networks/manage]) + :success-event [:navigate-back]})) (defn handle-connection-status-change [is-connected? {:keys [db] :as cofx}] diff --git a/src/status_im/protocol/core.cljs b/src/status_im/protocol/core.cljs index 8d4eded515..9d7381c5e1 100644 --- a/src/status_im/protocol/core.cljs +++ b/src/status_im/protocol/core.cljs @@ -72,4 +72,4 @@ (utils/show-popup "Ethereum node started incorrectly" "Ethereum node was started with incorrect configuration, application will be stopped to recover from that condition." - #(re-frame/dispatch [:close-application])))))))) + #(re-frame/dispatch [:protocol.ui/close-app-confirmed])))))))) diff --git a/test/cljs/status_im/test/screens/accounts/utils.cljs b/test/cljs/status_im/test/screens/accounts/utils.cljs index ee00d95863..5f768b7bd3 100644 --- a/test/cljs/status_im/test/screens/accounts/utils.cljs +++ b/test/cljs/status_im/test/screens/accounts/utils.cljs @@ -5,9 +5,9 @@ (deftest test-account-update (is (= (accounts.update/account-update {} nil) {:db {:account/account {}}, - :data-store/save-account {:after-update-event nil}}))) + :data-store/save-account {}}))) (deftest test-clean-seed-phrase (is (= (accounts.update/clean-seed-phrase nil) {:db {:account/account {:seed-backed-up? true, :mnemonic nil}}, - :data-store/save-account {:seed-backed-up? true, :mnemonic nil, :after-update-event nil}}))) + :data-store/save-account {:seed-backed-up? true, :mnemonic nil}})))