Allow to send transactions to non-contacts

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
This commit is contained in:
Andrea Maria Piana 2019-02-15 11:42:33 +01:00
parent dac323a3de
commit 9c6cce7d4d
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
8 changed files with 48 additions and 29 deletions

View File

@ -14,6 +14,7 @@
[status-im.ui.components.animation :as animation]
[status-im.ui.components.svgimage :as svgimage]
[status-im.i18n :as i18n]
[status-im.contact.db :as db.contact]
[status-im.constants :as constants]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.tokens :as tokens]
@ -296,7 +297,10 @@
protocol/Yielding
(yield-control [_ {{{amount :amount asset :asset} :params} :content} {:keys [db] :as cofx}]
;; Prefill wallet and navigate there
(let [recipient-contact (get-in db [:contacts/contacts (:current-chat-id db)])
(let [recipient-contact (or
(get-in db [:contacts/contacts (:current-chat-id db)])
(db.contact/public-key->new-contact (:current-chat-id db)))
sender-account (:account/account db)
chain (keyword (:chain db))
symbol-param (keyword asset)

View File

@ -63,17 +63,6 @@
(spec/def :contact/new-tag string?)
(spec/def :ui/contact (spec/keys :opt [:contact/new-tag]))
(defn public-key->new-contact [public-key]
{:name (gfycat/generate-gfy public-key)
:photo-path (identicon/identicon public-key)
:public-key public-key})
(defn public-key->contact
[contacts public-key]
(when public-key
(get contacts public-key
(public-key->new-contact public-key))))
(defn public-key->address [public-key]
(let [length (count public-key)
normalized-key (case length
@ -84,6 +73,18 @@
(when normalized-key
(subs (.sha3 js-dependencies/Web3.prototype normalized-key #js {:encoding "hex"}) 26))))
(defn public-key->new-contact [public-key]
{:name (gfycat/generate-gfy public-key)
:address (public-key->address public-key)
:photo-path (identicon/identicon public-key)
:public-key public-key})
(defn public-key->contact
[contacts public-key]
(when public-key
(get contacts public-key
(public-key->new-contact public-key))))
(defn- contact-by-address [[_ contact] address]
(when (ethereum/address= (:address contact) address)
contact))

View File

@ -67,9 +67,9 @@
:accessibility-label :chat-menu-button}
:handler #(on-options chat-id chat-name group-chat public?)}]])]
[connectivity/connectivity-view]
(when (and contact
(when (and (not group-chat)
(models.contact/can-add-to-contacts? contact))
[add-contact-bar (:public-key contact)])]))
[add-contact-bar chat-id])]))
(defmulti message-row (fn [{{:keys [type]} :row}] type))

View File

@ -17,14 +17,14 @@ execnet==1.4.1
future==0.16.0
idna==2.5
kiwisolver==1.0.1
lxml==3.8.0
lxml==4.3.1
matplotlib==2.2.2
multidict==3.1.3
namedlist==1.7
numpy==1.14.4
pbkdf2==1.3
Pillow==5.1.0
py==1.4.34
py==1.5.1
py-ecc==1.4.2
pycryptodome==3.6.1
pyethash==0.1.27
@ -35,7 +35,7 @@ pytest-forked==0.2
pytest-xdist==1.22.2
python-dateutil==2.7.3
pytz==2018.4
PyYAML==4.1
PyYAML==4.2b4
repoze.lru==0.7
requests==2.20.1
rlp==1.0.1
@ -48,4 +48,4 @@ urllib3==1.24
yarl==0.12.0
zbarlight==1.2
docker
influxdb
influxdb

View File

@ -68,7 +68,7 @@ class TestChatManagement(SingleDeviceTestCase):
@marks.testrail_id(5304)
@marks.critical
def test_add_contact_by_pasting_public_key(self):
def test_open_chat_by_pasting_public_key(self):
sign_in = SignInView(self.driver)
home = sign_in.create_user()
public_key = basic_user['public_key']
@ -87,10 +87,8 @@ class TestChatManagement(SingleDeviceTestCase):
pytest.fail('Public key is not pasted from clipboard')
start_new_chat.confirm()
start_new_chat.get_back_to_home_view()
home.plus_button.click()
start_new_chat.start_new_chat_button.click()
if not start_new_chat.element_by_text(basic_user['username']).is_element_displayed():
pytest.fail("List of contacts doesn't contain added user")
if not home.get_chat_with_user(basic_user['username']).is_element_present():
pytest.fail("No chat open in home view")
@marks.testrail_id(5387)
@marks.high

View File

@ -125,6 +125,7 @@ class HomeView(BaseView):
start_new_chat.public_key_edit_box.send_keys(public_key)
one_to_one_chat = self.get_chat_view()
start_new_chat.confirm_until_presence_of_element(one_to_one_chat.chat_message_input)
one_to_one_chat.add_to_contacts.click()
return one_to_one_chat
def start_1_1_chat(self, username):

View File

@ -4,13 +4,15 @@
[status-im.chat.commands.impl.transactions :as transactions]
[status-im.chat.commands.protocol :as protocol]))
(def public-key "0x04f96bc2229a0ba4125815451e47491d9ab923b8b03f205f6ff11d731c0f5759079c1aa0f3b73233c114372695c30a8e20ce18f73fafa23f924736cc39e726c3de")
(def address "f86b3cefae5851c19abfc48b7fb034b1dfa70b52")
(def cofx {:db {:account/account {:settings {:wallet {:visible-tokens {:mainnet #{:SNT}}}}
:wallet-set-up-passed? true}
:chain "mainnet"
:current-chat-id "recipient"
:contacts/contacts {"recipient" {:name "Recipient"
:address "0xAA"
:public-key "0xBB"}}
:current-chat-id public-key
:contacts/contacts {public-key {:name "Recipient"
:address address
:public-key public-key}}
:wallet/all-tokens {:mainnet {"0x744d70fdbe2ba4cf95131626614a1763df805b9e" {:address "0x744d70fdbe2ba4cf95131626614a1763df805b9e"
:name "Status Network Token"
:symbol :SNT
@ -44,6 +46,18 @@
(is (= (get-in fx [:db :wallet :send-transaction :amount-text]) "0.01"))
(is (= (get-in fx [:db :wallet :send-transaction :symbol]) :ETH)))))
(deftest from-contacts
(testing "the user is in our contacts"
(let [fx (protocol/yield-control personal-send-command {:content {:params {:asset "ETH" :amount "0.01"}}} cofx)]
(is (= (get-in fx [:db :wallet :send-transaction :to]) address))
(is (= (get-in fx [:db :wallet :send-transaction :to-name] "Recipient")))
(is (= (get-in fx [:db :wallet :send-transaction :public-key]) public-key)))
(testing "the user is not in our contacts"
(let [fx (protocol/yield-control personal-send-command {:content {:params {:asset "ETH" :amount "0.01"}}} (update-in cofx [:db :contacts/contacts] dissoc public-key))]
(is (= (get-in fx [:db :wallet :send-transaction :to]) address))
(is (= (get-in fx [:db :wallet :send-transaction :to-name]) "Plump Nippy Blobfish"))
(is (= (get-in fx [:db :wallet :send-transaction :public-key]) public-key))))))
;; testing the `/request` command
(def personal-request-command (transactions/PersonalRequestCommand.))

View File

@ -40,17 +40,18 @@
[{:name "Snappy Impressive Leonberger"
:photo-path "generated"
:admin? true
:public-key "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917"}
:address "71adb0644e2b590e37dafdfea8bd58f0c7668c7f"
:public-key "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917"}
{:name "User A"
:photo-path "photo2"
:public-key "0x048a2f8b80c60f89a91b4c1316e56f75b087f446e7b8701ceca06a40142d8efe1f5aa36bd0fee9e248060a8d5207b43ae98bef4617c18c71e66f920f324869c09f"}
{:description nil
:last-updated 0
:hide-contact? false
:address "eca8218b5ebeb2c47ba94c1b6e0a779d78fff7bc"
:name "User B"
:fcm-token nil
:photo-path "photo1"
:address "eca8218b5ebeb2c47ba94c1b6e0a779d78fff7bc"
:status nil
:blocked? false
:pending? true