Skip to content

Commit

Permalink
make app usable
Browse files Browse the repository at this point in the history
  • Loading branch information
yenda committed Jul 5, 2019
1 parent afe4b2b commit f12e114
Show file tree
Hide file tree
Showing 29 changed files with 95 additions and 499 deletions.
2 changes: 0 additions & 2 deletions clj-rn.conf.edn
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"react-native/Libraries/vendor/emitter/EventEmitter"
"react-native-background-timer"
"react-native-fetch-polyfill"
"text-encoding"
"js-sha3"
"react-navigation"
"hi-base32"
Expand Down Expand Up @@ -79,7 +78,6 @@
"react-native-desktop-config"
"react-native-desktop-shortcuts"
"react-native-desktop-notification"
"text-encoding"
"js-sha3"
"web3-utils"
"react-navigation"
Expand Down
1 change: 0 additions & 1 deletion desktop_files/package.json.orig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
"rn-snoopy": "git+https://github.com/status-im/rn-snoopy.git#v2.0.2-status",
"status-conan": "git+https://github.com/status-im/status-conan.git#v1.0.0",
"string_decoder": "0.10.31",
"text-encoding": "^0.6.4",
"url": "0.10.3",
"web3": "git+https://github.com/status-im/web3.js.git#0.20.3-status.alpha.3",
"web3-utils": "1.0.0-beta.36",
Expand Down
1 change: 0 additions & 1 deletion externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ var TopLevel = {
"ReactNative" : function () {},
"readDir" : function () {},
"readFile" : function () {},
"realm" : function () {},
"recoverAccount" : function () {},
"reduce" : function () {},
"register" : function () {},
Expand Down
1 change: 0 additions & 1 deletion mobile_files/package.json.orig
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"react-native-webview-bridge": "git+https://github.com/status-im/react-native-webview-bridge.git#fix/classnames-colision",
"react-navigation": "3.11.0",
"rn-snoopy": "git+https://github.com/status-im/rn-snoopy.git#v2.0.2-status",
"text-encoding": "0.6.4",
"url": "0.10.3",
"web3": "git+https://github.com/status-im/web3.js.git#0.20.3-status.alpha.3",
"web3-utils": "1.0.0-beta.36"
Expand Down
11 changes: 3 additions & 8 deletions mobile_files/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2032,9 +2032,9 @@ [email protected]:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.164:
version "1.3.186"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.186.tgz#17d87e7661121724ea4c81c9960c3f26a5228c0c"
integrity sha512-lRyyEUDKenKv/EBVFgfDZDYTDdoAZhzuE+inMUP79+22NDPAA2Ox+f3AShILIjPoUIqRGwvPNbzFcyU8km8g4A==
version "1.3.187"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.187.tgz#fea64435f370892c0f27aded1bbdcb6f235c592b"
integrity sha512-XCEygaK7Fs35/RwS+67YbBWs/ydG+oUFPuy1wv558jC3Opd2DHwRyRqrCmhxpmPmCSVlZujYX4TOmOXuMz2GZA==

elliptic@^6.4.0:
version "6.5.0"
Expand Down Expand Up @@ -5813,11 +5813,6 @@ [email protected]:
os-tmpdir "^1.0.0"
rimraf "~2.2.6"

[email protected]:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"
integrity sha1-45mpgiV6J22uQou5KEXLcb3CbRk=

throat@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a"
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/accounts/create/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
:processing true})}
(add-account account)
(when login?
(accounts.login/user-login true))))))
(accounts.login/user-login))))))

(defn reset-account-creation [{db :db}]
{:db (update db :accounts/create assoc
Expand Down
160 changes: 21 additions & 139 deletions src/status_im/accounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[status-im.utils.handlers :as handlers]
[status-im.utils.keychain.core :as keychain]
[status-im.utils.platform :as platform]
[status-im.utils.security :as security]
[status-im.biometric-auth.core :as biometric-auth]
Expand Down Expand Up @@ -47,26 +46,19 @@
(defn login! [address password]
(status/login address password #(re-frame/dispatch [:accounts.login.callback/login-success %])))

(defn verify! [address password realm-error]
(status/verify address password
#(re-frame/dispatch
[:accounts.login.callback/verify-success % realm-error])))

(defn clear-web-data! []
(status/clear-web-data))

(defn change-account! [address
password
create-database-if-not-exist?
current-fleet]
;; No matter what is the keychain we use, as checks are done on decrypting base
(.. (keychain/safe-get-encryption-key)

(then #(js/Promise. (fn [resolve reject]
(if (contract-fleet? current-fleet)
(fetch-nodes current-fleet resolve reject)
(resolve)))))
(then (fn [nodes] (re-frame/dispatch [:init.callback/account-change-success address nodes])))
(.. (js/Promise. (fn [resolve reject]
(if (contract-fleet? current-fleet)
(fetch-nodes current-fleet resolve reject)
(resolve))))
(then (fn [nodes]
(re-frame/dispatch [:init.callback/account-change-success address nodes])))
(catch (fn [error]
(log/warn "Could not change account" error)
;; If all else fails we fallback to showing initial error
Expand Down Expand Up @@ -102,22 +94,20 @@
:accounts.login/clear-web-data nil
:data-store/change-account [address
password
false
(get-in db [:accounts/accounts address :settings :fleet])]})))

(fx/defn user-login
[{:keys [db] :as cofx} create-database?]
[{:keys [db] :as cofx}]
(let [{:keys [address password]} (accounts.model/credentials cofx)]
(fx/merge
cofx
{:db (-> db
(assoc-in [:accounts/login :processing] true)
(assoc :node/on-ready :login))
:accounts.login/clear-web-data nil
:data-store/change-account [address
password
create-database?
(get-in db [:accounts/accounts address :settings :fleet])]})))
(fx/merge cofx
{:db
(-> db
(assoc-in [:accounts/login :processing] true)
(assoc :node/on-ready :login))
:accounts.login/clear-web-data nil
:data-store/change-account
[address password
(get-in db [:accounts/accounts address :settings :fleet])]})))

(fx/defn account-and-db-password-do-not-match
[{:keys [db] :as cofx} error]
Expand Down Expand Up @@ -177,113 +167,11 @@
(initialize-wallet)))
(account-and-db-password-do-not-match cofx error)))))

(fx/defn show-migration-error-dialog
[{:keys [db]} realm-error]
(let [{:keys [message]} realm-error
address (get-in db [:accounts/login :address])
erase-button (i18n/label :migrations-erase-accounts-data-button)]
{:ui/show-confirmation
{:title (i18n/label :invalid-key-title)
:content (i18n/label
:invalid-key-content
{:message message
:erase-accounts-data-button-text erase-button})
:confirm-button-text (i18n/label :invalid-key-confirm)
:on-cancel #(re-frame/dispatch
[:init.ui/data-reset-cancelled ""])
:on-accept #(re-frame/dispatch
[:init.ui/account-data-reset-accepted address])}}))
(fx/defn verify-callback
[cofx verify-result realm-error]
(let [data (types/json->clj verify-result)
error (:error data)
success (empty? error)]
(fx/merge
cofx
{:node/stop nil}
(fn [{:keys [db] :as cofx}]
(if success
(case (:error realm-error)
:decryption-failed
(show-migration-error-dialog cofx realm-error)

:database-does-not-exist
(let [{:keys [address password]} (accounts.model/credentials cofx)]
{:data-store/change-account [address
password
true
(get-in cofx
[:db
:accounts/accounts
address
:settings
:fleet])]}))
{:db (update db :accounts/login assoc
:error error
:processing false)})))))

(fx/defn migrations-failed
[{:keys [db]} {:keys [realm-error erase-button]}]
(let [{:keys [message details]} realm-error
address (get-in db [:accounts/login :address])]
{:ui/show-confirmation
{:title (i18n/label :migrations-failed-title)
:content (i18n/label
:migrations-failed-content
(merge
{:message message
:erase-accounts-data-button-text erase-button}
details))
:confirm-button-text erase-button
:on-cancel #(re-frame/dispatch
[:init.ui/data-reset-cancelled ""])
:on-accept #(re-frame/dispatch
[:init.ui/account-data-reset-accepted address])}}))

(fx/defn verify-account
[{:keys [db] :as cofx} {:keys [realm-error]}]
(fx/merge cofx
{:db (-> db
(assoc :node/on-ready :verify-account)
(assoc :realm-error realm-error))}
(node/initialize nil)))

(fx/defn unknown-realm-error
[cofx {:keys [realm-error erase-button]}]
(let [{:keys [message]} realm-error
{:keys [address]} (accounts.model/credentials cofx)]
{:ui/show-confirmation
{:title (i18n/label :unknown-realm-error)
:content (i18n/label
:unknown-realm-error-content
{:message message
:erase-accounts-data-button-text erase-button})
:confirm-button-text (i18n/label :invalid-key-confirm)
:on-cancel #(re-frame/dispatch
[:init.ui/data-reset-cancelled ""])
:on-accept #(re-frame/dispatch
[:init.ui/account-data-reset-accepted address])}}))

(fx/defn handle-change-account-error
[{:keys [db] :as cofx} error]
(let [{:keys [error] :as realm-error}
(if (map? error)
error
{:message (str error)})
erase-button (i18n/label :migrations-erase-accounts-data-button)]
(fx/merge
cofx
{:db (assoc-in db [:accounts/login :save-password?] false)}
(case error
:migrations-failed
(migrations-failed {:realm-error realm-error
:erase-button erase-button})

(:database-does-not-exist :decryption-failed)
(verify-account {:realm-error realm-error})

(unknown-realm-error {:realm-error realm-error
:erase-button erase-button})))))
;; does nothing for now
;; will handle errors from go side
)

(fx/defn open-keycard-login
[{:keys [db] :as cofx}]
Expand Down Expand Up @@ -323,7 +211,7 @@
(fx/merge cofx
{:db (assoc-in db [:accounts/login :password] password)}
(navigation/navigate-to-cofx :progress nil)
(user-login false))
(user-login))
(fx/merge cofx
(when bioauth-message
{:utils/show-popup {:title (i18n/label :t/biometric-auth-login-error-title) :content bioauth-message}})
Expand All @@ -341,19 +229,13 @@
(fn [[address password]]
(login! address (security/safe-unmask-data password))))

(re-frame/reg-fx
:accounts.login/verify
(fn [[address password realm-error]]
(verify! address (security/safe-unmask-data password) realm-error)))

(re-frame/reg-fx
:accounts.login/clear-web-data
clear-web-data!)

(re-frame/reg-fx
:data-store/change-account
(fn [[address password create-database-if-not-exist? current-fleet]]
(fn [[address password current-fleet]]
(change-account! address
(security/safe-unmask-data password)
create-database-if-not-exist?
current-fleet)))
3 changes: 2 additions & 1 deletion src/status_im/accounts/logout/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
(fx/merge
cofx
(init/initialize-app-db)
(init/load-accounts-and-initialize-views)
(init/load-accounts)
(init/initialize-views)
(node/stop)))

(fx/defn show-logout-confirmation [_]
Expand Down
1 change: 1 addition & 0 deletions src/status_im/android/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.android.core
(:require [reagent.core :as reagent]
[re-frame.core :refer [subscribe dispatch dispatch-sync]]
status-im.data-store.core
status-im.utils.db
status-im.ui.screens.db
status-im.ui.screens.events
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/data_store/accounts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@

(re-frame/reg-cofx
:data-store/get-all-accounts
(fn [coeffects _]))
(fn [coeffects _]
coeffects))
3 changes: 2 additions & 1 deletion src/status_im/data_store/browser.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

(re-frame/reg-cofx
:data-store/all-browsers
(fn [cofx _]))
(fn [cofx _]
cofx))

(defn save-browser-tx
"Returns tx function for saving browser"
Expand Down
9 changes: 5 additions & 4 deletions src/status_im/data_store/chats.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
(update :last-clock-value utils.clocks/safe-timestamp)
(update :last-message-content utils/safe-read-message-content)))

(re-frame/reg-cofx
:data-store/all-chats
(fn [cofx _]))

(defn save-chat-tx
"Returns tx function for saving chat"
[chat]
Expand Down Expand Up @@ -110,3 +106,8 @@
"Returns tx function for removing chat contacts"
[chat-id tag]
(fn [realm]))

(re-frame/reg-cofx
:data-store/all-chats
(fn [cofx _]
(assoc cofx :get-all-stored-chats (fn [] {}))))
3 changes: 2 additions & 1 deletion src/status_im/data_store/contacts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

(re-frame/reg-cofx
:data-store/get-all-contacts
(fn [coeffects _]))
(fn [coeffects _]
coeffects))

(defn save-contact-tx
"Returns tx function for saving contact"
Expand Down
10 changes: 10 additions & 0 deletions src/status_im/data_store/core.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(ns status-im.data-store.core
(:require [re-frame.core :as re-frame]))

(re-frame/reg-fx
:data-store/base-tx
(fn [transactions]))

(re-frame/reg-fx
:data-store/tx
(fn [transactions]))
3 changes: 2 additions & 1 deletion src/status_im/data_store/dapp_permissions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

(re-frame/reg-cofx
:data-store/all-dapp-permissions
(fn [cofx _]))
(fn [cofx _]
cofx))

(defn save-dapp-permissions
"Returns tx function for saving dapp permissions"
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/data_store/installations.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

(re-frame/reg-cofx
:data-store/get-all-installations
(fn [coeffects _]))
(fn [coeffects _]
coeffects))

(defn save
"Returns tx function for saving a installation"
Expand Down
Loading

0 comments on commit f12e114

Please sign in to comment.