2022-11-14 18:16:55 +00:00
|
|
|
(ns status-im2.subs.ens
|
2022-12-20 14:45:37 +00:00
|
|
|
(:require [clojure.string :as string]
|
|
|
|
[re-frame.core :as re-frame]
|
2022-09-21 14:03:06 +00:00
|
|
|
[status-im.ens.core :as ens]
|
|
|
|
[status-im.ethereum.core :as ethereum]
|
2022-12-20 14:45:37 +00:00
|
|
|
[status-im.utils.money :as money]))
|
2022-09-21 14:03:06 +00:00
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:multiaccount/usernames
|
|
|
|
:<- [:multiaccount]
|
|
|
|
(fn [multiaccount]
|
|
|
|
(:usernames multiaccount)))
|
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens/preferred-name
|
|
|
|
:<- [:multiaccount]
|
|
|
|
(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]
|
|
|
|
:<- [:wallet]
|
|
|
|
(fn [[{:keys [custom-domain? username address]}
|
|
|
|
chain default-account public-key chain-id wallet]]
|
|
|
|
(let [address (or address (ethereum/normalized-hex (:address default-account)))
|
|
|
|
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)
|
|
|
|
(ethereum/chain-keyword->snt-symbol chain)
|
|
|
|
18)
|
2022-09-21 14:03:06 +00:00
|
|
|
(get balance (ethereum/chain-keyword->snt-symbol chain)))})))
|
|
|
|
|
|
|
|
(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
|
|
|
|
|
|
|
(re-frame/reg-sub
|
|
|
|
:ens.name/screen
|
|
|
|
:<- [:get-screen-params :ens-name-details]
|
|
|
|
:<- [:ens/names]
|
|
|
|
(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
|
|
|
|
:<- [:multiaccount/usernames]
|
|
|
|
:<- [:multiaccount]
|
|
|
|
:<- [:ens/preferred-name]
|
|
|
|
:<- [:ens/registrations]
|
|
|
|
(fn [[names multiaccount preferred-name registrations]]
|
2022-12-20 14:45:37 +00:00
|
|
|
{:names names
|
|
|
|
:multiaccount multiaccount
|
|
|
|
:preferred-name preferred-name
|
|
|
|
:registrations registrations}))
|