Skip to content

Commit

Permalink
ENS now resolves from QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Nov 2, 2019
1 parent e9f70d2 commit 72fd6c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/status_im/ui/screens/wallet/components/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
[status-im.ui.screens.wallet.choose-recipient.views
:as
choose-recipient]
[status-im.ethereum.ens :as ens]
[status-im.ui.screens.wallet.components.styles :as styles]
[status-im.wallet.utils :as wallet.utils]
[status-im.utils.core :as utils.core]
Expand Down Expand Up @@ -162,10 +163,12 @@
(defn- recipient-address [address modal?]
[react/text {:style (merge styles/recipient-address (when-not address styles/recipient-no-address))
:accessibility-label :recipient-address-text}
(or (eip55/address->checksum (ethereum/normalized-address address))
(if modal?
(i18n/label :t/new-contract)
(i18n/label :t/specify-recipient)))])
(if (ens/is-valid-eth-name? address)
address
(or (eip55/address->checksum (ethereum/normalized-address address))
(if modal?
(i18n/label :t/new-contract)
(i18n/label :t/specify-recipient))))])

(views/defview recipient-contact [address name request?]
(views/letsubs [contact [:contacts/contact-by-address address]]
Expand Down Expand Up @@ -286,7 +289,7 @@
[react/view {:accessibility-label :choose-recipient-button}
(if name
[recipient-contact address name request?]
[recipient-address address modal?])]])
(if (= address nil) [recipient-address address modal?] [#(re-frame/dispatch [:wallet.send/set-recipient-2 address])]))]])

(defn amount-input [{:keys [input-options amount amount-text disabled?]}
{:keys [symbol decimals]}]
Expand Down
19 changes: 18 additions & 1 deletion src/status_im/wallet/choose_recipient/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
(fn [{old-symbol :symbol :as old-transaction}]
(let [symbol-changed? (not= old-symbol symbol)]
(cond-> (assoc old-transaction :to address :to-name name :public-key public-key)
(ens/is-valid-eth-name? address) (assoc :to (ens/get-addr :mainnet address nil))
value (assoc :amount value)
symbol (assoc :symbol symbol)
(and gas symbol-changed?) (assoc :gas (money/bignumber gas))
Expand Down Expand Up @@ -91,6 +90,24 @@
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})}))
{:ui/show-error (i18n/label :t/wallet-invalid-address {:data recipient})}))))

(fx/defn set-recipient-from-qr
{:events [:wallet.send/set-recipient-qr]}
[{:keys [db]} recipient]
(let [chain (ethereum/chain-keyword db)]
(if (ens/is-valid-eth-name? recipient)
{:resolve-address {:registry (get ens/ens-registries chain)
:ens-name recipient
:cb #(re-frame/dispatch [:wallet.send/set-recipient-2 %])}}
(if (ethereum/address? recipient)
(let [checksum (eip55/address->checksum recipient)]
(if (eip55/valid-address-checksum? checksum)
{:db (-> db
(assoc-in [:wallet :send-transaction :to] checksum)
(assoc-in [:wallet :send-transaction :to-name] nil))
}
{:ui/show-error (i18n/label :t/wallet-invalid-address-checksum {:data recipient})}))
{:ui/show-error (i18n/label :t/wallet-invalid-address {:data recipient})}))))

(fx/defn fill-request-from-url
{:events [:wallet/fill-request-from-url]}
[{{:networks/keys [current-network] :wallet/keys [all-tokens] :as db} :db} data origin]
Expand Down

0 comments on commit 72fd6c8

Please sign in to comment.