[#11189] Backward compatible ENS registrar
This commit is contained in:
parent
e52f6b8753
commit
9691626992
|
@ -69,8 +69,11 @@
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::get-expiration-time
|
::get-expiration-time
|
||||||
(fn [[registrar label-hash cb]]
|
(fn [[chain label-hash cb]]
|
||||||
(stateofus/get-expiration-time registrar label-hash cb)))
|
(stateofus/get-registrar
|
||||||
|
chain
|
||||||
|
(fn [registrar]
|
||||||
|
(stateofus/get-expiration-time registrar label-hash cb)))))
|
||||||
|
|
||||||
(fx/defn set-state
|
(fx/defn set-state
|
||||||
{:events [::name-resolved]}
|
{:events [::name-resolved]}
|
||||||
|
@ -166,19 +169,21 @@
|
||||||
address (ethereum/default-address db)
|
address (ethereum/default-address db)
|
||||||
chain (ethereum/chain-keyword db)
|
chain (ethereum/chain-keyword db)
|
||||||
chain-id (ethereum/chain-id db)
|
chain-id (ethereum/chain-id db)
|
||||||
contract (get stateofus/registrars chain)
|
|
||||||
amount (registration-cost chain-id)
|
amount (registration-cost chain-id)
|
||||||
{:keys [x y]} (ethereum/coordinates public-key)]
|
{:keys [x y]} (ethereum/coordinates public-key)]
|
||||||
(signing/eth-transaction-call
|
(stateofus/get-registrar
|
||||||
cofx
|
chain
|
||||||
{:contract (contracts/get-address db :status/snt)
|
(fn [contract]
|
||||||
:method "approveAndCall(address,uint256,bytes)"
|
(signing/eth-transaction-call
|
||||||
:params [contract
|
cofx
|
||||||
(money/unit->token amount 18)
|
{:contract (contracts/get-address db :status/snt)
|
||||||
(abi-spec/encode "register(bytes32,address,bytes32,bytes32)"
|
:method "approveAndCall(address,uint256,bytes)"
|
||||||
[(ethereum/sha3 username) address x y])]
|
:params [contract
|
||||||
:on-result [:update-ens-tx-state-and-redirect :submitted username custom-domain?]
|
(money/unit->token amount 18)
|
||||||
:on-error [::on-registration-failure]})))
|
(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]})))))
|
||||||
|
|
||||||
(defn- valid-custom-domain? [username]
|
(defn- valid-custom-domain? [username]
|
||||||
(and (ens/is-valid-eth-name? username)
|
(and (ens/is-valid-eth-name? username)
|
||||||
|
@ -280,11 +285,10 @@
|
||||||
{:events [::navigate-to-name]}
|
{:events [::navigate-to-name]}
|
||||||
[{:keys [db] :as cofx} username]
|
[{:keys [db] :as cofx} username]
|
||||||
(let [chain (ethereum/chain-keyword db)
|
(let [chain (ethereum/chain-keyword db)
|
||||||
registry (get ens/ens-registries chain)
|
registry (get ens/ens-registries chain)]
|
||||||
registrar (get stateofus/registrars chain)]
|
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{::get-expiration-time
|
{::get-expiration-time
|
||||||
[registrar
|
[chain
|
||||||
(-> username
|
(-> username
|
||||||
stateofus/username
|
stateofus/username
|
||||||
ethereum/sha3)
|
ethereum/sha3)
|
||||||
|
@ -317,4 +321,4 @@
|
||||||
(when (= name preferred-name)
|
(when (= name preferred-name)
|
||||||
(multiaccounts.update/multiaccount-update
|
(multiaccounts.update/multiaccount-update
|
||||||
:preferred-name (first new-names) {}))
|
:preferred-name (first new-names) {}))
|
||||||
(navigation/navigate-back))))
|
(navigation/navigate-back))))
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
(ns status-im.ethereum.stateofus
|
(ns status-im.ethereum.stateofus
|
||||||
(:require [clojure.string :as string]
|
(: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")
|
(def domain "stateofus.eth")
|
||||||
|
|
||||||
|
@ -24,12 +25,29 @@
|
||||||
(when (and name (string/ends-with? name domain))
|
(when (and name (string/ends-with? name domain))
|
||||||
(first (string/split name "."))))
|
(first (string/split name "."))))
|
||||||
|
|
||||||
(def registrars
|
(def old-registrars
|
||||||
{:mainnet "0xDB5ac1a559b02E12F29fC0eC0e37Be8E046DEF49"
|
{:mainnet "0xDB5ac1a559b02E12F29fC0eC0e37Be8E046DEF49"
|
||||||
;;NOTE: can be enabled for testing builds
|
;;NOTE: can be enabled for testing builds
|
||||||
;;:testnet "0x11d9F481effd20D76cEE832559bd9Aca25405841"
|
;;: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]
|
(defn lower-case? [s]
|
||||||
(when s
|
(when s
|
||||||
(= s (string/lower-case s))))
|
(= s (string/lower-case s))))
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
[status-im.contact.db :as contact.db]
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.ens.core :as ens]
|
[status-im.ens.core :as ens]
|
||||||
[status-im.ethereum.core :as ethereum]
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.ethereum.stateofus :as stateofus]
|
|
||||||
[status-im.ethereum.tokens :as tokens]
|
[status-im.ethereum.tokens :as tokens]
|
||||||
[status-im.ethereum.transactions.core :as transactions]
|
[status-im.ethereum.transactions.core :as transactions]
|
||||||
[status-im.fleet.core :as fleet]
|
[status-im.fleet.core :as fleet]
|
||||||
|
@ -2077,14 +2076,6 @@
|
||||||
(string/ends-with? screen-snt-amount ".")))))))))
|
(string/ends-with? screen-snt-amount ".")))))))))
|
||||||
|
|
||||||
;;ENS ==================================================================================================================
|
;;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
|
(re-frame/reg-sub
|
||||||
:multiaccount/usernames
|
:multiaccount/usernames
|
||||||
:<- [:multiaccount]
|
:<- [:multiaccount]
|
||||||
|
@ -2116,18 +2107,18 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:ens/checkout-screen
|
:ens/checkout-screen
|
||||||
:<- [:ens/registration]
|
:<- [:ens/registration]
|
||||||
:<- [:ens.stateofus/registrar]
|
:<- [:current-network]
|
||||||
:<- [:multiaccount/default-account]
|
:<- [:multiaccount/default-account]
|
||||||
:<- [:multiaccount/public-key]
|
:<- [:multiaccount/public-key]
|
||||||
:<- [:chain-id]
|
:<- [:chain-id]
|
||||||
:<- [:balance-default]
|
:<- [:balance-default]
|
||||||
(fn [[{:keys [custom-domain? username]}
|
(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))
|
{:address (ethereum/normalized-hex (:address default-account))
|
||||||
:username username
|
:username username
|
||||||
:public-key public-key
|
:public-key public-key
|
||||||
:custom-domain? custom-domain?
|
:custom-domain? custom-domain?
|
||||||
:contract registrar
|
:network network
|
||||||
:amount-label (ens-amount-label chain-id)
|
:amount-label (ens-amount-label chain-id)
|
||||||
:sufficient-funds? (money/sufficient-funds?
|
:sufficient-funds? (money/sufficient-funds?
|
||||||
(money/formatted->internal (money/bignumber 10) :SNT 18)
|
(money/formatted->internal (money/bignumber 10) :SNT 18)
|
||||||
|
|
|
@ -279,7 +279,7 @@
|
||||||
(let [checked? (reagent/atom false)]
|
(let [checked? (reagent/atom false)]
|
||||||
(fn []
|
(fn []
|
||||||
(let [{:keys [username address custom-domain? public-key
|
(let [{:keys [username address custom-domain? public-key
|
||||||
contract amount-label sufficient-funds?]}
|
network amount-label sufficient-funds?]}
|
||||||
@(re-frame/subscribe [:ens/checkout-screen])]
|
@(re-frame/subscribe [:ens/checkout-screen])]
|
||||||
[react/keyboard-avoiding-view {:flex 1}
|
[react/keyboard-avoiding-view {:flex 1}
|
||||||
[toolbar]
|
[toolbar]
|
||||||
|
@ -306,7 +306,7 @@
|
||||||
:typography :main-medium}}
|
:typography :main-medium}}
|
||||||
(domain-label custom-domain?)]
|
(domain-label custom-domain?)]
|
||||||
[react/view {:flex 1 :min-width 24}]]]
|
[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
|
[toolbar/toolbar
|
||||||
{:show-border? true
|
{:show-border? true
|
||||||
:size :large
|
:size :large
|
||||||
|
|
Loading…
Reference in New Issue