From eea4eeb5492be16ff4d8a10d946040276907ac39 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Tue, 17 Oct 2017 16:12:44 +0200 Subject: [PATCH] [BUG #2189] Do not clear user set amount when scanning QR code --- .../ui/screens/wallet/choose_recipient/events.cljs | 5 ++++- src/status_im/ui/screens/wallet/request/views.cljs | 2 +- src/status_im/utils/eip/eip67.cljs | 8 ++++++-- test/cljs/status_im/test/runner.cljs | 2 ++ test/cljs/status_im/test/utils/eip/eip67.cljs | 3 +++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/status_im/ui/screens/wallet/choose_recipient/events.cljs b/src/status_im/ui/screens/wallet/choose_recipient/events.cljs index 7dd7a320ae..1270f9b027 100644 --- a/src/status_im/ui/screens/wallet/choose_recipient/events.cljs +++ b/src/status_im/ui/screens/wallet/choose_recipient/events.cljs @@ -11,7 +11,10 @@ (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)))) (defn choose-address-and-name [db address name amount] - (update-in db [:wallet :send-transaction] assoc :to-address address :to-name name :amount amount)) + (update-in + db [:wallet :send-transaction] + #(cond-> (assoc % :to-address address :to-name name) + amount (assoc :amount amount)))) (defn- extract-details "First try to parse as EIP67 URI, if not assume this is an address directly. diff --git a/src/status_im/ui/screens/wallet/request/views.cljs b/src/status_im/ui/screens/wallet/request/views.cljs index bf68e19308..d26c851ef5 100644 --- a/src/status_im/ui/screens/wallet/request/views.cljs +++ b/src/status_im/ui/screens/wallet/request/views.cljs @@ -32,7 +32,7 @@ (views/defview qr-code [amount] (views/letsubs [account [:get-current-account]] [components.qr-code/qr-code - {:value (eip67/generate-uri (:address account) {:value amount}) + {:value (eip67/generate-uri (:address account) (when amount {:value amount})) :size 256}])) (views/defview request-transaction [] diff --git a/src/status_im/utils/eip/eip67.cljs b/src/status_im/utils/eip/eip67.cljs index 3890380e4a..b9e1272fac 100644 --- a/src/status_im/utils/eip/eip67.cljs +++ b/src/status_im/utils/eip/eip67.cljs @@ -32,9 +32,13 @@ (str (name k) key-value-separator v)))) (defn generate-uri - "Generate a EIP 67 URI based on `address` and an optional map of extra properties. + "Generate a EIP 67 URI based on `address` and an optional map (keyword, string) of extra properties. No validation of address format is performed." ([address] (generate-uri address nil)) ([address m] (when address - (str scheme scheme-separator address (when m (str parameters-separator (generate-parameter-string m))))))) \ No newline at end of file + (let [parameters (into {} (filter second m))] ;; filter nil values + (str scheme scheme-separator address + (when-not (empty? parameters) + (str parameters-separator (generate-parameter-string parameters)))))))) + diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index a176803621..ca69a85fa0 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -12,6 +12,7 @@ [status-im.test.utils.utils] [status-im.test.utils.money] [status-im.test.utils.clocks] + [status-im.test.utils.eip.eip67] [status-im.test.utils.erc20] [status-im.test.utils.random] [status-im.test.utils.gfycat.core] @@ -38,6 +39,7 @@ 'status-im.test.utils.utils 'status-im.test.utils.money 'status-im.test.utils.clocks + 'status-im.test.utils.eip.eip67 'status-im.test.utils.erc20 'status-im.test.utils.random 'status-im.test.utils.gfycat.core diff --git a/test/cljs/status_im/test/utils/eip/eip67.cljs b/test/cljs/status_im/test/utils/eip/eip67.cljs index de64b74d80..9dc2717428 100644 --- a/test/cljs/status_im/test/utils/eip/eip67.cljs +++ b/test/cljs/status_im/test/utils/eip/eip67.cljs @@ -14,5 +14,8 @@ (deftest generate-uri (is (= nil (eip67/generate-uri nil))) (is (= "ethereum:0x1234" (eip67/generate-uri "0x1234"))) + (is (= "ethereum:0x1234" (eip67/generate-uri "0x1234" nil))) + (is (= "ethereum:0x1234" (eip67/generate-uri "0x1234" {}))) + (is (= "ethereum:0x1234" (eip67/generate-uri "0x1234" {:to nil}))) (is (= "ethereum:0x1234?to=0x5678" (eip67/generate-uri "0x1234" {:to "0x5678"}))) (is (= "ethereum:0x1234?to=0x5678&value=1" (eip67/generate-uri "0x1234" {:to "0x5678" :value 1})))) \ No newline at end of file