From 67365b114e76be305df0f837ebd43e6e129edb34 Mon Sep 17 00:00:00 2001 From: Gheorghe Pinzaru Date: Fri, 15 May 2020 10:24:08 +0300 Subject: [PATCH] f pulling --- src/quo/react_native.cljs | 2 +- src/status_im/ethereum/contracts.cljs | 2 +- src/status_im/ethereum/tokens.cljs | 4 +++ src/status_im/subs.cljs | 4 --- .../ui/components/invite/events.cljs | 24 ++++++++++++----- src/status_im/ui/components/invite/views.cljs | 27 ++++++++++++++----- translations/en.json | 2 +- 7 files changed, 44 insertions(+), 21 deletions(-) diff --git a/src/quo/react_native.cljs b/src/quo/react_native.cljs index c00d9442584..7e5b3fc38ef 100644 --- a/src/quo/react_native.cljs +++ b/src/quo/react_native.cljs @@ -7,7 +7,7 @@ (def platform (.-Platform ^js rn)) (def view (reagent/adapt-react-class (.-View ^js rn))) - +(def image (reagent/adapt-react-class (.-Image ^js rn))) (def text (reagent/adapt-react-class (.-Text ^js rn))) (def scroll-view (reagent/adapt-react-class (.-ScrollView ^js rn))) diff --git a/src/status_im/ethereum/contracts.cljs b/src/status_im/ethereum/contracts.cljs index 17b0eca4ea6..61ce54d7534 100644 --- a/src/status_im/ethereum/contracts.cljs +++ b/src/status_im/ethereum/contracts.cljs @@ -17,7 +17,7 @@ {:testnet "0xf852198d0385c4b871e0b91804ecd47c6ba97351" :mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"} :status/acquisition - {:rinkeby "0x533406047A87c84EA7D1dc8a078eBed71186C8eE"}}) + {:rinkeby "0x75D370306139E22cBA52ec59408e9d85cAb9aa23"}}) (defn get-address [db contract] diff --git a/src/status_im/ethereum/tokens.cljs b/src/status_im/ethereum/tokens.cljs index e98e80ea73d..e571f2f46bb 100644 --- a/src/status_im/ethereum/tokens.cljs +++ b/src/status_im/ethereum/tokens.cljs @@ -804,3 +804,7 @@ (= (:symbol native-coin) symbol)) native-coin (symbol->token all-tokens symbol)))) + +(defn symbol->icon [sym] + (:icon (first (filter #(= sym (:symbol %)) + (:mainnet all-default-tokens))))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 482ff2d23cf..73768a73ab0 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -2199,10 +2199,6 @@ (not-any? :error (vals manage)))) ;; Acquisition Referral reward -(re-frame/reg-sub - :invite/default-reward - (fn [db] - (get-in db [:acquisition :referral :amount]))) (re-frame/reg-sub :invite/accounts-reward diff --git a/src/status_im/ui/components/invite/events.cljs b/src/status_im/ui/components/invite/events.cljs index ca1733295e1..70d21aad18c 100644 --- a/src/status_im/ui/components/invite/events.cljs +++ b/src/status_im/ui/components/invite/events.cljs @@ -1,6 +1,7 @@ (ns status-im.ui.components.invite.events (:require [re-frame.core :as re-frame] [oops.core :refer [oget]] + [reagent.ratom :refer [make-reaction]] [status-im.utils.fx :as fx] [status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.contracts :as contracts] @@ -18,7 +19,7 @@ (fx/defn share-link {:events [::share-link]} [_ response] - (let [invite-id (oget response "invite-id") + (let [invite-id (get response :invite-id) message (str "Hey join me on Status:" get-link invite-id)] {::share {:message message}})) @@ -27,7 +28,7 @@ [cofx {:keys [address]}] (acquisition/handle-acquisition cofx {:message {:address address} - :on-success [::share-link]})) + :on-success ::share-link})) (defn- get-reward [contract address on-success] (json-rpc/eth-call @@ -61,18 +62,27 @@ (fx/defn get-default-reward {:events [::get-default-reward]} - [{:keys [db] :as cofx}] + [{:keys [db]}] {::get-rewards [{:contract (contracts/get-address db :status/acquisition) :address (ethereum/default-address db) :on-success #(re-frame/dispatch [::default-reward-success %])}]}) +(re-frame/reg-sub-raw + ::default-reward + (fn [db] + (re-frame/dispatch [::get-default-reward]) + (make-reaction + (fn [] + (get-in @db [:acquisition :referral :amount]))))) + + (fx/defn get-accounts-reward {:events [::get-accounts-reward]} [{:keys [db]}] - (let [contract (contracts/get-address db :status/acquisition) - on-success #(re-frame/dispatch [::get-reward-success %]) - accounts (filter #(not= (:type %) :watch) (get db :multiaccount/accounts))] + (let [contract (contracts/get-address db :status/acquisition) + accounts (filter #(not= (:type %) :watch) (get db :multiaccount/accounts))] {::get-rewards (mapv (fn [{:keys [address]}] {:address address :contract contract - :on-success on-success}) accounts)})) + :on-success #(re-frame/dispatch [::get-reward-success address %])}) + accounts)})) diff --git a/src/status_im/ui/components/invite/views.cljs b/src/status_im/ui/components/invite/views.cljs index cbcb05fc371..8e7cd02c4fa 100644 --- a/src/status_im/ui/components/invite/views.cljs +++ b/src/status_im/ui/components/invite/views.cljs @@ -9,6 +9,8 @@ [status-im.utils.utils :as utils] [status-im.ui.components.button :as button] [status-im.i18n :as i18n] + [status-im.ethereum.tokens :as tokens] + [status-im.utils.money :as money] [quo.design-system.spacing :as spacing] [quo.design-system.colors :as colors] [status-im.ui.components.invite.events :as events] @@ -99,7 +101,9 @@ [bottom-sheet/bottom-sheet {:show? true :on-cancel #(reset! visible false) :content (accounts-list accounts account - change-account)}]] + (fn [a] + (change-account a) + (reset! visible false)))}]] [list-item/list-item {:icon [chat-icon/custom-icon-view-list (:name account) (:color account)] :title (:name account) @@ -139,23 +143,32 @@ :props props}]]))) (defn- button-component [{:keys [on-press]}] - (let [amount @(re-frame/subscribe [:invite/default-reward])] + (let [amount @(re-frame/subscribe [::events/default-reward])] [rn/view {:style {:align-items :center}} [rn/view {:style (:tiny spacing/padding-vertical)} [button/button {:label :t/invite-friends :on-press on-press :accessibility-label :invite-friends-button}]] - [rn/view {:style (:tiny spacing/padding-vertical)} + [rn/view {:style (merge (:tiny spacing/padding-vertical) + (:base spacing/padding-horizontal))} (when amount - [quo/text - (i18n/label :t/invite-reward {:amount (str amount)})])]])) + [rn/view {:style {:flex-direction :row + :align-items :center + :justify-content :center}} + [rn/view {:style (:tiny spacing/padding-horizontal)} + (when-let [{:keys [source]} (tokens/symbol->icon :SNT)] + [rn/image {:style {:width 20 + :height 20} + :source (source)}])] + [quo/text {:align :center} + (i18n/label :t/invite-reward {:value (money/wei->str :eth (* 1000000000000000 amount) "SNT")})]])]])) (defn- list-item-component [{:keys [on-press props]}] - (let [amount @(re-frame/subscribe [:invite/default-reward])] + (let [amount @(re-frame/subscribe [::events/default-reward])] [list-item/list-item {:theme :action :title (i18n/label :t/invite-friends) - :subtitle (i18n/label :t/invite-reward {:amount amount}) + :subtitle (i18n/label :t/invite-reward {:value (money/wei->str :eth amount "SNT")}) :icon :main-icons/share :accessibility-label (:accessibility-label props) :on-press on-press}])) diff --git a/translations/en.json b/translations/en.json index 546512baab7..2dae45f0d35 100644 --- a/translations/en.json +++ b/translations/en.json @@ -537,7 +537,7 @@ "invalid-pairing-password": "Invalid pairing password", "invalid-range": "Invalid format, must be between {{min}} and {{max}}", "invite-friends": "Invite friends", - "invite-reward": "Earn {{amount}} SNT for every friend you invite!", + "invite-reward": "Earn {{value}} for every friend you invite!", "invite-select-account": "Select an account to receive your referral bonus", "invited": "invited", "invite-button": "Invite",