-
Notifications
You must be signed in to change notification settings - Fork 991
[#18736] add address to watch using an ENS #19043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
72159b4
00bb8b8
4e3293b
7d6f6fa
f75c279
1e07933
aa953ad
f5a32c0
c28efbd
68d63e7
c7529bb
44b1c6d
144ca8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(ns status-im.contexts.wallet.accounts.add-account.address-to-watch.events | ||
(:require [clojure.string :as string] | ||
[status-im.constants :as constants] | ||
[taoensso.timbre :as log] | ||
[utils.re-frame :as rf])) | ||
|
||
(rf/reg-event-fx | ||
:wallet/ens-not-found | ||
(fn [{:keys [db]} _] | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :add-address-to-watch :activity-state] :invalid-ens) | ||
(assoc-in [:wallet :ui :add-address-to-watch :validated-address] nil))})) | ||
|
||
(rf/reg-event-fx | ||
:wallet/store-address-activity | ||
(fn [{:keys [db]} [address {:keys [hasActivity]}]] | ||
(let [registered-addresses (-> db :wallet :accounts keys set) | ||
address-already-registered? (registered-addresses address)] | ||
(if address-already-registered? | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :add-address-to-watch :activity-state] | ||
:address-already-registered) | ||
(assoc-in [:wallet :ui :add-address-to-watch :validated-address] nil))} | ||
(let [state (if hasActivity :has-activity :no-activity)] | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :add-address-to-watch :activity-state] state) | ||
(assoc-in [:wallet :ui :add-address-to-watch :validated-address] address))}))))) | ||
|
||
(rf/reg-event-fx | ||
:wallet/clear-address-activity | ||
(fn [{:keys [db]}] | ||
{:db (update-in db [:wallet :ui] dissoc :add-address-to-watch)})) | ||
|
||
(rf/reg-event-fx | ||
:wallet/get-address-details | ||
(fn [{:keys [db]} [address-or-ens]] | ||
(let [request-params [constants/ethereum-mainnet-chain-id address-or-ens] | ||
ens? (string/includes? address-or-ens ".")] | ||
{:db (-> db | ||
(assoc-in [:wallet :ui :add-address-to-watch :activity-state] :scanning) | ||
(assoc-in [:wallet :ui :add-address-to-watch :validated-address] nil)) | ||
:fx [(if ens? | ||
[:json-rpc/call | ||
[{:method "ens_addressOf" | ||
:params request-params | ||
:on-success [:wallet/get-address-details] | ||
:on-error [:wallet/ens-not-found]}]] | ||
[:json-rpc/call | ||
[{:method "wallet_getAddressDetails" | ||
:params request-params | ||
:on-success [:wallet/store-address-activity address-or-ens] | ||
:on-error #(log/info "failed to get address details" | ||
{:error % | ||
:event :wallet/get-address-details})}]])]}))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,13 @@ | |
[react-native.background-timer :as background-timer] | ||
[react-native.platform :as platform] | ||
[status-im.constants :as constants] | ||
[status-im.contexts.wallet.accounts.add-account.address-to-watch.events] | ||
[status-im.contexts.wallet.common.utils :as utils] | ||
[status-im.contexts.wallet.data-store :as data-store] | ||
[status-im.contexts.wallet.events.collectibles] | ||
[status-im.contexts.wallet.item-types :as item-types] | ||
[taoensso.timbre :as log] | ||
[utils.collection] | ||
[utils.ethereum.chain :as chain] | ||
[utils.ethereum.eip.eip55 :as eip55] | ||
[utils.i18n :as i18n] | ||
[utils.number] | ||
|
@@ -360,27 +360,6 @@ | |
(fn [{:keys [db]}] | ||
{:db (assoc db :wallet/valid-ens-or-address? false)})) | ||
|
||
(rf/reg-event-fx :wallet/get-address-details-success | ||
(fn [{:keys [db]} [{:keys [hasActivity]}]] | ||
{:db (assoc-in db | ||
[:wallet :ui :watch-address-activity-state] | ||
(if hasActivity :has-activity :no-activity))})) | ||
|
||
(rf/reg-event-fx :wallet/clear-address-activity-check | ||
(fn [{:keys [db]}] | ||
{:db (update-in db [:wallet :ui] dissoc :watch-address-activity-state)})) | ||
|
||
(rf/reg-event-fx :wallet/get-address-details | ||
(fn [{:keys [db]} [address]] | ||
{:db (assoc-in db [:wallet :ui :watch-address-activity-state] :scanning) | ||
:fx [[:json-rpc/call | ||
[{:method "wallet_getAddressDetails" | ||
:params [(chain/chain-id db) address] | ||
:on-success [:wallet/get-address-details-success] | ||
:on-error #(log/info "failed to get address details" | ||
{:error % | ||
:event :wallet/get-address-details})}]]]})) | ||
|
||
(rf/reg-event-fx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, so this file is really starting to bloat. e.g something like
etc.. Anyway, I'm not saying to do this refactor here, but perhaps we can at least create the appropriate ns for these events added and move them to that file and the others can be moved in a refactor. Also maybe these events are common enough to wallet that they should be in this ns. 🤷♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @J-Son89 Actually I noticed this while adding these events, but noticed it's only happening on Collectibles and wasn't sure. |
||
:wallet/navigate-to-chain-explorer-from-bottom-sheet | ||
(fn [_ [explorer-link address]] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,16 +115,15 @@ | |
|
||
(defn- local-suggestions-list | ||
[] | ||
(fn [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just removing an extra |
||
(let [local-suggestion (rf/sub [:wallet/local-suggestions])] | ||
[rn/view {:style {:flex 1}} | ||
[rn/flat-list | ||
{:data local-suggestion | ||
:content-container-style {:flex-grow 1} | ||
:key-fn :id | ||
:on-scroll-to-index-failed identity | ||
:keyboard-should-persist-taps :handled | ||
:render-fn suggestion-component}]]))) | ||
(let [local-suggestion (rf/sub [:wallet/local-suggestions])] | ||
[rn/view {:style {:flex 1}} | ||
[rn/flat-list | ||
{:data local-suggestion | ||
:content-container-style {:flex-grow 1} | ||
:key-fn :id | ||
:on-scroll-to-index-failed identity | ||
:keyboard-should-persist-taps :handled | ||
:render-fn suggestion-component}]])) | ||
|
||
(defn- f-view | ||
[] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
(ns status-im.subs.wallet.add-account.address-to-watch | ||
(:require [re-frame.core :as rf])) | ||
|
||
(rf/reg-sub | ||
:wallet/add-address-to-watch | ||
:<- [:wallet/ui] | ||
:-> :add-address-to-watch) | ||
|
||
(rf/reg-sub | ||
:wallet/watch-address-activity-state | ||
:<- [:wallet/add-address-to-watch] | ||
:-> :activity-state) | ||
|
||
(rf/reg-sub | ||
:wallet/watch-address-validated-address | ||
:<- [:wallet/add-address-to-watch] | ||
:-> :validated-address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if
was awhen
, while usingwhen
, two messages could be displayed under certain circumstances, because we have two components and the back-end response comes some time later.The message is the following:

I think we should only have a single component, having two makes the code more error prone. A bigger refactor on this component might be needed, but I didn't do it here because I wanted to keep the diff focused.