Skip to content

Commit

Permalink
bug #5356 - added snackbar for wallet errors, removed ATT from defaul…
Browse files Browse the repository at this point in the history
…t tokens on ropsten

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
  • Loading branch information
goranjovic committed Aug 14, 2018
1 parent 8f13d97 commit 879e33b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}})

Expand Down
8 changes: 6 additions & 2 deletions src/status_im/data_store/realm/schemas/base/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}])
28 changes: 28 additions & 0 deletions src/status_im/data_store/realm/schemas/base/v8/account.cljs
Original file line number Diff line number Diff line change
@@ -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)))))
13 changes: 13 additions & 0 deletions src/status_im/data_store/realm/schemas/base/v8/core.cljs
Original file line number Diff line number Diff line change
@@ -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))
4 changes: 4 additions & 0 deletions src/status_im/translations/en.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 5 additions & 11 deletions src/status_im/ui/screens/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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]}]
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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]}]
Expand Down
9 changes: 9 additions & 0 deletions src/status_im/ui/screens/wallet/main/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/status_im/ui/screens/wallet/main/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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?
Expand All @@ -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]}]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ui/screens/wallet/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 879e33b

Please sign in to comment.