Fixes #1222 Do not crash when sharing null address.

This commit is contained in:
Julien Eluard 2017-05-21 09:08:49 +02:00 committed by Roman Volosovskyi
parent 3bc19e69b1
commit 9c6e5e4984
2 changed files with 15 additions and 12 deletions

View File

@ -6,14 +6,16 @@
[status-im.utils.platform :refer [platform-specific]] [status-im.utils.platform :refer [platform-specific]]
[status-im.i18n :refer [label]])) [status-im.i18n :refer [label]]))
(defn open [opts] (defn open-share [content]
(.share sharing (clj->js opts))) (when (or (:message content)
(:url content))
(.share sharing (clj->js content))))
(defn share-options [text] (defn share-options [text]
[{:text (label :t/sharing-copy-to-clipboard) [{:text (label :t/sharing-copy-to-clipboard)
:value #(copy-to-clipboard text)} :value #(copy-to-clipboard text)}
{:text (label :t/sharing-share) {:text (label :t/sharing-share)
:value #(open {:message text})}]) :value #(open-share {:message text})}])
(defn share [text dialog-title] (defn share [text dialog-title]
(let [list-selection-fn (:list-selection-fn platform-specific)] (let [list-selection-fn (:list-selection-fn platform-specific)]
@ -22,7 +24,7 @@
:callback (fn [index] :callback (fn [index]
(case index (case index
0 (copy-to-clipboard text) 0 (copy-to-clipboard text)
1 (open {:message text}) 1 (open-share {:message text})
:default)) :default))
:cancel-text (label :t/sharing-cancel)}))) :cancel-text (label :t/sharing-cancel)})))

View File

@ -106,24 +106,25 @@
#(dispatch [:navigate-to-modal :qr-code-view {:contact contact #(dispatch [:navigate-to-modal :qr-code-view {:contact contact
:qr-source qr-source}])) :qr-source qr-source}]))
(defn profile-options [contact k text]
(into []
(concat [{:value (show-qr contact k)
:text (label :t/show-qr)}]
(when text
(share-options text)))))
(defn profile-info-address-item [{:keys [address] :as contact}] (defn profile-info-address-item [{:keys [address] :as contact}]
[profile-info-item [profile-info-item
{:label (label :t/address) {:label (label :t/address)
:value address :value address
:options (into [] :options (profile-options contact :address address)
(concat [{:value (show-qr contact :address)
:text (label :t/show-qr)}]
(share-options address)))
:text-mode :middle}]) :text-mode :middle}])
(defn profile-info-public-key-item [public-key contact] (defn profile-info-public-key-item [public-key contact]
[profile-info-item [profile-info-item
{:label (label :t/public-key) {:label (label :t/public-key)
:value public-key :value public-key
:options (into [] :options (profile-options contact :public-key public-key)
(concat [{:value (show-qr contact :public-key)
:text (label :t/show-qr)}]
(share-options public-key)))
:text-mode :middle}]) :text-mode :middle}])
(defn info-item-separator [] (defn info-item-separator []