Use different acquisition gateway based on chain
Do not persist empty tx Signed-off-by: Gheorghe Pinzaru <feross95@gmail.com>
This commit is contained in:
parent
716c968a23
commit
17c408bd06
|
@ -23,7 +23,7 @@
|
||||||
(if (= decision :accept)
|
(if (= decision :accept)
|
||||||
(gateway/handle-acquisition {:message payload
|
(gateway/handle-acquisition {:message payload
|
||||||
:method "PATCH"
|
:method "PATCH"
|
||||||
:url (gateway/get-url :clicks referral)
|
:url [:clicks referral]
|
||||||
:on-success [::claim/success-starter-pack-claim]})
|
:on-success [::claim/success-starter-pack-claim]})
|
||||||
{::persistence/set-referrer-state :declined})
|
{::persistence/set-referrer-state :declined})
|
||||||
(popover/hide-popover))))
|
(popover/hide-popover))))
|
||||||
|
|
|
@ -32,5 +32,5 @@
|
||||||
{:db (update db :acquisition dissoc :chat-referrer)}
|
{:db (update db :acquisition dissoc :chat-referrer)}
|
||||||
(gateway/handle-acquisition {:message payload
|
(gateway/handle-acquisition {:message payload
|
||||||
:method "PATCH"
|
:method "PATCH"
|
||||||
:url (gateway/get-url :clicks referral)
|
:url [:clicks referral]
|
||||||
:on-success [::claim/success-starter-pack-claim]}))))
|
:on-success [::claim/success-starter-pack-claim]}))))
|
||||||
|
|
|
@ -15,19 +15,19 @@
|
||||||
(fx/defn add-tx-watcher
|
(fx/defn add-tx-watcher
|
||||||
{:events [::add-tx-watcher]}
|
{:events [::add-tx-watcher]}
|
||||||
[cofx tx]
|
[cofx tx]
|
||||||
(transaction/watch-transaction cofx
|
(fx/merge cofx
|
||||||
tx
|
{::persistence/set-watch-tx tx}
|
||||||
{:trigger-fn (constantly true)
|
(transaction/watch-transaction tx
|
||||||
:on-trigger
|
{:trigger-fn (constantly true)
|
||||||
(fn []
|
:on-trigger
|
||||||
{:dispatch [::success-tx-received]})}))
|
(fn []
|
||||||
|
{:dispatch [::success-tx-received]})})))
|
||||||
|
|
||||||
(fx/defn success-starter-pack-claim
|
(fx/defn success-starter-pack-claim
|
||||||
{:events [::success-starter-pack-claim]}
|
{:events [::success-starter-pack-claim]}
|
||||||
[cofx {:keys [tx]}]
|
[cofx {:keys [tx]}]
|
||||||
(fx/merge cofx
|
(fx/merge cofx
|
||||||
{::persistence/set-watch-tx tx
|
{::persistence/set-referrer-state (if tx :accepted :claimed)}
|
||||||
::persistence/set-referrer-state (if tx :accepted :claimed)}
|
|
||||||
(when tx
|
(when tx
|
||||||
(add-tx-watcher tx))
|
(add-tx-watcher tx))
|
||||||
(notifications/request-permission)))
|
(notifications/request-permission)))
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
{:message message
|
{:message message
|
||||||
:on-success on-success
|
:on-success on-success
|
||||||
:method "POST"
|
:method "POST"
|
||||||
:url (gateway/get-url :registrations nil)}))
|
:url [:registrations nil]}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::get-referrer
|
::get-referrer
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
(if (= decision :accept)
|
(if (= decision :accept)
|
||||||
(gateway/handle-acquisition {:message payload
|
(gateway/handle-acquisition {:message payload
|
||||||
:method "PATCH"
|
:method "PATCH"
|
||||||
:url (gateway/get-url :clicks referral)
|
:url [:clicks referral]
|
||||||
:on-success [::success-claim]})
|
:on-success [::success-claim]})
|
||||||
{::persistence/set-referrer-state :declined})
|
{::persistence/set-referrer-state :declined})
|
||||||
(popover/hide-popover))))
|
(popover/hide-popover))))
|
||||||
|
|
|
@ -1,25 +1,29 @@
|
||||||
(ns status-im.acquisition.gateway
|
(ns status-im.acquisition.gateway
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
|
[status-im.ethereum.core :as ethereum]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.ethereum.json-rpc :as json-rpc]
|
[status-im.ethereum.json-rpc :as json-rpc]
|
||||||
[status-im.waku.core :as waku]
|
[status-im.waku.core :as waku]
|
||||||
[status-im.utils.types :as types]))
|
[status-im.utils.types :as types]))
|
||||||
|
|
||||||
(def acquisition-gateway "https://test-referral.status.im")
|
(def acquisition-gateway {:mainnet "https://get.status.im"
|
||||||
|
:rinkeby "https://test-referral.status.im"})
|
||||||
|
|
||||||
(def acquisition-routes {:clicks (str acquisition-gateway "/clicks")
|
(defn acquisition-routes [network type]
|
||||||
:registrations (str acquisition-gateway "/registrations")})
|
(get {:clicks (str (get acquisition-gateway network) "/clicks")
|
||||||
|
:registrations (str (get acquisition-gateway network) "/registrations")}
|
||||||
|
type))
|
||||||
|
|
||||||
(def network-statuses {:initiated 1
|
(def network-statuses {:initiated 1
|
||||||
:in-flight 2
|
:in-flight 2
|
||||||
:error 3
|
:error 3
|
||||||
:success 4})
|
:success 4})
|
||||||
|
|
||||||
(defn get-url [type referral]
|
(defn get-url [network [type referral]]
|
||||||
(if (= type :clicks)
|
(if (= type :clicks)
|
||||||
(str (get acquisition-routes :clicks) "/" referral)
|
(str (acquisition-routes network :clicks) "/" referral)
|
||||||
(get acquisition-routes :registrations)))
|
(acquisition-routes network :registrations)))
|
||||||
|
|
||||||
(fx/defn handle-error
|
(fx/defn handle-error
|
||||||
{:events [::on-error]}
|
{:events [::on-error]}
|
||||||
|
@ -32,7 +36,8 @@
|
||||||
(fx/defn handle-acquisition
|
(fx/defn handle-acquisition
|
||||||
{:events [::handle-acquisition]}
|
{:events [::handle-acquisition]}
|
||||||
[{:keys [db] :as cofx} {:keys [message on-success method url]}]
|
[{:keys [db] :as cofx} {:keys [message on-success method url]}]
|
||||||
(let [msg (types/clj->json message)]
|
(let [msg (types/clj->json message)
|
||||||
|
network (ethereum/chain-keyword db)]
|
||||||
{:db (assoc-in db [:acquisition :network-status]
|
{:db (assoc-in db [:acquisition :network-status]
|
||||||
(get network-statuses :initiated))
|
(get network-statuses :initiated))
|
||||||
::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "signMessageWithChatKey")
|
::json-rpc/call [{:method (json-rpc/call-ext-method (waku/enabled? cofx) "signMessageWithChatKey")
|
||||||
|
@ -42,7 +47,7 @@
|
||||||
{:chat-key (get-in db [:multiaccount :public-key])
|
{:chat-key (get-in db [:multiaccount :public-key])
|
||||||
:message msg
|
:message msg
|
||||||
:method method
|
:method method
|
||||||
:url url
|
:url (get-url network url)
|
||||||
:on-success on-success} %])}]}))
|
:on-success on-success} %])}]}))
|
||||||
(fx/defn call-acquisition-gateway
|
(fx/defn call-acquisition-gateway
|
||||||
{:events [::call-acquisition-gateway]}
|
{:events [::call-acquisition-gateway]}
|
||||||
|
@ -67,15 +72,16 @@
|
||||||
(re-frame/dispatch [::on-error (:error (types/json->clj (get error :response-body)))]))}}))
|
(re-frame/dispatch [::on-error (:error (types/json->clj (get error :response-body)))]))}}))
|
||||||
|
|
||||||
(fx/defn get-referrer
|
(fx/defn get-referrer
|
||||||
[cofx referrer on-success handled-error handle-error]
|
[{:keys [db]} referrer on-success handled-error handle-error]
|
||||||
{:http-get {:url (get-url :clicks referrer)
|
(let [network (ethereum/chain-keyword db)]
|
||||||
:on-success (fn [response]
|
{:http-get {:url (get-url network [:clicks referrer])
|
||||||
(re-frame/dispatch (on-success (types/json->clj response))))
|
:on-success (fn [response]
|
||||||
:on-error (fn [response]
|
(re-frame/dispatch (on-success (types/json->clj response))))
|
||||||
(let [error (types/json->clj response)]
|
:on-error (fn [response]
|
||||||
(if (handled-error error)
|
(let [error (types/json->clj response)]
|
||||||
(handle-error error)
|
(if (handled-error error)
|
||||||
(re-frame/dispatch [::on-error (:error error)]))))}})
|
(handle-error error)
|
||||||
|
(re-frame/dispatch [::on-error (:error error)]))))}}))
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::network-status
|
::network-status
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
|
|
@ -44,10 +44,11 @@
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::set-watch-tx
|
::set-watch-tx
|
||||||
(fn [tx]
|
(fn [tx]
|
||||||
(-> ^js async-storage
|
(when tx
|
||||||
(.setItem tx-store-key tx)
|
(-> ^js async-storage
|
||||||
(.catch (fn [error]
|
(.setItem tx-store-key tx)
|
||||||
(log/error "[async-storage]" error))))))
|
(.catch (fn [error]
|
||||||
|
(log/error "[async-storage]" error)))))))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::chat-initalized!
|
::chat-initalized!
|
||||||
|
|
Loading…
Reference in New Issue