[#11189] Backward compatible ENS registrar

This commit is contained in:
Roman Volosovskyi 2020-10-20 17:13:42 +03:00
parent e52f6b8753
commit 9691626992
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 46 additions and 33 deletions

View File

@ -69,8 +69,11 @@
(re-frame/reg-fx
::get-expiration-time
(fn [[registrar label-hash cb]]
(stateofus/get-expiration-time registrar label-hash cb)))
(fn [[chain label-hash cb]]
(stateofus/get-registrar
chain
(fn [registrar]
(stateofus/get-expiration-time registrar label-hash cb)))))
(fx/defn set-state
{:events [::name-resolved]}
@ -166,9 +169,11 @@
address (ethereum/default-address db)
chain (ethereum/chain-keyword db)
chain-id (ethereum/chain-id db)
contract (get stateofus/registrars chain)
amount (registration-cost chain-id)
{:keys [x y]} (ethereum/coordinates public-key)]
(stateofus/get-registrar
chain
(fn [contract]
(signing/eth-transaction-call
cofx
{:contract (contracts/get-address db :status/snt)
@ -178,7 +183,7 @@
(abi-spec/encode "register(bytes32,address,bytes32,bytes32)"
[(ethereum/sha3 username) address x y])]
:on-result [:update-ens-tx-state-and-redirect :submitted username custom-domain?]
:on-error [::on-registration-failure]})))
:on-error [::on-registration-failure]})))))
(defn- valid-custom-domain? [username]
(and (ens/is-valid-eth-name? username)
@ -280,11 +285,10 @@
{:events [::navigate-to-name]}
[{:keys [db] :as cofx} username]
(let [chain (ethereum/chain-keyword db)
registry (get ens/ens-registries chain)
registrar (get stateofus/registrars chain)]
registry (get ens/ens-registries chain)]
(fx/merge cofx
{::get-expiration-time
[registrar
[chain
(-> username
stateofus/username
ethereum/sha3)

View File

@ -1,6 +1,7 @@
(ns status-im.ethereum.stateofus
(:require [clojure.string :as string]
[status-im.ethereum.json-rpc :as json-rpc]))
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.ens :as ens]))
(def domain "stateofus.eth")
@ -24,12 +25,29 @@
(when (and name (string/ends-with? name domain))
(first (string/split name "."))))
(def registrars
(def old-registrars
{:mainnet "0xDB5ac1a559b02E12F29fC0eC0e37Be8E046DEF49"
;;NOTE: can be enabled for testing builds
;;:testnet "0x11d9F481effd20D76cEE832559bd9Aca25405841"
})
(def registrars-cache (atom {}))
(defn get-registrar [chain callback]
(if-let [contract (get @registrars-cache chain)]
(callback contract)
(let [registry (get ens/ens-registries chain)]
(ens/get-owner
registry
domain
(fn [addr]
(let [addr (or addr (get old-registrars chain))]
(swap! registrars-cache assoc chain addr)
(callback addr)))))))
(defn get-cached-registrar [chain]
(get @registrars-cache chain))
(defn lower-case? [s]
(when s
(= s (string/lower-case s))))

View File

@ -10,7 +10,6 @@
[status-im.contact.db :as contact.db]
[status-im.ens.core :as ens]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.stateofus :as stateofus]
[status-im.ethereum.tokens :as tokens]
[status-im.ethereum.transactions.core :as transactions]
[status-im.fleet.core :as fleet]
@ -2077,14 +2076,6 @@
(string/ends-with? screen-snt-amount ".")))))))))
;;ENS ==================================================================================================================
(re-frame/reg-sub
:ens.stateofus/registrar
:<- [:current-network]
(fn [network]
(let [chain (ethereum/network->chain-keyword network)]
(get stateofus/registrars chain))))
(re-frame/reg-sub
:multiaccount/usernames
:<- [:multiaccount]
@ -2116,18 +2107,18 @@
(re-frame/reg-sub
:ens/checkout-screen
:<- [:ens/registration]
:<- [:ens.stateofus/registrar]
:<- [:current-network]
:<- [:multiaccount/default-account]
:<- [:multiaccount/public-key]
:<- [:chain-id]
:<- [:balance-default]
(fn [[{:keys [custom-domain? username]}
registrar default-account public-key chain-id balance]]
network default-account public-key chain-id balance]]
{:address (ethereum/normalized-hex (:address default-account))
:username username
:public-key public-key
:custom-domain? custom-domain?
:contract registrar
:network network
:amount-label (ens-amount-label chain-id)
:sufficient-funds? (money/sufficient-funds?
(money/formatted->internal (money/bignumber 10) :SNT 18)

View File

@ -279,7 +279,7 @@
(let [checked? (reagent/atom false)]
(fn []
(let [{:keys [username address custom-domain? public-key
contract amount-label sufficient-funds?]}
network amount-label sufficient-funds?]}
@(re-frame/subscribe [:ens/checkout-screen])]
[react/keyboard-avoiding-view {:flex 1}
[toolbar]
@ -306,7 +306,7 @@
:typography :main-medium}}
(domain-label custom-domain?)]
[react/view {:flex 1 :min-width 24}]]]
[registration checked? contract address public-key]]
[registration checked? (stateofus/get-cached-registrar network) address public-key]]
[toolbar/toolbar
{:show-border? true
:size :large