From 879e33b9b55e30f8829718147b573bca51565fa8 Mon Sep 17 00:00:00 2001 From: Goran Jovic Date: Thu, 9 Aug 2018 10:19:18 +0200 Subject: [PATCH] bug #5356 - added snackbar for wallet errors, removed ATT from default tokens on ropsten Signed-off-by: Goran Jovic --- CHANGELOG.md | 2 ++ src/status_im/constants.cljs | 2 +- .../data_store/realm/schemas/base/core.cljs | 8 ++++-- .../realm/schemas/base/v8/account.cljs | 28 +++++++++++++++++++ .../realm/schemas/base/v8/core.cljs | 13 +++++++++ src/status_im/translations/en.cljs | 4 +++ src/status_im/ui/screens/wallet/events.cljs | 16 ++++------- .../ui/screens/wallet/main/styles.cljs | 9 ++++++ .../ui/screens/wallet/main/views.cljs | 13 +++++++-- src/status_im/ui/screens/wallet/subs.cljs | 2 +- 10 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 src/status_im/data_store/realm/schemas/base/v8/account.cljs create mode 100644 src/status_im/data_store/realm/schemas/base/v8/core.cljs diff --git a/CHANGELOG.md b/CHANGELOG.md index 674b4f2f3f..c1b575e6f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added dismiss button to "Add to contacts" bar ### Fixed +- Partially fixed issue with 0 fiat in main Wallet screen. We are now explicitly showing an error when app can't fetch +asset prices, instead of silently failing. ### Changed diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index f3e094266c..d4d24f39cd 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -146,7 +146,7 @@ (assoc default-wnodes-without-custom :custom (:testnet default-wnodes-without-custom))) (defn default-account-settings [] - {:wallet {:visible-tokens {:testnet #{:STT :ATT} + {:wallet {:visible-tokens {:testnet #{:STT :HND} :mainnet #{:SNT} :rinkeby #{:MOKSHA}}}}) diff --git a/src/status_im/data_store/realm/schemas/base/core.cljs b/src/status_im/data_store/realm/schemas/base/core.cljs index f140d9021a..6ba8ede945 100644 --- a/src/status_im/data_store/realm/schemas/base/core.cljs +++ b/src/status_im/data_store/realm/schemas/base/core.cljs @@ -5,7 +5,8 @@ [status-im.data-store.realm.schemas.base.v4.core :as v4] [status-im.data-store.realm.schemas.base.v5.core :as v5] [status-im.data-store.realm.schemas.base.v6.core :as v6] - [status-im.data-store.realm.schemas.base.v7.core :as v7])) + [status-im.data-store.realm.schemas.base.v7.core :as v7] + [status-im.data-store.realm.schemas.base.v8.core :as v8])) ;; put schemas ordered by version (def schemas [{:schema v1/schema @@ -28,4 +29,7 @@ :migration v6/migration} {:schema v7/schema :schemaVersion 7 - :migration v7/migration}]) + :migration v7/migration} + {:schema v8/schema + :schemaVersion 8 + :migration v8/migration}]) diff --git a/src/status_im/data_store/realm/schemas/base/v8/account.cljs b/src/status_im/data_store/realm/schemas/base/v8/account.cljs new file mode 100644 index 0000000000..ddde83e521 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v8/account.cljs @@ -0,0 +1,28 @@ +(ns status-im.data-store.realm.schemas.base.v8.account + (:require [taoensso.timbre :as log] + [cognitect.transit :as transit] + [clojure.set :as set] + [status-im.data-store.realm.schemas.base.v4.account :as v7])) + +(def schema v7/schema) + +(def removed-tokens + #{:ATT}) + +(def reader (transit/reader :json)) +(def writer (transit/writer :json)) + +(defn serialize [o] (transit/write writer o)) +(defn deserialize [o] (try (transit/read reader o) (catch :default e nil))) + +(defn migration [old-realm new-realm] + (log/debug "migrating accounts schema v8") + (let [accounts (.objects new-realm "account")] + (dotimes [i (.-length accounts)] + (let [account (aget accounts i) + old-settings (deserialize (aget account "settings")) + new-settings (-> old-settings + (update-in [:wallet :visible-tokens :testnet] + #(set/difference % removed-tokens))) + updated (serialize new-settings)] + (aset account "settings" updated))))) \ No newline at end of file diff --git a/src/status_im/data_store/realm/schemas/base/v8/core.cljs b/src/status_im/data_store/realm/schemas/base/v8/core.cljs new file mode 100644 index 0000000000..005edddf72 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v8/core.cljs @@ -0,0 +1,13 @@ +(ns status-im.data-store.realm.schemas.base.v8.core + (:require [status-im.data-store.realm.schemas.base.v1.network :as network] + [status-im.data-store.realm.schemas.base.v4.bootnode :as bootnode] + [status-im.data-store.realm.schemas.base.v8.account :as account] + [taoensso.timbre :as log])) + +(def schema [network/schema + bootnode/schema + account/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating base database v8: " old-realm new-realm) + (account/migration old-realm new-realm)) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 2bc9ac0c26..2976b618bb 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -458,6 +458,10 @@ :signing-phrase-description "Sign the transaction by entering your password. Make sure that the words above match your secret signing phrase" :wallet-insufficient-funds "Insufficient funds" :wallet-insufficient-gas "Not enough ETH for gas" + :error-unable-to-get-prices "Currency conversion error. Try to refresh to update later" + :error-unable-to-get-balance "Unable to get balance" + :error-unable-to-get-token-balance "Unable to get token balance" + :error-unable-to-get-transactions "Unable to get transaction history" :receive "Receive" :request-qr-legend "Share this code to receive assets" :send-request "Send request" diff --git a/src/status_im/ui/screens/wallet/events.cljs b/src/status_im/ui/screens/wallet/events.cljs index e23d461d13..ebe4cd805a 100644 --- a/src/status_im/ui/screens/wallet/events.cljs +++ b/src/status_im/ui/screens/wallet/events.cljs @@ -41,8 +41,7 @@ (on-error "web3, contract or account-id not available"))) (defn assoc-error-message [db error-type err] - (assoc-in db [:wallet :errors error-type] (or (when err (str err)) - :unknown-error))) + (assoc-in db [:wallet :errors error-type] (or err :unknown-error))) (defn clear-error-message [db error-type] (update-in db [:wallet :errors] dissoc error-type)) @@ -189,7 +188,7 @@ (fn [db [_ err]] (log/debug "Unable to get transactions: " err) (-> db - (assoc-error-message :transactions-update err) + (assoc-error-message :transactions-update :error-unable-to-get-transactions) (assoc-in [:wallet :transactions-loading?] false)))) (handlers/register-handler-db @@ -204,7 +203,7 @@ (fn [db [_ err]] (log/debug "Unable to get balance: " err) (-> db - (assoc-error-message :balance-update err) + (assoc-error-message :balance-update :error-unable-to-get-balance) (assoc-in [:wallet :balance-loading?] false)))) (defn update-token-balance-success [symbol balance {:keys [db]}] @@ -222,7 +221,7 @@ (fn [db [_ symbol err]] (log/debug "Unable to get token " symbol "balance: " err) (-> db - (assoc-error-message :balance-update err) + (assoc-error-message :balance-update :error-unable-to-get-token-balance) (assoc-in [:wallet :balance-loading?] false)))) (handlers/register-handler-db @@ -237,7 +236,7 @@ (fn [db [_ err]] (log/debug "Unable to get prices: " err) (-> db - (assoc-error-message :prices-update err) + (assoc-error-message :prices-update :error-unable-to-get-prices) (assoc :prices-loading? false)))) (handlers/register-handler-fx @@ -279,11 +278,6 @@ (assoc-in db [:wallet :send-transaction :gas] (money/bignumber (int (* gas 1.2)))) db))) -(handlers/register-handler-fx - :wallet/show-error - (fn [] - {:show-error (i18n/label :t/wallet-error)})) - (handlers/register-handler-fx :wallet-setup-navigate-back (fn [{:keys [db]}] diff --git a/src/status_im/ui/screens/wallet/main/styles.cljs b/src/status_im/ui/screens/wallet/main/styles.cljs index a64532ed35..4bcb42a365 100644 --- a/src/status_im/ui/screens/wallet/main/styles.cljs +++ b/src/status_im/ui/screens/wallet/main/styles.cljs @@ -65,6 +65,15 @@ :android {:letter-spacing 1.5} :ios {:letter-spacing 1.16}}) +(def snackbar-container + {:background-color colors/gray-notifications}) + +(def snackbar-text + {:color colors/white + :margin-horizontal 50 + :margin-vertical 10 + :text-align :center}) + ;; Actions section (def action-section diff --git a/src/status_im/ui/screens/wallet/main/views.cljs b/src/status_im/ui/screens/wallet/main/views.cljs index eb6929a76e..6590e61af0 100644 --- a/src/status_im/ui/screens/wallet/main/views.cljs +++ b/src/status_im/ui/screens/wallet/main/views.cljs @@ -18,7 +18,8 @@ status-im.ui.screens.wallet.collectibles.cryptokitties.views [status-im.ui.components.status-bar.view :as status-bar.view] [status-im.ui.components.text :as text] - [status-im.ui.screens.wallet.transactions.views :as transactions.views])) + [status-im.ui.screens.wallet.transactions.views :as transactions.views] + [status-im.ui.components.colors :as colors])) (defn toolbar-view [] [toolbar/toolbar {:style wallet.styles/toolbar :flat? true} @@ -147,12 +148,18 @@ :data nfts :render-fn #(render-collectible address-hex % modal?)}]}]])) +(defn snackbar [error-message] + [react/view styles/snackbar-container + [react/text {:style styles/snackbar-text} + (i18n/label error-message)]]) + (views/defview wallet-root [modal?] (views/letsubs [assets [:wallet/visible-assets-with-amount] currency [:wallet/currency] portfolio-value [:portfolio-value] {:keys [modal-history?]} [:get :wallet] {:keys [seed-backed-up?]} [:get-current-account] + error-message [:wallet/error-message] address-hex [:get-current-account-hex]] [react/view styles/main-section (if modal? @@ -166,7 +173,9 @@ [react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet]) :tint-color :white :refreshing false}])} - [total-section portfolio-value currency] + (if error-message + [snackbar error-message] + [total-section portfolio-value currency]) (when (and (not modal?) (not seed-backed-up?) (some (fn [{:keys [amount]}] diff --git a/src/status_im/ui/screens/wallet/subs.cljs b/src/status_im/ui/screens/wallet/subs.cljs index 84640874f1..14d76919f5 100644 --- a/src/status_im/ui/screens/wallet/subs.cljs +++ b/src/status_im/ui/screens/wallet/subs.cljs @@ -80,7 +80,7 @@ (fn [wallet] (:balance-loading? wallet))) -(re-frame/reg-sub :wallet/error-message? +(re-frame/reg-sub :wallet/error-message :<- [:wallet] (fn [wallet] (or (get-in wallet [:errors :balance-update])