Skip to content

Commit

Permalink
first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Nov 20, 2019
1 parent 8f62a60 commit 1edbe69
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 236 deletions.
14 changes: 14 additions & 0 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,11 @@
(fn []
(react/dismiss-keyboard!)))

(handlers/register-handler-fx
:dismiss-keyboard
(fn [_]
{:dismiss-keyboard nil}))

(handlers/register-handler-fx
:wallet-send-request
(fn [{:keys [db] :as cofx} [_ public-key amount symbol decimals]]
Expand All @@ -1586,3 +1591,12 @@
request-command
{:asset (name symbol)
:amount (str (money/internal->formatted amount symbol decimals))})))))

(handlers/register-handler-fx
:send-message-send-request
(fn [{:keys [db] :as cofx} [_ {:keys [from to amount-text]}]]
(let [{:keys [address]} from
{:keys [public-key]} to]
(fx/merge cofx
;;send request message
(bottom-sheet/hide-bottom-sheet)))))
27 changes: 18 additions & 9 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@
(reg-root-key-sub :prices-loading? :prices-loading?)
(reg-root-key-sub :wallet.transactions :wallet.transactions)
(reg-root-key-sub :wallet/custom-token-screen :wallet/custom-token-screen)
(reg-root-key-sub :wallet/prepare-transaction :wallet/prepare-transaction)

;;ethereum
(reg-root-key-sub :ethereum/current-block :ethereum/current-block)
Expand Down Expand Up @@ -488,6 +489,12 @@
(fn [[macc acc]]
(some #(when (= (:address %) (:address acc)) %) (:accounts macc))))

(re-frame/reg-sub
:account-by-address
:<- [:multiaccount]
(fn [macc [_ address]]
(some #(when (= (:address %) address) %) (:accounts macc))))

(re-frame/reg-sub
:multiple-multiaccounts?
:<- [:multiaccounts/multiaccounts]
Expand Down Expand Up @@ -2070,21 +2077,23 @@
(get-sufficient-gas-error balance nil nil gas gasPrice))))

(re-frame/reg-sub
:wallet.send/transaction
:<- [::send-transaction]
:wallet.send/prepare-transaction-with-balance
:<- [:wallet/prepare-transaction]
:<- [:wallet]
:<- [:offline?]
:<- [:wallet/all-tokens]
:<- [:ethereum/chain-keyword]
(fn [[{:keys [amount symbol from to amount-error] :as transaction}
(fn [[{:keys [amount symbol from to] :as transaction}
wallet offline? all-tokens chain]]
(let [balance (get-in wallet [:accounts from :balance])
token (tokens/asset-for all-tokens chain symbol)]
(assoc (merge transaction
(when amount
(get-sufficient-funds-error balance symbol amount)))
(let [balance (get-in wallet [:accounts (:address from) :balance])
token (tokens/asset-for all-tokens chain symbol)
{:keys [amount-error] :as transaction}
(merge transaction
(when amount
(get-sufficient-funds-error balance symbol amount)))]
(assoc transaction
:balance balance
:token token
:token (assoc token :amount (get balance (:symbol token)))
:sign-enabled? (and to
(nil? amount-error)
(not (nil? amount))
Expand Down
67 changes: 67 additions & 0 deletions src/status_im/ui/components/bottom_panel/views.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
(ns status-im.ui.components.bottom-panel.views
(:require-macros [status-im.utils.views :as views])
(:require [status-im.ui.components.react :as react]
[status-im.ui.components.animation :as anim]
[reagent.core :as reagent]))

(defn hide-panel-anim
[bottom-anim-value alpha-value window-height]
(anim/start
(anim/parallel
[(anim/spring bottom-anim-value {:toValue (- window-height)
:useNativeDriver true})
(anim/timing alpha-value {:toValue 0
:duration 500
:useNativeDriver true})])))

(defn show-panel-anim
[bottom-anim-value alpha-value]
(anim/start
(anim/parallel
[(anim/spring bottom-anim-value {:toValue 40
:useNativeDriver true})
(anim/timing alpha-value {:toValue 0.4
:duration 500
:useNativeDriver true})])))

(defn bottom-panel [obj render window-height]
(let [bottom-anim-value (anim/create-value window-height)
alpha-value (anim/create-value 0)
clear-timeout (atom nil)
update? (atom nil)
current-obj (reagent/atom nil)]
(reagent/create-class
{:component-will-update (fn [_ [_ obj _ _]]
(when @clear-timeout (js/clearTimeout @clear-timeout))
(when (or (not= obj @current-obj) @update?)
(cond
@update?
(do (reset! update? false)
(show-panel-anim bottom-anim-value alpha-value))

(and @current-obj obj)
(do (reset! update? true)
(js/setTimeout #(reset! current-obj obj) 600)
(hide-panel-anim bottom-anim-value alpha-value (- window-height)))

obj
(do (reset! current-obj obj)
(show-panel-anim bottom-anim-value alpha-value))

:else
(do (reset! clear-timeout (js/setTimeout #(reset! current-obj nil) 600))
(hide-panel-anim bottom-anim-value alpha-value (- window-height))))))
:reagent-render (fn []
(when @current-obj
[react/keyboard-avoiding-view {:style {:position :absolute :top 0 :bottom 0 :left 0 :right 0}}
[react/view {:flex 1}
[react/animated-view {:flex 1 :background-color :black :opacity alpha-value}]
[react/animated-view {:style {:position :absolute
:transform [{:translateY bottom-anim-value}]
:bottom 0 :left 0 :right 0}}
[react/view {:flex 1}
[render @current-obj]]]]]))})))

(views/defview animated-bottom-panel [val signing-view]
(views/letsubs [{window-height :height} [:dimensions/window]]
[bottom-panel (when val (select-keys val [:from :contact :amount :token :approve? :message])) signing-view window-height]))
2 changes: 1 addition & 1 deletion src/status_im/ui/components/button.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
(= :previous type)
{:padding-right 20 :padding-left 12}
:else nil)
{:padding-vertical 11 :border-radius 8
{:height 44 :border-radius 8
:align-items :center :justify-content :center
:background-color (cond
(#{:secondary :next :previous} type)
Expand Down
11 changes: 7 additions & 4 deletions src/status_im/ui/screens/chat/extensions/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[status-im.utils.platform :as platform]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.ui.components.animation :as anim]))
[status-im.ui.components.animation :as anim]
[status-im.ethereum.core :as ethereum]))

(def panel-height 270)

Expand Down Expand Up @@ -36,6 +37,8 @@
:height panel-height
:transform [{:translateY bottom-anim-value}]
:opacity alpha-value}}
[react/view {:width 127 :height 127 :align-items :center :justify-content :center
:background-color (colors/alpha "#887AF9" 0.2) :border-radius 16 :margin-left 8}
[react/text "Send transaction"]]]))
[react/touchable-highlight
{:on-press #(re-frame/dispatch [:wallet/prepare-transaction])}
[react/view {:width 127 :height 127 :align-items :center :justify-content :center
:background-color (colors/alpha "#887AF9" 0.2) :border-radius 16 :margin-left 8}
[react/text "Send transaction"]]]]))
3 changes: 3 additions & 0 deletions src/status_im/ui/screens/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@

(spec/def :popover/popover (spec/nilable map?))

(spec/def :wallet/prepare-transaction (spec/nilable map?))

(spec/def ::db (spec/keys :opt [:contacts/contacts
:contacts/new-identity
:contacts/new-identity-error
Expand Down Expand Up @@ -248,6 +250,7 @@
:bottom-sheet/view
:bottom-sheet/options
:wallet/custom-token-screen
:wallet/prepare-transaction
:signing/in-progress?
:signing/queue
:signing/sign
Expand Down
5 changes: 0 additions & 5 deletions src/status_im/ui/screens/routing/screens.cljs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(ns status-im.ui.screens.routing.screens
(:require [status-im.ui.screens.about-app.views :as about-app]
[status-im.ui.screens.multiaccounts.login.views :as login]
[status-im.ui.screens.multiaccounts.recover.views :as multiaccounts.recover]
[status-im.ui.screens.multiaccounts.views :as multiaccounts]
[status-im.ui.screens.add-new.new-chat.views :as new-chat]
[status-im.ui.screens.add-new.new-public-chat.view :as new-public-chat]
Expand Down Expand Up @@ -59,8 +58,6 @@
[status-im.ui.screens.stickers.views :as stickers]
[status-im.ui.screens.wallet.collectibles.views :as collectibles]
[status-im.ui.screens.wallet.components.views :as wallet.components]
[status-im.ui.screens.wallet.request.views :as request]
[status-im.ui.screens.wallet.send.views :as send]
[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.custom-tokens.views :as custom-tokens]
Expand Down Expand Up @@ -141,12 +138,10 @@
:wallet-account wallet.account/account
:collectibles-list collectibles/collectibles-list
:contact-code wallet.components/contact-code
:wallet-send-transaction send/send-transaction
:recent-recipients wallet.components/recent-recipients
:select-account wallet.components/accounts
:recipient-qr-code wallet.components/recipient-qr-code
:wallet-send-assets wallet.components/send-assets
:wallet-send-transaction-request request/send-transaction-request
:wallet-request-assets wallet.components/request-assets
:wallet-transaction-details wallet-transactions/transaction-details
:wallet-settings-hook wallet-settings/settings-hook
Expand Down
75 changes: 9 additions & 66 deletions src/status_im/ui/screens/signing/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
[re-frame.core :as re-frame]
[status-im.multiaccounts.core :as multiaccounts]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.animation :as anim]
[reagent.core :as reagent]
[status-im.ui.components.list-item.views :as list-item]
[status-im.ui.components.button :as button]
[status-im.ui.components.copyable-text :as copyable-text]
Expand All @@ -21,27 +19,8 @@
[clojure.string :as string]
[status-im.ui.screens.signing.styles :as styles]
[status-im.react-native.resources :as resources]
[status-im.ui.screens.hardwallet.pin.views :as pin.views]))

(defn hide-panel-anim
[bottom-anim-value alpha-value window-height]
(anim/start
(anim/parallel
[(anim/spring bottom-anim-value {:toValue (- window-height)
:useNativeDriver true})
(anim/timing alpha-value {:toValue 0
:duration 500
:useNativeDriver true})])))

(defn show-panel-anim
[bottom-anim-value alpha-value]
(anim/start
(anim/parallel
[(anim/spring bottom-anim-value {:toValue 40
:useNativeDriver true})
(anim/timing alpha-value {:toValue 0.4
:duration 500
:useNativeDriver true})])))
[status-im.ui.screens.hardwallet.pin.views :as pin.views]
[status-im.ui.components.bottom-panel.views :as bottom-panel]))

(defn separator []
[react/view {:height 1 :background-color colors/gray-lighter}])
Expand Down Expand Up @@ -299,47 +278,11 @@
:disabled? (or amount-error gas-error)
:label :t/sign-with-password}])]])])))

(defn signing-view [tx window-height]
(let [bottom-anim-value (anim/create-value window-height)
alpha-value (anim/create-value 0)
clear-timeout (atom nil)
current-tx (reagent/atom nil)
update? (reagent/atom nil)]
(reagent/create-class
{:component-will-update (fn [_ [_ tx _]]
(when @clear-timeout (js/clearTimeout @clear-timeout))
(cond
@update?
(do (reset! update? false)
(show-panel-anim bottom-anim-value alpha-value))

(and @current-tx tx)
(do (reset! update? true)
(js/setTimeout #(reset! current-tx tx) 600)
(hide-panel-anim bottom-anim-value alpha-value (- window-height)))

tx
(do (reset! current-tx tx)
(show-panel-anim bottom-anim-value alpha-value))

:else
(do (reset! clear-timeout (js/setTimeout #(reset! current-tx nil) 500))
(hide-panel-anim bottom-anim-value alpha-value (- window-height)))))
:reagent-render (fn []
(when @current-tx
[react/keyboard-avoiding-view {:style {:position :absolute :top 0 :bottom 0 :left 0 :right 0}}
[react/view {:flex 1}
[react/animated-view {:flex 1 :background-color :black :opacity alpha-value}]
[react/animated-view {:style {:position :absolute
:transform [{:translateY bottom-anim-value}]
:bottom 0 :left 0 :right 0}}
[react/view {:flex 1}
(if (:message @current-tx)
[message-sheet]
[sheet @current-tx])]]]]))})))

(views/defview signing []
(views/letsubs [tx [:signing/tx]
{window-height :height} [:dimensions/window]]
;;we use select-keys here because we don't want to update view if other keys in map is changed
[signing-view (when tx (select-keys tx [:from :contact :amount :token :approve? :message])) window-height]))
(views/letsubs [tx [:signing/tx]]
[bottom-panel/animated-bottom-panel
;;we use select-keys here because we don't want to update view if other keys in map are changed
(when tx (select-keys tx [:from :contact :amount :token :approve? :message]))
#(if (:message %)
[message-sheet]
[sheet %])]))
3 changes: 2 additions & 1 deletion src/status_im/ui/screens/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
[status-im.ui.screens.popover.views :as popover]
[status-im.ui.screens.multiaccounts.recover.views :as recover.views]
[status-im.utils.dimensions :as dimensions]
[status-im.ui.screens.wallet.send.views :as wallet]
status-im.ui.screens.wallet.collectibles.etheremon.views
status-im.ui.screens.wallet.collectibles.cryptostrikers.views
status-im.ui.screens.wallet.collectibles.cryptokitties.views
Expand Down Expand Up @@ -166,7 +167,7 @@
;; see https://reactnavigation.org/docs/en/state-persistence.html#development-mode
:persistNavigationState (when js/goog.DEBUG persist-state)
:loadNavigationState (when js/goog.DEBUG load-state)}]
[wallet/send-transaction]
[wallet/prepare-transaction]
[signing/signing]
[bottom-sheet]
[popover/popover]]))})))
5 changes: 3 additions & 2 deletions src/status_im/ui/screens/wallet/accounts/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(when active?
[react/view {:width 24 :height 3 :border-radius 4 :background-color colors/blue}])])

(defn render-asset [currency]
(defn render-asset [currency & [on-press]]
(fn [{:keys [icon decimals amount color value] :as token}]
[list-item/list-item
{:title-prefix (wallet.utils/format-amount amount decimals)
Expand All @@ -71,7 +71,8 @@
:subtitle (str (if value value 0) " " currency)
:icon (if icon
[list/item-image icon]
[chat-icon/custom-icon-view-list (:name token) color])}]))
[chat-icon/custom-icon-view-list (:name token) color])
:on-press #(on-press token)}]))

(views/defview assets []
(views/letsubs [{:keys [tokens nfts]} [:wallet/all-visible-assets-with-values]
Expand Down
Loading

0 comments on commit 1edbe69

Please sign in to comment.