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:
Gheorghe Pinzaru 2020-08-21 16:36:18 +03:00
parent 716c968a23
commit 17c408bd06
No known key found for this signature in database
GPG Key ID: C9A094959935A952
7 changed files with 40 additions and 33 deletions

View File

@ -23,7 +23,7 @@
(if (= decision :accept)
(gateway/handle-acquisition {:message payload
:method "PATCH"
:url (gateway/get-url :clicks referral)
:url [:clicks referral]
:on-success [::claim/success-starter-pack-claim]})
{::persistence/set-referrer-state :declined})
(popover/hide-popover))))

View File

@ -32,5 +32,5 @@
{:db (update db :acquisition dissoc :chat-referrer)}
(gateway/handle-acquisition {:message payload
:method "PATCH"
:url (gateway/get-url :clicks referral)
:url [:clicks referral]
:on-success [::claim/success-starter-pack-claim]}))))

View File

@ -15,19 +15,19 @@
(fx/defn add-tx-watcher
{:events [::add-tx-watcher]}
[cofx tx]
(transaction/watch-transaction cofx
tx
{:trigger-fn (constantly true)
:on-trigger
(fn []
{:dispatch [::success-tx-received]})}))
(fx/merge cofx
{::persistence/set-watch-tx tx}
(transaction/watch-transaction tx
{:trigger-fn (constantly true)
:on-trigger
(fn []
{:dispatch [::success-tx-received]})})))
(fx/defn success-starter-pack-claim
{:events [::success-starter-pack-claim]}
[cofx {:keys [tx]}]
(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
(add-tx-watcher tx))
(notifications/request-permission)))

View File

@ -24,7 +24,7 @@
{:message message
:on-success on-success
:method "POST"
:url (gateway/get-url :registrations nil)}))
:url [:registrations nil]}))
(re-frame/reg-fx
::get-referrer

View File

@ -34,7 +34,7 @@
(if (= decision :accept)
(gateway/handle-acquisition {:message payload
:method "PATCH"
:url (gateway/get-url :clicks referral)
:url [:clicks referral]
:on-success [::success-claim]})
{::persistence/set-referrer-state :declined})
(popover/hide-popover))))

View File

@ -1,25 +1,29 @@
(ns status-im.acquisition.gateway
(:require [re-frame.core :as re-frame]
[status-im.utils.fx :as fx]
[status-im.ethereum.core :as ethereum]
[status-im.i18n :as i18n]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.waku.core :as waku]
[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")
:registrations (str acquisition-gateway "/registrations")})
(defn acquisition-routes [network type]
(get {:clicks (str (get acquisition-gateway network) "/clicks")
:registrations (str (get acquisition-gateway network) "/registrations")}
type))
(def network-statuses {:initiated 1
:in-flight 2
:error 3
:success 4})
(defn get-url [type referral]
(defn get-url [network [type referral]]
(if (= type :clicks)
(str (get acquisition-routes :clicks) "/" referral)
(get acquisition-routes :registrations)))
(str (acquisition-routes network :clicks) "/" referral)
(acquisition-routes network :registrations)))
(fx/defn handle-error
{:events [::on-error]}
@ -32,7 +36,8 @@
(fx/defn handle-acquisition
{:events [::handle-acquisition]}
[{: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]
(get network-statuses :initiated))
::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])
:message msg
:method method
:url url
:url (get-url network url)
:on-success on-success} %])}]}))
(fx/defn call-acquisition-gateway
{:events [::call-acquisition-gateway]}
@ -67,15 +72,16 @@
(re-frame/dispatch [::on-error (:error (types/json->clj (get error :response-body)))]))}}))
(fx/defn get-referrer
[cofx referrer on-success handled-error handle-error]
{:http-get {:url (get-url :clicks referrer)
:on-success (fn [response]
(re-frame/dispatch (on-success (types/json->clj response))))
:on-error (fn [response]
(let [error (types/json->clj response)]
(if (handled-error error)
(handle-error error)
(re-frame/dispatch [::on-error (:error error)]))))}})
[{:keys [db]} referrer on-success handled-error handle-error]
(let [network (ethereum/chain-keyword db)]
{:http-get {:url (get-url network [:clicks referrer])
:on-success (fn [response]
(re-frame/dispatch (on-success (types/json->clj response))))
:on-error (fn [response]
(let [error (types/json->clj response)]
(if (handled-error error)
(handle-error error)
(re-frame/dispatch [::on-error (:error error)]))))}}))
(re-frame/reg-sub
::network-status
(fn [db]

View File

@ -44,10 +44,11 @@
(re-frame/reg-fx
::set-watch-tx
(fn [tx]
(-> ^js async-storage
(.setItem tx-store-key tx)
(.catch (fn [error]
(log/error "[async-storage]" error))))))
(when tx
(-> ^js async-storage
(.setItem tx-store-key tx)
(.catch (fn [error]
(log/error "[async-storage]" error)))))))
(re-frame/reg-fx
::chat-initalized!