Skip to content
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

[Fixes #8066] Added native ENS registration #8248

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a6bd0fc
[Fixes #8066] Added native ENS registration
jeluard May 21, 2019
aa49c7e
[#8239] App crash when submit cryptokitties with different than it's …
flexsurfer May 22, 2019
c5a6204
[feature] use subscriptions for tokens
May 9, 2019
9435641
[feature] use new block signal to get new transactions
May 13, 2019
0e95003
[refactor] transaction details
May 16, 2019
d755296
[refactor] transaction history and filters
May 17, 2019
85ed5cf
[performance] improve wallet update performances
May 18, 2019
143c9f5
[refactoring] remove web3, clean up wallet effects
May 19, 2019
d519ab5
[refactor] remove ethereum `call` and `call-params`
May 20, 2019
a26bfaf
[fix] always show tokens that have a balance
May 21, 2019
5cd64e2
added test_open_blocked_site
antdanchenko May 23, 2019
eeb1343
[fix] remove duplicates of :hardwallet/verify-pin event
May 23, 2019
c63c65e
add MOBILE_UI_FOR_DESKTOP=0 to other env files
jakubgs May 23, 2019
6090642
[refactor] use `ethereum` `current-address` and `chain-keyword`
May 22, 2019
b546fb2
[refactor] move utils.ethereum to ethereum
May 22, 2019
6420e8c
[nix] patch realm as a nodePackage for linux and darwin and use it fr…
hlolli Apr 1, 2019
d546396
nix: Move debug realm into desktop folder and use RN cli from node_mo…
pombeirp May 22, 2019
d25b617
Send logs on shaking device
rasom May 7, 2019
a105346
App version and more detail in logs email
rasom May 7, 2019
6b9684c
[#8256] do not call getApplicationInfo every time card connected
dmitryn May 22, 2019
44fd9b4
[#8277] Report a bug template
rasom May 24, 2019
025210c
[dev feature] extend the defn macro
May 23, 2019
d0733d5
RAM bundle basic setup
rasom May 22, 2019
756636e
fix custom tokens
flexsurfer May 27, 2019
4294281
Enable asset in Wallet before usage
May 27, 2019
32bcd4a
[fix] superfluous keyword
May 28, 2019
cab3629
save keycard key-uid to account and use it to login
dmitryn May 23, 2019
2ad1c3f
e2e pairing 1-1 and contacts
churik May 29, 2019
ce3a5e3
Add goerli testnet
dshulyak Mar 14, 2019
f9138e3
[fix] on-result event for in app transactions
May 28, 2019
d267d5b
Prepare to use status-go based protocol: 1-1 and public chat manageme…
mandrigin May 29, 2019
75ed78d
bump version to 0.14.0
mandrigin May 29, 2019
23eae3c
Update Play Store phone screenshots
May 28, 2019
f11c319
[Fixes #8066] Added native ENS registration
jeluard May 21, 2019
733c87b
[refactor] transaction details
May 16, 2019
7fe060d
[performance] improve wallet update performances
May 18, 2019
862b1d6
[refactor] remove ethereum `call` and `call-params`
May 20, 2019
8addae6
[refactor] move utils.ethereum to ethereum
May 22, 2019
2a8f46f
[Fixes #8066] Added native ENS registration
jeluard May 21, 2019
1dd84fa
Connect and persist usernames
jeluard May 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added resources/images/ui/ens-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ui/ens-header@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/ui/ens-header@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/status_im/react_native/resources.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
:warning-sign (js/require "./resources/images/ui/warning-sign.png")
:phone-nfc-on (js/require "./resources/images/ui/phone-nfc-on.png")
:phone-nfc-off (js/require "./resources/images/ui/phone-nfc-off.png")
:dapp-store (js/require "./resources/images/ui/dapp-store.png")})
:dapp-store (js/require "./resources/images/ui/dapp-store.png")
:ens-header (js/require "./resources/images/ui/ens-header.png")})
25 changes: 25 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
[status-im.utils.config :as config]
[status-im.utils.datetime :as datetime]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.stateofus :as stateofus]
[status-im.utils.ethereum.tokens :as tokens]
[status-im.utils.hex :as utils.hex]
[status-im.utils.identicon :as identicon]
Expand Down Expand Up @@ -1633,3 +1634,27 @@
:<- [:search/filter]
(fn [[chats search-filter]]
(apply-filter search-filter chats extract-chat-attributes)))

;;ENS ==================================================================================================================

(re-frame/reg-sub
:ens/state
(fn [db]
jeluard marked this conversation as resolved.
Show resolved Hide resolved
(get-in db [:ens :state])))

(re-frame/reg-sub
:ens/username
(fn [db]
(get-in db [:ens :username])))
jeluard marked this conversation as resolved.
Show resolved Hide resolved

(re-frame/reg-sub
:ens/custom-domain?
(fn [db]
(get-in db [:ens :custom-domain?])))

(re-frame/reg-sub
:ens.stateofus/registrar
:<- [:account/network]
(fn [network]
(let [chain (ethereum/network->chain-keyword network)]
(get stateofus/registrars chain))))
2 changes: 1 addition & 1 deletion src/status_im/ui/components/list/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
active? true
style {}}}]
{:pre [(or icon image-source activity-indicator)
(and action-fn text)
text
(or (nil? accessibility-label) (keyword? accessibility-label))]}
[react/touchable-highlight
{:on-press action-fn
Expand Down
1 change: 1 addition & 0 deletions src/status_im/ui/components/status_bar/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
:profile-stack {:type :main}
:my-profile-ext-settings {:type :main}
:contacts-list {:type :main}
:ens-usernames {:type :main}
:browser {:type :main}
:mobile-network-settings {:type :main}
:backup-seed {:type :main}
Expand Down
123 changes: 123 additions & 0 deletions src/status_im/ui/screens/ens/events.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
(ns status-im.ui.screens.ens.events
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe we don't use events in ui namespace, handlers should be in root events file, fx and functions in core.cljs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are plenty events files.

Copy link
Contributor

@yenda yenda May 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is wrong there shouldnt be any

(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.models.wallet :as wallet]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.ethereum.abi-spec :as abi-spec]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.ens :as ens]
[status-im.utils.ethereum.resolver :as resolver]
[status-im.utils.ethereum.stateofus :as stateofus]
[status-im.utils.fx :as fx]
[status-im.utils.handlers :as handlers]
[status-im.utils.money :as money]))

(re-frame/reg-fx
::ens/resolve
(fn [[registry name cb]]
(ens/get-addr registry name cb)))

(defn- on-resolve [registry custom-domain? name address public-key s]
(if (and (seq address) (= address (ethereum/normalized-address s)))
(resolver/pubkey registry name
(fn [ss]
(if (= ss public-key)
(re-frame/dispatch [:ens/set-state :connected])
jeluard marked this conversation as resolved.
Show resolved Hide resolved
(re-frame/dispatch [:ens/set-state :registrable]))))
(if (and (nil? s) (not custom-domain?)) ;; No address for a stateofus subdomain: it can be registered
(re-frame/dispatch [:ens/set-state :registrable])
(re-frame/dispatch [:ens/set-state :unregistrable]))))

(defn- chain [{:keys [network] :as db}]
(let [network (get-in db [:account/account :networks network])]
(ethereum/network->chain-keyword network)))
jeluard marked this conversation as resolved.
Show resolved Hide resolved

(defn- assoc-state [db state]
(assoc-in db [:ens :state] state))

(defn- assoc-username [db username]
(assoc-in db [:ens :username] username))

(defn- valid-custom-domain? [username]
(and (ens/is-valid-eth-name? username)
(stateofus/lower-case? username)))

(defn- valid-username? [custom-domain? username]
(if custom-domain?
(valid-custom-domain? username)
(stateofus/valid-username? username)))

(handlers/register-handler-fx
:ens/set-state
(fn [{:keys [db]} [_ state]]
{:db (assoc-state db state)}))

(defn- state [valid? username]
(cond
(string/blank? username) :initial
valid? :typing
:else
:invalid))

(handlers/register-handler-fx
:ens/set-username
(fn [{:keys [db]} [_ custom-domain? username]]
(let [valid? (valid-username? custom-domain? username)]
(merge
{:db (-> db
(assoc-username username)
(assoc-state (state valid? username)))}
(when valid?
(let [{:keys [account/account]} db
{:keys [address public-key]} account
registry (get ens/ens-registries (chain db))
name (if custom-domain? username (stateofus/subdomain username))]
{::ens/resolve [registry name #(on-resolve registry custom-domain? name address public-key %)]}))))))

(handlers/register-handler-fx
:ens/navigate-back
(fn [{:keys [db] :as cofx} _]
(fx/merge cofx
{:db (-> db
(assoc-state :initial)
(assoc-username ""))}
(navigation/navigate-back))))

(handlers/register-handler-fx
:ens/switch-domain-type
(fn [{:keys [db]} _]
{:db (-> (update-in db [:ens :custom-domain?] not)
(assoc-state :initial)
(assoc-username ""))}))

(handlers/register-handler-fx
:ens/on-registration-success
(fn [{:keys [db]} _]
{:db (assoc-state db :registered)
:dispatch [:navigate-back]}))

(handlers/register-handler-fx
:ens/on-registration-failure
(fn [{:keys [db]} _]
{:db (assoc-state db :registration-failed)}))

(defn- prepare-extension-transaction [{:keys [contract username address public-key]}]
(let [method "register(bytes32,address,bytes32,bytes32)"
{:keys [x y]} (ethereum/coordinates public-key)
data (abi-spec/encode method [(ethereum/sha3 username) address x y])]
{:to-name "Stateofus registrar"
:symbol :ETH
:method method
:amount (money/bignumber 0)
:to contract
:gas (money/bignumber 200000)
:data data
:on-result [:ens/on-registration-success]
:on-error [:ens/on-registration-failure]}))

(handlers/register-handler-fx
:ens/register
(fn [{db :db} [_ data]]
(let [transaction (prepare-extension-transaction data)]
;; Last argument is nil: no need to estimate gas
(wallet/open-modal-wallet-for-transaction db transaction nil))))
jeluard marked this conversation as resolved.
Show resolved Hide resolved
Loading