Send request to server
This commit is contained in:
parent
681adafdcb
commit
fa6e8c913a
|
@ -11,6 +11,9 @@ switching between android device
|
|||
|
||||
https://github.com/drapanjanas/re-natal#switching-between-android-devices
|
||||
|
||||
|
||||
Change `server-address` value at `/src/messenger/android/utils.cljs`
|
||||
|
||||
## Issues
|
||||
|
||||
`Requiring unknown module "react"`
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
[re-natal.support :as sup]
|
||||
[syng-im.protocol.whisper :as whisper]
|
||||
[messenger.state :as state]
|
||||
[messenger.android.utils :refer [log toast]]
|
||||
[messenger.android.utils :refer [log toast http-post]]
|
||||
[messenger.android.resources :as res]
|
||||
[messenger.android.sign-up-confirm :refer [sign-up-confirm]]))
|
||||
|
||||
|
@ -25,11 +25,16 @@
|
|||
:name "sign-up-confirm"}))))
|
||||
|
||||
(defn sign-in [phone-number whisper-identity]
|
||||
(toast (str "TODO: send number: " phone-number ", "
|
||||
(subs whisper-identity 0 2) ".."
|
||||
(subs whisper-identity (- (count whisper-identity) 2)
|
||||
(count whisper-identity))))
|
||||
(show-confirm-view))
|
||||
;; (toast (str "TODO: send number: " phone-number ", "
|
||||
;; (subs whisper-identity 0 2) ".."
|
||||
;; (subs whisper-identity (- (count whisper-identity) 2)
|
||||
;; (count whisper-identity))))
|
||||
(http-post "sign-up"
|
||||
{:phone-number phone-number
|
||||
:whisper-identity whisper-identity}
|
||||
(fn [body]
|
||||
(log body)
|
||||
(show-confirm-view))))
|
||||
|
||||
(defn identity-handler [error result]
|
||||
(if error
|
||||
|
@ -42,6 +47,7 @@
|
|||
(let [web3 (whisper/make-web3 ethereum-rpc-url)]
|
||||
(str (.newIdentity (whisper/whisper web3) handler))))
|
||||
|
||||
|
||||
(defn get-whisper-identity-handler [phone-number]
|
||||
(fn [identity]
|
||||
;; TODO to test newIdentity. Change to 'identity' to use saved identity.
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
[re-natal.support :as sup]
|
||||
[syng-im.protocol.whisper :as whisper]
|
||||
[messenger.state :as state]
|
||||
[messenger.android.utils :refer [log toast]]
|
||||
[messenger.android.utils :refer [log toast http-post]]
|
||||
[messenger.android.resources :as res]
|
||||
[messenger.android.contacts-list :refer [contacts-list]]))
|
||||
|
||||
|
@ -27,16 +27,22 @@
|
|||
(defn send-check-contacts []
|
||||
)
|
||||
|
||||
(defn handle-send-code-response [response]
|
||||
)
|
||||
(defn handle-send-code-response [body]
|
||||
(log body)
|
||||
(toast (if (:confirmed body)
|
||||
"Confirmed"
|
||||
"Wrong code"))
|
||||
(when (:confirmed body)
|
||||
(show-home-view)))
|
||||
|
||||
(defn code-valid? [code]
|
||||
(= 4 (count code)))
|
||||
|
||||
(defn send-code [code]
|
||||
(when (code-valid? code)
|
||||
(toast (str code))
|
||||
(show-home-view)))
|
||||
(http-post "sign-up-confirm"
|
||||
{:code code}
|
||||
handle-send-code-response)))
|
||||
|
||||
(defn update-code [value]
|
||||
(let [formatted value]
|
||||
|
|
|
@ -4,8 +4,31 @@
|
|||
[natal-shell.alert :refer [alert]]
|
||||
[natal-shell.toast-android :as toast]))
|
||||
|
||||
(def server-address "http://10.0.3.2:3000/")
|
||||
|
||||
(defn log [obj]
|
||||
(.log js/console obj))
|
||||
|
||||
(defn toast [s]
|
||||
(toast/show s (toast/long)))
|
||||
|
||||
(defn http-post
|
||||
([action data on-success]
|
||||
(http-post action data on-success nil))
|
||||
([action data on-success on-error]
|
||||
(-> (.fetch js/window
|
||||
(str server-address action)
|
||||
(clj->js {:method "POST"
|
||||
:headers {:accept "application/json"
|
||||
:content-type "application/json"}
|
||||
:body (.stringify js/JSON (clj->js data))}))
|
||||
(.then (fn [response]
|
||||
(log response)
|
||||
(.text response)))
|
||||
(.then (fn [text]
|
||||
(let [json (.parse js/JSON text)
|
||||
obj (js->clj json :keywordize-keys true)]
|
||||
(on-success obj))))
|
||||
(.catch (or on-error
|
||||
(fn [error]
|
||||
(toast (str error))))))))
|
||||
|
|
Loading…
Reference in New Issue