Skip to content

Commit

Permalink
f pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferossgp committed Jun 16, 2020
1 parent 20ffa7a commit bf4ef8d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/quo/react_native.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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)))
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ethereum/contracts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{:testnet "0xf852198d0385c4b871e0b91804ecd47c6ba97351"
:mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"}
:status/acquisition
{:rinkeby "0x533406047A87c84EA7D1dc8a078eBed71186C8eE"}})
{:rinkeby "0x75D370306139E22cBA52ec59408e9d85cAb9aa23"}})

(defn get-address
[db contract]
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/ethereum/tokens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))))
4 changes: 0 additions & 4 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,10 +2203,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
Expand Down
25 changes: 17 additions & 8 deletions src/status_im/ui/components/invite/events.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(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]
Expand All @@ -18,7 +18,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}}))

Expand All @@ -27,7 +27,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
Expand Down Expand Up @@ -61,18 +61,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)}))
27 changes: 20 additions & 7 deletions src/status_im/ui/components/invite/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}]))
Expand Down
2 changes: 1 addition & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,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",
Expand Down

0 comments on commit bf4ef8d

Please sign in to comment.