[#2884] added name lookup for recipient after qr code scanning, moved address comparision function to utils.ethereum namespace, address= will now expect address to be passed (instead of contact)

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
karol 2018-10-17 19:07:14 +02:00 committed by Goran Jovic
parent e09476f5d3
commit 18b4bf590c
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
4 changed files with 34 additions and 26 deletions

View File

@ -1,7 +1,6 @@
(ns status-im.contact.subs (ns status-im.contact.subs
(:require [re-frame.core :refer [reg-sub subscribe]] (:require [re-frame.core :refer [reg-sub subscribe]]
[status-im.utils.contacts :as utils.contacts] [status-im.utils.contacts :as utils.contacts]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.identicon :as identicon])) [status-im.utils.identicon :as identicon]))
(reg-sub :get-current-contact-identity :contacts/identity) (reg-sub :get-current-contact-identity :contacts/identity)
@ -149,19 +148,10 @@
:else :else
(identicon/identicon chat-id))))) (identicon/identicon chat-id)))))
(defn- address= [{:keys [address] :as contact} s]
(when (and address (= (ethereum/normalized-address s)
(ethereum/normalized-address address)))
contact))
(defn- contact-by-address [[_ contact] s]
(when (address= contact s)
contact))
(reg-sub :get-contact-by-address (reg-sub :get-contact-by-address
:<- [:get-contacts] :<- [:get-contacts]
(fn [contacts [_ address]] (fn [contacts [_ address]]
(some #(contact-by-address % address) contacts))) (utils.contacts/find-contact-by-address contacts address)))
(reg-sub :get-contacts-by-address (reg-sub :get-contacts-by-address
:<- [:get-contacts] :<- [:get-contacts]

View File

@ -6,7 +6,8 @@
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.money :as money] [status-im.utils.money :as money]
[status-im.utils.ethereum.ens :as ens] [status-im.utils.ethereum.ens :as ens]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[status-im.utils.contacts :as utils.contacts]))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/toggle-flashlight :wallet/toggle-flashlight
@ -15,21 +16,25 @@
toggled-state (if (= :on flashlight-state) :off :on)] toggled-state (if (= :on flashlight-state) :off :on)]
{:db (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)}))) {:db (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)})))
(defn- find-address-name [db address]
(:name (utils.contacts/find-contact-by-address (:contacts/contacts db) address)))
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice whisper-identity from-chat?]}] (defn- fill-request-details [db {:keys [address name value symbol gas gasPrice whisper-identity from-chat?]}]
{:pre [(not (nil? address))]} {:pre [(not (nil? address))]}
(update-in (let [name (or name (find-address-name db address))]
db [:wallet :send-transaction] (update-in
(fn [{old-symbol :symbol :as old-transaction}] db [:wallet :send-transaction]
(let [symbol-changed? (not= old-symbol symbol)] (fn [{old-symbol :symbol :as old-transaction}]
(cond-> (assoc old-transaction :to address :to-name name :whisper-identity whisper-identity) (let [symbol-changed? (not= old-symbol symbol)]
value (assoc :amount value) (cond-> (assoc old-transaction :to address :to-name name :whisper-identity whisper-identity)
symbol (assoc :symbol symbol) value (assoc :amount value)
(and gas symbol-changed?) (assoc :gas (money/bignumber gas)) symbol (assoc :symbol symbol)
from-chat? (assoc :from-chat? from-chat?) (and gas symbol-changed?) (assoc :gas (money/bignumber gas))
(and gasPrice symbol-changed?) from-chat? (assoc :from-chat? from-chat?)
(assoc :gas-price (money/bignumber gasPrice)) (and gasPrice symbol-changed?)
(and symbol (not gasPrice) symbol-changed?) (assoc :gas-price (money/bignumber gasPrice))
(assoc :gas-price (ethereum/estimate-gas symbol))))))) (and symbol (not gasPrice) symbol-changed?)
(assoc :gas-price (ethereum/estimate-gas symbol))))))))
(defn- extract-details (defn- extract-details
"First try to parse as EIP681 URI, if not assume this is an address directly. "First try to parse as EIP681 URI, if not assume this is an address directly.

View File

@ -1,7 +1,8 @@
(ns status-im.utils.contacts (ns status-im.utils.contacts
(:require [status-im.js-dependencies :as js-dependencies] (:require [status-im.js-dependencies :as js-dependencies]
[status-im.utils.identicon :as identicon] [status-im.utils.identicon :as identicon]
[status-im.utils.gfycat.core :as gfycat])) [status-im.utils.gfycat.core :as gfycat]
[status-im.utils.ethereum.core :as ethereum]))
(defn whisper-id->new-contact [whisper-id] (defn whisper-id->new-contact [whisper-id]
{:name (gfycat/generate-gfy whisper-id) {:name (gfycat/generate-gfy whisper-id)
@ -17,3 +18,10 @@
nil)] nil)]
(when normalized-key (when normalized-key
(subs (.sha3 js-dependencies/Web3.prototype normalized-key #js {:encoding "hex"}) 26)))) (subs (.sha3 js-dependencies/Web3.prototype normalized-key #js {:encoding "hex"}) 26))))
(defn- contact-by-address [[_ contact] address]
(when (ethereum/address= (:address contact) address)
contact))
(defn find-contact-by-address [contacts address]
(some #(contact-by-address % address) contacts))

View File

@ -171,3 +171,8 @@
(if-not error (if-not error
(cb (js->clj result :keywordize-keys true)) (cb (js->clj result :keywordize-keys true))
(handle-error error))))) (handle-error error)))))
(defn address= [address1 address2]
(and address1 address2
(= (normalized-address address1)
(normalized-address address2))))