[#7139] Fix crash on logout

The crash was caused by RPC calls which happened after `StopNode` call.

Implementation:
- The first suggestion was to `StopNode` only after all `.stopWatching`
  calls are done, but this only lowered probability of the crash,
  but did not fix the issue.
- Another suggestion was to prevent RPC calls after `StopNode` call,
  but it also only lowered probability of the crash.
- So the last resort was a fix on `status-go` side
  https://github.com/status-im/status-go/pull/1329,
  and it actually worked.
- Advanced settings are hidden until `Statusgo.Login` is finished
This commit is contained in:
Roman Volosovskyi 2018-12-19 14:20:03 +02:00
parent b81cb82fc6
commit dd2ff11216
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
7 changed files with 39 additions and 17 deletions

View File

@ -1 +1 @@
0.17.9-beta
0.17.10-beta.1

View File

@ -13,10 +13,16 @@
{:keychain/clear-user-password (get-in db [:account/account :address])
:dev-server/stop nil}
(transactions/stop-sync)
(transport/stop-whisper)
(init/initialize-app-db)
(init/load-accounts-and-initialize-views)
(node/stop)))
(transport/stop-whisper
#(re-frame/dispatch [:accounts.logout/filters-removed]))))
(fx/defn leave-account
[cofx]
(fx/merge
cofx
(init/initialize-app-db)
(init/load-accounts-and-initialize-views)
(node/stop)))
(fx/defn show-logout-confirmation [_]
{:ui/show-confirmation

View File

@ -286,15 +286,19 @@
(handlers/register-handler-fx
:accounts.logout.ui/logout-confirmed
[(re-frame/inject-cofx :data-store/get-all-accounts)]
(fn [cofx _]
(accounts.logout/logout cofx)))
(handlers/register-handler-fx
:accounts.logout/filters-removed
[(re-frame/inject-cofx :data-store/get-all-accounts)]
(fn [cofx]
(accounts.logout/leave-account cofx)))
;; accounts update module
(handlers/register-handler-fx
:accounts.update.callback/save-settings-success
[(re-frame/inject-cofx :data-store/get-all-accounts)]
(fn [cofx _]
(accounts.logout/logout cofx)))

View File

@ -6,10 +6,14 @@
(defn start-node [config]
(native-module/start-node config))
(def node-started (atom false))
(defn node-ready []
(reset! node-started true)
(native-module/node-ready))
(defn stop-node []
(reset! node-started false)
(native-module/stop-node))
(defn create-account [password callback]
@ -31,10 +35,12 @@
(native-module/clear-web-data))
(defn call-rpc [payload callback]
(native-module/call-rpc payload callback))
(when @node-started
(native-module/call-rpc payload callback)))
(defn call-private-rpc [payload callback]
(native-module/call-private-rpc payload callback))
(when @node-started
(native-module/call-private-rpc payload callback)))
(defn sign-message [rpcParams callback]
(native-module/sign-message rpcParams callback))

View File

@ -68,6 +68,6 @@
It is necessary to remove the filters because status-go there isn't currently a logout feature in status-go
to clean-up after logout. When logging out of account A and logging in account B, account B would receive
account A messages without this."
[{:keys [db]}]
[{:keys [db]} callback]
(let [{:transport/keys [filters]} db]
{:shh/remove-filters filters}))
{:shh/remove-filters [filters callback]}))

View File

@ -7,12 +7,14 @@
[status-im.utils.handlers :as handlers]
[taoensso.timbre :as log]))
(defn remove-filter! [{:keys [chat-id filter]}]
(defn remove-filter! [{:keys [chat-id filter success-callback?]
:or {success-callback? true}}]
(.stopWatching filter
(fn [error _]
(if error
(log/warn :remove-filter-error filter error)
(re-frame/dispatch [:shh.callback/filter-removed chat-id]))))
(when success-callback?
(re-frame/dispatch [:shh.callback/filter-removed chat-id])))))
(log/debug :stop-watching filter))
(defn add-filter!
@ -72,7 +74,10 @@
(re-frame/reg-fx
:shh/remove-filters
(fn [filters]
(fn [[filters callback]]
(doseq [[chat-id filter] filters]
(when filter (remove-filter! {:chat-id chat-id
:filter filter})))))
(when filter (remove-filter!
{:chat-id chat-id
:filter filter
:success-callback false})))
(callback)))

View File

@ -255,4 +255,5 @@
(i18n/label :t/share-my-profile)]]
[react/view styles/my-profile-info-container
[my-profile-settings current-account shown-account currency (nil? login-data)]]
[advanced shown-account on-show-advanced]]])))
(when (nil? login-data)
[advanced shown-account on-show-advanced])]])))