Skip to content

Commit

Permalink
move custom tokens to a separate table
Browse files Browse the repository at this point in the history
Signed-off-by: yenda <eric@status.im>
  • Loading branch information
yenda committed Dec 12, 2019
1 parent 0e25aa2 commit 6a800b2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
"status_chats" {}
"wallet_getTransfers" {}
"wallet_getTokensBalances" {}
"wallet_getCustomTokens" {}
"wallet_addCustomToken" {}
"wallet_deleteCustomToken" {}
"browsers_getBrowsers" {}
"browsers_addBrowser" {}
"browsers_deleteBrowser" {}
Expand Down
19 changes: 11 additions & 8 deletions src/status_im/multiaccounts/login/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@
(fn [[account-data hashed-password]]
(status/login account-data hashed-password)))

(fx/defn initialize-wallet [cofx]
(fx/defn initialize-wallet
{:events [::initialize-wallet]}
[cofx custom-tokens]
(fx/merge cofx
(wallet/initialize-tokens)
(wallet/initialize-tokens custom-tokens)
(wallet/update-balances nil)
(wallet/update-prices)
(transactions/initialize)))
Expand Down Expand Up @@ -161,7 +163,11 @@
multiaccount))}
(and platform/android?
notifications-enabled?)
(assoc ::notifications/enable nil))
(assoc ::notifications/enable nil)
(not platform/desktop?)
(assoc ::json-rpc/call
[{:method "wallet_getCustomTokens"
:on-success #(re-frame/dispatch [::initialize-wallet %])}]))
;; NOTE: initializing mailserver depends on user mailserver
;; preference which is why we wait for config callback
(protocol/initialize-protocol {:default-mailserver true})
Expand All @@ -171,9 +177,7 @@
(contact/initialize-contacts)
(stickers/init-stickers-packs)
(mobile-network/on-network-status-change)
(chaos-mode/check-chaos-mode)
(when-not platform/desktop?
(initialize-wallet)))))
(chaos-mode/check-chaos-mode))))

(defn get-new-auth-method [auth-method save-password?]
(if save-password?
Expand Down Expand Up @@ -249,7 +253,7 @@
:default-mailserver true})
(chaos-mode/check-chaos-mode)
(when-not platform/desktop?
(initialize-wallet)))))
(initialize-wallet nil)))))

(defn- keycard-setup? [cofx]
(boolean (get-in cofx [:db :hardwallet :flow])))
Expand Down Expand Up @@ -408,4 +412,3 @@
(popover/show-popover {:view :secure-with-biometric})
(when-not (= previous-auth-method keychain/auth-method-none)
(popover/show-popover {:view :disable-password-saving})))))))

14 changes: 11 additions & 3 deletions src/status_im/wallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,18 @@
(set/difference (set visible-token-symbols)
(set (map :symbol (tokens/nfts-for all-tokens chain)))))

(defn rpc->token [tokens]
(reduce (fn [acc {:keys [address] :as token}]
(assoc acc
address
(assoc token :custom? true)))
{}
tokens))

(fx/defn initialize-tokens
[{:keys [db] :as cofx}]
(let [custom-tokens (get-in db [:multiaccount :settings :wallet :custom-tokens])
chain (ethereum/chain-keyword db)
[{:keys [db] :as cofx} custom-tokens]
(let [chain (ethereum/chain-keyword db)
custom-tokens {chain (rpc->token custom-tokens)}
;;TODO why do we need all tokens ? chain can be changed only through relogin
all-tokens (merge-with
merge
Expand Down
12 changes: 7 additions & 5 deletions src/status_im/wallet/custom_tokens/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,20 @@
new-token {:address contract
:name name
:symbol symbol
:custom? true
:decimals (int decimals)
:color (rand-nth colors/chat-colors)}]
(fx/merge (assoc-in cofx
[:db :wallet/all-tokens chain-key contract]
new-token)
(fx/merge {:db (assoc-in db [:wallet/all-tokens chain-key contract]
(assoc new-token :custom? true))
::json-rpc/call [{:method "wallet_addCustomToken"
:params [new-token]}]}
(wallet/add-custom-token new-token))))

(fx/defn remove-custom-token
[{:keys [db] :as cofx} {:keys [address] :as token}]
(let [chain-key (ethereum/chain-keyword db)]
(fx/merge (update-in cofx [:db :wallet/all-tokens chain-key] dissoc address)
(fx/merge {:db (update-in db [:wallet/all-tokens chain-key] dissoc address)
::json-rpc/call [{:method "wallet_deleteCustomToken"
:params [address]}]}
(wallet/remove-custom-token token))))

(fx/defn field-is-edited
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.38.0",
"commit-sha1": "baa0767c263fa25fdd8d90a42d13f1f1fffce804",
"src-sha256": "0m7baga353vyjqb8zlzd22w68kkm24baq8059a89xdv57ln35axi"
"version": "v0.0.2.experimental.tokens",
"commit-sha1": "0571f561f0e526a996408be96f649c9e17c47c01",
"src-sha256": "1skk9mbjrnbs7jy3nlag9gbn9wlig50piafvbilrg01flcalc3i3"
}

0 comments on commit 6a800b2

Please sign in to comment.