[#10142] Add possibility to select wallet for ENS names

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2021-10-28 16:35:40 +02:00
parent 9b3fb2ac69
commit 21c9248536
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
3 changed files with 42 additions and 18 deletions

View File

@ -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]

View File

@ -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

View File

@ -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}]]