Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2020-01-10 14:18:59 +01:00
parent 73f8b4692e
commit 48d3087f81
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
3 changed files with 22 additions and 24 deletions

View File

@ -1423,21 +1423,6 @@
(fn [cofx [_ field-key value]]
(custom-tokens/field-is-edited cofx field-key value)))
(handlers/register-handler-fx
:wallet.custom-token.ui/add-pressed
(fn [cofx _]
(fx/merge cofx
(custom-tokens/add-custom-token)
(navigation/navigate-back))))
(handlers/register-handler-fx
:wallet.custom-token.ui/remove-pressed
(fn [cofx [_ token navigate-back?]]
(fx/merge cofx
(custom-tokens/remove-custom-token token)
(when navigate-back?
(navigation/navigate-back)))))
;; ethereum subscriptions events
(handlers/register-handler-fx

View File

@ -181,7 +181,8 @@
:on-success resolve
:on-error reject})))]))
(.then (fn [[accounts custom-tokens]]
(callback accounts custom-tokens)))
(callback accounts
(mapv #(update % :symbol keyword) custom-tokens))))
(.catch (fn [error]
(log/error "Failed to initialize wallet"))))))
@ -203,7 +204,9 @@
(assoc ::notifications/enable nil)
(not platform/desktop?)
(assoc ::initialize-wallet
#(re-frame/dispatch [::initialize-wallet %])))
(fn [accounts custom-tokens]
(re-frame/dispatch [::initialize-wallet
accounts custom-tokens]))))
;; NOTE: initializing mailserver depends on user mailserver
;; preference which is why we wait for config callback
(protocol/initialize-protocol {:default-mailserver true})

View File

@ -9,6 +9,7 @@
[status-im.utils.fx :as fx]
[status-im.utils.money :as money]
[status-im.wallet.core :as wallet]
[status-im.ui.screens.navigation :as navigation]
[status-im.multiaccounts.update.core :as multiaccounts.update]))
(re-frame/reg-fx
@ -165,6 +166,7 @@
:error (i18n/label :t/wrong-contract)})}))
(fx/defn add-custom-token
{:events [:wallet.custom-token.ui/add-pressed]}
[{:keys [db] :as cofx}]
(let [{:keys [contract name symbol decimals]} (get db :wallet/custom-token-screen)
chain-key (ethereum/chain-keyword db)
@ -174,19 +176,27 @@
:symbol symbol
:decimals (int decimals)
:color (rand-nth colors/chat-colors)}]
(fx/merge {:db (assoc-in db [:wallet/all-tokens chain-key contract]
(fx/merge cofx
{: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))))
:params [new-token]
:on-success #()}]}
(wallet/add-custom-token new-token)
(navigation/navigate-back))))
(fx/defn remove-custom-token
[{:keys [db] :as cofx} {:keys [address] :as token}]
{:events [:wallet.custom-token.ui/remove-pressed]}
[{:keys [db] :as cofx} {:keys [address] :as token} navigate-back?]
(let [chain-key (ethereum/chain-keyword db)]
(fx/merge {:db (update-in db [:wallet/all-tokens chain-key] dissoc address)
(fx/merge cofx
{:db (update-in db [:wallet/all-tokens chain-key] dissoc address)
::json-rpc/call [{:method "wallet_deleteCustomToken"
:params [address]}]}
(wallet/remove-custom-token token))))
:params [address]
:on-success #()}]}
(wallet/remove-custom-token token)
(when navigate-back?
(navigation/navigate-back)))))
(fx/defn field-is-edited
[{:keys [db] :as cofx} field-key value]