Skip to content

Commit

Permalink
feature #6843 - wallet redesign - qr code scanner and ens name support
Browse files Browse the repository at this point in the history
  • Loading branch information
goranjovic committed Jan 11, 2019
1 parent 580ec92 commit 5c51345
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 240 deletions.
5 changes: 2 additions & 3 deletions src/status_im/chat/commands/impl/transactions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
[status-im.utils.money :as money]
[status-im.utils.platform :as platform]
[status-im.ui.screens.wallet.db :as wallet.db]
[status-im.ui.screens.wallet.choose-recipient.events :as choose-recipient.events]
[status-im.ui.screens.currency-settings.subs :as currency-settings.subs]
[status-im.models.transactions :as wallet.transactions]
[status-im.ui.screens.navigation :as navigation]
Expand Down Expand Up @@ -313,8 +312,8 @@
:amount (money/formatted->internal value symbol decimals)
:amount-text amount
:amount-error error)
(choose-recipient.events/fill-request-details
(transaction-details recipient-contact symbol))
#_(choose-recipient.events/fill-request-details
(transaction-details recipient-contact symbol))
(update-in [:wallet :send-transaction]
dissoc :id :password :wrong-password?))
;; TODO(janherich) - refactor wallet send events, updating gas price
Expand Down
1 change: 0 additions & 1 deletion src/status_im/ui/screens/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
status-im.ui.screens.wallet.request.events
status-im.ui.screens.wallet.settings.events
status-im.ui.screens.wallet.transactions.events
status-im.ui.screens.wallet.choose-recipient.events
status-im.ui.screens.wallet.collectibles.cryptokitties.events
status-im.ui.screens.wallet.collectibles.cryptostrikers.events
status-im.ui.screens.wallet.collectibles.etheremon.events
Expand Down
10 changes: 4 additions & 6 deletions src/status_im/ui/screens/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
[status-im.ui.screens.wallet.send.views :as send.views
:refer [send-transaction send-transaction-modal sign-message-modal]]
[status-im.ui.screens.wallet.choose-recipient.views :refer [choose-recipient]]
[status-im.ui.screens.wallet.request.views :refer [request-transaction send-transaction-request]]
[status-im.ui.screens.wallet.request.views :refer [wallet-request-contacts-list request-transaction send-transaction-request]]
[status-im.ui.screens.wallet.components.views :as wallet.components]
[status-im.ui.screens.wallet.onboarding.views :as wallet.onboarding]
[status-im.ui.screens.wallet.transaction-fee.views :as wallet.transaction-fee]
[status-im.ui.screens.wallet.settings.views :as wallet-settings]
[status-im.ui.screens.wallet.transactions.views :as wallet-transactions]
[status-im.ui.screens.wallet.transaction-sent.views :refer [transaction-sent transaction-sent-modal]]
[status-im.ui.screens.wallet.components.views :refer [contact-code recent-recipients recipient-qr-code]]
[status-im.ui.screens.wallet.components.views :refer [recipient-qr-code]]
[status-im.ui.screens.network-settings.views :refer [network-settings]]
[status-im.ui.screens.network-settings.network-details.views :refer [network-details]]
[status-im.ui.screens.network-settings.edit-network.views :refer [edit-network]]
Expand Down Expand Up @@ -228,9 +228,8 @@
:collectibles-list collectibles-list
:wallet-onboarding-setup wallet.onboarding/screen
:wallet-send-transaction-chat send-transaction
:contact-code contact-code
:send-transaction-stack {:screens {:wallet-send-transaction send-transaction
:recent-recipients recent-recipients
:recent-recipients wallet-request-contacts-list
:wallet-transaction-sent transaction-sent
:recipient-qr-code recipient-qr-code
:wallet-choose-amount send.views/choose-amount-token
Expand All @@ -241,7 +240,7 @@
:request-transaction-stack {:screens {:wallet-request-transaction request-transaction
:wallet-send-transaction-request send-transaction-request
:wallet-request-assets wallet.components/request-assets
:recent-recipients recent-recipients}
:recent-recipients wallet-request-contacts-list}
:config {:headerMode "none"}}
:unsigned-transactions wallet-transactions/transactions
:transactions-history wallet-transactions/transactions
Expand Down Expand Up @@ -355,7 +354,6 @@
:add-participants-toggle-list add-participants-toggle-list
:contact-toggle-list contact-toggle-list
:group-chat-profile profile.group-chat/group-chat-profile
:contact-code contact-code
[react/view [react/text (str "Unknown view: " view-id)]]))

(defonce rand-label (rand/id))
Expand Down
119 changes: 0 additions & 119 deletions src/status_im/ui/screens/wallet/choose_recipient/events.cljs

This file was deleted.

25 changes: 17 additions & 8 deletions src/status_im/ui/screens/wallet/choose_recipient/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@
[status-im.ui.components.toolbar.actions :as actions]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.screens.wallet.choose-recipient.styles :as styles]
[status-im.utils.platform :as platform]))
[status-im.utils.platform :as platform]
[status-im.utils.dimensions :as dimensions]
[reagent.core :as reagent]))

(defn toggle-flashlight [old-value]
(if (= :off old-value)
:on
:off))

(defn- toolbar-view [camera-flashlight]
[toolbar/toolbar styles/toolbar
[toolbar/nav-button (actions/back-white actions/default-handler)]
[toolbar/content-title {:color :white}
(i18n/label :t/wallet-choose-recipient)]
[toolbar/actions [{:icon (if (= :on camera-flashlight)
[toolbar/actions [{:icon (if (= :on @camera-flashlight)
:icons/flash-active
:icons/flash-inactive)
:icon-opts {:color :white}
:handler #(re-frame/dispatch [:wallet/toggle-flashlight])}]]])
:handler #(swap! camera-flashlight toggle-flashlight)}]]])

(defn- viewfinder [{:keys [height width]} size]
(let [height (cond-> height
Expand All @@ -44,9 +51,10 @@
(int (* 2 (/ (min height width) 3))))

(defview choose-recipient []
(letsubs [read-once? (atom false)
dimensions [:dimensions/window]
camera-flashlight [:wallet.send/camera-flashlight]]
(letsubs [{:keys [on-recipient]} [:get-screen-params :recipient-qr-code]
camera-flashlight (reagent/atom :off) ;; values are :off and :on
read-once? (atom false)
dimensions (dimensions/window)]
[react/view {:style styles/qr-code}
[status-bar/status-bar {:type :transparent}]
[toolbar-view camera-flashlight]
Expand All @@ -60,10 +68,11 @@
[camera/camera {:style styles/preview
:aspect :fill
:captureAudio false
:torchMode (camera/set-torch camera-flashlight)
:torchMode (camera/set-torch @camera-flashlight)
:onBarCodeRead #(when-not @read-once?
(reset! read-once? true)
(re-frame/dispatch [:wallet/fill-request-from-url (camera/get-qr-code-data %) :qr]))}]]
(on-recipient (camera/get-qr-code-data %))
(re-frame/dispatch [:navigate-back]))}]]
[viewfinder dimensions (size dimensions)]]
[bottom-buttons/bottom-button
[button/button {:disabled? false
Expand Down
4 changes: 0 additions & 4 deletions src/status_im/ui/screens/wallet/components/styles.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@
(def recipient-no-address
{:color colors/white-transparent})

(def recent-recipients
{:flex 1
:background-color colors/white})

(def wallet-value-container
{:flex 1
:flex-direction :row})
Expand Down
41 changes: 0 additions & 41 deletions src/status_im/ui/screens/wallet/components/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -199,47 +199,6 @@
:accessibility-label (if request? :contact-address-text :recipient-address-text)}
(ethereum/normalized-address address)]]])))

(defn render-contact [contact]
[list/touchable-item #(re-frame/dispatch [:wallet/fill-request-from-contact contact])
[list/item
[photos/photo (:photo-path contact) {:size list.styles/image-size}]
[list/item-content
[list/item-primary {:accessibility-label :contact-name-text}
(:name contact)]
[react/text {:style list.styles/secondary-text
:accessibility-label :contact-address-text}
(ethereum/normalized-address (:address contact))]]]])

(views/defview recent-recipients []
(views/letsubs [contacts [:contacts/all-added-people-contacts]]
[simple-screen
[toolbar (i18n/label :t/recipient)]
[react/view styles/recent-recipients
[list/flat-list {:data contacts
:key-fn :address
:render-fn render-contact}]]]))

(defn contact-code []
(let [content (reagent/atom nil)]
(fn []
[simple-screen {:avoid-keyboard? true}
[toolbar {:style wallet.styles/toolbar-bottom-line}
default-action
(i18n/label :t/recipient)]
[react/view components.styles/flex
[cartouche {}
(i18n/label :t/recipient)
[text-input {:multiline true
:style styles/contact-code-text-input
:placeholder (i18n/label :t/recipient-code)
:on-change-text #(reset! content %)
:accessibility-label :recipient-address-input}]]
[bottom-buttons/bottom-button
[button/button {:disabled? (string/blank? @content)
:on-press #(re-frame/dispatch [:wallet.send/set-recipient @content])
:fit-to-text? false}
(i18n/label :t/done)]]]])))

(defn recipient-qr-code []
[choose-recipient/choose-recipient])

Expand Down
30 changes: 29 additions & 1 deletion src/status_im/ui/screens/wallet/request/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,35 @@
[status-im.chat.models :as chat-model]
[status-im.chat.commands.sending :as commands-sending]
[status-im.utils.fx :as fx]
[status-im.utils.money :as money]))
[status-im.utils.money :as money]
[status-im.contact.db :as contact.db]
[status-im.utils.ethereum.core :as ethereum]))

(defn- find-address-name [db address]
(:name (contact.db/find-contact-by-address (:contacts/contacts db) address)))

(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice public-key from-chat?]}]
{:pre [(not (nil? address))]}
(let [name (or name (find-address-name db address))]
(update-in
db [:wallet :request-transaction]
(fn [{old-symbol :symbol :as old-transaction}]
(let [symbol-changed? (not= old-symbol symbol)]
(cond-> (assoc old-transaction :to address :to-name name :public-key public-key)
value (assoc :amount value)
symbol (assoc :symbol symbol)
(and gas symbol-changed?) (assoc :gas (money/bignumber gas))
from-chat? (assoc :from-chat? from-chat?)
(and gasPrice symbol-changed?)
(assoc :gas-price (money/bignumber gasPrice))
(and symbol (not gasPrice) symbol-changed?)
(assoc :gas-price (ethereum/estimate-gas symbol))))))))

(handlers/register-handler-fx
:wallet/fill-request-from-contact
(fn [{db :db} [_ {:keys [address name public-key]}]]
{:db (fill-request-details db {:address address :name name :public-key public-key})
:dispatch [:navigate-back]}))

(handlers/register-handler-fx
:wallet-send-request
Expand Down
Loading

0 comments on commit 5c51345

Please sign in to comment.