Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add watch only address using qrcode #9898

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@
(or (not (ethereum/address? address))
(some #(when (= (:address %) address) %) accounts))))

(re-frame/reg-sub
:add-account-scanned-address
:<- [:add-account]
(fn [add-account]
(get add-account :scanned-address)))

;;CHAT ==============================================================================================================

(re-frame/reg-sub
Expand Down
24 changes: 20 additions & 4 deletions src/status_im/ui/screens/wallet/add_new/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[status-im.multiaccounts.db :as multiaccounts.db]
[status-im.ui.components.toolbar :as toolbar]
[status-im.ui.components.styles :as components.styles]
[status-im.ethereum.core :as ethereum]
[status-im.ui.components.topbar :as topbar]))
[status-im.ui.components.topbar :as topbar]
[status-im.utils.utils :as utils.utils]))

(defn add-account []
[react/view {:flex 1}
Expand Down Expand Up @@ -62,10 +62,25 @@
:padding-horizontal 16
:background-color colors/gray-lighter})

(defn- request-camera-permissions []
(let [options {:handler :wallet.add-new/qr-scanner-result}]
(re-frame/dispatch
[:request-permissions
{:permissions [:camera]
:on-allowed
#(re-frame/dispatch [:wallet.add-new/qr-scanner-allowed options])
:on-denied
#(utils.utils/set-timeout
(fn []
(utils.utils/show-popup (i18n/label :t/error)
(i18n/label :t/camera-access-error)))
50)}])))

(defview add-watch-account []
(letsubs [add-account-disabled? [:add-account-disabled?]]
(letsubs [add-account-disabled? [:add-account-disabled?]
add-account-scanned-address [:add-account-scanned-address]]
[react/keyboard-avoiding-view {:flex 1}
[topbar/topbar]
[topbar/topbar {:accessories [{:icon :qr :handler #(request-camera-permissions)}]}]
[react/view {:flex 1
:justify-content :space-between
:align-items :center :margin-horizontal 16}
Expand All @@ -78,6 +93,7 @@
[react/text-input {:auto-focus true
:multiline true
:text-align :center
:default-value add-account-scanned-address
:placeholder (i18n/label :t/enter-address)
:style {:typography :header :flex 1}
:on-change-text #(re-frame/dispatch [:set-in [:add-account :address] %])}]]]
Expand Down
15 changes: 15 additions & 0 deletions src/status_im/wallet/accounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[status-im.constants :as constants]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.eip55 :as eip55]
[status-im.ethereum.eip681 :as eip681]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.i18n :as i18n]
[status-im.multiaccounts.update.core :as multiaccounts.update]
Expand Down Expand Up @@ -169,3 +170,17 @@
:type :watch
:color (rand-nth colors/account-colors)})}
(navigation/navigate-to-cofx :account-added nil))))

(fx/defn view-only-qr-scanner-result
{:events [:wallet.add-new/qr-scanner-result]}
[{db :db :as cofx} data _]
(let [address (or (when (ethereum/address? data) data)
(:address (eip681/parse-uri data)))]
(fx/merge cofx
(merge {:db (-> db
(assoc-in [:add-account :scanned-address] address)
(assoc-in [:add-account :address] address))}
(when-not address
{:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/invalid-address-qr-code)}}))
(navigation/navigate-back))))
7 changes: 7 additions & 0 deletions src/status_im/wallet/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,13 @@
(bottom-sheet/hide-bottom-sheet)
(navigation/navigate-to-cofx :qr-scanner options)))

(fx/defn view-only-qr-scanner-allowed
{:events [:wallet.add-new/qr-scanner-allowed]}
[{:keys [db] :as cofx} options]
(fx/merge cofx
{:db (update-in db [:add-account] dissoc :address)}
(navigation/navigate-to-cofx :qr-scanner options)))

(fx/defn wallet-send-set-symbol
{:events [:wallet.send/set-symbol]}
[{:keys [db] :as cofx} symbol]
Expand Down
1 change: 1 addition & 0 deletions test/cljs/status_im/test/i18n.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@
:intro-wizard-title4
:intro-wizard-title5
:intro-wizard-title6
:invalid-address-qr-code
:invalid-extension
:invalid-format
:invalid-key-confirm
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@
"enter-recipient-address-or-username": "Enter address or username of the recepient",
"enter-seed-phrase": "Enter seed phrase",
"enter-url": "Enter URL",
"enter-watch-account-address": "Enter the address to watch",
"enter-watch-account-address": "Scan a QR code\nor\nenter the address to watch",
"enter-word": "Enter word",
"enter-your-code": "Enter your 6-digit passcode",
"enter-your-password": "Enter your password",
Expand Down Expand Up @@ -563,6 +563,7 @@
"intro-wizard-title6": "Enable notifications",
"are-you-sure-to-cancel": "Are you sure you want to cancel?",
"you-will-start-from-scratch": "You will start from scratch with a new set of keys",
"invalid-address-qr-code": "Scanned QR code doesn't contain a valid address",
"invalid-extension": "Invalid extension URI",
"invalid-format": "Invalid format\nMust be {{format}}",
"invalid-key-confirm": "Apply",
Expand Down