Resolve contract by ens name

Do not show referrals if contract is not available

Do not check contract for referral accept

Rename invite event namespace require

Remove dispatch from raw subs

Do nothing if there is no contract

Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
This commit is contained in:
Gheorghe Pinzaru 2020-08-07 17:24:09 +03:00
parent ac4f65be97
commit c644ab3501
No known key found for this signature in database
GPG Key ID: C9A094959935A952
5 changed files with 82 additions and 69 deletions

View File

@ -1,6 +1,10 @@
(ns status-im.acquisition.core
(:require [re-frame.core :as re-frame]
[clojure.string :as string]
[status-im.utils.fx :as fx]
[status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens]
[status-im.ethereum.contracts :as contracts]
[status-im.acquisition.chat :as chat]
[status-im.acquisition.advertiser :as advertiser]
[status-im.acquisition.persistance :as persistence]
@ -84,12 +88,23 @@
(when-not (nil? tx)
(re-frame/dispatch [::add-tx-watcher tx])))})))))
(fx/defn create
{}
[_]
{::get-referrer nil})
(re-frame/reg-fx
::resolve-contract
(fn [{:keys [chain contract on-success]}]
(let [register (get ens/ens-registries chain)]
(when contract
(if (string/starts-with? contract "0x")
(on-success contract)
(ens/resolver register contract on-success))))))
(fx/defn login
{}
[_]
{::check-referrer nil})
(fx/defn create [{:keys [db]}]
{::resolve-contract {:chain (ethereum/chain-keyword db)
:contract (contracts/get-address db :status/acquisition)
:on-success #(re-frame/dispatch [:set-in [:acquisition :contract] %])}
::get-referrer nil})
(fx/defn login [{:keys [db]}]
{::resolve-contract {:chain (ethereum/chain-keyword db)
:contract (contracts/get-address db :status/acquisition)
:on-success #(re-frame/dispatch [:set-in [:acquisition :contract] %])}
::check-referrer nil})

View File

@ -17,8 +17,8 @@
{:testnet "0xf852198d0385c4b871e0b91804ecd47c6ba97351"
:mainnet "0x110101156e8F0743948B2A61aFcf3994A8Fb172e"}
:status/acquisition
{:rinkeby "0x719C016d16ff0396274d488Efc4D8aEaAA126b48"
:mainnet "0x81142267f927bffc6dba200a928c376fbf6675a8"}})
{:rinkeby "0xf8Ea093cE1441ad51EDD4C0FD15410b457e88906"
:mainnet "statusreferrals.eth"}})
(defn get-address
[db contract]

View File

@ -180,6 +180,7 @@
(and platform/android?
notifications-enabled?)
(assoc ::notifications/enable nil))
(acquisition/login)
(initialize-appearance)
;; NOTE: initializing mailserver depends on user mailserver
;; preference which is why we wait for config callback
@ -228,7 +229,12 @@
(fx/defn create-only-events
[{:keys [db] :as cofx}]
(let [{:keys [multiaccount :multiaccount/accounts]} db]
(let [{:keys [multiaccount multiaccounts :multiaccount/accounts]} db
{:keys [creating?]} (:multiaccounts/login db)
recovering? (get-in db [:intro-wizard :recovering?])
first-account? (and creating?
(not recovering?)
(empty? multiaccounts))]
(fx/merge cofx
{:db (-> db
(dissoc :multiaccounts/login)
@ -243,6 +249,8 @@
:filters/initialized 1))
:filters/load-filters [[(:waku-enabled multiaccount) []]]}
(finish-keycard-setup)
(when first-account?
(acquisition/create))
(protocol/initialize-protocol {:mailservers []
:mailserver-ranges {}
:mailserver-topics {}
@ -259,9 +267,6 @@
(let [{:keys [key-uid password save-password? creating?]} (:multiaccounts/login db)
multiaccounts (:multiaccounts/multiaccounts db)
recovering? (get-in db [:intro-wizard :recovering?])
first-account? (and creating?
(not recovering?)
(empty? multiaccounts))
login-only? (not (or creating?
recovering?
(keycard-setup? cofx)))
@ -288,9 +293,6 @@
(if login-only?
(login-only-events key-uid password save-password?)
(create-only-events))
(if first-account?
(acquisition/create)
(acquisition/login))
(when recovering?
(navigation/navigate-to-cofx :tabs {:screen :chat-stack
:params {:screen :home}})))))

View File

@ -2,8 +2,8 @@
(:require [re-frame.core :as re-frame]
[reagent.ratom :refer [make-reaction]]
[status-im.utils.fx :as fx]
[status-im.utils.config :as config]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.ethereum.contracts :as contracts]
[status-im.ethereum.core :as ethereum]
[status-im.ui.components.react :as react]
[status-im.navigation :as navigation]
@ -53,7 +53,7 @@
(fx/defn go-to-invite
{:events [::open-invite]}
[{:keys [db] :as cofx}]
(let [contract (contracts/get-address db :status/acquisition)
(let [contract (get-in db [:acquisition :contract])
accounts (filter #(not= (:type %) :watch) (get db :multiaccount/accounts))]
(fx/merge cofx
{::get-rewards (mapv (fn [{:keys [address]}]
@ -135,18 +135,13 @@
(let [[address amount] data]
{:db (assoc-in db [:acquisition :accounts account :tokens address] (money/wei->ether amount))})))
(fx/defn get-default-reward
{:events [::get-default-reward]}
[{:keys [db]}]
{::get-rewards [{:contract (contracts/get-address db :status/acquisition)
:address (ethereum/default-address db)
:on-success (fn [type data]
(re-frame/dispatch [::default-reward-success type data]))}]})
(re-frame/reg-sub-raw
::default-reward
(fn [db]
(re-frame/dispatch [::get-default-reward])
(get-reward (get-in @db [:acquisition :contract])
(ethereum/default-address @db)
(fn [type data]
(re-frame/dispatch [::default-reward-success type data])))
(make-reaction
(fn []
(get-in @db [:acquisition :referral-reward])))))
@ -162,19 +157,21 @@
(map money/wei->ether tokens-amount))
:sticker-packs sticker-packs})})
(fx/defn starter-pack
{:events [::starter-pack]}
[{:keys [db]}]
(let [contract (contracts/get-address db :status/acquisition)]
{::json-rpc/eth-call [{:contract contract
:method "getDefaultPack()"
:outputs ["address" "uint256" "address[]" "uint256[]" "uint256[]"]
:on-success #(re-frame/dispatch [::starter-pack-amount (vec %) (prn %)])}]}))
(re-frame/reg-sub-raw
::starter-pack
(fn [db]
(re-frame/dispatch [::starter-pack])
(let [contract (get-in @db [:acquisition :contract])]
(json-rpc/eth-call
{:contract contract
:method "getDefaultPack()"
:outputs ["address" "uint256" "address[]" "uint256[]" "uint256[]"]
:on-success #(re-frame/dispatch [::starter-pack-amount (vec %)])})
(make-reaction
(fn []
(get-in @db [:acquisition :starter-pack :pack])))))
(get-in @db [:acquisition :starter-pack :pack]))))))
(re-frame/reg-sub
::enabled
(fn [db]
(and config/referrals-invite-enabled?
(get-in db [:acquisition :contract]))))

View File

@ -11,9 +11,8 @@
[quo.design-system.colors :as colors]
[status-im.ui.components.invite.style :as styles]
[status-im.ui.components.topbar :as topbar]
[status-im.ui.components.invite.events :as events]
[status-im.ui.components.invite.events :as invite.events]
[status-im.ui.components.invite.utils :refer [transform-tokens]]
[status-im.utils.config :as config]
[quo.react-native :as rn]
[clojure.string :as cstr]))
@ -191,8 +190,8 @@
(let [accounts @(re-frame/subscribe [:accounts-without-watch-only])
default-account @(re-frame/subscribe [:multiaccount/default-account])
account (or @account* default-account)
reward @(re-frame/subscribe [::events/default-reward])
starter-pack @(re-frame/subscribe [::events/starter-pack])]
reward @(re-frame/subscribe [::invite.events/default-reward])
starter-pack @(re-frame/subscribe [::invite.events/starter-pack])]
[rn/view {:flex 1}
[topbar/topbar {:modal? true
:show-border? true
@ -210,27 +209,27 @@
(i18n/label :t/invite-privacy-policy1)
" "
[quo/text {:color :link
:on-press #(re-frame/dispatch [::events/terms-and-conditions])}
:on-press #(re-frame/dispatch [::invite.events/terms-and-conditions])}
(i18n/label :t/invite-privacy-policy2)]]]]
[toolbar/toolbar
{:show-border? true
:center
[quo/button {:type :secondary
:on-press #(re-frame/dispatch [::events/generate-invite
:on-press #(re-frame/dispatch [::invite.events/generate-invite
{:address (get account :address)}])}
(i18n/label :t/invite-button)]}]]))))
(defn button []
(if-not config/referrals-invite-enabled?
(if-not @(re-frame/subscribe [::invite.events/enabled])
[rn/view {:style {:align-items :center}}
[rn/view {:style (:tiny spacing/padding-vertical)}
[quo/button {:on-press #(re-frame/dispatch [::events/share-link nil])
[quo/button {:on-press #(re-frame/dispatch [::invite.events/share-link nil])
:accessibility-label :invite-friends-button}
(i18n/label :t/invite-friends)]]]
(let [reward @(re-frame/subscribe [::events/default-reward])]
(let [reward @(re-frame/subscribe [::invite.events/default-reward])]
[rn/view {:style {:align-items :center}}
[rn/view {:style (:tiny spacing/padding-vertical)}
[quo/button {:on-press #(re-frame/dispatch [::events/open-invite])
[quo/button {:on-press #(re-frame/dispatch [::invite.events/open-invite])
:accessibility-label :invite-friends-button}
(i18n/label :t/invite-friends)]]
[rn/view {:style (merge (:tiny spacing/padding-vertical)
@ -248,7 +247,7 @@
(i18n/label :t/invite-reward {:value (str (get reward :eth-amount) " ETH")})]])]])))
(defn list-item [{:keys [accessibility-label]}]
(if-not config/referrals-invite-enabled?
(if-not @(re-frame/subscribe [::invite.events/enabled])
[quo/list-item
{:theme :accent
:title (i18n/label :t/invite-friends)
@ -257,8 +256,8 @@
:on-press (fn []
(re-frame/dispatch [:bottom-sheet/hide])
(js/setTimeout
#(re-frame/dispatch [::events/share-link nil]) 250))}]
(let [amount @(re-frame/subscribe [::events/default-reward])]
#(re-frame/dispatch [::invite.events/share-link nil]) 250))}]
(let [amount @(re-frame/subscribe [::invite.events/default-reward])]
[quo/list-item
{:theme :accent
:title (i18n/label :t/invite-friends)
@ -267,7 +266,7 @@
:accessibility-label accessibility-label
:on-press #(do
(re-frame/dispatch [:bottom-sheet/hide])
(re-frame/dispatch [::events/open-invite]))}])))
(re-frame/dispatch [::invite.events/open-invite]))}])))