0?(c=s,r=f):(a=-a,r=u),r.reverse();a--;r.push(0));r.reverse()}for(a=u.length,n=f.length,0>a-n&&(r=f,f=u,u=r,n=a),a=0;n;)a=(u[--n]=u[n]+f[n]+a)/k|0,u[n]%=k;return a&&(u.unshift(a),++c),N(t,u,c)},R.precision=R.sd=function(t){var e,n,r=this,o=r.c;if(null!=t&&t!==!!t&&1!==t&&0!==t&&(W&&D(13,"argument"+b,t),t!=!!t&&(t=null)),!o)return null;if(n=o.length-1,e=n*B+1,n=o[n]){for(;n%10==0;n/=10,e--);for(n=o[0];n>=10;n/=10,e++);}return t&&r.e+1>e&&(e=r.e+1),e},R.round=function(t,n){var r=new e(this);return(null==t||J(t,0,F,15))&&P(r,~~t+this.e+1,null!=n&&J(n,0,8,15,_)?0|n:j),r},R.shift=function(t){var n=this;return J(t,-S,S,16,"argument")?n.times("1e"+l(t)):new e(n.c&&n.c[0]&&(-S>t||t>S)?n.s*(0>t?0:1/0):n)},R.squareRoot=R.sqrt=function(){var t,n,r,a,s,c=this,u=c.c,f=c.s,p=c.e,l=H+4,h=new e("0.5");if(1!==f||!u||!u[0])return new e(!f||0>f&&(!u||u[0])?NaN:u?c:1/0);if(f=Math.sqrt(+c),0==f||f==1/0?(n=i(u),(n.length+p)%2==0&&(n+="0"),f=Math.sqrt(n),p=o((p+1)/2)-(0>p||p%2),f==1/0?n="1e"+p:(n=f.toExponential(),n=n.slice(0,n.indexOf("e")+1)+p),r=new e(n)):r=new e(f+""),r.c[0])for(p=r.e,f=p+l,3>f&&(f=0);;)if(s=r,r=h.times(s.plus(T(c,s,l,1))),i(s.c).slice(0,f)===(n=i(r.c)).slice(0,f)){if(r.ef&&(y=_,_=w,w=y,a=f,f=h,h=a),a=f+h,y=[];a--;y.push(0));for(g=k,v=C,a=h;--a>=0;){for(r=0,d=w[a]%v,m=w[a]/v|0,c=f,s=a+c;s>a;)p=_[--c]%v,l=_[c]/v|0,u=m*p+l*d,p=d*p+u%v*v+y[s]+r,r=(p/g|0)+(u/v|0)+m*l,y[s--]=p%g;y[s]=r}return r?++i:y.shift(),N(t,y,i)},R.toDigits=function(t,n){var r=new e(this);return t=null!=t&&J(t,1,F,18,"precision")?0|t:null,n=null!=n&&J(n,0,8,18,_)?0|n:j,t?P(r,t,n):r},R.toExponential=function(t,e){return h(this,null!=t&&J(t,0,F,19)?~~t+1:null,e,19)},R.toFixed=function(t,e){return h(this,null!=t&&J(t,0,F,20)?~~t+this.e+1:null,e,20)},R.toFormat=function(t,e){var n=h(this,null!=t&&J(t,0,F,21)?~~t+this.e+1:null,e,21);if(this.c){var r,o=n.split("."),i=+K.groupSize,a=+K.secondaryGroupSize,s=K.groupSeparator,c=o[0],u=o[1],f=this.s<0,p=f?c.slice(1):c,l=p.length;if(a&&(r=i,i=a,a=r,l-=r),i>0&&l>0){for(r=l%i||i,c=p.substr(0,r);l>r;r+=i)c+=s+p.substr(r,i);a>0&&(c+=s+p.slice(r)),f&&(c="-"+c)}n=u?c+K.decimalSeparator+((a=+K.fractionGroupSize)?u.replace(new RegExp("\\d{"+a+"}\\B","g"),"$&"+K.fractionGroupSeparator):u):c}return n},R.toFraction=function(t){var n,r,o,a,s,c,u,f,p,l=W,h=this,d=h.c,m=new e(M),y=r=new e(M),g=u=new e(M);if(null!=t&&(W=!1,c=new e(t),W=l,(!(l=c.isInt())||c.lt(M))&&(W&&D(22,"max denominator "+(l?"out of range":"not an integer"),t),t=!l&&c.c&&P(c,c.e+1,1).gte(M)?c:null)),!d)return h.toString();for(p=i(d),a=m.e=p.length-h.e-1,m.c[0]=A[(s=a%B)<0?B+s:s],t=!t||c.cmp(m)>0?a>0?m:y:c,s=U,U=1/0,c=new e(p),u.c[0]=0;f=T(c,m,0,1),o=r.plus(f.times(g)),1!=o.cmp(t);)r=g,g=o,y=u.plus(f.times(o=y)),u=o,m=c.minus(f.times(o=m)),c=o;return o=T(t.minus(r),g,0,1),u=u.plus(o.times(y)),r=r.plus(o.times(g)),u.s=y.s=h.s,a*=2,n=T(y,g,a,j).minus(h).abs().cmp(T(u,r,a,j).minus(h).abs())<1?[y.toString(),g.toString()]:[u.toString(),r.toString()],U=s,n},R.toNumber=function(){var t=this;return+t||(t.s?0*t.s:NaN)},R.toPower=R.pow=function(t){var n,r,o=v(0>t?-t:+t),i=this;if(!J(t,-S,S,23,"exponent")&&(!isFinite(t)||o>S&&(t/=0)||parseFloat(t)!=t&&!(t=NaN)))return new e(Math.pow(+i,t));for(n=$?g($/B+2):0,r=new e(M);;){if(o%2){if(r=r.times(i),!r.c)break;n&&r.c.length>n&&(r.c.length=n)}if(o=v(o/2),!o)break;i=i.times(i),n&&i.c&&i.c.length>n&&(i.c.length=n)}return 0>t&&(r=M.div(r)),n?P(r,$,j):r},R.toPrecision=function(t,e){return h(this,null!=t&&J(t,1,F,24,"precision")?0|t:null,e,24)},R.toString=function(t){var e,r=this,o=r.s,a=r.e;return null===a?o?(e="Infinity",0>o&&(e="-"+e)):e="NaN":(e=i(r.c),e=null!=t&&J(t,2,64,25,"base")?n(p(e,a),0|t,10,o):q>=a||a>=L?f(e,a):p(e,a),0>o&&r.c[0]&&(e="-"+e)),e},R.truncated=R.trunc=function(){return P(new e(this),this.e+1,1)},R.valueOf=R.toJSON=function(){return this.toString()},null!=t&&e.config(t),e}function o(t){var e=0|t;return t>0||t===e?e:e-1}function i(t){for(var e,n,r=1,o=t.length,i=t[0]+"";o>r;){for(e=t[r++]+"",n=B-e.length;n--;e="0"+e);i+=e}for(o=i.length;48===i.charCodeAt(--o););return i.slice(0,o+1||1)}function a(t,e){var n,r,o=t.c,i=e.c,a=t.s,s=e.s,c=t.e,u=e.e;if(!a||!s)return null;if(n=o&&!o[0],r=i&&!i[0],n||r)return n?r?0:-s:a;if(a!=s)return a;if(n=0>a,r=c==u,!o||!i)return r?0:!o^n?1:-1;if(!r)return c>u^n?1:-1;for(s=(c=o.length)<(u=i.length)?c:u,a=0;s>a;a++)if(o[a]!=i[a])return o[a]>i[a]^n?1:-1;return c==u?0:c>u^n?1:-1}function s(t,e,n){return(t=l(t))>=e&&n>=t}function c(t){return"[object Array]"==Object.prototype.toString.call(t)}function u(t,e,n){for(var r,o,i=[0],a=0,s=t.length;s>a;){for(o=i.length;o--;i[o]*=e);for(i[r=0]+=x.indexOf(t.charAt(a++));rn-1&&(null==i[r+1]&&(i[r+1]=0),i[r+1]+=i[r]/n|0,i[r]%=n)}return i.reverse()}function f(t,e){return(t.length>1?t.charAt(0)+"."+t.slice(1):t)+(0>e?"e":"e+")+e}function p(t,e){var n,r;if(0>e){for(r="0.";++e;r+="0");t=r+t}else if(n=t.length,++e>n){for(r="0",e-=n;--e;r+="0");t+=r}else n>e&&(t=t.slice(0,e)+"."+t.slice(e));return t}function l(t){return t=parseFloat(t),0>t?g(t):v(t)}var h,d,m,y=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,g=Math.ceil,v=Math.floor,b=" not a boolean or binary digit",_="rounding mode",w="number type has more than 15 significant digits",x="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_",k=1e14,B=14,S=9007199254740991,A=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],C=1e7,F=1e9;if(h=r(),"function"==typeof define&&define.amd)define(function(){return h});else if("undefined"!=typeof e&&e.exports){if(e.exports=h,!d)try{d=t("crypto")}catch(I){}}else n.BigNumber=h}(this)},{crypto:49}],web3:[function(t,e,n){var r=t("./lib/web3");"undefined"!=typeof window&&"undefined"==typeof window.Web3&&(window.Web3=r),e.exports=r},{"./lib/web3":22}]},{},["web3"]);
\ No newline at end of file
diff --git a/src/messenger/android/login.cljs b/src/messenger/android/login.cljs
index 10ded41287..de2ba82f04 100644
--- a/src/messenger/android/login.cljs
+++ b/src/messenger/android/login.cljs
@@ -7,58 +7,82 @@
[natal-shell.alert :refer [alert]])
(:require [om.next :as om :refer-macros [defui]]
[re-natal.support :as sup]
+ [syng-im.protocol.whisper :as whisper]
[messenger.state :as state]
[messenger.android.resources :as res]
[messenger.android.contacts-list :refer [contacts-list]]))
+(def nav-atom (atom nil))
+
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
(def country-code "US")
-
-(set! js/Web3 (js/require "web3"))
(def ethereum-rpc-url "http://localhost:8545")
-(defn make-web3 [rpc-url]
- (->> (js/Web3.providers.HttpProvider. rpc-url)
- (js/Web3.)))
-(defn new-identity [web3 handler]
- (.newIdentity (.-shh web3) handler))
-(defn my-handler [error result]
+(defn show-home-view []
+ (binding [state/*nav-render* false]
+ (.replace @nav-atom (clj->js {:component contacts-list
+ :name "contacts-list"}))))
+
+(defn sign-in [phone-number whisper-identity]
+ (alert (str "TODO: send number: " phone-number ", "
+ (subs whisper-identity 0 2) ".."
+ (subs whisper-identity (- (count whisper-identity) 2)
+ (count whisper-identity))))
+ (show-home-view))
+
+(defn identity-handler [error result]
(if error
(do (alert (str error))
(.log js/console "error")
(.log js/console error))
- (alert (str result)))
- (.log js/console "result")
- (.log js/console result))
+ (alert (str result))))
-;; (def web3 (make-web3 ethereum-rpc-url))
-(new-identity (make-web3 ethereum-rpc-url) my-handler)
-;; (def whisper-identity (new-identity web3 my-handler))
-;; (alert (str whisper-identity))
+(defn get-identity [handler]
+ (let [web3 (whisper/make-web3 ethereum-rpc-url)]
+ (str (.newIdentity (whisper/whisper web3) handler))))
+(defn get-whisper-identity-handler [phone-number]
+ (fn [identity]
+ (if identity
+ (sign-in phone-number identity)
+ (get-identity (fn [error identity]
+ (if (not error)
+ (do (set-item "user-whisper-identity" identity)
+ (swap! state/app-state assoc :user-whisper-identity identity)
+ (sign-in phone-number identity))
+ (alert error)))))))
+(defn load-user-whisper-identity [handler]
+ (get-item "user-whisper-identity"
+ (fn [error value]
+ (if (not error)
+ (let [whisper-identity (when value (str value))]
+ (swap! state/app-state assoc :user-whisper-identity whisper-identity)
+ (handler whisper-identity))
+ (alert (str "error" error))))))
-(defn show-home-view [nav]
- (binding [state/*nav-render* false]
- (.replace nav (clj->js {:component contacts-list
- :name "contacts-list"}))))
+(defn handle-phone-number [phone-number]
+ (when phone-number
+ (load-user-whisper-identity (get-whisper-identity-handler phone-number))))
-(defn save-phone-number [nav]
+(defn save-phone-number []
(let [phone-number (:user-phone-number @state/app-state)]
(set-item "user-phone-number" phone-number)
- (show-home-view nav)))
+ (handle-phone-number phone-number)))
(defn update-phone-number [value]
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
(swap! state/app-state assoc :user-phone-number
formatted)))
-(defn load-user-phone-number []
+(defn load-user-phone-number [handler]
(get-item "user-phone-number"
(fn [error value]
(if (not error)
- (swap! state/app-state assoc :user-phone-number
- value)
+ (let [phone-number (when value (str value))]
+ (swap! state/app-state assoc :user-phone-number phone-number)
+ (when handler
+ (handler phone-number)))
(alert (str "error" error))))))
(defui Login
@@ -67,10 +91,11 @@
'[:user-phone-number])
Object
(componentDidMount [this]
- (load-user-phone-number))
+ (load-user-phone-number nil))
(render [this]
(let [{:keys [user-phone-number]} (om/props this)
{:keys [nav]} (om/get-computed this)]
+ (reset! nav-atom nav)
(view
{:style {:flex 1
:backgroundColor "white"}}
@@ -94,7 +119,7 @@
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}}
user-phone-number)
- (touchable-highlight {:onPress #(save-phone-number nav)
+ (touchable-highlight {:onPress #(save-phone-number)
:style {:alignSelf "center"
:borderRadius 7
:backgroundColor "#E5F5F6"
diff --git a/src/messenger/state.cljs b/src/messenger/state.cljs
index 3961596c96..4138c5a2c4 100644
--- a/src/messenger/state.cljs
+++ b/src/messenger/state.cljs
@@ -5,7 +5,8 @@
(set! js/React (js/require "react-native"))
(defonce app-state (atom {:component nil
- :user-phone-number nil}))
+ :user-phone-number nil
+ :user-whisper-identity nil}))
(def ^{:dynamic true :private true} *nav-render*
"Flag to suppress navigator re-renders from outside om when pushing/popping."
true)