2023-10-16 13:47:20 +00:00
|
|
|
(ns status-im.subs.ens
|
2023-10-16 22:03:18 +00:00
|
|
|
(:require
|
|
|
|
[clojure.string :as string]
|
|
|
|
[re-frame.core :as re-frame]
|
|
|
|
[status-im.ens.core :as ens]
|
|
|
|
[utils.address :as address]
|
|
|
|
[utils.ethereum.chain :as chain]
|
|
|
|
[utils.money :as money]))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/preferred-name
|
2023-06-28 11:48:34 +00:00
|
|
|
:<- [:profile/profile]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [multiaccount]
|
|
|
|
(:preferred-name multiaccount)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/search-screen
|
|
|
|
:<- [:ens/registration]
|
|
|
|
(fn [{:keys [custom-domain? username state]}]
|
|
|
|
{:state state
|
|
|
|
:username username
|
|
|
|
:custom-domain? custom-domain?}))
|
|
|
|
|
|
|
|
(defn- ens-amount-label
|
|
|
|
[chain-id]
|
|
|
|
(str (ens/registration-cost chain-id)
|
|
|
|
(case chain-id
|
|
|
|
3 " STT"
|
|
|
|
1 " SNT"
|
|
|
|
"")))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/checkout-screen
|
|
|
|
:<- [:ens/registration]
|
|
|
|
:<- [:chain-keyword]
|
|
|
|
:<- [:multiaccount/default-account]
|
|
|
|
:<- [:multiaccount/public-key]
|
|
|
|
:<- [:chain-id]
|
2023-10-19 11:50:55 +00:00
|
|
|
:<- [:wallet-legacy]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [[{:keys [custom-domain? username address]}
|
|
|
|
chain default-account public-key chain-id wallet]]
|
2023-09-27 09:57:51 +00:00
|
|
|
(let [address (or address (address/normalized-hex (:address default-account)))
|
2022-09-21 14:03:06 +00:00
|
|
|
balance (get-in wallet [:accounts address :balance])]
|
|
|
|
{:address address
|
|
|
|
:username username
|
|
|
|
:public-key public-key
|
|
|
|
:custom-domain? custom-domain?
|
|
|
|
:chain chain
|
|
|
|
:amount-label (ens-amount-label chain-id)
|
|
|
|
:sufficient-funds? (money/sufficient-funds?
|
2022-12-20 14:45:37 +00:00
|
|
|
(money/formatted->internal (money/bignumber 10)
|
2023-09-27 09:57:51 +00:00
|
|
|
(chain/chain-keyword->snt-symbol chain)
|
2022-12-20 14:45:37 +00:00
|
|
|
18)
|
2023-09-27 09:57:51 +00:00
|
|
|
(get balance (chain/chain-keyword->snt-symbol chain)))})))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/confirmation-screen
|
|
|
|
:<- [:ens/registration]
|
|
|
|
(fn [{:keys [username state]}]
|
2022-12-20 14:45:37 +00:00
|
|
|
{:state state
|
|
|
|
:username username}))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
2023-12-06 02:04:39 +00:00
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/current-names
|
|
|
|
:<- [:ens/names]
|
|
|
|
:<- [:chain-id]
|
|
|
|
(fn [[all-names chain-id]]
|
|
|
|
(get all-names chain-id)))
|
|
|
|
|
2022-09-21 14:03:06 +00:00
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens.name/screen
|
|
|
|
:<- [:get-screen-params :ens-name-details]
|
2023-12-06 02:04:39 +00:00
|
|
|
:<- [:ens/current-names]
|
2022-09-21 14:03:06 +00:00
|
|
|
(fn [[name ens]]
|
|
|
|
(let [{:keys [address public-key expiration-date releasable?]} (get ens name)
|
2022-12-20 14:45:37 +00:00
|
|
|
pending? (nil? address)]
|
2022-09-21 14:03:06 +00:00
|
|
|
(cond-> {:name name
|
|
|
|
:custom-domain? (not (string/ends-with? name ".stateofus.eth"))}
|
|
|
|
pending?
|
|
|
|
(assoc :pending? true)
|
|
|
|
(not pending?)
|
2022-12-20 14:45:37 +00:00
|
|
|
(assoc :address address
|
|
|
|
:public-key public-key
|
|
|
|
:releasable? releasable?
|
2022-09-21 14:03:06 +00:00
|
|
|
:expiration-date expiration-date)))))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens.main/screen
|
2023-12-06 02:04:39 +00:00
|
|
|
:<- [:ens/current-names]
|
2023-06-28 11:48:34 +00:00
|
|
|
:<- [:profile/profile]
|
2022-09-21 14:03:06 +00:00
|
|
|
:<- [:ens/preferred-name]
|
|
|
|
:<- [:ens/registrations]
|
|
|
|
(fn [[names multiaccount preferred-name registrations]]
|
2023-09-16 03:37:06 +00:00
|
|
|
(let [not-in-progress-names (reduce (fn [acc {:keys [username custom-domain?]}]
|
|
|
|
(let [full-name (ens/fullname custom-domain? username)]
|
|
|
|
(remove #(= % full-name) acc)))
|
|
|
|
(keys names)
|
|
|
|
(vals registrations))]
|
|
|
|
{:names not-in-progress-names
|
|
|
|
:profile/profile multiaccount
|
|
|
|
:preferred-name preferred-name
|
|
|
|
:registrations registrations})))
|