From 21c92485365371ca9ca97028e42ee30ea2256f20 Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 28 Oct 2021 16:35:40 +0200 Subject: [PATCH] [#10142] Add possibility to select wallet for ENS names Signed-off-by: andrey --- src/status_im/ens/core.cljs | 14 ++++++++++--- src/status_im/subs.cljs | 26 +++++++++++++------------ src/status_im/ui/screens/ens/views.cljs | 20 ++++++++++++++++--- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/status_im/ens/core.cljs b/src/status_im/ens/core.cljs index 37db1038e2..d217e1eb79 100644 --- a/src/status_im/ens/core.cljs +++ b/src/status_im/ens/core.cljs @@ -15,7 +15,8 @@ [status-im.utils.datetime :as datetime] [status-im.utils.fx :as fx] [status-im.utils.money :as money] - [status-im.utils.random :as random])) + [status-im.utils.random :as random] + [status-im.bottom-sheet.core :as bottom-sheet])) (defn fullname [custom-domain? username] (if custom-domain? @@ -165,10 +166,9 @@ (fx/defn register-name {:events [::register-name-pressed]} [{:keys [db] :as cofx}] - (let [{:keys [custom-domain? username]} + (let [{:keys [custom-domain? username address]} (:ens/registration db) {:keys [public-key]} (:multiaccount db) - address (ethereum/default-address db) chain (ethereum/chain-keyword db) chain-id (ethereum/chain-id db) amount (registration-cost chain-id) @@ -180,6 +180,7 @@ cofx {:contract (contracts/get-address db :status/snt) :method "approveAndCall(address,uint256,bytes)" + :from address :params [contract (money/unit->token amount 18) (abi-spec/encode "register(bytes32,address,bytes32,bytes32)" @@ -250,6 +251,13 @@ (update :ens/registration dissoc :username :state) (update-in [:ens/registration :custom-domain?] not))})) +(fx/defn change-address + {:events [::change-address]} + [{:keys [db] :as cofx} _ {:keys [address]}] + (fx/merge cofx + {:db (assoc-in db [:ens/registration :address] address)} + (bottom-sheet/hide-bottom-sheet))) + (fx/defn save-preferred-name {:events [::save-preferred-name]} [{:keys [db] :as cofx} name] diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 70edbfb770..8b3ee30835 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -2612,18 +2612,20 @@ :<- [:multiaccount/default-account] :<- [:multiaccount/public-key] :<- [:chain-id] - :<- [:balance-default] - (fn [[{:keys [custom-domain? username]} - chain default-account public-key chain-id balance]] - {:address (ethereum/normalized-hex (:address default-account)) - :username username - :public-key public-key - :custom-domain? custom-domain? - :chain chain - :amount-label (ens-amount-label chain-id) - :sufficient-funds? (money/sufficient-funds? - (money/formatted->internal (money/bignumber 10) (ethereum/chain-keyword->snt-symbol chain) 18) - (get balance (ethereum/chain-keyword->snt-symbol chain)))})) + :<- [: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? + (money/formatted->internal (money/bignumber 10) (ethereum/chain-keyword->snt-symbol chain) 18) + (get balance (ethereum/chain-keyword->snt-symbol chain)))}))) (re-frame/reg-sub :ens/confirmation-screen diff --git a/src/status_im/ui/screens/ens/views.cljs b/src/status_im/ui/screens/ens/views.cljs index d6a84c91cf..b415950abd 100644 --- a/src/status_im/ui/screens/ens/views.cljs +++ b/src/status_im/ui/screens/ens/views.cljs @@ -23,7 +23,10 @@ [status-im.utils.debounce :as debounce] [clojure.string :as string] [status-im.ethereum.tokens :as tokens] - [quo.core :as quo]) + [quo.core :as quo] + [status-im.ui.components.chat-icon.screen :as chat-icon] + [status-im.utils.utils :as utils] + [status-im.ui.screens.wallet.send.sheets :as sheets]) (:require-macros [status-im.utils.views :as views])) (defn- link @@ -261,11 +264,22 @@ "\n" (i18n/label :t/ens-understand)]]) +(defn render-account [address] + (let [account @(re-frame/subscribe [:account-by-address address])] + [quo/list-item + {:icon [chat-icon/custom-icon-view-list (:name account) (:color account)] + :title (:name account) + :subtitle (utils/get-shortened-checksum-address (:address account)) + :chevron true + :on-press #(re-frame/dispatch [:bottom-sheet/show-sheet + {:content (fn [] [sheets/accounts-list :from ::ens/change-address])}])}])) + (defn- registration [checked contract address public-key] [react/view {:style {:flex 1 :margin-top 24}} - [section {:title (i18n/label :t/wallet-address) - :content address}] + [react/text {:style {:color colors/gray :font-size 15 :margin-horizontal 16}} + (i18n/label :t/wallet)] + [render-account address] [react/view {:style {:margin-top 14}} [section {:title (i18n/label :t/key) :content public-key}]]