feature #4842 - initially autoconfiguring visible tokens based on balance upon onboarding
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
746d580e34
commit
a8f267e662
|
@ -4,7 +4,6 @@
|
||||||
[status-im.native-module.core :as status]
|
[status-im.native-module.core :as status]
|
||||||
[status-im.utils.types :refer [json->clj]]
|
[status-im.utils.types :refer [json->clj]]
|
||||||
[status-im.utils.identicon :refer [identicon]]
|
[status-im.utils.identicon :refer [identicon]]
|
||||||
[status-im.utils.random :as random]
|
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
|
@ -17,12 +16,11 @@
|
||||||
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
[status-im.utils.gfycat.core :refer [generate-gfy]]
|
||||||
[status-im.utils.hex :as utils.hex]
|
[status-im.utils.hex :as utils.hex]
|
||||||
[status-im.constants :as constants]
|
[status-im.constants :as constants]
|
||||||
[status-im.transport.message.core :as transport]
|
|
||||||
status-im.ui.screens.accounts.create.navigation
|
status-im.ui.screens.accounts.create.navigation
|
||||||
[status-im.chat.models :as chat.models]
|
|
||||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||||
[status-im.data-store.accounts :as accounts-store]
|
[status-im.data-store.accounts :as accounts-store]
|
||||||
[status-im.ui.screens.navigation :as navigation]))
|
[status-im.ui.screens.navigation :as navigation]
|
||||||
|
[status-im.ui.screens.wallet.settings.models :as wallet.settings.models]))
|
||||||
|
|
||||||
;;;; COFX
|
;;;; COFX
|
||||||
|
|
||||||
|
@ -173,4 +171,5 @@
|
||||||
(handlers-macro/merge-fx
|
(handlers-macro/merge-fx
|
||||||
cofx
|
cofx
|
||||||
(wallet-set-up-passed db modal?)
|
(wallet-set-up-passed db modal?)
|
||||||
|
(wallet.settings.models/wallet-autoconfig-tokens)
|
||||||
(accounts.utils/account-update {:wallet-set-up-passed? true}))))
|
(accounts.utils/account-update {:wallet-set-up-passed? true}))))
|
||||||
|
|
|
@ -207,12 +207,15 @@
|
||||||
(assoc-error-message :balance-update err)
|
(assoc-error-message :balance-update err)
|
||||||
(assoc-in [:wallet :balance-loading?] false))))
|
(assoc-in [:wallet :balance-loading?] false))))
|
||||||
|
|
||||||
(handlers/register-handler-db
|
(defn update-token-balance-success [symbol balance {:keys [db]}]
|
||||||
:update-token-balance-success
|
{:db (-> db
|
||||||
(fn [db [_ symbol balance]]
|
|
||||||
(-> db
|
|
||||||
(assoc-in [:wallet :balance symbol] balance)
|
(assoc-in [:wallet :balance symbol] balance)
|
||||||
(assoc-in [:wallet :balance-loading?] false))))
|
(assoc-in [:wallet :balance-loading?] false))})
|
||||||
|
|
||||||
|
(handlers/register-handler-fx
|
||||||
|
:update-token-balance-success
|
||||||
|
(fn [cofx [_ symbol balance]]
|
||||||
|
(update-token-balance-success symbol balance cofx)))
|
||||||
|
|
||||||
(handlers/register-handler-db
|
(handlers/register-handler-db
|
||||||
:update-token-balance-fail
|
:update-token-balance-fail
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
(ns status-im.ui.screens.wallet.settings.events
|
(ns status-im.ui.screens.wallet.settings.events
|
||||||
(:require [status-im.ui.screens.accounts.events :as accounts]
|
(:require [status-im.ui.screens.wallet.settings.models :as models]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.ui.screens.accounts.events :as accounts]
|
||||||
[status-im.utils.handlers :as handlers]))
|
[status-im.utils.handlers :as handlers]))
|
||||||
|
|
||||||
(defn- toggle-checked [ids id checked?]
|
|
||||||
(if checked?
|
|
||||||
(conj (or ids #{}) id)
|
|
||||||
(disj ids id)))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet.settings/toggle-visible-token
|
:wallet.settings/toggle-visible-token
|
||||||
(fn [{{:keys [account/account] :as db} :db :as cofx} [_ symbol checked?]]
|
(fn [cofx [_ symbol checked?]]
|
||||||
(let [network (get (:networks account) (:network account))
|
(models/toggle-visible-token symbol checked? accounts/update-settings cofx)))
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
settings (get account :settings)
|
(handlers/register-handler-fx
|
||||||
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
|
:configure-token-balance-and-visibility
|
||||||
(accounts/update-settings new-settings cofx))))
|
(fn [cofx [_ symbol balance]]
|
||||||
|
(models/configure-token-balance-and-visibility symbol balance accounts/update-settings cofx)))
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
(ns status-im.ui.screens.wallet.settings.models
|
||||||
|
(:require [status-im.utils.ethereum.core :as ethereum]
|
||||||
|
[status-im.utils.handlers-macro :as handlers-macro]
|
||||||
|
[status-im.ui.screens.wallet.events :as wallet.events]
|
||||||
|
[status-im.utils.ethereum.tokens :as tokens]
|
||||||
|
[re-frame.core :as re-frame]))
|
||||||
|
|
||||||
|
(defn- set-checked [ids id checked?]
|
||||||
|
(if checked?
|
||||||
|
(conj (or ids #{}) id)
|
||||||
|
(disj ids id)))
|
||||||
|
|
||||||
|
(defn toggle-visible-token [symbol checked? update-settings-fx {{:keys [account/account]} :db :as cofx}]
|
||||||
|
(let [network (get (:networks account) (:network account))
|
||||||
|
chain (ethereum/network->chain-keyword network)
|
||||||
|
settings (get account :settings)
|
||||||
|
new-settings (update-in settings [:wallet :visible-tokens chain] #(set-checked % symbol checked?))]
|
||||||
|
(update-settings-fx new-settings cofx)))
|
||||||
|
|
||||||
|
(defn configure-token-balance-and-visibility [symbol balance update-settings-fx cofx]
|
||||||
|
(handlers-macro/merge-fx cofx
|
||||||
|
(toggle-visible-token symbol true update-settings-fx)
|
||||||
|
;;TODO(goranjovic): move `update-token-balance-success` function to wallet models
|
||||||
|
(wallet.events/update-token-balance-success symbol balance)))
|
||||||
|
|
||||||
|
(defn wallet-autoconfig-tokens [{:keys [db]}]
|
||||||
|
(let [{:keys [account/account web3]} db
|
||||||
|
network (get (:networks account) (:network account))
|
||||||
|
chain (ethereum/network->chain-keyword network)
|
||||||
|
contracts (->> (tokens/tokens-for chain)
|
||||||
|
(remove :hidden?))]
|
||||||
|
(doseq [{:keys [address symbol]} contracts]
|
||||||
|
;;TODO(goranjovic): move `get-token-balance` function to wallet models
|
||||||
|
(wallet.events/get-token-balance {:web3 web3
|
||||||
|
:contract address
|
||||||
|
:account-id (:address account)
|
||||||
|
:on-success #(when (> % 0)
|
||||||
|
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))}))))
|
Loading…
Reference in New Issue