From 0a5ce64fe25837166b9798953f3bed961fe634c3 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 13 Jun 2016 19:35:18 +0300 Subject: [PATCH 01/19] added login and users screens --- .../app/src/main/res/drawable-hdpi/avatar.png | Bin 0 -> 1546 bytes .../src/main/res/drawable-hdpi/icon_plus.png | Bin 0 -> 245 bytes .../app/src/main/res/drawable-mdpi/avatar.png | Bin 0 -> 1017 bytes .../src/main/res/drawable-mdpi/icon_plus.png | Bin 0 -> 158 bytes .../src/main/res/drawable-xhdpi/avatar.png | Bin 0 -> 2168 bytes .../src/main/res/drawable-xhdpi/icon_plus.png | Bin 0 -> 278 bytes .../src/main/res/drawable-xxhdpi/avatar.png | Bin 0 -> 3335 bytes .../main/res/drawable-xxhdpi/icon_plus.png | Bin 0 -> 410 bytes .../src/main/res/drawable-xxxhdpi/avatar.png | Bin 0 -> 4638 bytes .../main/res/drawable-xxxhdpi/icon_plus.png | Bin 0 -> 530 bytes src/status_im/login/handlers.cljs | 23 +++++ src/status_im/login/screen.cljs | 83 ++++++++++++++++++ src/status_im/login/styles.cljs | 54 ++++++++++++ src/status_im/users/handlers.cljs | 1 + src/status_im/users/screen.cljs | 68 ++++++++++++++ src/status_im/users/styles.cljs | 83 ++++++++++++++++++ src/status_im/users/subs.cljs | 1 + src/status_im/users/views/user.cljs | 39 ++++++++ 18 files changed, 352 insertions(+) create mode 100644 android/app/src/main/res/drawable-hdpi/avatar.png create mode 100644 android/app/src/main/res/drawable-hdpi/icon_plus.png create mode 100644 android/app/src/main/res/drawable-mdpi/avatar.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_plus.png create mode 100644 android/app/src/main/res/drawable-xhdpi/avatar.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_plus.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/avatar.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_plus.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/avatar.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_plus.png create mode 100644 src/status_im/login/handlers.cljs create mode 100644 src/status_im/login/screen.cljs create mode 100644 src/status_im/login/styles.cljs create mode 100644 src/status_im/users/handlers.cljs create mode 100644 src/status_im/users/screen.cljs create mode 100644 src/status_im/users/styles.cljs create mode 100644 src/status_im/users/subs.cljs create mode 100644 src/status_im/users/views/user.cljs diff --git a/android/app/src/main/res/drawable-hdpi/avatar.png b/android/app/src/main/res/drawable-hdpi/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..b1c2c64e3db6414cb35df84451f6169a00818cf4 GIT binary patch literal 1546 zcmV+l2KD)gP)Px)#7RU!RA>d&T0LwWMHHU<_5Jy5pM5ySA@Kzq2ke9fs1P|*AO*<+3ZP3#Iz&em z0VN$msgP(=AyEK|lpuJv~k+6Q}i9zN)CV*pv8VMu<*keE+~@&hzokj!qKC;#F$*t1Z_&nyqTAz zh{2lE&+gK3TDJX8fK42C<2$HF>aO(9s03H9AY-}F?6QRzNb$9L6FS=5*`~*vi0gTf zOEkvUj@VUnIM>)o=6AJP6Pr6(k=)LTOs*)3rHTRL^|(aP?-h~ZfEXPL2&c0p1Q~bN zK|iv5;lIE-$_ea^IVM_lSWM zfBy)5&b-)b%TZcd-VmGHnVw8XhlAqe)R^k%{RF2kfSj>Ha5hBn7Jf^UBHEqb*Lx;K z|GW{jH6r2(IbrPNV2Ckd_0i(mXu5vB=jM;Ul49)vms#>M5evgp`cX}YK`aF!2XYZ6vGWRG#)|@@t^#4$5`!-tMKQQI>(g*S7K|^9 ztyE6dyv2@K#8i+4a^i@wMiG?-N~QA%q$+FPVn-}uDhRpEkyu;-L==kueRx$cnr$^; z#z~CTBxxyE^b^y7IZI+Jkx7f&CBH1{N6nEMh9kpfWLL=ObaiVjTPC#L|%Q8^rceC4VtPM;aq(y>CVgV(Ac$m~t)@ z@O#9OF{K%8a3Kb6ZPh39 zp63-3<8nod@S#6-A}XFbHYT__eweTi`_e|k3!~B9BE55eN~>_GAB_b2S@UR)|2DUR zPUGy)%~$^C$7e{4Q+pjMo#ET;COkkqB3X;ui4KBtTwmuz| zia9nRw^z(D-pL#~$VCMAg-U=GEa_SG&7mMuu2c=J)LR}?+%Bh~u6oO3Ke7#0hh6Gb z;fwW0YyX>AAGMwerm1wnSjLk~CR-HwVp#x3>fRtA;q$shFyJ*vGQ$st2719dP%u64 zu}4tzK)T)ujUn&s=Ede#MkG;}H|z18`m3I2oj-#5{^&^1NY@So+X~*k#BKHixt2|d zT)re$@260)&5Ckae<{H9ZPmKnE~IM#G5J_n_Lzd=zKuj@sZ4%h`QFyoD1$MVw5{MdtWF&rc|9ET zwS0%$2F{Kym*bjk8Px-0jO|GAvgPym%hKAfcv+mXBSEa+emi|~;^|JYwH-0D^W5~2 zXNSZ7JLa)nTE>Lf&RE4`NemBa5dgEp;lQ_6ApN|?SQryxv)q=kBxVLYH$8qX8VP-f zEJ0t9-URQmrEkW-Sh_K>e8!pqR{l=DxV4k}CY>#6D^4`~Xm=b6c#|VT{@0E_9{Hi& z^>*iaB4z?CCLVm0O6T6k=0Q(6k7?g+i;8d|9P)oW6N`S(t&Q1FiWrR(iG;6M3w@f- z70x3w(Mk}RMIq!Lxa@VL-;Kp$QhQ3$#LPQ`OvQoy=lAl3(mR=4X&QflkSgY*uu}>8 zJ$HQrp3krk{Rv(Ua@lk}FlAyULAE5BSWUiJEsHmba_n^0&Zt+!YGV-M=nZ{WD1x;gDrF>sXYXATM07*qoM6N<$g8dESs{jB1 literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-hdpi/icon_plus.png b/android/app/src/main/res/drawable-hdpi/icon_plus.png new file mode 100644 index 0000000000000000000000000000000000000000..19e2a45b574a418ac158cf5d4ae4f95ac7378005 GIT binary patch literal 245 zcmVPx#uSrBfR7ef&Ra**#Fbp&Tz#`S|;QCMeL-ET&g{Z_zdj7ku1T<+|$@UiI)MgzqJOxnEP7qSvc<3I485-dvk2c v*esQm`1dmEYE!g^`H4j)JJI0-C%WtcrBD}jJ}ujI00000NkvXXu0mjf27ziO literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-mdpi/avatar.png b/android/app/src/main/res/drawable-mdpi/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..f208650ddb5a9906a4bc4cd985ad6d70069baa30 GIT binary patch literal 1017 zcmVPx&vq?ljR9FecSW8b+K@^_*XfL-9+d?Z)s3ZnWj2l-jKoVK7k_|rqH!h9QKfsDV zfH5xJ_#fP8q9%w7_qvgoK(Pf2l+qV%@5A#oOw*R$-nr1~Nlu2Dd%kl%&di)SATf_( z+jfi~k4TqDZ;&R>l?IkM*IgPvkiL^7DNp0zg@~+>ek5&>iVAFjSs553ayC!8MS4|% zkNHazBd|icaa9&Q@bIa4B1V8H>H8ke2DJp=Q6W+=B>gd{$bI}EMt@RdfNdIPX1e(y zmh<+}$6=hAZW7(|jrOgR_=K!*1HSON+h|%g%N!KgaiPkpwMNri*L-X=qO;_9geh{% zwVNw^e?awW3qQ0_L5Ogf9I~^T(bIH9Q`ziHoJB$-J-_!@{7QtHB|*kV zB7?#uOy>K~14lCO2cob6aY30o=fIkT2=q(@h;2e<2<&PO8`uIPC`}GB0r561h=6cr zoVKYK9=5;;$^y6`L(8P92u^}3b+|6m;ltleo5P9W$?GP#@T|Nd=%OgRRyU|AGnipm z%rq@#kU~^NW(ujQ%1oz&t@*ioAs<5E$XW^iq zI>`WyniHB7^|AuyPVM{m<% zJn8r_zzKXKMmHIRxR4;aja2m5SSe8>bz`m3Fc)ieGeJdCH!Z9A4+BM(O)7>}&9CHq nKIK!`udXMPv7L6j+s}UiACKU5*8%<~00000NkvXXu0mjfVu##n literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-mdpi/icon_plus.png b/android/app/src/main/res/drawable-mdpi/icon_plus.png new file mode 100644 index 0000000000000000000000000000000000000000..a26e891239298c026ac03c7a4c216429406ac647 GIT binary patch literal 158 zcmeAS@N?(olHy`uVBq!ia0vp^LLkh+1|-AI^@Rf|#^NA%Cx&(BWL^R}5uPrNAr^wk z2?`AV{{NrPbBJY%;Rb;qhAGokop_mr4ZAu5jk5$E1}ut_Fm$@i5g6EWJhp%3GbNj8 z4oe#J@)#1GxK=(}6xhtcYRdez$lmbj#pFZp5)&90Zf_U1o5MZZ184_>r>mdKI;Vst E07>yNcK`qY literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xhdpi/avatar.png b/android/app/src/main/res/drawable-xhdpi/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..8cc91adff5a4808fde018824aad226b5e5d66600 GIT binary patch literal 2168 zcmV-;2#5EHP)Px-GD$>1RCodHTia_CR~SEgzi+Z8F)=Y}LQ4dxLG4o!L#`jY~avG+I%tV1J8AlZh#>82qc~Z*PPF~ zERs8jwx7%TqDzym6w9JcaC8HzOZ(~#;;YL0NVlIWnNSfRfWtY5Y1Pb;Qw)a$F1}G| zPAUr!!0CsO8{lS~bBckIe~lCO?s8AJk|_gl7%_a5uUBvg7JWOP^_AxZR1zSJJPB@= zbxwg}Ra~Ht^tC7zO)((KCHhrx(f*>6YPc9(NQh_iF%gQyMLd}jiDX)lVz*g@!)6tJ zuS0BTbqkM6`t+B9;(bW9Yx!;z0040KlE-=HrToE0ozDW4hZA!mwwTl<((SZ~E!_dp z2CyX3ZOG<)l+x-b2GCIq7}gFl>NuWAiMwMnA{7_++q8p>IA$8%8GR~}spT}PRi@2q5!?GWD(P3Nj57DlqHh~Oil}4qC+UyS zAqAX&?oHMW4vi+jltsWL5Pc^GIm$&4qQ{A=ERc8QdJQ;WTHU zZj;c{hbU6!0c`{wM2Df^&>_w_^`;f&Tv4OIw zLjvWnPyj-D@zcx!qZRQ{E}JCjIFQ98_jdjc9MMKo-F|TqsCS)Hk230@E`y0!C~2mG z!jF1}5?9ELB1yUwOw0%+g0#IKMv+8aegfo^;Rq{%jUtJpkve_Dxvf{C&?L7MTi&p22GY~|4B?~HpGdl5ks3Lredh0D($ z4kbOloW*2C#GENP{Q2w1VUb(^Bh932UT8vWS8QI$)kP6fivWomr%uRlY9adtG`f() zR=bo)V!K@e8xT^dC9$-W5%|}M(o(nCY*OCc*jlY-VaMwQ>&|wRaXqf(`j1Oqt!bE8 zs2JoTh!+5mAseV7v4n_{@kuxmi;EaQNiT8UGmb3yq~``$UbjOjn0efG9M`>5FTreh5X=5WqYh*3QR*P8#T9&~I_+3icR*-WW{gpRy zQV2jQxea(Ro)V9r2F3Jj)bO;a;6TmYOvjEkkLcOhBAkvDNu$ctzYREd2mYyt<4@Fc z&MS|nf=U_zK=pD{wMZW&{dziE^5?75==-#oGX*K84gv_A@&23-E$n$b6;kFHwQoJN zoTGX={i4jotHLZ9dxeJn?1Q%rl~ zzYk`9nwpIq#@wX)9_{^Ws=p}LbYJA62)7aaOt zbu^4Un*DrgCNhkLVb%AlV6R4tg=40(-FvKWbK9wE^w;F%_>;MznYq|+c-Qh&qinUt zVsk^ZJ>Y(`cT-@bS{rHth)O0h8Fy%O`s!>jwtKD4OPp`oTHH7M{T=(dO{SXmCD#m) z`b&(C&wM-=T0DVrhP+)0sI34X?h(v!3hU2fJC}#YY4pmW+ z7R9u5i_dY%<@Frd(&1r^-4HSqAk`v7lzZ&avu{F?#Y3nd24u}qoMTX7ob!8~XZtp9 z_!{Rm%`>Xq#abx|DqnM|a&p)%+P+fabBsB0^(S+J-}qmGjVhirDs ueTU6*%WAV+33s;qy2F6EMQc~NPx#&`Cr=R9Fe^mVpVwAP_}+9iUsJ(=^L;g6?Fu=@wbQ-lYl`2>i%NE9DCz#;@n+ zd6JV;u;rYu8sb*MBoTQ$AldNnA|EbYtKwnf(X6QbEnd)^J@|Hc-p5gj+`y5%+g&z6C z$IzO3^X;`G{UML+i1Dw@At8jCgh&VxKss}Xgb)Fw|78yO(#7`?j9tA4p`?+`$Xd_r c?$R*$1|T9FAlF{}&Hw-a07*qoM6N<$g1XsyJOBUy literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxhdpi/avatar.png b/android/app/src/main/res/drawable-xxhdpi/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..7fb2d0b42b570a94bcd2574ae2ed2b779ba889df GIT binary patch literal 3335 zcmV+i4fyhjP)Px>!AV3xRCodHU0ZA%R~a6A@4H^F*O&Dr&ZUlN>a?YOfDj;n2t+~<=nJ9}5{LqV zh9{8VjfaA0Uy6iyp{0n6ctEsL9|Czm3Jn4U=uINf5-TA|6DQb?Z|mExz1|z&H`!Tc z*L$6ropW|Qzw~P^J9Ex={%`&>XU_T0*)FAxB%jZB0q!{Th)xe(DDYz0=jzmB(>g2n`^ufFKXRy%&12pvSNcL9LVo5_=tbp`dSoz_gVaSece|gn^`f z6!3BAXP_sbJy1Jk6PaCvo`t>y@>cB3ye;ygCqW;Bz6?!4Wf5W_CSs$v?`?q*hM>F%s+0o?{J#-Us~=Gy!clA!cIV*YU)mkTK|UP?@Sdz%e8&1IrTYIO0&KZs-|k z9NKBZGO=vkb`aO{Rw4?*X8BK`@3Esm0`qtid7nY6lG~O^%bp4l#g^Z*K>jMU)5#)1 zEaPh|Gt15st&o;@7yust*cYM4TLHQa(&R(>IJ|AfYOI!f7|7xW?sBN(3l35WN6>!ZKu?mC!FyoUfsZ%$O~f zX~IBO03i6j`m|Xv9e)4sQ9i!cw#<~%6k#BX!y4zHA2b7E58eA$l=U=7<1mjQF-%y& zv(6(|hpgsIPtr~q^)y3`j>0>O)u2OGb7b*q+U!Nx(AE5{ieiW`WW)xB^UgA2@q72s zc0V(6d((vB$zapnX$=~&cIiD&6l_^~w$4#g?=WP*k79mjIbxj!9>e?Wca0|3Fkv9; zAQJrt)cGiG)Vhsb7sq9fg0z`NE^nwx1X&&=_FJe!RwGtz?i$*ZjS$+nt~5j#Qh5ft zm-`0m8q(wiv@LC1SL#-YV4mYy?0s&O+`5@sc|meJt*opj6>fLZS!hPxG7qoE1$C?2 zpx>kP_XQPhC6yd-9Y@vpMlF0b2?JRq={2ZS<5?ujuuNH^q^a_ab%H`S+#sB+OeUwi{hxW|&itC?WYHkGTux1!c`z>tgf{WS57*yBLam6B^ugwM{2jHU0C-tgU3}i$+g-*#V1`xGt^Mi#%bW*0bVQVt;& zViG9i;*0NAQ%Ob==OoHW$`uvN8p*rNu$J6>B?c8T~6MHaZ6JjDZ zfpWUQjS8Vi7>+niRajG=eS-id&@Pp;CMIGNDCC6PsG=u~qshXA9l5fK1lWq)sD$Au zV(X9-z=a4uRGaN}w-YF_3I3QqQQ)XJ#>FwO9y^Vo&r5^xh8z_MJ6RE> zO(zAv)Eg?L1Q=D0w0D?L!UTWoG(?yL81E5=x{>>%q9ugK7Z7e>$jL4N$h)og?3rj&5 ziDLM)tRfLMc?e^yJ7O24Vv$VbBaH2isfiex z`Qo~Q?oEn_$uj*&|IDa_aXyk%!kBi>B5}D`W7{jtlX(k{tFKn*Ra%7qMIxPW%Fny+ zAGOuf=vmBDg6T%p__$8OILlH>q2V}-#Ey3w^I%>QlSPiMNKF_KvTAzhT_Xx7CbXi- z&!#)mW*(AOgEWICSGo`id7;}HoPjPltt=nP-nH`sZ}Bm&{E`-S*{=;Y!)VQII_zETos2a3GkKm ze-A61IJfI^=Y(hroYTl65cM6VL-cFizOyTb1xh$6R*A%hYEk&YDstFJ8Wgn`Rw=YZ z_$LC6$YFsO3Y-+tlz14=!pnxRxe1jvP%w){F4+y0re?BA4ofrSagJLqfT=Bl$=-cc zF^t{CeQZ5$m*P>^0(L1bi2{CL?{cZQIGENoRlFFCE`l_A**A+P1?;4DGHUC&vciE@d6OG51SiMTblSJVk41K z);CkwZYv3N=!#y#h~s1-^izgIehi@cu=Uv)K~;5u%Zh{*NaI4mPjcUCNn<_4)%7hU z4qe~eR_IObAoMzpOh|Iieuo$kkY?0>8Ar zn07h=gDO2iuS#AN!#3QvNEj4Vb&=+(gfVj%)zmWRTUbGci)&G3Ug^dPLvw};!@8*f zb2D*_ErVVlj33rb{n0=sn^P8+H&v20lPN1~(ROL{1br%Tv4I}N-CU^Nn<%XDKN_H= z;ALDgr|w^QaO8J(aa~!0H(Aw+WB%<*7%ho;Vh#3T5LS03&4vgg7?5@Vn@b=n>JUYXm=hgw z*8kxfp@IFGo3pDwzIt=X@hWp%sduwxqAh7t+P2Xo8}=|Q!E3jc{y4w1@iFb#*&4UN z$YA)D$%BI*ZzhGN31i}yuPt0&SxZbclaX_6sRjBYq3NTOv7@DD>mTtut7(}!JoG5K zXy%)~(YZmj0BuJb8Zn0Pl*wRf1G-3!l?xC${GuqB*eumy*`pi~V@{!r4yO&otw#M}5o&8b^^o0YnV}rv- z`}@00{jrQ`!U&5W*3;J)-om5=XR*vup420(q;qBJaO`1JgLOZQE8Jdk%5asaPlZ5^ zP7XhSuXiVUSZ^5Y(TFs<7(wE_=Dm7r=>mpZK7jp} z*vWLWky$#=rwWxB4>G;j$fq^f9sI1|H8obdK z!Za**SGOltW0#x%DjJ(tr?fvX{>|<5 z^BWtfhY?O71cOoQV%R?)4*TBf@q3;;G(PZmqv;sEPpGjL7S<-$x6(h2uWx@OwUd_m z-v)eMPd3`?|8sA^^YvIPa?Pm0&E6-JFbzE3alRXOmY>>4?0h+q+!>OkRf%^}J{0sW zhC|+8OpFgag=67iU{VmK5y$QP{OWyM>Fjrt+nG;nBvYfAOx9M6ZnrBR4*KSTe)k^& z9@h^>M*7~-;}gAat1+4_EIiHs&h6!|Y^QUd%cL_8rqbCc!n!SOWg`4K=kvJYZjbxl zeoyyH_w66}IXp?)5HP6;D<_y$<=uGVq3vYq)J`UUJe|%=p$}{jEzUqLoAaOnd-e%QTo|ml0{{vBo_i6x$ RSQ!8S002ovPDHLkV1m(=RMG$d literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxhdpi/icon_plus.png b/android/app/src/main/res/drawable-xxhdpi/icon_plus.png new file mode 100644 index 0000000000000000000000000000000000000000..dad95d18143730ebaf829da75d880ef277748583 GIT binary patch literal 410 zcmV;L0cHM)P)Px$R7pfZRA>e5nn4bNKnz74AZ8FRBoxF#WH%%QF@ty^q1_TIV(#ZYWO2s#r0aj@mekmVjAhp6oVVHK?|dt| z&-j|P^Gh^z`;2j8d{6ea9z44r=dSpc?C0g-jf!4QS1kv9ZBhN&xodn~KVxeINgo4Z z=@E$nK}-me-UPAqh(v)PCIm@uf>?S)qCgN6f}}S=EIlGoAczS;(wiWb9+4=p1u-5w z%cc3`IVQVBW7^zO^O+iv!7ct1T+b~z|L3EDEM#l@4eUQ63}Y)$X#fBK07*qoM6N<$ Eg8eSA+yDRo literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxxhdpi/avatar.png b/android/app/src/main/res/drawable-xxxhdpi/avatar.png new file mode 100644 index 0000000000000000000000000000000000000000..c33ac676196df6cc69ba2fd1f5a217ef28ba1919 GIT binary patch literal 4638 zcmV+(65;KMP)Px`*hxe|RCodHU2AL{)fFD^+TQhg*N?T=Ph#Rg;y@Y{LKU^)ktU)l&(e}s6$M&? zS{^_8haZ(7tttc|Qh)HXJX#T2UaHz4P$7Uoq#-~nR04uRNdh=HBzEF>{a&vhyW8(u zc9->fA2YKvJ9EePNXIifbMKvV&i#Duo%=Xbr7SZ_Boft7c@?-X#j9})f&&E@mzBu^ z9LDvd;KM2YysD~d0q4txs+_DTz)}zWE(Ko(J|DamOz_lz&7gS{`Z@R$@W<3TNL25$v#18)MG1r`*oiU_KAz^{Y%gWm?AW^r@`2@jx@m$@FbaU*yO z*lY8ei9)^u;HSXPite3+1Q0;ug7N8LZU%1$v#Ao1*tG2hKLLInV2X>TgirtiaC%|j z+rc-1yG1j033*T8{*&NG0HppBX>D^`2mk>%?EKyh{wbJmQBEel#XSw)4Ir^IZfmkN zfB>8gu-;BE`#5a2mJ_i#dltM4KziS{0pz8}gT0!#2{M*(ei zh&H4xwP!abhb0~e3U@>NXTY4Nl2pD04x)$~;EgzzR8gw92LgDmfQEc6mEbY1s%gvj zQ?@m(R23yv3_wt>8oV1a?E|-}kWD7hW&zrCA8kxqYs;!Xbw!#mDAWQGp95c_UsRb> zg9YA1+8>}v8_|$QS5ngf1n~4gvRA;Ij*wJ23ve3bdjQdZnU6FTKmgA=2v6{^(=4g- z7GS5EAo|FxN1N6M0(khE$+rUu9WmapmSva)W>C_1 z0U}O=7(#{t2;gCdnSCDFY#CBDrWL}O{7a4MSQ`Q$fQPT@Z-Zrr*|d5$v|zrSZ3c+S ze#I}l6AkcikWjv=8(P1n7sh||S5kFX*2BsI5CmXHnIp_{kg%+3up~3K33Z z0O6_kf#vjsZu487k#)y9)J?kkKtL{M)j2V$yA0h@%Zx@^fU6p>LVxIGJ%#G3e1L~- zD3@f&S#>>Dw_lz!5NQKIqniTIuO*QrcSl<~_vxlDT=Y46HX0)UO)j?7c0bW_u}z{a^%>sGBOsig=j5J zK4s0ykm7QcG`B6}%@X280O*>m-%C!5Y6S1I0Xg1VlFP;y*vI+bXQ!3v3O8A$Oj3^~ z?Ywi^6!wt>qYD8d&N}3!Qq9uNyt!<8k>L5@@SyF$Lvs<(l+El;ya`oP6axi45WEkk z`?(#Y6v#}FS$mOew(JU?Y;EX?F6iqNsX1d`XdS#z-f(-xz;QP+7Q3Hq7t7Dt=doL} zmCq=Yk+KRz!~n67m-2cbc%NRRJ^~h^!M4NOR$l8CxhUA%83)hSzzg-~s#M6sFqEzk z;Ndur)vxNgMpg5hGE;Uzh*%&dme3La!Ta#qO-oYR^a2M7MJ2&xzbS={Mdn@tAl%&s z=7KTX6Q?ICJ;H3HQ7Aig5QK;cVq+2I1JKQjQrPqdCq_B9B|1?D>LLg&!Nwv0!9~?W zk?kTV!&!9!$5fV>mO4-uL1=plBN=fQ0SH$a5uPBjHSzzIOER27)I|^JvNGD>1SV>YgfVQSD+WE)@@OsxU+gUH_MBN0T3|6uMv`qxzxqHH?B#>?y ztRw-HdNtc5Ld9_FjZ;Y=-8Q8#lbLPjrm`9lDn=k9Yc{7qx)CeHOa?%gY1Y=F4BYhR zR1!?LBxcfmpmm~D3U`b;l?2o6eAYu6Kz*WAN_xAoDDrBNQ!w4QVpVaWGsLwXtF$O8 z(@F~vGsF%(5Wyov2b$H!KnG4G!E_^LR*HgfV!=w2V$IOVMstDtG2Cxy0s8M0o5AXAR!}zIh6#|Eg&3#7*>vv!JJ0a zNx+bKNdO5K35j9loJNA`xS^i` zEuBKtg*pjHNdO5bw~~y8DqygtCAOvxjO;2Zu@5vUqVNo*%V?;g6Lk9s9{PwfF#{HjKl}P`aWJ zWfe4bbgqe=0U&C{ILr)SX?LQGl+_`W1W?!s$}osG<1p9Sc)bv1ql^Lu94`csFyF$C z7P>3ib&jbpgsvSuQ98V@6UMHxaB-9X;#YVaLunA%sZT^%2yBOehnP8Bg_ZSdc;XlY zWhr8Z@V|nE^UboJs?$CKh}(MjRT4+86=m2I`MD=mV9=U~K?;1yIXr-fVeEz4ouO4* z`N27@7Au+lFanRSO$QTa6Xs|Damt`IST8?$SrQkj6C}T#kp>Vys`7o+Sp`kVNz3l` zMx_fZKe}6XC4S5j(oNVEIDe_^A_Xl#e)d~e#a)Re?Bz6o7`~O?3~*#eT9!(WV$Yez=z%aQ@Xu@WhD&v7t7Y-E7DsM^)D9V8}cxa3afKrxu zN?J%-po9e$VIDF?5O2T>F_b;m3FQSD(}+TI_&^JJo=1G2Gj0qS0;Q4VOS&M1`0Bu0V_X=gU z>N*?+J`XvoOiq8zqJ2Z2TYLibo(%ha9&{b7vS`ugUI+laUnoUMkpZF?kooFD1ytfX zzb86A8C52x2$-lcJu{bVaw_rcNb**X-=j1Jymp92`y#+|O)(p&0nkM# zfQ!v4+83I}2WUsJB`1vUsngp4$i?(<+&xqr!v1=cAYvyrBLYc1!W&nZ*!S54Io>Vy z+>!udW>nroINVXJpmOiA6Z;ilA`16%vC}K*YYVVL&TufnMqd(871&?@Fu-%?*AnDE zQwtzQapKmWQ2t`{UnOXU!_)9I5k;^s_UTu;%$)qH4}lcIHYIu|6KEJ^_5na#Cts9Q z0f;5Q3*Cal9-fy=?EDfmXU3+Juhiw1x195H$e^{UJ_#mv$_=6&0MFxU%F+TLracJ0 zSWUsXY3N-}jZ7&+!;=bMuO%680S*^*gaS%CHc^)G?XkBY*`)xGs!peB08w3dq4hW% z0;`_l;F!$d>4~Jr5$v0wR9Q&kmk-&zF?=w`o-`1rEH(l>AF9ox2|z3qAi5uiouwWS z9*Za^;cdnzXG$fN_f51wW1vpyf>#Qv3jw$b;Q5Ufar6L)2WmK+!l$mfW*%7RRGV+dIZxAAU^C!|L}p+;i=2? zJXq$jhXvY#{x{b2hPLRHrYr!#3)TMj=+H^bQwjCmRlUY?T0YFTjeKKuM;E-$oL=3^ zn&0AsyUuFdfO#7Es-?FEEXv0^W8IYl9*SNTfLK6_&-Z0}Yttp3+8T}_ND{yTtSi#kgJ%LWhy=nB;zY76;(SY7R2v|_(p;beZ}ExV2N^uApyYdwbL8X4|A90HP9@_V9etKfE97guaFI ziapnC1KO#4j4CIv?&sfYdqZ1so{V8=wtN-q;8LOUR<&*J3N_qQTT?9u91X5n+LX4X zjVlEns$hvH7#f;de|miKpA%Ejpuu)rmc=#rz2UaTz;`-2{Hm9t8f7R;07T)@jJZD@ z7A&To`b z%b^^fw|1&I;Qd8!Ps?Ae)YozVQF(YH*QZ~cd31Clx?^sBp@H&?FC2awqv@u6UB4-UxOh1n|wF~2MISrDw3y&_Bi*H!(g&OLwYiTKe8Af*5 z<(%6JKxsvWh9|B)Ga7khY;vYEeQh}(n*w!%tgt=y4;ksUMB zvky$o%(XAKu_H8334dMfsk(a4J!^Ve_M~lMx1+5Als49}!SIzck%b50k@~PjS_qlb zvTHqJOL77p=Wv~``mU9oLEC>tQmD!ZPt9Hs9+`X)o$W2NbMuaxpye`CbdC=MTLO0l z{hklB0?(@SLIEgkB#t3{_QlBE)6u!x5v{CS)Nv$^;~*;8iF$ACBj=pmvfHY$oU~o_ z9EAi>wxWZBlc8vAZfA5hwjJT`x)GSl);b|jR03h_PIx`;y#eDZ{cJuKyL@&&wi+RSTjm#HruLm`s@)3+?K|SBaUZR5yI-46xc{qk|2Ww&rTM<_L+vq#3Ps9^vEyNOyu~^K9HQZi!vFdnSaV3<5i*XxC z=&NAXxhjsZJ8^iA1*|cSy4~(bwYzG(%2o9x?th3dXjd-}>aR7HypY?3(nn_I#tC~bu z*cfIjur@LtQ1ft1VA#MJBp|_%L!z+5g@}KfR-Iq@ui9eG&wD@g{R>w5drh8m-bUi7 z+P2k=8|^gpHm*1rcrNtJpR6_hT#k2b9@Ql;_^h_KaFYy&W1;h=yJiJkjpxkM8SaJ z28$*K4}%#Q!qFZ9BHVAb3f;DTcHyHK%hXqsz1{=}R?7neYwxcm8|~8bANEVF|EFJ3 nxM;P}6Nz0@9=a`0`^|oMk@>93gG>E@k<8%f>gTe~DWM4fgYwmO literal 0 HcmV?d00001 diff --git a/src/status_im/login/handlers.cljs b/src/status_im/login/handlers.cljs new file mode 100644 index 0000000000..62315642bd --- /dev/null +++ b/src/status_im/login/handlers.cljs @@ -0,0 +1,23 @@ +(ns status-im.login.handlers + (:require [re-frame.core :refer [register-handler after dispatch]] + [status-im.utils.handlers :as u])) + + +(defn set-login-from-qr + [{:keys [login] :as db} [_ _ login-info]] + (assoc db :login (merge login login-info))) + +(register-handler :set-login-from-qr set-login-from-qr) + + +(defn go-back + [_ _] + (dispatch [:navigate-back])) + +(defn login + [{:keys [login] :as db} [_ _]] + (assoc db :current-account {:address (:address login)})) + +(register-handler :login-account + (-> login + ((after go-back)))) \ No newline at end of file diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs new file mode 100644 index 0000000000..e8974cffff --- /dev/null +++ b/src/status_im/login/screen.cljs @@ -0,0 +1,83 @@ +(ns status-im.login.screen + (:require-macros [status-im.utils.views :refer [defview]]) + (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [status-im.components.react :refer [view + text + text-input + image + linear-gradient + touchable-highlight]] + [status-im.components.toolbar :refer [toolbar]] + [status-im.components.styles :refer [color-purple + color-white + icon-search + icon-back + icon-qr + toolbar-background1 + toolbar-title-container + toolbar-title-text + button-input-container + button-input + white-form-text-input]] + [status-im.qr-scanner.views.import-button :refer [import-button]] + [status-im.i18n :refer [label]] + [status-im.login.styles :as st])) + +(def toolbar-title + [view toolbar-title-container + [text {:style (merge toolbar-title-text {:color color-white})} + (label :t/login)]]) + +(defview address-input [address] + [view button-input-container + [text-input + {:underlineColorAndroid color-white + :placeholderTextColor color-white + :style (merge white-form-text-input button-input) + :autoFocus true + :placeholder (label :t/address) + :onChangeText #(dispatch [:set-in [:login :address] %])} + address] + [import-button #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])]]) + +(defview password-input [] + [] + [text-input + {:underlineColorAndroid color-white + :placeholderTextColor color-white + :style white-form-text-input + :autoFocus true + :placeholder (label :t/password) + :onChangeText #(dispatch [:set-in [:login :password] %])} + ""]) + +(defview login [] + [{:keys [address]} [:get :login]] + [view st/screen-container + [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] + :start [0, 0] + :end [0.5, 1] + :locations [0, 0.8 ,1] + :style st/gradient-background}] + + [toolbar {:background-color :transparent + :nav-action {:image {:source {:uri :icon_back_white} + :style icon-back} + :handler #(dispatch [:navigate-back])} + :custom-content toolbar-title + :action {:image {:style icon-search} + :handler #()}}] + [view st/form-container + [address-input (or address "")] + [password-input] + ] + [view st/bottom-actions-container + [view st/recover-text-container + [touchable-highlight + {:on-press #()} + [text {:style st/recover-text} (label :t/recover-from-passphrase)]]] + [view st/connect-button-container + [touchable-highlight + {:on-press #(dispatch [:login-account])} + [view st/connect-button + [text {:style st/connect-button-text} (label :t/connect)]]]]]]) diff --git a/src/status_im/login/styles.cljs b/src/status_im/login/styles.cljs new file mode 100644 index 0000000000..677c3e7799 --- /dev/null +++ b/src/status_im/login/styles.cljs @@ -0,0 +1,54 @@ +(ns status-im.login.styles + (:require [status-im.components.styles :refer [font + title-font + text1-color + color-white + toolbar-background2 + online-color]])) + + +(def screen-container + {:flex 1 + :color :white}) + +(def gradient-background + {:position :absolute + :top 0 + :right 0 + :bottom 0 + :left 0}) + +(def form-container + {:marginLeft 16 + :margin-top 70}) + +(def bottom-actions-container + {:position :absolute + :left 0 + :right 0 + :bottom 16}) + +(def recover-text-container + {:flex 1 + :flexWrap :nowrap + :padding 16}) + +(def recover-text + {:flex 1 + :color color-white}) + +(def connect-button-container + {:position :absolute + :right 16 + :top 0}) + +(def connect-button + {:backgroundColor color-white + :borderRadius 55 + :paddingVertical 16 + :paddingHorizontal 28 + }) + +(def connect-button-text + {:color "#7099e6" + :fontSize 16}) \ No newline at end of file diff --git a/src/status_im/users/handlers.cljs b/src/status_im/users/handlers.cljs new file mode 100644 index 0000000000..7aa5f85efa --- /dev/null +++ b/src/status_im/users/handlers.cljs @@ -0,0 +1 @@ +(ns status-im.users.handlers) \ No newline at end of file diff --git a/src/status_im/users/screen.cljs b/src/status_im/users/screen.cljs new file mode 100644 index 0000000000..b40e29a30d --- /dev/null +++ b/src/status_im/users/screen.cljs @@ -0,0 +1,68 @@ +(ns status-im.users.screen + (:require-macros [status-im.utils.views :refer [defview]]) + (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] + [status-im.components.react :refer [view + text + list-view + list-item + image + linear-gradient + touchable-highlight]] + [status-im.components.toolbar :refer [toolbar]] + [status-im.components.styles :refer [color-purple + color-white + icon-search + icon-back + icon-qr + toolbar-background1 + toolbar-title-container + toolbar-title-text + button-input-container + button-input + white-form-text-input]] + [status-im.utils.listview :as lw] + [status-im.users.views.user :refer [user-view]] + [status-im.i18n :refer [label]] + [status-im.users.styles :as st])) + +(def toolbar-title + [view toolbar-title-container + [text {:style (merge toolbar-title-text {:color color-white})} + (label :t/switch-users)]]) + +(defn render-row [row _ _] + (list-item [user-view row])) + +(defn render-separator [_ row-id _] + (list-item [view {:style st/row-separator + :key row-id}])) + +(defview users [] + [accounts [:get :accounts]] + (let [accounts (conj accounts {:name (label :t/add-account) + :address "0x0" + :photo-path :icon_plus})] + [view st/screen-container + [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] + :start [0, 0] + :end [0.5, 1] + :locations [0, 0.8 ,1] + :style st/gradient-background}] + + [toolbar {:background-color :transparent + :nav-action {:image {:source {:uri :icon_back_white} + :style icon-back} + :handler #(dispatch [:navigate-back])} + :custom-content toolbar-title + :action {:image {:style icon-search} + :handler #()}}] + + [view st/user-list-container + [list-view {:dataSource (lw/to-datasource accounts) + :enableEmptySections true + :renderRow render-row + :renderSeparator render-separator + :style st/user-list}]]])) + + +;(re-frame.core/dispatch [:set :view-id :users]) \ No newline at end of file diff --git a/src/status_im/users/styles.cljs b/src/status_im/users/styles.cljs new file mode 100644 index 0000000000..1c580d8f73 --- /dev/null +++ b/src/status_im/users/styles.cljs @@ -0,0 +1,83 @@ +(ns status-im.users.styles + (:require [status-im.components.styles :refer [font + title-font + text1-color + color-white + toolbar-background2 + online-color]])) + + +(def screen-container + {:flex 1 + :color :white}) + +(def gradient-background + {:position :absolute + :top 0 + :right 0 + :bottom 0 + :left 0}) + +(def user-list-container1 + {:position :absolute + :top 56 + :right 0 + :bottom 0 + :left 0 + :justifyContent :center}) + +(def user-list-container + {:flex 1 + :flexDirection :column + :justifyContent :center}) + +(def user-list + {}) + +(def row-separator + {:borderBottomWidth 1 + :borderBottomColor "#bababa"}) + +(def user-container + {:flex 1 + :flexDirection :row + :height 69 + :backgroundColor "rgba(255, 255, 255, 0.1)" + :alignItems :center + :justifyContent :center}) + +(def photo-container + {:flex 0.2 + :flexDirection :column + :alignItems :center + :justifyContent :center}) + +(def user-photo-container + {:flex 1 + :backgroundColor "rgba(255, 255, 255, 0.2)" + :borderRadius 50 + :width 36 + :height 36 + :alignItems :center + :justifyContent :center}) + +(def photo-image + {:borderRadius 50 + :width 36 + :height 36}) + +(def name-container + {:flex 1 + :flexDirection :column}) + +(def name-text + {:color color-white}) + +(def address-text + {:color color-white}) + +(def online-container + {:flex 0.2 + :flexDirection :column + :alignItems :center + :justifyContent :center}) diff --git a/src/status_im/users/subs.cljs b/src/status_im/users/subs.cljs new file mode 100644 index 0000000000..805245ffd2 --- /dev/null +++ b/src/status_im/users/subs.cljs @@ -0,0 +1 @@ +(ns status-im.users.subs) \ No newline at end of file diff --git a/src/status_im/users/views/user.cljs b/src/status_im/users/views/user.cljs new file mode 100644 index 0000000000..3ff295ed10 --- /dev/null +++ b/src/status_im/users/views/user.cljs @@ -0,0 +1,39 @@ +(ns status-im.users.views.user + (:require-macros [status-im.utils.views :refer [defview]]) + (:require [clojure.string :as s] + [status-im.resources :as res] + [status-im.components.react :refer [view + text + image + touchable-highlight]] + [re-frame.core :refer [dispatch subscribe]] + [status-im.components.styles :refer [icon-ok + icon-plus]] + [status-im.users.styles :as st])) + +(defn on-press [address] + (dispatch [:navigate-to :login address]) + (dispatch [:set-in [:login :address] address])) + +(defview user-view [{:keys [address photo-path name ] :as account}] + [current-account [:get :current-account]] + [touchable-highlight + {:onPress #(on-press address)} + [view st/user-container + [view st/photo-container + [view st/user-photo-container + (if (not= address "0x0") + [image {:source {:uri (if (s/blank? photo-path) :avatar photo-path)} + :style st/photo-image}] + [image {:source {:uri :icon_plus} + :style icon-plus}])]] + [view st/name-container + [text {:style st/name-text + :numberOfLines 1} name] + (when (not= address "0x0") + [text {:style st/address-text + :numberOfLines 1} address])] + [view st/online-container + (when (= address (:address current-account)) + [image {:source {:uri :icon_ok} + :style icon-ok}])]]]) From c5f41344d4a7ce5f50da08adee76b5becff38850 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Fri, 1 Jul 2016 00:11:48 +0300 Subject: [PATCH 02/19] add links to new screens --- src/status_im/android/core.cljs | 3 +++ src/status_im/components/drawer/view.cljs | 1 + 2 files changed, 4 insertions(+) diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 5405f58393..63586efbb2 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -14,6 +14,7 @@ [status-im.discovery.screen :refer [discovery]] [status-im.discovery.tag :refer [discovery-tag]] [status-im.chat.screen :refer [chat]] + [status-im.users.screen :refer [users]] [status-im.chats-list.screen :refer [chats-list]] [status-im.new-group.screen :refer [new-group]] [status-im.participants.views.add :refer [new-participants]] @@ -76,6 +77,8 @@ :qr-scanner [qr-scanner] :chat [chat] :profile [profile] + :users [users] + :login [login] :my-profile [my-profile]))}))) (defn init [] diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index a98fb9d542..c040b8cb7c 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -65,6 +65,7 @@ [view st/switch-users-container [touchable-opacity {:onPress (fn [] (close-drawer) + (dispatch [:navigate-to :users]) ;; TODO not implemented )} [text {:style st/switch-users-text} From 6e42338fdcdc2204093b6545451e8af057c74015 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 18:56:17 +0300 Subject: [PATCH 03/19] update select user screen --- src/status_im/accounts/handlers.cljs | 5 ++++- src/status_im/android/core.cljs | 1 + src/status_im/persistence/realm.cljs | 6 ++++-- src/status_im/users/screen.cljs | 6 +++--- src/status_im/users/views/user.cljs | 4 ++-- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index cfb6d32d9b..a3d6550853 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -6,6 +6,7 @@ [status-im.utils.types :refer [json->clj]] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] + [status-im.utils.identicon :refer [identicon]] [clojure.string :as str])) @@ -25,7 +26,9 @@ public-key (:pubkey data) address (:address data) account {:public-key public-key - :address address}] + :address address + :name address + :photo-path (identicon address)}] (log/debug "Created account: " result) (when (not (str/blank? public-key)) (do diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 77174edd2b..f71789f8ab 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -14,6 +14,7 @@ [status-im.discovery.screen :refer [discovery]] [status-im.discovery.tag :refer [discovery-tag]] [status-im.chat.screen :refer [chat]] + [status-im.login.screen :refer [login]] [status-im.users.screen :refer [users]] [status-im.chats-list.screen :refer [chats-list]] [status-im.new-group.screen :refer [new-group]] diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs index e9e9e1098d..08e7ae84f4 100644 --- a/src/status_im/persistence/realm.cljs +++ b/src/status_im/persistence/realm.cljs @@ -17,8 +17,10 @@ :optinal true}}} {:name :accounts :primaryKey :address - :properties {:address "string" - :public-key "string"}} + :properties {:address "string" + :public-key "string" + :name "string" + :photo-path "string"}} {:name :requests :properties {:message-id :string :chat-id :string diff --git a/src/status_im/users/screen.cljs b/src/status_im/users/screen.cljs index b40e29a30d..09de1948e6 100644 --- a/src/status_im/users/screen.cljs +++ b/src/status_im/users/screen.cljs @@ -39,9 +39,9 @@ (defview users [] [accounts [:get :accounts]] - (let [accounts (conj accounts {:name (label :t/add-account) - :address "0x0" - :photo-path :icon_plus})] + (let [accounts (conj (vals accounts) {:name (label :t/add-account) + :address "0x0" + :photo-path :icon_plus})] [view st/screen-container [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] :start [0, 0] diff --git a/src/status_im/users/views/user.cljs b/src/status_im/users/views/user.cljs index 3ff295ed10..daf1a41387 100644 --- a/src/status_im/users/views/user.cljs +++ b/src/status_im/users/views/user.cljs @@ -15,7 +15,7 @@ (dispatch [:navigate-to :login address]) (dispatch [:set-in [:login :address] address])) -(defview user-view [{:keys [address photo-path name ] :as account}] +(defview user-view [{:keys [address photo-path name] :as account}] [current-account [:get :current-account]] [touchable-highlight {:onPress #(on-press address)} @@ -29,7 +29,7 @@ :style icon-plus}])]] [view st/name-container [text {:style st/name-text - :numberOfLines 1} name] + :numberOfLines 1} (or name address)] (when (not= address "0x0") [text {:style st/address-text :numberOfLines 1} address])] From 6841e8e430ace8b939fa6eaea5e5c364142d5e18 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 19:14:41 +0300 Subject: [PATCH 04/19] renamed users to accounts and fixed current account setting --- src/status_im/accounts/handlers.cljs | 11 +++++++---- src/status_im/{users => accounts}/screen.cljs | 14 +++++++------- src/status_im/{users => accounts}/styles.cljs | 12 ++++++------ src/status_im/{users => accounts}/views/user.cljs | 10 +++++----- src/status_im/android/core.cljs | 4 ++-- src/status_im/users/handlers.cljs | 1 - src/status_im/users/subs.cljs | 1 - 7 files changed, 27 insertions(+), 26 deletions(-) rename src/status_im/{users => accounts}/screen.cljs (89%) rename src/status_im/{users => accounts}/styles.cljs (90%) rename src/status_im/{users => accounts}/views/user.cljs (86%) delete mode 100644 src/status_im/users/handlers.cljs delete mode 100644 src/status_im/users/subs.cljs diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index a3d6550853..7525fe61be 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -33,9 +33,9 @@ (when (not (str/blank? public-key)) (do (save-password password) + (dispatch [:add-account account]) (dispatch [:login-account address password]) - (dispatch [:initialize-protocol account]) - (dispatch [:add-account account]))))) + (dispatch [:initialize-protocol account]))))) (register-handler :create-account (-> (fn [db [_ password]] @@ -44,5 +44,8 @@ (register-handler :login-account (-> (fn [db [_ address password]] - (.login geth address password (fn [result] (log/debug "Logged in account: " address result))) - db))) \ No newline at end of file + (.login geth address password (fn [result] + (log/debug "Logged in account: " address result) + (dispatch [:set :current-account (get-in db [:accounts address])]))) + db))) + diff --git a/src/status_im/users/screen.cljs b/src/status_im/accounts/screen.cljs similarity index 89% rename from src/status_im/users/screen.cljs rename to src/status_im/accounts/screen.cljs index 09de1948e6..34cc1d1982 100644 --- a/src/status_im/users/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -1,4 +1,4 @@ -(ns status-im.users.screen +(ns status-im.accounts.screen (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.components.react :refer [view @@ -21,9 +21,9 @@ button-input white-form-text-input]] [status-im.utils.listview :as lw] - [status-im.users.views.user :refer [user-view]] + [status-im.accounts.views.account :refer [account-view]] [status-im.i18n :refer [label]] - [status-im.users.styles :as st])) + [status-im.accounts.styles :as st])) (def toolbar-title [view toolbar-title-container @@ -31,13 +31,13 @@ (label :t/switch-users)]]) (defn render-row [row _ _] - (list-item [user-view row])) + (list-item [account-view row])) (defn render-separator [_ row-id _] (list-item [view {:style st/row-separator :key row-id}])) -(defview users [] +(defview accounts [] [accounts [:get :accounts]] (let [accounts (conj (vals accounts) {:name (label :t/add-account) :address "0x0" @@ -57,12 +57,12 @@ :action {:image {:style icon-search} :handler #()}}] - [view st/user-list-container + [view st/account-list-container [list-view {:dataSource (lw/to-datasource accounts) :enableEmptySections true :renderRow render-row :renderSeparator render-separator - :style st/user-list}]]])) + :style st/account-list}]]])) ;(re-frame.core/dispatch [:set :view-id :users]) \ No newline at end of file diff --git a/src/status_im/users/styles.cljs b/src/status_im/accounts/styles.cljs similarity index 90% rename from src/status_im/users/styles.cljs rename to src/status_im/accounts/styles.cljs index 1c580d8f73..ac899e71bb 100644 --- a/src/status_im/users/styles.cljs +++ b/src/status_im/accounts/styles.cljs @@ -1,4 +1,4 @@ -(ns status-im.users.styles +(ns status-im.accounts.styles (:require [status-im.components.styles :refer [font title-font text1-color @@ -18,7 +18,7 @@ :bottom 0 :left 0}) -(def user-list-container1 +(def account-list-container1 {:position :absolute :top 56 :right 0 @@ -26,19 +26,19 @@ :left 0 :justifyContent :center}) -(def user-list-container +(def account-list-container {:flex 1 :flexDirection :column :justifyContent :center}) -(def user-list +(def account-list {}) (def row-separator {:borderBottomWidth 1 :borderBottomColor "#bababa"}) -(def user-container +(def account-container {:flex 1 :flexDirection :row :height 69 @@ -52,7 +52,7 @@ :alignItems :center :justifyContent :center}) -(def user-photo-container +(def account-photo-container {:flex 1 :backgroundColor "rgba(255, 255, 255, 0.2)" :borderRadius 50 diff --git a/src/status_im/users/views/user.cljs b/src/status_im/accounts/views/user.cljs similarity index 86% rename from src/status_im/users/views/user.cljs rename to src/status_im/accounts/views/user.cljs index daf1a41387..af714d566e 100644 --- a/src/status_im/users/views/user.cljs +++ b/src/status_im/accounts/views/user.cljs @@ -1,4 +1,4 @@ -(ns status-im.users.views.user +(ns status-im.accounts.views.account (:require-macros [status-im.utils.views :refer [defview]]) (:require [clojure.string :as s] [status-im.resources :as res] @@ -9,19 +9,19 @@ [re-frame.core :refer [dispatch subscribe]] [status-im.components.styles :refer [icon-ok icon-plus]] - [status-im.users.styles :as st])) + [status-im.accounts.styles :as st])) (defn on-press [address] (dispatch [:navigate-to :login address]) (dispatch [:set-in [:login :address] address])) -(defview user-view [{:keys [address photo-path name] :as account}] +(defview account-view [{:keys [address photo-path name] :as account}] [current-account [:get :current-account]] [touchable-highlight {:onPress #(on-press address)} - [view st/user-container + [view st/account-container [view st/photo-container - [view st/user-photo-container + [view st/account-photo-container (if (not= address "0x0") [image {:source {:uri (if (s/blank? photo-path) :avatar photo-path)} :style st/photo-image}] diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index f71789f8ab..bc6406e039 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -15,7 +15,7 @@ [status-im.discovery.tag :refer [discovery-tag]] [status-im.chat.screen :refer [chat]] [status-im.login.screen :refer [login]] - [status-im.users.screen :refer [users]] + [status-im.accounts.screen :refer [accounts]] [status-im.chats-list.screen :refer [chats-list]] [status-im.new-group.screen :refer [new-group]] [status-im.participants.views.add :refer [new-participants]] @@ -78,7 +78,7 @@ :qr-scanner [qr-scanner] :chat [chat] :profile [profile] - :users [users] + :users [accounts] :login [login] :my-profile [my-profile]))}))) diff --git a/src/status_im/users/handlers.cljs b/src/status_im/users/handlers.cljs deleted file mode 100644 index 7aa5f85efa..0000000000 --- a/src/status_im/users/handlers.cljs +++ /dev/null @@ -1 +0,0 @@ -(ns status-im.users.handlers) \ No newline at end of file diff --git a/src/status_im/users/subs.cljs b/src/status_im/users/subs.cljs deleted file mode 100644 index 805245ffd2..0000000000 --- a/src/status_im/users/subs.cljs +++ /dev/null @@ -1 +0,0 @@ -(ns status-im.users.subs) \ No newline at end of file From 14c2b1940200540f5211c1b871f6375d568fbab1 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 19:59:03 +0300 Subject: [PATCH 05/19] implemented login flow on startup --- src/status_im/accounts/handlers.cljs | 20 +++++++++++++++---- .../views/{user.cljs => account.cljs} | 0 src/status_im/android/core.cljs | 14 +++++++++---- src/status_im/db.cljs | 1 + src/status_im/handlers.cljs | 7 +------ src/status_im/login/handlers.cljs | 15 +------------- src/status_im/login/screen.cljs | 4 ++-- src/status_im/navigation/handlers.cljs | 8 ++++++++ 8 files changed, 39 insertions(+), 30 deletions(-) rename src/status_im/accounts/views/{user.cljs => account.cljs} (100%) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 7525fe61be..88aeabb432 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -7,6 +7,7 @@ [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] [status-im.utils.identicon :refer [identicon]] + [status-im.db :refer [default-view]] [clojure.string :as str])) @@ -34,8 +35,7 @@ (do (save-password password) (dispatch [:add-account account]) - (dispatch [:login-account address password]) - (dispatch [:initialize-protocol account]))))) + (dispatch [:login-account address password]))))) (register-handler :create-account (-> (fn [db [_ password]] @@ -45,7 +45,19 @@ (register-handler :login-account (-> (fn [db [_ address password]] (.login geth address password (fn [result] - (log/debug "Logged in account: " address result) - (dispatch [:set :current-account (get-in db [:accounts address])]))) + (let [account (get-in db [:accounts address])] + (log/debug "Logged in account: " address result) + (dispatch [:set :login {}]) + (dispatch [:set :current-account account]) + (dispatch [:initialize-protocol account]) + (dispatch [:navigate-to-clean default-view])))) db))) +(defn load-accounts! [db _] + (let [accounts (->> (accounts/get-accounts) + (map (fn [{:keys [address] :as account}] + [address account])) + (into {}))] + (assoc db :accounts accounts))) + +(register-handler :load-accounts load-accounts!) \ No newline at end of file diff --git a/src/status_im/accounts/views/user.cljs b/src/status_im/accounts/views/account.cljs similarity index 100% rename from src/status_im/accounts/views/user.cljs rename to src/status_im/accounts/views/account.cljs diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index bc6406e039..e591c69abb 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -8,7 +8,7 @@ [status-im.components.react :refer [navigator app-registry device-event-emitter orientation]] [status-im.components.main-tabs :refer [main-tabs]] - [status-im.contacts.views.contact-list :refer [contact-list] ] + [status-im.contacts.views.contact-list :refer [contact-list]] [status-im.contacts.views.new-contact :refer [new-contact]] [status-im.qr-scanner.screen :refer [qr-scanner]] [status-im.discovery.screen :refer [discovery]] @@ -23,7 +23,8 @@ [status-im.group-settings.screen :refer [group-settings]] [status-im.profile.screen :refer [profile my-profile]] [status-im.utils.utils :refer [toast]] - [status-im.utils.encryption])) + [status-im.utils.encryption] + [status-im.utils.logging :as log])) (defn init-back-button-handler! [] (let [new-listener (fn [] @@ -42,7 +43,9 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) view-id (subscribe [:get :view-id]) + account (subscribe [:get :current-account]) keyboard-height (subscribe [:get :keyboard-height])] + (log/debug "Current account: " @account) (r/create-class {:component-will-mount (fn [] @@ -64,7 +67,9 @@ #(dispatch [:set :keyboard-height 0])))) :render (fn [] - (case (if @signed-up @view-id :chat) + (let [startup-view (if @account @view-id (if (= @view-id :login) :login :users))] + (log/debug startup-view) + (case (if @signed-up startup-view :chat) :discovery [main-tabs] :discovery-tag [discovery-tag] :add-participants [new-participants] @@ -80,12 +85,13 @@ :profile [profile] :users [accounts] :login [login] - :my-profile [my-profile]))}))) + :my-profile [my-profile])))}))) (defn init [] (dispatch-sync [:initialize-db]) (dispatch [:initialize-crypt]) (dispatch [:initialize-geth]) + (dispatch [:load-accounts]) (dispatch [:initialize-chats]) ;protocol must be initialized after user enters password and we create account ;(dispatch [:initialize-protocol]) diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 9d1cc6fa5d..8eefb216ad 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -12,6 +12,7 @@ (def app-db {:identity-password "replace-me-with-user-entered-password" :identity "me" :accounts {} + :current-account false :contacts [] :contacts-ids #{} :selected-contacts #{} diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index ee070f1ceb..0a6f9b2dda 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -79,12 +79,7 @@ (dispatch [:crypt-initialized])))))))) (defn node-started [db result] - (let [identity (:user-identity db) - password (:password db)] - (log/debug "Started Node: " result) - (when identity (do - (dispatch [:login-account (:address identity) password]) - (dispatch [:initialize-protocol identity]))))) + (log/debug "Started Node: " result)) (register-handler :initialize-geth (u/side-effect! diff --git a/src/status_im/login/handlers.cljs b/src/status_im/login/handlers.cljs index 62315642bd..79c6944d31 100644 --- a/src/status_im/login/handlers.cljs +++ b/src/status_im/login/handlers.cljs @@ -7,17 +7,4 @@ [{:keys [login] :as db} [_ _ login-info]] (assoc db :login (merge login login-info))) -(register-handler :set-login-from-qr set-login-from-qr) - - -(defn go-back - [_ _] - (dispatch [:navigate-back])) - -(defn login - [{:keys [login] :as db} [_ _]] - (assoc db :current-account {:address (:address login)})) - -(register-handler :login-account - (-> login - ((after go-back)))) \ No newline at end of file +(register-handler :set-login-from-qr set-login-from-qr) \ No newline at end of file diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index e8974cffff..eef2ff99cc 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -52,7 +52,7 @@ ""]) (defview login [] - [{:keys [address]} [:get :login]] + [{:keys [address password]} [:get :login]] [view st/screen-container [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] :start [0, 0] @@ -78,6 +78,6 @@ [text {:style st/recover-text} (label :t/recover-from-passphrase)]]] [view st/connect-button-container [touchable-highlight - {:on-press #(dispatch [:login-account])} + {:on-press #(dispatch [:login-account address password])} [view st/connect-button [text {:style st/connect-button-text} (label :t/connect)]]]]]]) diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index db33411902..5d61fe3163 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -80,3 +80,11 @@ (push-view :profile))) (register-handler :show-profile show-profile) + +(defn navigate-to-clean + [db [_ view-id]] + (-> db + (assoc :navigation-stack (list)) + (push-view view-id))) + +(register-handler :navigate-to-clean navigate-to-clean) From e787a190a9a6fb04510423f03f4fb2c28487a0c6 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 20:02:41 +0300 Subject: [PATCH 06/19] remove add account item --- src/status_im/accounts/screen.cljs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index 34cc1d1982..fff89e7cf8 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -39,9 +39,7 @@ (defview accounts [] [accounts [:get :accounts]] - (let [accounts (conj (vals accounts) {:name (label :t/add-account) - :address "0x0" - :photo-path :icon_plus})] + (let [accounts (vals accounts)] [view st/screen-container [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] :start [0, 0] @@ -65,4 +63,7 @@ :style st/account-list}]]])) -;(re-frame.core/dispatch [:set :view-id :users]) \ No newline at end of file +;(re-frame.core/dispatch [:set :view-id :users]) +;{:name (label :t/add-account) +;:address "0x0" +;:photo-path :icon_plus} \ No newline at end of file From af3f21629b64f4de4e4c4fca4543537d44ea99d4 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 21:19:12 +0300 Subject: [PATCH 07/19] updated design for login input fields --- .../res/drawable-hdpi/icon_scan_white.png | Bin 0 -> 284 bytes .../res/drawable-mdpi/icon_scan_white.png | Bin 0 -> 188 bytes .../res/drawable-xhdpi/icon_scan_white.png | Bin 0 -> 314 bytes .../res/drawable-xxhdpi/icon_scan_white.png | Bin 0 -> 479 bytes .../res/drawable-xxxhdpi/icon_scan_white.png | Bin 0 -> 668 bytes src/status_im/components/text_field/view.cljs | 2 +- src/status_im/contacts/views/new_contact.cljs | 3 +- src/status_im/login/screen.cljs | 40 +++++++++--------- src/status_im/login/styles.cljs | 12 +++++- .../qr_scanner/views/scan-button.cljs | 19 +++++---- 10 files changed, 45 insertions(+), 31 deletions(-) create mode 100644 android/app/src/main/res/drawable-hdpi/icon_scan_white.png create mode 100644 android/app/src/main/res/drawable-mdpi/icon_scan_white.png create mode 100644 android/app/src/main/res/drawable-xhdpi/icon_scan_white.png create mode 100644 android/app/src/main/res/drawable-xxhdpi/icon_scan_white.png create mode 100644 android/app/src/main/res/drawable-xxxhdpi/icon_scan_white.png diff --git a/android/app/src/main/res/drawable-hdpi/icon_scan_white.png b/android/app/src/main/res/drawable-hdpi/icon_scan_white.png new file mode 100644 index 0000000000000000000000000000000000000000..a9496cb1857881193e088326efefa39b6ecd11cf GIT binary patch literal 284 zcmV+%0ptFOP)Px#)=5M`R7ef&R&5T0APmJ_WjoOB;u+kp?Jm2IUPS-kduB~oq!u@DSwfQnw)OQR zKylvt8+Zh7Q4i(WMTl}R^;<;z&S9_|2}m39#s6C|Fy@iQDfDe-i;sq*MBIR6oof#9 zPq{!-aH_MEDw#HimvMN7B(oXeP6NRmc+PkO@L)!7h@HSI^V0Y$hgI;$6)3%1-th4u zjju0JvkcrKz>zplv8ifL}w4M<&X{V isi09V4N@^#@b5D#tQlVMT{3zJOO2d=|knqyo< z4Sw(>G5*TdZmnA!V&8g=U-s<+7EZ1;{||h5;oP_R;jcu^Vw2RzJZ=?n%&nqQ3af0I lX7U(yOi}4uz2YVpgPln=ZPx#^hrcPR9Fe^SYZx^APCj(9Ce^B@*TXqhe4Z-Xbx;zf1aBY0f9XoDk0~*P~WI~ z8|yB?Xsknh^%^C;!)|1PY)^)LElx4USu^GQsoftLX$?mD?M+V{P-|mE|BgkhlN@>% z72dKeIkXi~&PUVQ{}Y6U#)yC{c!3ZQvJkN3e1>H5lC-t9mt6Wxff7@>TwRxDuPBP0 zul<)eFaiM}00d41zD`Ux|HP1Ap!JOOB|`hho7w^%FGe6_Az;aIhMEzgL}fMCQO(rfTVm7-mHDXpP|&}QivQQxmtTjqRYlHaI&Vo&-jij0Z9I;`4o>5$XwU|?GXMYp M07*qoM6N<$f)fpc8UO$Q literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxhdpi/icon_scan_white.png b/android/app/src/main/res/drawable-xxhdpi/icon_scan_white.png new file mode 100644 index 0000000000000000000000000000000000000000..9aeeecba40d601b143edba702742a9417132510c GIT binary patch literal 479 zcmV<50U-W~P)Px$nMp)JRA>e5T0xG3Fbsq}^bhTeyWgO1D?Ees?9xhg9oiv5c2|xRi6nMBo&l5) zx_O=tQqNLHsWs&)&Y0)Wkp(`BFXpHz$l(vea#1sx_C1q%b$ejwWztcA99b|c_EX>Y zrYP2pNg@J zdE2LA-U_hsQ!$n?Z~IitTLCtHQ8B$Lexu#umm~Ur#bUy50A@|-Esq4SwjONU2m9jc zzR1Mufe8OAcDNO%*H}N!VnSj=W7u2fvkvcSU=8}<@8Lcr8!cWQ)^3=A0sr4`Ha|~S VhXTcCNt^%x002ovPDHLkV1l--%i90| literal 0 HcmV?d00001 diff --git a/android/app/src/main/res/drawable-xxxhdpi/icon_scan_white.png b/android/app/src/main/res/drawable-xxxhdpi/icon_scan_white.png new file mode 100644 index 0000000000000000000000000000000000000000..8011c4a64d1af599ef76d5bb5578c79b2489e80b GIT binary patch literal 668 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!jKx9jP7LeL$-HD>U<&heaSW+o zd^;yF?~ntJ3#a=F`Bv)-#g~d1u6y)fuon5Dx!37c=cT#@SA@6h_6zS>IyGa@$6NZs z6Xv9eb8lYv+RTj4?3`KA?UPJO-`KLB8gy@!OHwM!V{X1*BmJAXbN}s%Qxo?HKR#V^ zds(L49Lp=BbKhSwx^+{7m%TN)H@wDU%ZZxufD1Q;;#Adazkcb~d{O!8$;QfyKb;%{ z3y!_|`~G+sgGgp>+tGVQM`p+{ZI3XoEW34N_1u3!7pIrR=e9I`kS#yK$S%p>u>IS| z4Cam9QlS%6uZWyYc=q58Usu3|GaQ$ui7OoPZ(!*VP{`BtXy9OcG_46YM~&grEWdgE zE$fcGy;{-M6t#THg@5ZOyL(QL-(Py=L&(>zbGLdQMr>QYP*vNfvsWtj$5;NzA9jfL z#~SuoOxsl8`+QNDG=Frx?{%-8T@4%^n8<;nabaSM+D-q%JZBfXXV2)pZht^B+p=y} zzHCuzT1?BeeBlMt_UG6qzf<&%epvU{>|piM7b26M_H=Lf^|k(z+lk$FRhwR2G@Q@C zDWK?ZCujnLAkz_DRsx(5$7_0?TZ4YHztuHdf74tu|4_Q4behfq*?+gb@xSt3%(aV| zVRqE*e~z`b6S)pGZG9_$rCdb+%_aK{|C^%M@Ul!uUVGxZd(@qzz}b7QZmSRYzj)K0 zoBhj=yluPQ%V##pJiO^r{wLQrci7l&%wBPS<9lf@K5>gr2@>VNgTe~DWM4f D5Yj3X literal 0 HcmV?d00001 diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index f3757ac1bc..21ca793111 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -18,7 +18,7 @@ (def config {:label-top 16 :label-bottom 37 :label-font-large 16 - :label-font-small 12 + :label-font-small 13 :label-animation-duration 200}) (def default-props {:wrapperStyle {} diff --git a/src/status_im/contacts/views/new_contact.cljs b/src/status_im/contacts/views/new_contact.cljs index 2dbe6abc82..c0158168d1 100644 --- a/src/status_im/contacts/views/new_contact.cljs +++ b/src/status_im/contacts/views/new_contact.cljs @@ -57,7 +57,8 @@ :wrapperStyle (merge button-input) :label (label :t/address) :onChangeText #(dispatch [:set-in [:new-contact :whisper-identity] %])}] - [scan-button #(dispatch [:scan-qr-code {:toolbar-title (label :t/new-contact)} :set-new-contact-from-qr])]])) + [scan-button {:showLabel (zero? (count whisper-identity)) + :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/new-contact)} :set-new-contact-from-qr])}]])) (defview new-contact [] [{:keys [name whisper-identity phone-number] :as new-contact} [:get :new-contact]] diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index eef2ff99cc..c9de6ac25a 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -8,6 +8,7 @@ linear-gradient touchable-highlight]] [status-im.components.toolbar :refer [toolbar]] + [status-im.components.text-field.view :refer [text-field]] [status-im.components.styles :refer [color-purple color-white icon-search @@ -19,7 +20,7 @@ button-input-container button-input white-form-text-input]] - [status-im.qr-scanner.views.import-button :refer [import-button]] + [status-im.qr-scanner.views.scan-button :refer [scan-button]] [status-im.i18n :refer [label]] [status-im.login.styles :as st])) @@ -30,26 +31,27 @@ (defview address-input [address] [view button-input-container - [text-input - {:underlineColorAndroid color-white - :placeholderTextColor color-white - :style (merge white-form-text-input button-input) - :autoFocus true - :placeholder (label :t/address) - :onChangeText #(dispatch [:set-in [:login :address] %])} - address] - [import-button #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])]]) + [text-field + {:value address + :label (label :t/address) + :labelColor "#ffffff80" + :lineColor :white + :inputStyle st/input-style + :wrapperStyle (merge button-input st/address-input-wrapper) + :onChangeText #(dispatch [:set-in [:login :address] %])}] + [scan-button {:labelStyle st/scan-label + :icon :icon_scan_white + :showLabel (zero? (count address)) + :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}]]) (defview password-input [] - [] - [text-input - {:underlineColorAndroid color-white - :placeholderTextColor color-white - :style white-form-text-input - :autoFocus true - :placeholder (label :t/password) - :onChangeText #(dispatch [:set-in [:login :password] %])} - ""]) + [text-field + {:value "" + :label (label :t/password) + :labelColor "#ffffff80" + :lineColor :white + :inputStyle st/input-style + :onChangeText #(dispatch [:set-in [:login :password] %])}]) (defview login [] [{:keys [address password]} [:get :login]] diff --git a/src/status_im/login/styles.cljs b/src/status_im/login/styles.cljs index 677c3e7799..8278790c11 100644 --- a/src/status_im/login/styles.cljs +++ b/src/status_im/login/styles.cljs @@ -51,4 +51,14 @@ (def connect-button-text {:color "#7099e6" - :fontSize 16}) \ No newline at end of file + :fontSize 16}) + +(def input-style + {:color :white + :font-size 12}) + +(def scan-label + {:color :white}) + +(def address-input-wrapper + {}) \ No newline at end of file diff --git a/src/status_im/qr_scanner/views/scan-button.cljs b/src/status_im/qr_scanner/views/scan-button.cljs index 9ed1fd39e5..81dae39990 100644 --- a/src/status_im/qr_scanner/views/scan-button.cljs +++ b/src/status_im/qr_scanner/views/scan-button.cljs @@ -12,12 +12,13 @@ [status-im.qr-scanner.styles :as st])) -(defview scan-button [handler] - [] - [view st/scan-button - [touchable-highlight - {:on-press handler} - [view st/scan-button-content - [image {:source {:uri :scan_blue} - :style icon-scan}] - [text {:style st/scan-text} (label :t/scan-qr)]]]]) \ No newline at end of file +(defview scan-button [{:keys [showLabel icon labelStyle handler]}] + (let [showLabel (if (nil? showLabel) true showLabel)] + [view st/scan-button + [touchable-highlight + {:on-press handler} + [view st/scan-button-content + [image {:source {:uri (or icon :scan_blue)} + :style icon-scan}] + (when showLabel [text {:style (merge st/scan-text labelStyle)} + (label :t/scan-qr)])]]])) \ No newline at end of file From cd22ab834dd58f6027b28b45ba435a20559f9de7 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 21:29:58 +0300 Subject: [PATCH 08/19] updated login button design --- src/status_im/login/screen.cljs | 2 +- src/status_im/login/styles.cljs | 14 +++++++------- src/status_im/translations/en.cljs | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index c9de6ac25a..8f46d32741 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -77,7 +77,7 @@ [view st/recover-text-container [touchable-highlight {:on-press #()} - [text {:style st/recover-text} (label :t/recover-from-passphrase)]]] + [text {:style st/recover-text} (label :t/recover-access)]]] [view st/connect-button-container [touchable-highlight {:on-press #(dispatch [:login-account address password])} diff --git a/src/status_im/login/styles.cljs b/src/status_im/login/styles.cljs index 8278790c11..37278d33cb 100644 --- a/src/status_im/login/styles.cljs +++ b/src/status_im/login/styles.cljs @@ -26,25 +26,25 @@ {:position :absolute :left 0 :right 0 - :bottom 16}) + :bottom 0}) (def recover-text-container {:flex 1 - :flexWrap :nowrap + :alignItems :center :padding 16}) (def recover-text {:flex 1 - :color color-white}) + :color color-white + :fontSize 16}) (def connect-button-container - {:position :absolute - :right 16 - :top 0}) + {:flex 1}) (def connect-button {:backgroundColor color-white - :borderRadius 55 + :flex 1 + :alignItems :center :paddingVertical 16 :paddingHorizontal 28 }) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index c667275426..05fa0ab1ac 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -127,7 +127,7 @@ :address-explication "Maybe here should be some text explaining what an address is and where to look for it" ;login - :recover-from-passphrase "Recover from passphrase" + :recover-access "Recover access" :connect "Connect" :address "Address" :password "Password" From d1446634b4ecb85a9d572c342623469edc1a9307 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 21:52:16 +0300 Subject: [PATCH 09/19] added add account button --- src/status_im/accounts/screen.cljs | 8 +++++++- src/status_im/accounts/styles.cljs | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index fff89e7cf8..b1ec3e433d 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -14,6 +14,7 @@ icon-search icon-back icon-qr + icon-plus toolbar-background1 toolbar-title-container toolbar-title-text @@ -60,7 +61,12 @@ :enableEmptySections true :renderRow render-row :renderSeparator render-separator - :style st/account-list}]]])) + :style st/account-list}]] + [view st/add-account-button-container + [view st/add-account-button + [image {:source {:uri :icon_add} + :style st/icon-plus}] + [text {:style st/add-account-text} (label :t/add-account)]]]])) ;(re-frame.core/dispatch [:set :view-id :users]) diff --git a/src/status_im/accounts/styles.cljs b/src/status_im/accounts/styles.cljs index ac899e71bb..823d511c50 100644 --- a/src/status_im/accounts/styles.cljs +++ b/src/status_im/accounts/styles.cljs @@ -81,3 +81,27 @@ :flexDirection :column :alignItems :center :justifyContent :center}) + +(def add-account-button-container + {:position :absolute + :bottom 16 + :height 50 + :left 100 + :right 100 + :justifyContent :center + :alignItems :center}) + +(def add-account-button + {:flexDirection :row}) + +(def icon-plus + {:flexDirection :column + :paddingTop 2 + :width 20 + :height 20}) + +(def add-account-text + {:flexDirection :column + :color :white + :fontSize 16 + :marginLeft 8}) From 1555002bcdee0d37296193e00428f0868147f747 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Tue, 5 Jul 2016 22:24:09 +0300 Subject: [PATCH 10/19] added add account button functionality --- src/status_im/accounts/handlers.cljs | 19 ++++++++++++++++++- src/status_im/accounts/screen.cljs | 16 +++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 88aeabb432..6f8d0ab569 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -8,6 +8,9 @@ [status-im.protocol.state.storage :as storage] [status-im.utils.identicon :refer [identicon]] [status-im.db :refer [default-view]] + [status-im.utils.random :as random] + [status-im.i18n :refer [label]] + [status-im.constants :refer [content-type-command-request]] [clojure.string :as str])) @@ -60,4 +63,18 @@ (into {}))] (assoc db :accounts accounts))) -(register-handler :load-accounts load-accounts!) \ No newline at end of file +(register-handler :load-accounts load-accounts!) + +(defn console-create-account [db _] + (let [msg-id (random/id)] + (dispatch [:received-msg + {:msg-id msg-id + :content {:command (name :keypair) + :content (label :t/keypair-generated)} + :content-type content-type-command-request + :outgoing false + :from "console" + :to "me"}]) + db)) + +(register-handler :console-create-account console-create-account) \ No newline at end of file diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index b1ec3e433d..8c3f22101b 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -24,7 +24,8 @@ [status-im.utils.listview :as lw] [status-im.accounts.views.account :refer [account-view]] [status-im.i18n :refer [label]] - [status-im.accounts.styles :as st])) + [status-im.accounts.styles :as st] + [status-im.utils.logging :as log])) (def toolbar-title [view toolbar-title-container @@ -38,6 +39,10 @@ (list-item [view {:style st/row-separator :key row-id}])) +(defn create-account [event] + (dispatch [:console-create-account]) + (dispatch [:navigate-to :chat "console"])) + (defview accounts [] [accounts [:get :accounts]] (let [accounts (vals accounts)] @@ -63,10 +68,11 @@ :renderSeparator render-separator :style st/account-list}]] [view st/add-account-button-container - [view st/add-account-button - [image {:source {:uri :icon_add} - :style st/icon-plus}] - [text {:style st/add-account-text} (label :t/add-account)]]]])) + [touchable-highlight {:on-press create-account} + [view st/add-account-button + [image {:source {:uri :icon_add} + :style st/icon-plus}] + [text {:style st/add-account-text} (label :t/add-account)]]]]])) ;(re-frame.core/dispatch [:set :view-id :users]) From 88e5a0c9d897863308f829beff5cdcf167fc78f8 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 6 Jul 2016 09:26:28 +0300 Subject: [PATCH 11/19] centered account list --- src/status_im/accounts/screen.cljs | 16 ++++++++-------- src/status_im/accounts/styles.cljs | 11 ++++++++--- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index 8c3f22101b..a11cfcab3b 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -60,13 +60,13 @@ :custom-content toolbar-title :action {:image {:style icon-search} :handler #()}}] - - [view st/account-list-container - [list-view {:dataSource (lw/to-datasource accounts) - :enableEmptySections true - :renderRow render-row - :renderSeparator render-separator - :style st/account-list}]] + [view st/accounts-container + [view st/account-list-view-container + [list-view {:dataSource (lw/to-datasource accounts) + :enableEmptySections true + :renderRow render-row + ;:renderSeparator render-separator + :style st/account-list}]]] [view st/add-account-button-container [touchable-highlight {:on-press create-account} [view st/add-account-button @@ -78,4 +78,4 @@ ;(re-frame.core/dispatch [:set :view-id :users]) ;{:name (label :t/add-account) ;:address "0x0" -;:photo-path :icon_plus} \ No newline at end of file +;:photo-path :icon_plus} diff --git a/src/status_im/accounts/styles.cljs b/src/status_im/accounts/styles.cljs index 823d511c50..ab20bcd40e 100644 --- a/src/status_im/accounts/styles.cljs +++ b/src/status_im/accounts/styles.cljs @@ -26,9 +26,14 @@ :left 0 :justifyContent :center}) -(def account-list-container - {:flex 1 - :flexDirection :column +(def accounts-container + {:flex 1 + :flex-direction :column + :justifyContent :center + :padding-bottom 56}) + +(def account-list-view-container + {:flexDirection :column :justifyContent :center}) (def account-list From a2e6701db70992a22943ec285e09a0c720cb6194 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 6 Jul 2016 23:10:41 +0300 Subject: [PATCH 12/19] fix font size, back button and add account button --- src/status_im/accounts/handlers.cljs | 8 +-- src/status_im/accounts/screen.cljs | 63 +++++++++++------------ src/status_im/accounts/styles.cljs | 6 ++- src/status_im/android/core.cljs | 4 +- src/status_im/components/drawer/view.cljs | 2 +- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 6f8d0ab569..2f9e3b0d27 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -25,7 +25,7 @@ (defn save-password [password] (storage/put kv/kv-store :password password)) -(defn account-created [result password] +(defn account-created [db result password] (let [data (json->clj result) public-key (:pubkey data) address (:address data) @@ -38,11 +38,11 @@ (do (save-password password) (dispatch [:add-account account]) - (dispatch [:login-account address password]))))) + (when (not (:signed-up db)) (dispatch [:login-account address password])))))) (register-handler :create-account (-> (fn [db [_ password]] - (.createAccount geth password (fn [result] (account-created result password))) + (.createAccount geth password (fn [result] (account-created db result password))) db))) (register-handler :login-account @@ -53,7 +53,7 @@ (dispatch [:set :login {}]) (dispatch [:set :current-account account]) (dispatch [:initialize-protocol account]) - (dispatch [:navigate-to-clean default-view])))) + (when (:signed-up db) (dispatch [:navigate-to-clean default-view]))))) db))) (defn load-accounts! [db _] diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index a11cfcab3b..61ab31be7c 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -44,38 +44,35 @@ (dispatch [:navigate-to :chat "console"])) (defview accounts [] - [accounts [:get :accounts]] - (let [accounts (vals accounts)] - [view st/screen-container - [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] - :start [0, 0] - :end [0.5, 1] - :locations [0, 0.8 ,1] - :style st/gradient-background}] - - [toolbar {:background-color :transparent - :nav-action {:image {:source {:uri :icon_back_white} - :style icon-back} - :handler #(dispatch [:navigate-back])} - :custom-content toolbar-title - :action {:image {:style icon-search} - :handler #()}}] - [view st/accounts-container - [view st/account-list-view-container - [list-view {:dataSource (lw/to-datasource accounts) - :enableEmptySections true - :renderRow render-row - ;:renderSeparator render-separator - :style st/account-list}]]] - [view st/add-account-button-container - [touchable-highlight {:on-press create-account} - [view st/add-account-button - [image {:source {:uri :icon_add} - :style st/icon-plus}] - [text {:style st/add-account-text} (label :t/add-account)]]]]])) - + [accounts [:get :accounts] + stack [:get :navigation-stack]] + (let [accounts (vals accounts) + show-back? (> (count stack) 1)] + [view st/screen-container + [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] + :start [0, 0] + :end [0.5, 1] + :locations [0, 0.8, 1] + :style st/gradient-background}] + [toolbar {:background-color :transparent + :nav-action {:image {:source (if show-back? {:uri :icon_back_white} nil) + :style icon-back} + :handler (if show-back? #(dispatch [:navigate-back]) nil)} + :custom-content toolbar-title + :action {:image {:style icon-search} + :handler #()}}] + [view st/accounts-container + [view st/account-list-view-container + [list-view {:dataSource (lw/to-datasource accounts) + :enableEmptySections true + :renderRow render-row + ;:renderSeparator render-separator + :style st/account-list}]]] + [view st/add-account-button-container + [touchable-highlight {:on-press create-account} + [view st/add-account-button + [image {:source {:uri :icon_add} + :style st/icon-plus}] + [text {:style st/add-account-text} (label :t/add-account)]]]]])) ;(re-frame.core/dispatch [:set :view-id :users]) -;{:name (label :t/add-account) -;:address "0x0" -;:photo-path :icon_plus} diff --git a/src/status_im/accounts/styles.cljs b/src/status_im/accounts/styles.cljs index ab20bcd40e..6ad1c9c930 100644 --- a/src/status_im/accounts/styles.cljs +++ b/src/status_im/accounts/styles.cljs @@ -76,10 +76,12 @@ :flexDirection :column}) (def name-text - {:color color-white}) + {:color color-white + :fontSize 16}) (def address-text - {:color color-white}) + {:color color-white + :fontSize 12}) (def online-container {:flex 0.2 diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e591c69abb..6f7eff59f2 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -67,7 +67,7 @@ #(dispatch [:set :keyboard-height 0])))) :render (fn [] - (let [startup-view (if @account @view-id (if (= @view-id :login) :login :users))] + (let [startup-view (if @account @view-id (if (contains? #{:login :chat} @view-id) @view-id :accounts))] (log/debug startup-view) (case (if @signed-up startup-view :chat) :discovery [main-tabs] @@ -83,7 +83,7 @@ :qr-scanner [qr-scanner] :chat [chat] :profile [profile] - :users [accounts] + :accounts [accounts] :login [login] :my-profile [my-profile])))}))) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index c040b8cb7c..726f9251d4 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -65,7 +65,7 @@ [view st/switch-users-container [touchable-opacity {:onPress (fn [] (close-drawer) - (dispatch [:navigate-to :users]) + (dispatch [:navigate-to :accounts]) ;; TODO not implemented )} [text {:style st/switch-users-text} From b28427cddd2842cbd70d1f7561f9fe7a6ca1003b Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 6 Jul 2016 23:15:39 +0300 Subject: [PATCH 13/19] hide scan button from login --- src/status_im/login/screen.cljs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index 8f46d32741..81e7409d2c 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -39,10 +39,11 @@ :inputStyle st/input-style :wrapperStyle (merge button-input st/address-input-wrapper) :onChangeText #(dispatch [:set-in [:login :address] %])}] - [scan-button {:labelStyle st/scan-label - :icon :icon_scan_white - :showLabel (zero? (count address)) - :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}]]) + ;[scan-button {:labelStyle st/scan-label + ; :icon :icon_scan_white + ; :showLabel (zero? (count address)) + ; :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}] + ]) (defview password-input [] [text-field From 9d8bd7d740f2f25c3c2990add35ee7d0baddf89d Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 6 Jul 2016 23:47:57 +0300 Subject: [PATCH 14/19] fixed failed login, disabled address field, added error message --- .../com/statusim/geth/module/GethModule.java | 2 +- src/status_im/accounts/handlers.cljs | 18 +++++++--- src/status_im/components/text_field/view.cljs | 6 ++-- src/status_im/login/screen.cljs | 33 +++++++++++-------- src/status_im/translations/en.cljs | 1 + 5 files changed, 38 insertions(+), 22 deletions(-) diff --git a/android/app/src/main/java/com/statusim/geth/module/GethModule.java b/android/app/src/main/java/com/statusim/geth/module/GethModule.java index 058ab03667..2aeb3b0902 100644 --- a/android/app/src/main/java/com/statusim/geth/module/GethModule.java +++ b/android/app/src/main/java/com/statusim/geth/module/GethModule.java @@ -117,7 +117,7 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE case GethMessages.MSG_LOGGED_IN: callback = unlockAccountCallbacks.remove(callbackIdentifier); if (callback != null) { - callback.invoke(null, "{ \"result\": \"" + data.getString("result") + "\"}"); + callback.invoke(data.getString("result")); } break; default: diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 2f9e3b0d27..9b0e59f444 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -45,15 +45,23 @@ (.createAccount geth password (fn [result] (account-created db result password))) db))) +(defn login [db address] + (let [account (get-in db [:accounts address])] + (dispatch [:set :login {}]) + (dispatch [:set :current-account account]) + (dispatch [:initialize-protocol account]) + (when (:signed-up db) (dispatch [:navigate-to-clean default-view])))) + (register-handler :login-account (-> (fn [db [_ address password]] (.login geth address password (fn [result] - (let [account (get-in db [:accounts address])] + (let [data (json->clj result) + error (:error data) + success (zero? (count error))] (log/debug "Logged in account: " address result) - (dispatch [:set :login {}]) - (dispatch [:set :current-account account]) - (dispatch [:initialize-protocol account]) - (when (:signed-up db) (dispatch [:navigate-to-clean default-view]))))) + (if success + (login db address) + (dispatch [:set-in [:login :error] error]))))) db))) (defn load-accounts! [db _] diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index 21ca793111..2b78927d0a 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -24,6 +24,7 @@ (def default-props {:wrapperStyle {} :inputStyle {} :lineStyle {} + :editable true :labelColor "#838c93" :lineColor "#0000001f" :focusLineColor "#0000001f" @@ -141,16 +142,17 @@ max-line-width] :as state} (r/state component) {:keys [wrapperStyle inputStyle lineColor focusLineColor labelColor errorColor error label value onFocus onBlur - onChangeText onChange] :as props} (merge default-props (r/props component)) + onChangeText onChange editable] :as props} (merge default-props (r/props component)) lineColor (if error errorColor lineColor) focusLineColor (if error errorColor focusLineColor) labelColor (if (and error (not float-label?)) errorColor labelColor) label (if error (str label " *") label)] - (log/debug "reagent-render: " data state) + (log/debug "reagent-render: " data) [view (merge st/text-field-container wrapperStyle) [animated-text {:style (st/label label-top label-font-size labelColor)} label] [text-input {:style (merge st/text-input inputStyle) :placeholder "" + :editable editable :onFocus #(on-focus {:component component :animation {:top label-top :to-top (:label-top config) diff --git a/src/status_im/login/screen.cljs b/src/status_im/login/screen.cljs index 81e7409d2c..3329467df6 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/login/screen.cljs @@ -33,6 +33,7 @@ [view button-input-container [text-field {:value address + :editable false :label (label :t/address) :labelColor "#ffffff80" :lineColor :white @@ -45,34 +46,38 @@ ; :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/login)} :set-address-from-qr])}] ]) -(defview password-input [] +(defview password-input [error] [text-field {:value "" + :error (when (pos? (count error)) (label :t/wrong-password)) + :errorColor :white :label (label :t/password) :labelColor "#ffffff80" :lineColor :white - :inputStyle st/input-style - :onChangeText #(dispatch [:set-in [:login :password] %])}]) + :inputStyle st/input-style + :onChangeText #(do + (dispatch [:set-in [:login :password] %]) + (dispatch [:set-in [:login :error] ""]))}]) (defview login [] - [{:keys [address password]} [:get :login]] + [{:keys [address password error]} [:get :login]] [view st/screen-container - [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] - :start [0, 0] - :end [0.5, 1] - :locations [0, 0.8 ,1] - :style st/gradient-background}] + [linear-gradient {:colors ["rgba(182, 116, 241, 1)" "rgba(107, 147, 231, 1)" "rgba(43, 171, 238, 1)"] + :start [0, 0] + :end [0.5, 1] + :locations [0, 0.8, 1] + :style st/gradient-background}] [toolbar {:background-color :transparent - :nav-action {:image {:source {:uri :icon_back_white} - :style icon-back} - :handler #(dispatch [:navigate-back])} + :nav-action {:image {:source {:uri :icon_back_white} + :style icon-back} + :handler #(dispatch [:navigate-back])} :custom-content toolbar-title - :action {:image {:style icon-search} + :action {:image {:style icon-search} :handler #()}}] [view st/form-container [address-input (or address "")] - [password-input] + [password-input error] ] [view st/bottom-actions-container [view st/recover-text-container diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 05fa0ab1ac..1da6f4a519 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -132,6 +132,7 @@ :address "Address" :password "Password" :login "Login" + :wrong-password "Wrong password" ;users :add-account "Add account" From 5392b8d9a230096d7dbe9ba838d95d9af36b3b7d Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Wed, 13 Jul 2016 18:53:23 +0300 Subject: [PATCH 15/19] Added address validation --- src/status_im/components/text_field/view.cljs | 20 +++--- src/status_im/contacts/validations.cljs | 10 ++- src/status_im/contacts/views/new_contact.cljs | 71 +++++++++++++------ src/status_im/translations/en.cljs | 3 + 4 files changed, 73 insertions(+), 31 deletions(-) diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index 2b78927d0a..4949c00ef2 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -69,7 +69,7 @@ (:label-font-large config) (:label-font-small config))) :float-label? (if (s/blank? value) false true)}] - (log/debug "component-will-mount") + ;(log/debug "component-will-mount") (r/set-state component data))) ; Invoked once, only on the client (not on the server), immediately after the @@ -79,7 +79,8 @@ ; parent components. (defn component-did-mount [component] (let [props (r/props component)] - (log/debug "component-did-mount:"))) + ;(log/debug "component-did-mount:") + )) ; Invoked when a component is receiving new props. This method is not called for ; the initial render. Use this as an opportunity to react to a prop transition @@ -87,7 +88,8 @@ ; The old props can be accessed via this.props. Calling this.setState() within ; this function will not trigger an additional render. (defn component-will-receive-props [component new-props] - (log/debug "component-will-receive-props: new-props=" new-props)) + ;(log/debug "component-will-receive-props: new-props=" new-props) + ) ; Invoked before rendering when new props or state are being received. This method ; is not called for the initial render or when forceUpdate is used. Use this as @@ -97,20 +99,22 @@ ; until the next state change. In addition, componentWillUpdate and ; componentDidUpdate will not be called. (defn should-component-update [component next-props next-state] - (log/debug "should-component-update: " next-props next-state) + ;(log/debug "should-component-update: " next-props next-state) true) ; Invoked immediately before rendering when new props or state are being received. ; This method is not called for the initial render. Use this as an opportunity ; to perform preparation before an update occurs. (defn component-will-update [component next-props next-state] - (log/debug "component-will-update: " next-props next-state)) + ;(log/debug "component-will-update: " next-props next-state) + ) ; Invoked immediately after the component's updates are flushed to the DOM. ; This method is not called for the initial render. Use this as an opportunity ; to operate on the DOM when the component has been updated. (defn component-did-update [component prev-props prev-state] - (log/debug "component-did-update: " prev-props prev-state)) + ;(log/debug "component-did-update: " prev-props prev-state) + ) (defn on-focus [{:keys [component animation onFocus]}] (do @@ -147,7 +151,7 @@ focusLineColor (if error errorColor focusLineColor) labelColor (if (and error (not float-label?)) errorColor labelColor) label (if error (str label " *") label)] - (log/debug "reagent-render: " data) + ;(log/debug "reagent-render: " data) [view (merge st/text-field-container wrapperStyle) [animated-text {:style (st/label label-top label-font-size labelColor)} label] [text-input {:style (merge st/text-input inputStyle) @@ -187,5 +191,5 @@ :component-did-update component-did-update :display-name "text-field" :reagent-render reagent-render}] - (log/debug "Creating text-field component: " data) + ;(log/debug "Creating text-field component: " data) (r/create-class component-data))) \ No newline at end of file diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs index 1e4d517682..f2aa252434 100644 --- a/src/status_im/contacts/validations.cljs +++ b/src/status_im/contacts/validations.cljs @@ -1,13 +1,21 @@ (ns status-im.contacts.validations (:require [cljs.spec :as s] + [cljsjs.web3] [status-im.persistence.realm :as realm])) +(defn is-address? [s] + (.isAddress js/Web3.prototype s)) + (defn unique-identity? [identity] (println identity) (not (realm/exists? :contacts :whisper-identity identity))) (defn valid-length? [identity] - (= 132 (count identity))) + (let [length (count identity)] + (or + (= 130 length) + (= 132 length) + (is-address? identity)))) (s/def ::identity-length valid-length?) (s/def ::unique-identity unique-identity?) diff --git a/src/status_im/contacts/views/new_contact.cljs b/src/status_im/contacts/views/new_contact.cljs index c0158168d1..d0673a22ea 100644 --- a/src/status_im/contacts/views/new_contact.cljs +++ b/src/status_im/contacts/views/new_contact.cljs @@ -11,6 +11,7 @@ [status-im.components.text-field.view :refer [text-field]] [status-im.utils.identicon :refer [identicon]] [status-im.components.toolbar :refer [toolbar]] + [status-im.utils.utils :refer [log on-error http-post toast]] [status-im.components.styles :refer [color-purple color-white icon-search @@ -43,12 +44,12 @@ :label (label :t/name) :onChangeText #(dispatch [:set-in [:new-contact :name] %])}]) -(defview contact-whisper-id-input [whisper-identity] +(defview contact-whisper-id-input [whisper-identity error] [] - (let [error (if (str/blank? whisper-identity) "" nil) + (let [error (if (str/blank? whisper-identity) "" error) error (if (s/valid? ::v/whisper-identity whisper-identity) error - "Please enter a valid address or scan a QR code")] + (label :t/enter-valid-address))] [view button-input-container [text-field {:error error @@ -56,26 +57,52 @@ :value whisper-identity :wrapperStyle (merge button-input) :label (label :t/address) - :onChangeText #(dispatch [:set-in [:new-contact :whisper-identity] %])}] + :onChangeText #(do + (dispatch [:set-in [:new-contact :whisper-identity] %]) + (dispatch [:set :new-contact-address-error nil]))}] [scan-button {:showLabel (zero? (count whisper-identity)) :handler #(dispatch [:scan-qr-code {:toolbar-title (label :t/new-contact)} :set-new-contact-from-qr])}]])) +(defn on-add-contact [whisper-identity new-contact] + (if (v/is-address? whisper-identity) + (http-post "get-contacts-by-address" {:addresses [whisper-identity]} + (fn [{:keys [contacts]}] + (if (> (count contacts) 0) + (let [contact (first contacts) + new-contact (merge + new-contact + {:address whisper-identity + :whisper-identity (:whisper-identity contact)})] + (dispatch [:add-new-contact new-contact])) + (dispatch [:set :new-contact-address-error (label :t/unknown-address)])))) + (dispatch [:add-new-contact new-contact]))) + +(defn toolbar-action [whisper-identity new-contact error] + (let [valid-contact? (and + (s/valid? ::v/contact new-contact) + (nil? error))] + {:image {:source {:uri (if valid-contact? + :icon_ok_blue + :icon_ok_disabled)} + :style icon-search} + :handler #(when valid-contact? + (let [contact (merge + {:photo-path (identicon whisper-identity)} + new-contact)] + (on-add-contact whisper-identity contact)))})) + (defview new-contact [] - [{:keys [name whisper-identity phone-number] :as new-contact} [:get :new-contact]] - (let [valid-contact? (s/valid? ::v/contact new-contact)] - [view st/contact-form-container - [toolbar {:background-color :white - :nav-action {:image {:source {:uri :icon_back} - :style icon-back} - :handler #(dispatch [:navigate-back])} - :custom-content toolbar-title - :action {:image {:source {:uri (if valid-contact? - :icon_ok_blue - :icon_ok_disabled)} - :style icon-search} - :handler #(when valid-contact? (dispatch [:add-new-contact (merge {:photo-path (identicon whisper-identity)} new-contact)]))}}] - [view st/form-container - [contact-name-input name] - [contact-whisper-id-input whisper-identity]] - [view st/address-explication-container - [text {:style st/address-explication} (label :t/address-explication)]]])) + [{:keys [name whisper-identity phone-number] :as new-contact} [:get :new-contact] + error [:get :new-contact-address-error]] + [view st/contact-form-container + [toolbar {:background-color :white + :nav-action {:image {:source {:uri :icon_back} + :style icon-back} + :handler #(dispatch [:navigate-back])} + :custom-content toolbar-title + :action (toolbar-action whisper-identity new-contact error)}] + [view st/form-container + [contact-name-input name] + [contact-whisper-id-input whisper-identity error]] + [view st/address-explication-container + [text {:style st/address-explication} (label :t/address-explication)]]]) diff --git a/src/status_im/translations/en.cljs b/src/status_im/translations/en.cljs index 1da6f4a519..c663c49399 100644 --- a/src/status_im/translations/en.cljs +++ b/src/status_im/translations/en.cljs @@ -125,6 +125,9 @@ :name "Name" :whisper-identity "Whisper Identity" :address-explication "Maybe here should be some text explaining what an address is and where to look for it" + :enter-valid-address "Please enter a valid address or scan a QR code" + :unknown-address "Unknown address" + ;login :recover-access "Recover access" From d19b595b9faa7e77b6af8f70840dff7dd75d8e96 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 18 Jul 2016 15:42:48 +0300 Subject: [PATCH 16/19] account database separation try --- package.json | 2 +- src/status_im/accounts/handlers.cljs | 28 ++- src/status_im/accounts/screen.cljs | 3 +- src/status_im/accounts/views/account.cljs | 2 +- src/status_im/android/core.cljs | 15 +- src/status_im/chat/handlers.cljs | 73 ++++--- src/status_im/chat/handlers/requests.cljs | 26 +-- src/status_im/chat/sign_up.cljs | 10 +- src/status_im/commands/handlers/loading.cljs | 18 +- src/status_im/contacts/validations.cljs | 4 +- src/status_im/db.cljs | 5 +- src/status_im/discovery/model.cljs | 50 ++--- src/status_im/group_settings/handlers.cljs | 11 +- src/status_im/handlers.cljs | 24 ++- src/status_im/models/accounts.cljs | 12 +- src/status_im/models/chats.cljs | 59 +++--- src/status_im/models/contacts.cljs | 16 +- src/status_im/models/messages.cljs | 16 +- src/status_im/models/requests.cljs | 21 ++ src/status_im/persistence/realm.cljs | 200 ------------------ src/status_im/persistence/realm/core.cljs | 151 +++++++++++++ src/status_im/persistence/realm/schemas.cljs | 100 +++++++++ .../persistence/simple_kv_store.cljs | 28 +-- 23 files changed, 509 insertions(+), 365 deletions(-) create mode 100644 src/status_im/models/requests.cljs delete mode 100644 src/status_im/persistence/realm.cljs create mode 100644 src/status_im/persistence/realm/core.cljs create mode 100644 src/status_im/persistence/realm/schemas.cljs diff --git a/package.json b/package.json index 7890c53cb7..f63ef15e2c 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "react-native-randombytes": "^2.1.0", "react-native-vector-icons": "^1.3.4", "react-native-orientation": "^1.17.0", - "realm": "^0.11.1", + "realm": "^0.14.0", "react-native-status": "git+ssh://git@github.com/status-im/react-native-status" } } diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 9b0e59f444..7533014d43 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.accounts.handlers (:require [status-im.models.accounts :as accounts] - [re-frame.core :refer [register-handler after dispatch debug]] + [re-frame.core :refer [register-handler after dispatch dispatch-sync debug]] [status-im.utils.logging :as log] [status-im.components.react :refer [geth]] [status-im.utils.types :refer [json->clj]] @@ -9,6 +9,7 @@ [status-im.utils.identicon :refer [identicon]] [status-im.db :refer [default-view]] [status-im.utils.random :as random] + [status-im.persistence.realm.core :as realm] [status-im.i18n :refer [label]] [status-im.constants :refer [content-type-command-request]] [clojure.string :as str])) @@ -32,24 +33,31 @@ account {:public-key public-key :address address :name address - :photo-path (identicon address)}] - (log/debug "Created account: " result) + :photo-path (identicon address)} + ] + (log/debug "account-created: " account) (when (not (str/blank? public-key)) (do - (save-password password) - (dispatch [:add-account account]) - (when (not (:signed-up db)) (dispatch [:login-account address password])))))) + ;(save-password password) + (dispatch-sync [:add-account account]) + (dispatch [:login-account address password]))))) (register-handler :create-account (-> (fn [db [_ password]] (.createAccount geth password (fn [result] (account-created db result password))) db))) -(defn login [db address] +(defn logged-in [db address] (let [account (get-in db [:accounts address])] + (log/debug "Logged in: " address account) + (realm/close-account-realm) + (reset! realm/account-realm (realm/create-account-realm address)) (dispatch [:set :login {}]) - (dispatch [:set :current-account account]) - (dispatch [:initialize-protocol account]) + (dispatch [:set :is-logged-in true]) + (dispatch [:set :user-identity account]) + (dispatch [:save-console]) + + (dispatch [:initialize-account account]) (when (:signed-up db) (dispatch [:navigate-to-clean default-view])))) (register-handler :login-account @@ -60,7 +68,7 @@ success (zero? (count error))] (log/debug "Logged in account: " address result) (if success - (login db address) + (logged-in db address) (dispatch [:set-in [:login :error] error]))))) db))) diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index 61ab31be7c..ea9f1a361a 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -40,7 +40,8 @@ :key row-id}])) (defn create-account [event] - (dispatch [:console-create-account]) + ;(dispatch [:console-create-account]) + (dispatch-sync [:reset-app]) (dispatch [:navigate-to :chat "console"])) (defview accounts [] diff --git a/src/status_im/accounts/views/account.cljs b/src/status_im/accounts/views/account.cljs index af714d566e..63afee013e 100644 --- a/src/status_im/accounts/views/account.cljs +++ b/src/status_im/accounts/views/account.cljs @@ -16,7 +16,7 @@ (dispatch [:set-in [:login :address] address])) (defview account-view [{:keys [address photo-path name] :as account}] - [current-account [:get :current-account]] + [current-account [:get :user-identity]] [touchable-highlight {:onPress #(on-press address)} [view st/account-container diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 6f7eff59f2..8762730a95 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -43,7 +43,7 @@ (defn app-root [] (let [signed-up (subscribe [:get :signed-up]) view-id (subscribe [:get :view-id]) - account (subscribe [:get :current-account]) + account (subscribe [:get :user-identity]) keyboard-height (subscribe [:get :keyboard-height])] (log/debug "Current account: " @account) (r/create-class @@ -88,16 +88,13 @@ :my-profile [my-profile])))}))) (defn init [] - (dispatch-sync [:initialize-db]) + (dispatch-sync [:reset-app]) (dispatch [:initialize-crypt]) (dispatch [:initialize-geth]) - (dispatch [:load-accounts]) - (dispatch [:initialize-chats]) - ;protocol must be initialized after user enters password and we create account - ;(dispatch [:initialize-protocol]) + (dispatch [:load-user-phone-number]) - (dispatch [:load-contacts]) - (dispatch [:init-console-chat]) - (dispatch [:init-chat]) + + + ;(dispatch [:init-chat]) (init-back-button-handler!) (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 97df9c4281..83bda90f99 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -15,7 +15,7 @@ [status-im.models.chats :as chats] [status-im.navigation.handlers :as nav] [status-im.utils.handlers :refer [register-handler] :as u] - [status-im.persistence.realm :as r] + [status-im.persistence.realm.core :as r] [status-im.handlers.server :as server] [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.utils.phone-number :refer [format-phone-number]] @@ -31,9 +31,10 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - (fn [{:keys [current-chat-id] :as db} _] - (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?])] - (if all-loaded? + (fn [{:keys [is-logged-in current-chat-id] :as db} _] + (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?]) + account-realm-exists? (or (not= current-chat-id "console") is-logged-in)] + (if (or all-loaded? (not account-realm-exists?)) db (let [messages-path [:chats current-chat-id :messages] messages (get-in db messages-path) @@ -291,21 +292,22 @@ :content content}))))) (defn save-message-to-realm! - [{:keys [new-message current-chat-id]} _] - (when new-message + [{:keys [is-logged-in new-message current-chat-id]} _] + (when (and new-message is-logged-in) (messages/save-message current-chat-id new-message))) (defn save-commands-to-realm! - [{:keys [new-commands current-chat-id]} _] - (doseq [new-command new-commands] - (messages/save-message - current-chat-id - (dissoc new-command :rendered-preview :to-message)))) + [{:keys [is-logged-in new-commands current-chat-id]} _] + (when is-logged-in + (doseq [new-command new-commands] + (messages/save-message + current-chat-id + (dissoc new-command :rendered-preview :to-message))))) (defn dispatch-responded-requests! [{:keys [new-commands current-chat-id]} _] - (doseq [{:keys [to-message]} new-commands] - (when to-message + (doseq [{:keys [is-logged-in to-message]} new-commands] + (when (and to-message is-logged-in) (dispatch [:request-answered! current-chat-id to-message])))) (defn invoke-commands-handlers! @@ -409,6 +411,18 @@ ((enrich init-chat)) ((after load-commands!)))) + +(register-handler :save-console + (fn [db _] + (when-not (chats/chat-exists? "console") + (let [console-chat (get-in db [:chats "console"])] + (when console-chat + (do + (chats/create-chat console-chat) + (doseq [message (reverse (:messages console-chat))] + (messages/save-message "console" message)))))) + db)) + (defn initialize-chats [{:keys [loaded-chats] :as db} _] (let [chats (->> loaded-chats @@ -429,11 +443,13 @@ ((enrich initialize-chats) load-chats!)) (defn store-message! - [{:keys [new-message]} [_ {chat-id :from}]] - (messages/save-message chat-id new-message)) + [{:keys [is-logged-in new-message]} [_ {chat-id :from}]] + (if (or (not= chat-id "console") is-logged-in) + (messages/save-message chat-id new-message))) (defn dispatch-request! [{:keys [new-message]} [_ {chat-id :from}]] + (log/debug "Dispatching request: " new-message) (when (= (:content-type new-message) content-type-command-request) (dispatch [:add-request chat-id new-message]))) @@ -455,15 +471,20 @@ (messages/save-message chat-id msg)))) (defmethod nav/preload-data! :chat - [{:keys [current-chat-id] :as db} [_ _ id]] + [{:keys [is-logged-in current-chat-id] :as db} [_ _ id]] (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) - db' (assoc db :current-chat-id chat-id)] - (dispatch [:load-requests! chat-id]) + db' (assoc db :current-chat-id chat-id) + account-realm-exists? (or (not= chat-id "console") is-logged-in)] + (when account-realm-exists? + (dispatch [:load-requests! chat-id])) (if (seq messages) db' (-> db' - load-messages! + ((fn [db] + (if account-realm-exists? + (load-messages! db) + db))) init-chat)))) (defn prepare-chat @@ -525,17 +546,17 @@ (defn delete-messages! [{:keys [current-chat-id]} _] - (r/write + (r/write :account (fn [] - (r/delete (r/get-by-field :msgs :chat-id current-chat-id))))) + (r/delete :account (r/get-by-field :account :msgs :chat-id current-chat-id))))) (defn delete-chat! [{:keys [current-chat-id]} _] - (r/write - (fn [] - (-> (r/get-by-field :chats :chat-id current-chat-id) - (r/single) - (r/delete))))) + (r/write :account + (fn [] :account + (->> (r/get-by-field :account :chats :chat-id current-chat-id) + (r/single) + (r/delete :account))))) (register-handler :leave-group-chat ;; todo oreder of operations tbd diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index d229b0dc94..7789e5a445 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -1,14 +1,15 @@ (ns status-im.chat.handlers.requests (:require [re-frame.core :refer [after dispatch enrich]] [status-im.utils.handlers :refer [register-handler]] - [status-im.persistence.realm :as realm] + [status-im.persistence.realm.core :as realm] + [status-im.models.requests :as requests] [status-im.utils.handlers :as u])) (defn store-request! - [{:keys [new-request]}] - (realm/write - (fn [] - (realm/create :requests new-request)))) + [{:keys [is-logged-in new-request] :as db}] + (if (or (not= (:chat-id new-request) "console") is-logged-in) + (requests/save-request new-request) + db)) (defn add-request [db [_ chat-id {:keys [msg-id content]}]] @@ -24,9 +25,9 @@ (defn load-requests! [{:keys [current-chat-id] :as db} [_ chat-id]] (let [chat-id' (or chat-id current-chat-id) - requests (-> :requests - ;; todo maybe limit is needed - (realm/get-by-fields {:chat-id chat-id' + requests (-> ;; todo maybe limit is needed + (realm/get-by-fields :account :requests + {:chat-id chat-id' :status "open"}) (realm/sorted :added :desc) (realm/collection->map)) @@ -35,12 +36,11 @@ (defn mark-request-as-answered! [_ [_ chat-id message-id]] - (realm/write + (realm/write :account (fn [] - (-> :requests - (realm/get-by-fields - {:chat-id chat-id - :message-id message-id}) + (-> (realm/get-by-fields :account :requests + {:chat-id chat-id + :message-id message-id}) (realm/single) (.-status) (set! "answered"))))) diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index e4140eab16..e592ea2061 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -5,7 +5,8 @@ [status-im.protocol.state.storage :as s] [status-im.models.chats :as c] [status-im.components.styles :refer [default-chat-color]] - [status-im.utils.utils :refer [log on-error http-post toast]] + [status-im.utils.utils :refer [on-error http-post toast]] + [status-im.utils.logging :as log] [status-im.utils.random :as random] [status-im.utils.sms-listener :refer [add-sms-listener remove-sms-listener]] @@ -198,14 +199,15 @@ (defn create-chat [handler] (fn [db] (let [{:keys [new-chat] :as db'} (handler db)] - (when new-chat + (log/debug new-chat) + (when (and new-chat (not= (:chat-id new-chat) "console")) (c/create-chat new-chat)) (dissoc db' :new-chat)))) (def init (create-chat - (fn [{:keys [chats] :as db}] - (if (chats "console") + (fn [{:keys [is-logged-in chats] :as db}] + (if is-logged-in db (-> db (assoc-in [:chats "console"] console-chat) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index ccecdc86e5..eee3ddc22a 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -4,7 +4,7 @@ [status-im.utils.handlers :as u] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] - [status-im.persistence.realm :as realm] + [status-im.persistence.realm.core :as realm] [status-im.components.jail :as j] [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [reg-handler]])) @@ -13,12 +13,16 @@ (defn load-commands! [_ [identity]] + (let [is-console? (= identity "console") + schema (if is-console? + :base + :account)] (dispatch [::fetch-commands! identity]) ;; todo uncomment - #_(if-let [{:keys [file]} (realm/get-one-by-field :commands :chat-id - identity)] + #_(if-let [{:keys [file]} (realm/get-one-by-field schema :commands + :chat-id identity)] (dispatch [::parse-commands! identity file]) - (dispatch [::fetch-commands! identity]))) + (dispatch [::fetch-commands! identity])))) (defn fetch-commands! [db [identity]] @@ -73,7 +77,11 @@ (defn save-commands-js! [_ [id file]] - (realm/create-object :commands {:chat-id id :file file})) + (let [is-console? (= id "console") + schema (if is-console? + :base + :account)] + (realm/create-object schema :commands {:chat-id id :file file}))) (defn loading-failed! [db [id reason details]] diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs index f2aa252434..dc8f7b7938 100644 --- a/src/status_im/contacts/validations.cljs +++ b/src/status_im/contacts/validations.cljs @@ -1,14 +1,14 @@ (ns status-im.contacts.validations (:require [cljs.spec :as s] [cljsjs.web3] - [status-im.persistence.realm :as realm])) + [status-im.persistence.realm.core :as realm])) (defn is-address? [s] (.isAddress js/Web3.prototype s)) (defn unique-identity? [identity] (println identity) - (not (realm/exists? :contacts :whisper-identity identity))) + (not (realm/exists? :account :contacts :whisper-identity identity))) (defn valid-length? [identity] (let [length (count identity)] diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 8eefb216ad..0f1887ea9e 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -11,8 +11,9 @@ ;; initial state of app-db (def app-db {:identity-password "replace-me-with-user-entered-password" :identity "me" + :is-logged-in false :accounts {} - :current-account false + :user-identity nil :contacts [] :contacts-ids #{} :selected-contacts #{} @@ -23,7 +24,7 @@ :chats-updated-signal 0 :show-actions false :selected-participants #{} - :signed-up true + :signed-up false :view-id default-view :navigation-stack (list default-view) ;; TODO fix hardcoded values diff --git a/src/status_im/discovery/model.cljs b/src/status_im/discovery/model.cljs index 6547321ff7..7b8a72b3a8 100644 --- a/src/status_im/discovery/model.cljs +++ b/src/status_im/discovery/model.cljs @@ -1,12 +1,11 @@ (ns status-im.discovery.model ;status-im.models.discoveries (:require [status-im.utils.logging :as log] - [status-im.persistence.realm :as realm] - [status-im.persistence.realm :as r])) + [status-im.persistence.realm.core :as r])) (defn get-tag [tag] (log/debug "Getting tag: " tag) - (-> (r/get-by-field :tag :name tag) + (-> (r/get-by-field :base :tag :name tag) (r/single-cljs))) (defn decrease-tag-counter [tag] @@ -15,18 +14,20 @@ (if tag-object (let [counter (dec (:count tag-object))] (if (zero? counter) - (realm/delete tag-object) - (realm/create :tag {:name tag - :count counter} - true)))))) + (r/delete :base tag-object) + (r/create :base :tag + {:name tag + :count counter} + true)))))) (defn increase-tag-counter [tag] (let [tag (:name tag) tag-object (get-tag tag)] (if tag-object - (realm/create :tag {:name tag - :count (inc (:count tag-object))} - true)))) + (r/create :base :tag + {:name tag + :count (inc (:count tag-object))} + true)))) (defn decrease-tags-counter [tags] (doseq [tag tags] @@ -37,45 +38,46 @@ (increase-tag-counter tag))) (defn get-tags [whisper-id] - (:tags (-> (r/get-by-field :discoveries :whisper-id whisper-id) + (:tags (-> (r/get-by-field :base :discoveries :whisper-id whisper-id) (r/single-cljs)))) (defn- create-discovery [{:keys [tags] :as discovery}] (log/debug "Creating discovery: " discovery tags) - (realm/create :discoveries discovery true) + (r/create :base :discoveries discovery true) (increase-tags-counter tags)) (defn- update-discovery [{:keys [whisper-id tags] :as discovery}] (let [old-tags (get-tags whisper-id) tags (map :name tags)] (decrease-tags-counter old-tags) - (realm/create :discoveries discovery true) + (r/create :base :discoveries discovery true) (increase-tags-counter tags))) (defn- discovery-exist? [discoveries discovery] (some #(= (:whisper-id discovery) (:whisper-id %)) discoveries)) (defn discovery-list [] - (->> (-> (r/get-all :discoveries) + (->> (-> (r/get-all :base :discoveries) (r/sorted :last-updated :desc) r/collection->map) (map #(update % :tags vals)))) (defn- add-discoveries [discoveries] - (realm/write (fn [] - (let [db-discoveries (discovery-list)] - (mapv (fn [discovery] - (if-not (discovery-exist? db-discoveries - discovery) - (create-discovery discovery) - (update-discovery discovery))) - discoveries))))) + (r/write :base + (fn [] + (let [db-discoveries (discovery-list)] + (mapv (fn [discovery] + (if-not (discovery-exist? db-discoveries + discovery) + (create-discovery discovery) + (update-discovery discovery))) + discoveries))))) (defn save-discoveries [discoveries] (add-discoveries discoveries)) (defn discoveries-by-tag [tag limit] - (let [discoveries (-> (r/get-by-filter :discoveries (str "tags.name = '" tag "'")) + (let [discoveries (-> (r/get-by-filter :base :discoveries (str "tags.name = '" tag "'")) (r/sorted :last-updated :desc))] (log/debug "Discoveries by tag: " tag) (if (pos? limit) @@ -83,7 +85,7 @@ discoveries))) (defn all-tags [] - (-> (r/get-all :tag) + (-> (r/get-all :base :tag) (r/sorted :count :desc) r/collection->map)) diff --git a/src/status_im/group_settings/handlers.cljs b/src/status_im/group_settings/handlers.cljs index 6f5e94d558..0c0521bcfd 100644 --- a/src/status_im/group_settings/handlers.cljs +++ b/src/status_im/group_settings/handlers.cljs @@ -1,7 +1,7 @@ (ns status-im.group-settings.handlers (:require [re-frame.core :refer [debug dispatch after enrich]] [status-im.utils.handlers :refer [register-handler]] - [status-im.persistence.realm :as r] + [status-im.persistence.realm.core :as r] [status-im.chat.handlers :refer [delete-messages!]] [status-im.protocol.api :as api] [status-im.utils.random :as random] @@ -20,8 +20,9 @@ [db-name property-name] (fn [{:keys [current-chat-id] :as db} _] (let [property (db-name db)] - (r/write (fn [] - (-> (r/get-by-field :chats :chat-id current-chat-id) + (r/write :account + (fn [] + (-> (r/get-by-field :account :chats :chat-id current-chat-id) (r/single) (aset (name property-name) property))))))) @@ -76,9 +77,9 @@ (defn remove-members-from-realm! [{:keys [current-chat-id selected-participants] :as db} _] (let [chat (get-in db [:chats current-chat-id])] - (r/write + (r/write :account (fn [] - (r/create + (r/create :account :chats (update chat :contacts remove-identities selected-participants) true))))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 0a6f9b2dda..fb60e6e368 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.handlers (:require - [re-frame.core :refer [after dispatch debug]] + [re-frame.core :refer [after dispatch dispatch-sync debug]] [schema.core :as s :include-macros true] [status-im.db :refer [app-db schema]] [status-im.persistence.simple-kv-store :as kv] @@ -56,12 +56,34 @@ (assoc-in db [:animations k] v))) (register-handler :initialize-db + (fn [_ _] + (assoc app-db + :user-identity nil))) + +(register-handler :initialize-account-db (fn [_ _] (assoc app-db :signed-up (storage/get kv/kv-store :signed-up) :user-identity (protocol/stored-identity nil) :password (storage/get kv/kv-store :password)))) +(register-handler :initialize-account + (u/side-effect! + (fn [_ [_ account]] + (dispatch [:initialize-protocol account]) + (dispatch [:initialize-chats]) + (dispatch [:load-contacts]) + ; TODO: initialize protocol here + (dispatch [:init-chat])))) + +(register-handler :reset-app + (u/side-effect! + (fn [_ _] + (dispatch [:initialize-db]) + (dispatch [:load-accounts]) + (dispatch [:init-console-chat]) + (dispatch [:load-commands! "console"])))) + (register-handler :initialize-crypt (u/side-effect! (fn [_ _] diff --git a/src/status_im/models/accounts.cljs b/src/status_im/models/accounts.cljs index a9f333c3c7..834db43e94 100644 --- a/src/status_im/models/accounts.cljs +++ b/src/status_im/models/accounts.cljs @@ -1,22 +1,22 @@ (ns status-im.models.accounts - (:require [status-im.persistence.realm :as r])) + (:require [status-im.persistence.realm.core :as r])) (defn get-accounts [] - (-> (r/get-all :accounts) + (-> (r/get-all :base :accounts) r/collection->map)) (defn create-account [{:keys [address public-key] :as account}] (->> account - (r/create :accounts))) + (r/create :base :accounts))) (defn save-accounts [accounts] - (r/write #(mapv create-account accounts))) + (r/write :base #(mapv create-account accounts))) ;;;;;;;;;;;;;;;;;;;;---------------------------------------------- (defn accounts-list [] - (r/get-all :accounts)) + (r/get-all :base :accounts)) (defn account-by-address [address] - (r/single-cljs (r/get-by-field :accounts :address address))) + (r/single-cljs (r/get-by-field :base :accounts :address address))) diff --git a/src/status_im/models/chats.cljs b/src/status_im/models/chats.cljs index 33e003a10d..9e86014fe4 100644 --- a/src/status_im/models/chats.cljs +++ b/src/status_im/models/chats.cljs @@ -1,7 +1,7 @@ (ns status-im.models.chats (:require [clojure.set :refer [difference]] [re-frame.core :refer [dispatch]] - [status-im.persistence.realm :as r] + [status-im.persistence.realm.core :as r] [status-im.utils.random :as random :refer [timestamp]] [clojure.string :refer [join blank?]] [status-im.utils.logging :as log] @@ -12,7 +12,7 @@ (defn chat-name-from-contacts [identities] (let [chat-name (->> identities (map (fn [identity] - (-> (r/get-by-field :contacts :whisper-identity identity) + (-> (r/get-by-field :account :contacts :whisper-identity identity) (r/single-cljs) :name))) (filter identity) @@ -25,7 +25,7 @@ chat-id)) (defn chat-exists? [chat-id] - (r/exists? :chats :chat-id chat-id)) + (r/exists? :account :chats :chat-id chat-id)) (defn add-status-message [chat-id] ;; TODO Get real status @@ -42,32 +42,35 @@ (defn create-chat ([{:keys [last-msg-id] :as chat}] (let [chat (assoc chat :last-msg-id (or last-msg-id ""))] - (r/write #(r/create :chats chat)))) + (log/debug "Creating chat" chat) + (r/write :account #(r/create :account :chats chat)))) ([db chat-id identities group-chat? chat-name] + (log/debug "Creating chat" chat-id) (when-not (chat-exists? chat-id) (let [chat-name (or chat-name (get-chat-name chat-id identities)) _ (log/debug "creating chat" chat-name)] - (r/write + (r/write :account (fn [] (let [contacts (mapv (fn [ident] {:identity ident}) identities)] - (r/create :chats {:chat-id chat-id - :is-active true - :name chat-name - :group-chat group-chat? - :timestamp (timestamp) - :contacts contacts - :last-msg-id ""})))) + (r/create :account :chats + {:chat-id chat-id + :is-active true + :name chat-name + :group-chat group-chat? + :timestamp (timestamp) + :contacts contacts + :last-msg-id ""})))) (add-status-message chat-id))))) (defn chat-contacts [chat-id] - (-> (r/get-by-field :chats :chat-id chat-id) + (-> (r/get-by-field :account :chats :chat-id chat-id) (r/single) (aget "contacts"))) (defn re-join-group-chat [db group-id identities group-name] - (r/write + (r/write :account (fn [] (let [new-identities (set identities) only-old-contacts (->> (chat-contacts group-id) @@ -78,10 +81,11 @@ (mapv (fn [ident] {:identity ident})) (concat only-old-contacts))] - (r/create :chats {:chat-id group-id - :is-active true - :name group-name - :contacts contacts} true)))) + (r/create :account :chats + {:chat-id group-id + :is-active true + :name group-name + :contacts contacts} true)))) db) (defn normalize-contacts @@ -89,23 +93,23 @@ (map #(update % :contacts vals) chats)) (defn chats-list [] - (-> (r/get-all :chats) + (-> (r/get-all :account :chats) (r/sorted :timestamp :desc) r/collection->map normalize-contacts)) (defn chat-by-id [chat-id] - (-> (r/get-by-field :chats :chat-id chat-id) + (-> (r/get-by-field :account :chats :chat-id chat-id) (r/single-cljs) (r/list-to-array :contacts))) (defn chat-by-id2 [chat-id] - (-> (r/get-by-field :chats :chat-id chat-id) + (-> (r/get-by-field :account :chats :chat-id chat-id) r/collection->map first)) (defn chat-add-participants [chat-id identities] - (r/write + (r/write :account (fn [] (let [contacts (chat-contacts chat-id)] (doseq [contact-identity identities] @@ -118,23 +122,24 @@ ;; TODO deprecated? (is there need to remove multiple member at once?) (defn chat-remove-participants [chat-id identities] - (r/write + (r/write :account (fn [] (let [query (include-query :identity identities) - chat (r/single (r/get-by-field :chats :chat-id chat-id))] + chat (r/single (r/get-by-field :account :chats :chat-id chat-id))] (-> (aget chat "contacts") (r/filtered query) (.forEach (fn [object _ _] (aset object "is-in-chat" false)))))))) (defn active-group-chats [] - (let [results (r/filtered (r/get-all :chats) + (let [results (r/filtered (r/get-all :account :chats) "group-chat = true && is-active = true")] (js->clj (.map results (fn [object _ _] (aget object "chat-id")))))) (defn set-chat-active [chat-id active?] - (r/write (fn [] - (-> (r/get-by-field :chats :chat-id chat-id) + (r/write :account + (fn [] + (-> (r/get-by-field :account :chats :chat-id chat-id) (r/single) (aset "is-active" active?))))) diff --git a/src/status_im/models/contacts.cljs b/src/status_im/models/contacts.cljs index 6c3ea62a7a..d10904e789 100644 --- a/src/status_im/models/contacts.cljs +++ b/src/status_im/models/contacts.cljs @@ -1,11 +1,11 @@ (ns status-im.models.contacts - (:require [status-im.persistence.realm :as r] + (:require [status-im.persistence.realm.core :as r] [status-im.utils.identicon :refer [identicon]] [status-im.persistence.realm-queries :refer [include-query exclude-query]])) (defn get-contacts [] - (-> (r/get-all :contacts) + (-> (r/get-all :account :contacts) (r/sorted :name :asc) r/collection->map)) @@ -13,22 +13,22 @@ (->> {:name (or name "") :photo-path (or photo-path (identicon whisper-identity))} (merge contact) - (r/create :contacts))) + (r/create :account :contacts))) (defn save-contacts [contacts] - (r/write #(mapv create-contact contacts))) + (r/write :account #(mapv create-contact contacts))) ;;;;;;;;;;;;;;;;;;;;---------------------------------------------- (defn contacts-list [] - (r/sorted (r/get-all :contacts) :name :asc)) + (r/sorted (r/get-all :account :contacts) :name :asc)) (defn contacts-list-exclude [exclude-idents] (if (empty? exclude-idents) (contacts-list) (let [query (exclude-query :whisper-identity exclude-idents)] - (-> (r/get-all :contacts) + (-> (r/get-all :account :contacts) (r/filtered query) (r/sorted :name :asc))))) @@ -36,9 +36,9 @@ (if (empty? include-indents) () (let [query (include-query :whisper-identity include-indents)] - (-> (r/get-all :contacts) + (-> (r/get-all :account :contacts) (r/filtered query) (r/sorted :name :asc))))) (defn contact-by-identity [identity] - (r/single-cljs (r/get-by-field :contacts :whisper-identity identity))) + (r/single-cljs (r/get-by-field :account :contacts :whisper-identity identity))) diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 38d7342ae3..122ba94c64 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -1,5 +1,5 @@ (ns status-im.models.messages - (:require [status-im.persistence.realm :as r] + (:require [status-im.persistence.realm.core :as r] [re-frame.core :refer [dispatch]] [cljs.reader :refer [read-string]] [status-im.utils.random :refer [timestamp]] @@ -28,8 +28,8 @@ ;; todo remove chat-id parameter [chat-id {:keys [msg-id content] :as message}] - (when-not (r/exists? :msgs :msg-id msg-id) - (r/write + (when-not (r/exists? :account :msgs :msg-id msg-id) + (r/write :account (fn [] (let [content' (if (string? content) content @@ -40,7 +40,7 @@ :content content' :timestamp (timestamp) :delivery-status nil})] - (r/create :msgs message' true)))))) + (r/create :account :msgs message' true)))))) (defn command-type? [type] (contains? @@ -50,7 +50,7 @@ (defn get-messages ([chat-id] (get-messages chat-id 0)) ([chat-id from] - (->> (-> (r/get-by-field :msgs :chat-id chat-id) + (->> (-> (r/get-by-field :account :msgs :chat-id chat-id) (r/sorted :timestamp :desc) (r/page from (+ from c/default-number-of-messages)) (r/collection->map)) @@ -63,7 +63,7 @@ (defn update-message! [{:keys [msg-id] :as msg}] (log/debug "update-message!" msg) - (r/write + (r/write :account (fn [] - (when (r/exists? :msgs :msg-id msg-id) - (r/create :msgs msg true))))) + (when (r/exists? :account :msgs :msg-id msg-id) + (r/create :account :msgs msg true))))) diff --git a/src/status_im/models/requests.cljs b/src/status_im/models/requests.cljs new file mode 100644 index 0000000000..c29f3ee8a1 --- /dev/null +++ b/src/status_im/models/requests.cljs @@ -0,0 +1,21 @@ +(ns status-im.models.requests + (:require [status-im.persistence.realm.core :as r])) + +(defn get-requests [] + (-> (r/get-all :account :requests) + r/collection->map)) + +(defn create-request [request] + (r/create :account :requests request true)) + +(defn save-request [request}] + (r/write :account + (fn [] + (create-request request)))) + +(defn save-requests [requests] + (r/write :account #(mapv create-request requests))) + +(defn requests-list [] + (r/get-all :account :requests)) + diff --git a/src/status_im/persistence/realm.cljs b/src/status_im/persistence/realm.cljs deleted file mode 100644 index 08e7ae84f4..0000000000 --- a/src/status_im/persistence/realm.cljs +++ /dev/null @@ -1,200 +0,0 @@ -(ns status-im.persistence.realm - (:require [cljs.reader :refer [read-string]] - [status-im.components.styles :refer [default-chat-color]] - [status-im.utils.types :refer [to-string]] - [status-im.utils.utils :as u] - [clojure.string :as str]) - (:refer-clojure :exclude [exists?])) - -(def opts {:schema [{:name :contacts - :primaryKey :whisper-identity - :properties {:phone-number {:type "string" - :optional true} - :whisper-identity "string" - :name {:type "string" - :optional true} - :photo-path {:type "string" - :optinal true}}} - {:name :accounts - :primaryKey :address - :properties {:address "string" - :public-key "string" - :name "string" - :photo-path "string"}} - {:name :requests - :properties {:message-id :string - :chat-id :string - :type :string - :status {:type :string - :default "open"} - :added :date}} - {:name :kv-store - :primaryKey :key - :properties {:key "string" - :value "string"}} - {:name :msgs - :primaryKey :msg-id - :properties {:msg-id "string" - :from "string" - :to {:type "string" - :optional true} - :content "string" ;; TODO make it ArrayBuffer - :content-type "string" - :timestamp "int" - :chat-id {:type "string" - :indexed true} - :outgoing "bool" - :delivery-status {:type "string" - :optional true} - :same-author "bool" - :same-direction "bool" - :preview {:type :string - :optional true}}} - {:name :chat-contact - :properties {:identity "string" - :is-in-chat {:type "bool" - :default true}}} - {:name :chats - :primaryKey :chat-id - :properties {:chat-id "string" - :name "string" - :color {:type "string" - :default default-chat-color} - :group-chat {:type "bool" - :indexed true} - :is-active "bool" - :timestamp "int" - :contacts {:type "list" - :objectType "chat-contact"} - :dapp-url {:type :string - :optional true} - :dapp-hash {:type :int - :optional true} - :last-msg-id "string"}} - {:name :commands - :primaryKey :chat-id - :properties {:chat-id "string" - :file "string"}} - {:name :tag - :primaryKey :name - :properties {:name "string" - :count {:type "int" - :optional true - :default 0}}} - {:name :discoveries - :primaryKey :whisper-id - :properties {:name "string" - :status "string" - :whisper-id "string" - :photo "string" - :location "string" - :tags {:type "list" - :objectType "tag"} - :last-updated "date"}}]}) - -(def realm-class (u/require "realm")) - -(def realm (when (cljs.core/exists? js/window) - (realm-class. (clj->js opts)))) - -(def schema-by-name (->> (:schema opts) - (mapv (fn [{:keys [name] :as schema}] - [name schema])) - (into {}))) - -(defn field-type [schema-name field] - (let [field-def (get-in schema-by-name [schema-name :properties field])] - (if (map? field-def) - (:type field-def) - field-def))) - -(defn write [f] - (.write realm f)) - -(defn create - ([schema-name obj] - (create schema-name obj false)) - ([schema-name obj update?] - (.create realm (to-string schema-name) (clj->js obj) update?))) - -(defn create-object - [schema-name obj] - (write (fn [] (create schema-name obj true)))) - -(defn and-q [queries] - (str/join " and " queries)) - -(defmulti to-query (fn [schema-name operator field value] - operator)) - -(defmethod to-query :eq [schema-name operator field value] - (let [value (to-string value) - query (str (name field) "=" (if (= "string" (name (field-type - schema-name field))) - (str "\"" value "\"") - value))] - query)) - -(defn get-by-filter [schema-name filter] - (-> (.objects realm (name schema-name)) - (.filtered filter))) - -(defn get-by-field [schema-name field value] - (let [q (to-query schema-name :eq field value)] - (.filtered (.objects realm (name schema-name)) q))) - -(defn get-by-fields [schema-name fields] - (let [queries (map (fn [[k v]] - (to-query schema-name :eq k v)) - fields)] - (.filtered (.objects realm (name schema-name)) (and-q queries)))) - -(defn get-all [schema-name] - (.objects realm (to-string schema-name))) - -(defn sorted [results field-name order] - (.sorted results (to-string field-name) (if (= order :asc) - false - true))) - -(defn filtered [results filter-query] - (.filtered results filter-query)) - -(defn page [results from to] - (js/Array.prototype.slice.call results from to)) - -(defn single [result] - (-> (aget result 0))) - -(defn single-cljs [result] - (some-> (aget result 0) - (js->clj :keywordize-keys true))) - -(defn cljs-list [results] - (-> (js->clj results :keywordize-keys true) - (vals))) - -(defn list-to-array [record list-field] - (update-in record [list-field] (comp vec vals))) - -(defn decode-value [{:keys [key value]}] - (read-string value)) - -(defn delete [obj] - (.delete realm obj)) - -(defn exists? [schema-name field value] - (pos? (.-length (get-by-field schema-name field value)))) - -(defn get-count [objs] - (.-length objs)) - -(defn get-list [schema-name] - (vals (js->clj (.objects realm (to-string schema-name)) :keywordize-keys true))) - -(defn collection->map [collection] - (-> (.map collection (fn [object _ _] object)) - (js->clj :keywordize-keys true))) - -(defn get-one-by-field [schema-name field value] - (single-cljs (get-by-field schema-name field value))) diff --git a/src/status_im/persistence/realm/core.cljs b/src/status_im/persistence/realm/core.cljs new file mode 100644 index 0000000000..e7a85996d9 --- /dev/null +++ b/src/status_im/persistence/realm/core.cljs @@ -0,0 +1,151 @@ +(ns status-im.persistence.realm.core + (:require [cljs.reader :refer [read-string]] + [status-im.components.styles :refer [default-chat-color]] + [status-im.utils.types :refer [to-string]] + [status-im.utils.utils :as u] + [status-im.utils.logging :as log] + [status-im.persistence.realm.schemas :refer [base account]] + [clojure.string :as str]) + (:refer-clojure :exclude [exists?])) + + +(def realm-class (u/require "realm")) + +(def base-realm + (when (cljs.core/exists? js/window) + (realm-class. (clj->js base)))) + +(def account-realm (atom nil)) + +(defn create-account-realm [address] + (let [opts (merge account {:path (str address ".realm")})] + (when (cljs.core/exists? js/window) + (realm-class. (clj->js opts))))) + +(defn realm [schema] + (log/debug "Schema: " schema) + (case schema + :base base-realm + :account @account-realm)) + +(defn close [schema] + (let [realm-db (realm schema)] + (when realm-db + (.close realm-db)))) + +(defn close-account-realm [] + (close :account) + (reset! account-realm nil)) + +(defn get-schema-by-name [opts] + (->> (:schema opts) + (mapv (fn [{:keys [name] :as schema}] + [name schema])) + (into {}))) + +(def schema-by-name + {:base (get-schema-by-name base) + :account (get-schema-by-name account)}) + +(defn field-type [schema schema-name field] + (let [schema-by-name (get schema-by-name schema) + field-def (get-in schema-by-name [schema-name :properties field])] + (if (map? field-def) + (:type field-def) + field-def))) + +(defn write [schema f] + (.write (realm schema) f)) + +(defn create + ([schema schema-name obj] + (create schema schema-name obj false)) + ([schema schema-name obj update?] + (.create (realm schema) (to-string schema-name) (clj->js obj) update?))) + +(defn create-object + [schema schema-name obj] + (write schema (fn [] (create schema schema-name obj true)))) + +(defn and-q [queries] + (str/join " and " queries)) + +(defmulti to-query (fn [schema schema-name operator field value] + operator)) + +(defmethod to-query :eq [schema schema-name operator field value] + (let [value (to-string value) + field-type (field-type schema schema-name field) + query (str (name field) "=" (if (= "string" (name field-type)) + (str "\"" value "\"") + value))] + query)) + +(defn get-by-filter [schema schema-name filter] + (log/debug "Get by filter: " schema schema-name field) + (-> (.objects (realm schema) (name schema-name)) + (.filtered filter))) + +(defn get-by-field [schema schema-name field value] + (log/debug "Get by field: " schema schema-name field value) + (let [q (to-query schema schema-name :eq field value)] + (.filtered (.objects (realm schema) (name schema-name)) q))) + +(defn get-by-fields [schema schema-name fields] + (log/debug "Get by fields: " schema schema-name fields) + (let [queries (map (fn [[k v]] + (to-query schema schema-name :eq k v)) + fields)] + (.filtered (.objects (realm schema) (name schema-name)) (and-q queries)))) + +(defn get-all [schema schema-name] + (log/debug "Get all: " schema schema-name) + (.objects (realm schema) (to-string schema-name))) + +(defn sorted [results field-name order] + (.sorted results (to-string field-name) (if (= order :asc) + false + true))) + +(defn filtered [results filter-query] + (.filtered results filter-query)) + +(defn page [results from to] + (js/Array.prototype.slice.call results from to)) + +(defn single [result] + (-> (aget result 0))) + +(defn single-cljs [result] + (some-> (aget result 0) + (js->clj :keywordize-keys true))) + +(defn cljs-list [results] + (-> (js->clj results :keywordize-keys true) + (vals))) + +(defn list-to-array [record list-field] + (update-in record [list-field] (comp vec vals))) + +(defn decode-value [{:keys [key value]}] + (read-string value)) + +(defn delete [schema obj] + (.delete (realm schema) obj)) + +(defn exists? [schema schema-name field value] + (pos? (.-length (get-by-field schema schema-name field value)))) + +(defn get-count [objs] + (.-length objs)) + +(defn get-list [schema schema-name] + (log/debug "Get list: " schema schema-name) + (vals (js->clj (.objects (realm schema) (to-string schema-name)) :keywordize-keys true))) + +(defn collection->map [collection] + (-> (.map collection (fn [object _ _] object)) + (js->clj :keywordize-keys true))) + +(defn get-one-by-field [schema schema-name field value] + (single-cljs (get-by-field schema schema-name field value))) \ No newline at end of file diff --git a/src/status_im/persistence/realm/schemas.cljs b/src/status_im/persistence/realm/schemas.cljs new file mode 100644 index 0000000000..4625b8b2c8 --- /dev/null +++ b/src/status_im/persistence/realm/schemas.cljs @@ -0,0 +1,100 @@ +(ns status-im.persistence.realm.schemas + (:require [status-im.components.styles :refer [default-chat-color]])) + +(def base {:schema [{:name :accounts + :primaryKey :address + :properties {:address "string" + :public-key "string" + :name "string" + :photo-path "string"}} + {:name :tag + :primaryKey :name + :properties {:name "string" + :count {:type "int" + :optional true + :default 0}}} + {:name :discoveries + :primaryKey :whisper-id + :properties {:name "string" + :status "string" + :whisper-id "string" + :photo "string" + :location "string" + :tags {:type "list" + :objectType "tag"} + :last-updated "date"}} + {:name :kv-store + :primaryKey :key + :properties {:key "string" + :value "string"}} + {:name :commands + :primaryKey :chat-id + :properties {:chat-id "string" + :file "string"}}] + :schemaVersion 0}) + +(def account {:schema [{:name :contacts + :primaryKey :whisper-identity + :properties {:phone-number {:type "string" + :optional true} + :whisper-identity "string" + :name {:type "string" + :optional true} + :photo-path {:type "string" + :optinal true}}} + {:name :requests + :properties {:message-id :string + :chat-id :string + :type :string + :status {:type :string + :default "open"} + :added :date}} + {:name :kv-store + :primaryKey :key + :properties {:key "string" + :value "string"}} + {:name :msgs + :primaryKey :msg-id + :properties {:msg-id "string" + :from "string" + :to {:type "string" + :optional true} + :content "string" ;; TODO make it ArrayBuffer + :content-type "string" + :timestamp "int" + :chat-id {:type "string" + :indexed true} + :outgoing "bool" + :delivery-status {:type "string" + :optional true} + :same-author "bool" + :same-direction "bool" + :preview {:type :string + :optional true}}} + {:name :chat-contact + :properties {:identity "string" + :is-in-chat {:type "bool" + :default true}}} + {:name :chats + :primaryKey :chat-id + :properties {:chat-id "string" + :name "string" + :color {:type "string" + :default default-chat-color} + :group-chat {:type "bool" + :indexed true} + :is-active "bool" + :timestamp "int" + :contacts {:type "list" + :objectType "chat-contact"} + :dapp-url {:type :string + :optional true} + :dapp-hash {:type :int + :optional true} + :last-msg-id "string"}} + {:name :commands + :primaryKey :chat-id + :properties {:chat-id "string" + :file "string"}}] + :schemaVersion 0}) + diff --git a/src/status_im/persistence/simple_kv_store.cljs b/src/status_im/persistence/simple_kv_store.cljs index 84dd85bff3..84151ef522 100644 --- a/src/status_im/persistence/simple_kv_store.cljs +++ b/src/status_im/persistence/simple_kv_store.cljs @@ -1,25 +1,29 @@ (ns status-im.persistence.simple-kv-store (:require [status-im.protocol.state.storage :as st] - [status-im.persistence.realm :as r] + [status-im.persistence.realm.core :as r] [status-im.utils.types :refer [to-edn-string]])) -(defrecord SimpleKvStore [] +(defrecord SimpleKvStore [schema] st/Storage (put [_ key value] - (r/write + (r/write schema (fn [] - (r/create :kv-store {:key key - :value (to-edn-string value)} true)))) + (r/create schema :kv-store + {:key key + :value (to-edn-string value)} true)))) (get [_ key] - (some-> (r/get-by-field :kv-store :key key) + (some-> (r/get-by-field schema :kv-store :key key) (r/single-cljs) (r/decode-value))) (contains-key? [_ key] - (r/exists? :kv-store :key key)) + (r/exists? schema :kv-store :key key)) (delete [_ key] - (r/write (fn [] - (-> (r/get-by-field :kv-store :key key) - (r/single) - (r/delete)))))) + (r/write schema + (fn [] + (->> (r/get-by-field schema :kv-store :key key) + (r/single) + (r/delete schema)))))) -(def kv-store (->SimpleKvStore)) +(def kv-store (->SimpleKvStore :account)) + +(def base-kv-store (->SimpleKvStore :base)) From fac008b0875b81045b1dcdfa5077f18a35775bbe Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 18 Jul 2016 19:29:51 +0300 Subject: [PATCH 17/19] fix account database separation --- .re-natal | 3 +- android/app/build.gradle | 1 + .../main/java/com/statusim/MainActivity.java | 3 + android/settings.gradle | 3 + package.json | 7 ++- src/status_im/accounts/handlers.cljs | 17 +++--- src/status_im/android/core.cljs | 6 +- src/status_im/chat/handlers.cljs | 56 ++++++------------- src/status_im/chat/handlers/requests.cljs | 6 +- src/status_im/chat/sign_up.cljs | 6 +- src/status_im/handlers.cljs | 3 +- src/status_im/models/requests.cljs | 2 +- src/status_im/persistence/realm/core.cljs | 43 ++++++++++++-- src/status_im/utils/fs.cljs | 11 ++++ 14 files changed, 98 insertions(+), 69 deletions(-) create mode 100644 src/status_im/utils/fs.cljs diff --git a/.re-natal b/.re-natal index 74c8704bf6..3df6476527 100644 --- a/.re-natal +++ b/.re-natal @@ -21,7 +21,8 @@ "react-native-camera", "react-native-qrcode", "react-native-orientation", - "identicon.js" + "identicon.js", + "react-native-fs" ], "imageDirs": [ "images" diff --git a/android/app/build.gradle b/android/app/build.gradle index 913abe3bc0..0682d5fac0 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -133,6 +133,7 @@ dependencies { compile project(':react-native-camera') compile project(':react-native-status') compile project(':react-native-orientation') + compile project(':react-native-fs') //compile(name:'statusgo-android-16', ext:'aar') compile(group: 'status-im', name: 'status-go', version: '0.1.0-201607011545-da53ec', ext: 'aar') diff --git a/android/app/src/main/java/com/statusim/MainActivity.java b/android/app/src/main/java/com/statusim/MainActivity.java index 6c779cee3b..6303b63e9f 100644 --- a/android/app/src/main/java/com/statusim/MainActivity.java +++ b/android/app/src/main/java/com/statusim/MainActivity.java @@ -29,6 +29,8 @@ import com.lwansbrough.RCTCamera.*; import com.i18n.reactnativei18n.ReactNativeI18n; import android.content.res.Configuration; +import com.rnfs.RNFSPackage; + public class MainActivity extends ReactActivity { private static final String TAG = "MainActivity"; @@ -112,6 +114,7 @@ public class MainActivity extends ReactActivity { new RCTCameraPackage(), new SmsListener(this), new OrientationPackage(this), + new RNFSPackage(), new GethPackage() ); } diff --git a/android/settings.gradle b/android/settings.gradle index c238c1e7d2..77a38a09cf 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -26,3 +26,6 @@ project(':react-native-camera').projectDir = new File(rootProject.projectDir, include ':react-native-orientation', ':app' project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android') + +include ':react-native-fs' +project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android') diff --git a/package.json b/package.json index f63ef15e2c..44873810b8 100644 --- a/package.json +++ b/package.json @@ -15,15 +15,16 @@ "react-native-camera": "github:codyhazelwood/react-native-camera", "react-native-circle-checkbox": "^0.1.3", "react-native-contacts": "^0.2.4", + "react-native-fs": "^1.5.1", "react-native-i18n": "0.0.8", "react-native-invertible-scroll-view": "^1.0.0", "react-native-linear-gradient": "1.5.7", "react-native-loading-spinner-overlay": "0.0.8", + "react-native-orientation": "^1.17.0", "react-native-qrcode": "^0.2.2", "react-native-randombytes": "^2.1.0", + "react-native-status": "git+ssh://git@github.com/status-im/react-native-status", "react-native-vector-icons": "^1.3.4", - "react-native-orientation": "^1.17.0", - "realm": "^0.14.0", - "react-native-status": "git+ssh://git@github.com/status-im/react-native-status" + "realm": "^0.14.0" } } diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 7533014d43..e5bd588fed 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -47,18 +47,19 @@ (.createAccount geth password (fn [result] (account-created db result password))) db))) -(defn logged-in [db address] - (let [account (get-in db [:accounts address])] - (log/debug "Logged in: " address account) - (realm/close-account-realm) - (reset! realm/account-realm (realm/create-account-realm address)) +(defn initialize-account [db account] + (let [is-login-screen? (= (:view-id db) :login)] (dispatch [:set :login {}]) (dispatch [:set :is-logged-in true]) (dispatch [:set :user-identity account]) - (dispatch [:save-console]) - (dispatch [:initialize-account account]) - (when (:signed-up db) (dispatch [:navigate-to-clean default-view])))) + (when is-login-screen? (dispatch [:navigate-to-clean default-view])))) + +(defn logged-in [db address] + (let [account (get-in db [:accounts address])] + (log/debug "Logged in: " address account) + (realm/change-account-realm address #(when (nil? %) + (initialize-account db account))))) (register-handler :login-account (-> (fn [db [_ address password]] diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 8762730a95..b039e9e472 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -69,7 +69,7 @@ (fn [] (let [startup-view (if @account @view-id (if (contains? #{:login :chat} @view-id) @view-id :accounts))] (log/debug startup-view) - (case (if @signed-up startup-view :chat) + (case (if true startup-view :chat) :discovery [main-tabs] :discovery-tag [discovery-tag] :add-participants [new-participants] @@ -91,10 +91,6 @@ (dispatch-sync [:reset-app]) (dispatch [:initialize-crypt]) (dispatch [:initialize-geth]) - (dispatch [:load-user-phone-number]) - - - ;(dispatch [:init-chat]) (init-back-button-handler!) (.registerComponent app-registry "StatusIm" #(r/reactify-component app-root))) diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 83bda90f99..7efa2706e9 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -31,10 +31,9 @@ (assoc db :show-actions show-actions))) (register-handler :load-more-messages - (fn [{:keys [is-logged-in current-chat-id] :as db} _] - (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?]) - account-realm-exists? (or (not= current-chat-id "console") is-logged-in)] - (if (or all-loaded? (not account-realm-exists?)) + (fn [{:keys [current-chat-id] :as db} _] + (let [all-loaded? (get-in db [:chats current-chat-id :all-loaded?])] + (if all-loaded? db (let [messages-path [:chats current-chat-id :messages] messages (get-in db messages-path) @@ -292,22 +291,21 @@ :content content}))))) (defn save-message-to-realm! - [{:keys [is-logged-in new-message current-chat-id]} _] - (when (and new-message is-logged-in) + [{:keys [new-message current-chat-id]} _] + (when new-message (messages/save-message current-chat-id new-message))) (defn save-commands-to-realm! - [{:keys [is-logged-in new-commands current-chat-id]} _] - (when is-logged-in - (doseq [new-command new-commands] - (messages/save-message - current-chat-id - (dissoc new-command :rendered-preview :to-message))))) + [{:keys [new-commands current-chat-id]} _] + (doseq [new-command new-commands] + (messages/save-message + current-chat-id + (dissoc new-command :rendered-preview :to-message)))) (defn dispatch-responded-requests! [{:keys [new-commands current-chat-id]} _] - (doseq [{:keys [is-logged-in to-message]} new-commands] - (when (and to-message is-logged-in) + (doseq [{:keys [to-message]} new-commands] + (when to-message (dispatch [:request-answered! current-chat-id to-message])))) (defn invoke-commands-handlers! @@ -411,18 +409,6 @@ ((enrich init-chat)) ((after load-commands!)))) - -(register-handler :save-console - (fn [db _] - (when-not (chats/chat-exists? "console") - (let [console-chat (get-in db [:chats "console"])] - (when console-chat - (do - (chats/create-chat console-chat) - (doseq [message (reverse (:messages console-chat))] - (messages/save-message "console" message)))))) - db)) - (defn initialize-chats [{:keys [loaded-chats] :as db} _] (let [chats (->> loaded-chats @@ -443,9 +429,8 @@ ((enrich initialize-chats) load-chats!)) (defn store-message! - [{:keys [is-logged-in new-message]} [_ {chat-id :from}]] - (if (or (not= chat-id "console") is-logged-in) - (messages/save-message chat-id new-message))) + [{:keys [new-message]} [_ {chat-id :from}]] + (messages/save-message chat-id new-message)) (defn dispatch-request! [{:keys [new-message]} [_ {chat-id :from}]] @@ -471,20 +456,15 @@ (messages/save-message chat-id msg)))) (defmethod nav/preload-data! :chat - [{:keys [is-logged-in current-chat-id] :as db} [_ _ id]] + [{:keys [current-chat-id] :as db} [_ _ id]] (let [chat-id (or id current-chat-id) messages (get-in db [:chats chat-id :messages]) - db' (assoc db :current-chat-id chat-id) - account-realm-exists? (or (not= chat-id "console") is-logged-in)] - (when account-realm-exists? - (dispatch [:load-requests! chat-id])) + db' (assoc db :current-chat-id chat-id)] + (dispatch [:load-requests! chat-id]) (if (seq messages) db' (-> db' - ((fn [db] - (if account-realm-exists? - (load-messages! db) - db))) + load-messages! init-chat)))) (defn prepare-chat diff --git a/src/status_im/chat/handlers/requests.cljs b/src/status_im/chat/handlers/requests.cljs index 7789e5a445..a536ac946e 100644 --- a/src/status_im/chat/handlers/requests.cljs +++ b/src/status_im/chat/handlers/requests.cljs @@ -6,10 +6,8 @@ [status-im.utils.handlers :as u])) (defn store-request! - [{:keys [is-logged-in new-request] :as db}] - (if (or (not= (:chat-id new-request) "console") is-logged-in) - (requests/save-request new-request) - db)) + [{:keys [new-request] :as db}] + (requests/save-request new-request)) (defn add-request [db [_ chat-id {:keys [msg-id content]}]] diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index e592ea2061..e6b129b7d9 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -200,14 +200,14 @@ (fn [db] (let [{:keys [new-chat] :as db'} (handler db)] (log/debug new-chat) - (when (and new-chat (not= (:chat-id new-chat) "console")) + (when new-chat (c/create-chat new-chat)) (dissoc db' :new-chat)))) (def init (create-chat - (fn [{:keys [is-logged-in chats] :as db}] - (if is-logged-in + (fn [{:keys [chats] :as db}] + (if (chats "console") db (-> db (assoc-in [:chats "console"] console-chat) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index fb60e6e368..93044f0e34 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -3,6 +3,7 @@ [re-frame.core :refer [after dispatch dispatch-sync debug]] [schema.core :as s :include-macros true] [status-im.db :refer [app-db schema]] + [status-im.persistence.realm.core :as realm] [status-im.persistence.simple-kv-store :as kv] [status-im.protocol.state.storage :as storage] [status-im.utils.logging :as log] @@ -57,6 +58,7 @@ (register-handler :initialize-db (fn [_ _] + (realm/reset-account) (assoc app-db :user-identity nil))) @@ -73,7 +75,6 @@ (dispatch [:initialize-protocol account]) (dispatch [:initialize-chats]) (dispatch [:load-contacts]) - ; TODO: initialize protocol here (dispatch [:init-chat])))) (register-handler :reset-app diff --git a/src/status_im/models/requests.cljs b/src/status_im/models/requests.cljs index c29f3ee8a1..62a2dfb6fb 100644 --- a/src/status_im/models/requests.cljs +++ b/src/status_im/models/requests.cljs @@ -8,7 +8,7 @@ (defn create-request [request] (r/create :account :requests request true)) -(defn save-request [request}] +(defn save-request [request] (r/write :account (fn [] (create-request request)))) diff --git a/src/status_im/persistence/realm/core.cljs b/src/status_im/persistence/realm/core.cljs index e7a85996d9..7c5f234d5d 100644 --- a/src/status_im/persistence/realm/core.cljs +++ b/src/status_im/persistence/realm/core.cljs @@ -3,24 +3,31 @@ [status-im.components.styles :refer [default-chat-color]] [status-im.utils.types :refer [to-string]] [status-im.utils.utils :as u] + [status-im.utils.fs :as fs] [status-im.utils.logging :as log] [status-im.persistence.realm.schemas :refer [base account]] [clojure.string :as str]) (:refer-clojure :exclude [exists?])) +(def new-account-filename "new-account") (def realm-class (u/require "realm")) +(defn create-account-realm [address] + (let [opts (merge account {:path (str address ".realm")})] + (when (cljs.core/exists? js/window) + (realm-class. (clj->js opts))))) + (def base-realm (when (cljs.core/exists? js/window) (realm-class. (clj->js base)))) (def account-realm (atom nil)) -(defn create-account-realm [address] - (let [opts (merge account {:path (str address ".realm")})] - (when (cljs.core/exists? js/window) - (realm-class. (clj->js opts))))) +(defn is-new-account? [] + (let [path (.-path @account-realm) + realm_file (str new-account-filename ".realm")] + (str/ends-with? path realm_file))) (defn realm [schema] (log/debug "Schema: " schema) @@ -37,6 +44,32 @@ (close :account) (reset! account-realm nil)) +(defn reset-account [] + (when @account-realm + (close-account-realm)) + (reset! account-realm (create-account-realm new-account-filename)) + (.write @account-realm #(.deleteAll @account-realm))) + +(defn move-file-handler [address err handler] + (if err + (log/error "Error moving account realm: " (.-message err)) + (reset! account-realm (create-account-realm address))) + (handler err)) + +(defn change-account-realm [address handler] + (let [path (.-path @account-realm) + realm-file (str new-account-filename ".realm") + _ (log/debug "account realm path: " path address) + is-new-account? (str/ends-with? path realm-file)] + (close-account-realm) + (if is-new-account? + (let [new-path (str/replace path realm-file (str address ".realm"))] + (log/debug "account new path: " new-path) + (fs/move-file path new-path #(move-file-handler address % handler))) + (do + (reset! account-realm (create-account-realm address)) + (handler nil))))) + (defn get-schema-by-name [opts] (->> (:schema opts) (mapv (fn [{:keys [name] :as schema}] @@ -82,7 +115,7 @@ query)) (defn get-by-filter [schema schema-name filter] - (log/debug "Get by filter: " schema schema-name field) + (log/debug "Get by filter: " schema schema-name) (-> (.objects (realm schema) (name schema-name)) (.filtered filter))) diff --git a/src/status_im/utils/fs.cljs b/src/status_im/utils/fs.cljs new file mode 100644 index 0000000000..c81ab9dae8 --- /dev/null +++ b/src/status_im/utils/fs.cljs @@ -0,0 +1,11 @@ +(ns status-im.utils.fs + (:require [clojure.string :as s] + [status-im.utils.utils :as u])) + +(def fs (u/require "react-native-fs")) + +(defn move-file [src dst handler] + (let [result (.moveFile fs src dst) + result (.then result #(handler nil %)) + result (.catch result #(handler % nil))] + result)) \ No newline at end of file From cff3349c7d55bb372c4b5fb71a7f3ad008b9262b Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 18 Jul 2016 19:50:13 +0300 Subject: [PATCH 18/19] cleanup --- src/status_im/accounts/handlers.cljs | 1 + src/status_im/{ => accounts}/login/handlers.cljs | 2 +- src/status_im/{ => accounts}/login/screen.cljs | 4 ++-- src/status_im/{ => accounts}/login/styles.cljs | 2 +- src/status_im/android/core.cljs | 2 +- src/status_im/chat/sign_up.cljs | 2 -- src/status_im/commands/handlers/loading.cljs | 14 +++----------- src/status_im/handlers.cljs | 2 +- src/status_im/models/chats.cljs | 2 -- src/status_im/persistence/realm/core.cljs | 8 -------- src/status_im/persistence/realm/schemas.cljs | 6 +----- 11 files changed, 11 insertions(+), 34 deletions(-) rename src/status_im/{ => accounts}/login/handlers.cljs (71%) rename src/status_im/{ => accounts}/login/screen.cljs (97%) rename src/status_im/{ => accounts}/login/styles.cljs (96%) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index e5bd588fed..408ff3a973 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -12,6 +12,7 @@ [status-im.persistence.realm.core :as realm] [status-im.i18n :refer [label]] [status-im.constants :refer [content-type-command-request]] + status-im.accounts.login.handlers [clojure.string :as str])) diff --git a/src/status_im/login/handlers.cljs b/src/status_im/accounts/login/handlers.cljs similarity index 71% rename from src/status_im/login/handlers.cljs rename to src/status_im/accounts/login/handlers.cljs index 79c6944d31..5a00d18935 100644 --- a/src/status_im/login/handlers.cljs +++ b/src/status_im/accounts/login/handlers.cljs @@ -1,4 +1,4 @@ -(ns status-im.login.handlers +(ns status-im.accounts.login.handlers (:require [re-frame.core :refer [register-handler after dispatch]] [status-im.utils.handlers :as u])) diff --git a/src/status_im/login/screen.cljs b/src/status_im/accounts/login/screen.cljs similarity index 97% rename from src/status_im/login/screen.cljs rename to src/status_im/accounts/login/screen.cljs index 3329467df6..6c00fe2642 100644 --- a/src/status_im/login/screen.cljs +++ b/src/status_im/accounts/login/screen.cljs @@ -1,4 +1,4 @@ -(ns status-im.login.screen +(ns status-im.accounts.login.screen (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.components.react :refer [view @@ -22,7 +22,7 @@ white-form-text-input]] [status-im.qr-scanner.views.scan-button :refer [scan-button]] [status-im.i18n :refer [label]] - [status-im.login.styles :as st])) + [status-im.accounts.login.styles :as st])) (def toolbar-title [view toolbar-title-container diff --git a/src/status_im/login/styles.cljs b/src/status_im/accounts/login/styles.cljs similarity index 96% rename from src/status_im/login/styles.cljs rename to src/status_im/accounts/login/styles.cljs index 37278d33cb..e718fed938 100644 --- a/src/status_im/login/styles.cljs +++ b/src/status_im/accounts/login/styles.cljs @@ -1,4 +1,4 @@ -(ns status-im.login.styles +(ns status-im.accounts.login.styles (:require [status-im.components.styles :refer [font title-font text1-color diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index b039e9e472..3cd4552193 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -14,7 +14,7 @@ [status-im.discovery.screen :refer [discovery]] [status-im.discovery.tag :refer [discovery-tag]] [status-im.chat.screen :refer [chat]] - [status-im.login.screen :refer [login]] + [status-im.accounts.login.screen :refer [login]] [status-im.accounts.screen :refer [accounts]] [status-im.chats-list.screen :refer [chats-list]] [status-im.new-group.screen :refer [new-group]] diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index e6b129b7d9..c60f6d2bce 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -6,7 +6,6 @@ [status-im.models.chats :as c] [status-im.components.styles :refer [default-chat-color]] [status-im.utils.utils :refer [on-error http-post toast]] - [status-im.utils.logging :as log] [status-im.utils.random :as random] [status-im.utils.sms-listener :refer [add-sms-listener remove-sms-listener]] @@ -199,7 +198,6 @@ (defn create-chat [handler] (fn [db] (let [{:keys [new-chat] :as db'} (handler db)] - (log/debug new-chat) (when new-chat (c/create-chat new-chat)) (dissoc db' :new-chat)))) diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index eee3ddc22a..feeb9be155 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -13,16 +13,12 @@ (defn load-commands! [_ [identity]] - (let [is-console? (= identity "console") - schema (if is-console? - :base - :account)] (dispatch [::fetch-commands! identity]) ;; todo uncomment - #_(if-let [{:keys [file]} (realm/get-one-by-field schema :commands + #_(if-let [{:keys [file]} (realm/get-one-by-field :account :commands :chat-id identity)] (dispatch [::parse-commands! identity file]) - (dispatch [::fetch-commands! identity])))) + (dispatch [::fetch-commands! identity]))) (defn fetch-commands! [db [identity]] @@ -77,11 +73,7 @@ (defn save-commands-js! [_ [id file]] - (let [is-console? (= id "console") - schema (if is-console? - :base - :account)] - (realm/create-object schema :commands {:chat-id id :file file}))) + (realm/create-object :account :commands {:chat-id id :file file})) (defn loading-failed! [db [id reason details]] diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 93044f0e34..e6422caeca 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -66,13 +66,13 @@ (fn [_ _] (assoc app-db :signed-up (storage/get kv/kv-store :signed-up) - :user-identity (protocol/stored-identity nil) :password (storage/get kv/kv-store :password)))) (register-handler :initialize-account (u/side-effect! (fn [_ [_ account]] (dispatch [:initialize-protocol account]) + (dispatch [:initialize-account-db]) (dispatch [:initialize-chats]) (dispatch [:load-contacts]) (dispatch [:init-chat])))) diff --git a/src/status_im/models/chats.cljs b/src/status_im/models/chats.cljs index 9e86014fe4..854e7bcc57 100644 --- a/src/status_im/models/chats.cljs +++ b/src/status_im/models/chats.cljs @@ -42,10 +42,8 @@ (defn create-chat ([{:keys [last-msg-id] :as chat}] (let [chat (assoc chat :last-msg-id (or last-msg-id ""))] - (log/debug "Creating chat" chat) (r/write :account #(r/create :account :chats chat)))) ([db chat-id identities group-chat? chat-name] - (log/debug "Creating chat" chat-id) (when-not (chat-exists? chat-id) (let [chat-name (or chat-name (get-chat-name chat-id identities)) diff --git a/src/status_im/persistence/realm/core.cljs b/src/status_im/persistence/realm/core.cljs index 7c5f234d5d..801e245409 100644 --- a/src/status_im/persistence/realm/core.cljs +++ b/src/status_im/persistence/realm/core.cljs @@ -30,7 +30,6 @@ (str/ends-with? path realm_file))) (defn realm [schema] - (log/debug "Schema: " schema) (case schema :base base-realm :account @account-realm)) @@ -59,12 +58,10 @@ (defn change-account-realm [address handler] (let [path (.-path @account-realm) realm-file (str new-account-filename ".realm") - _ (log/debug "account realm path: " path address) is-new-account? (str/ends-with? path realm-file)] (close-account-realm) (if is-new-account? (let [new-path (str/replace path realm-file (str address ".realm"))] - (log/debug "account new path: " new-path) (fs/move-file path new-path #(move-file-handler address % handler))) (do (reset! account-realm (create-account-realm address)) @@ -115,24 +112,20 @@ query)) (defn get-by-filter [schema schema-name filter] - (log/debug "Get by filter: " schema schema-name) (-> (.objects (realm schema) (name schema-name)) (.filtered filter))) (defn get-by-field [schema schema-name field value] - (log/debug "Get by field: " schema schema-name field value) (let [q (to-query schema schema-name :eq field value)] (.filtered (.objects (realm schema) (name schema-name)) q))) (defn get-by-fields [schema schema-name fields] - (log/debug "Get by fields: " schema schema-name fields) (let [queries (map (fn [[k v]] (to-query schema schema-name :eq k v)) fields)] (.filtered (.objects (realm schema) (name schema-name)) (and-q queries)))) (defn get-all [schema schema-name] - (log/debug "Get all: " schema schema-name) (.objects (realm schema) (to-string schema-name))) (defn sorted [results field-name order] @@ -173,7 +166,6 @@ (.-length objs)) (defn get-list [schema schema-name] - (log/debug "Get list: " schema schema-name) (vals (js->clj (.objects (realm schema) (to-string schema-name)) :keywordize-keys true))) (defn collection->map [collection] diff --git a/src/status_im/persistence/realm/schemas.cljs b/src/status_im/persistence/realm/schemas.cljs index 4625b8b2c8..1506f3ad96 100644 --- a/src/status_im/persistence/realm/schemas.cljs +++ b/src/status_im/persistence/realm/schemas.cljs @@ -26,11 +26,7 @@ {:name :kv-store :primaryKey :key :properties {:key "string" - :value "string"}} - {:name :commands - :primaryKey :chat-id - :properties {:chat-id "string" - :file "string"}}] + :value "string"}}] :schemaVersion 0}) (def account {:schema [{:name :contacts From 753bdbbd4f66433997a5397b728b5002eb9f91e1 Mon Sep 17 00:00:00 2001 From: Adrian Tiberius Date: Mon, 18 Jul 2016 22:11:54 +0300 Subject: [PATCH 19/19] fix account switching --- src/status_im/accounts/handlers.cljs | 10 +++++++--- src/status_im/accounts/screen.cljs | 3 ++- src/status_im/android/core.cljs | 1 + src/status_im/handlers.cljs | 4 ++-- src/status_im/persistence/realm/core.cljs | 13 ++++++++----- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 408ff3a973..c9de35487b 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -57,10 +57,14 @@ (when is-login-screen? (dispatch [:navigate-to-clean default-view])))) (defn logged-in [db address] - (let [account (get-in db [:accounts address])] + (let [account (get-in db [:accounts address]) + is-login-screen? (= (:view-id db) :login) + new-account? (not is-login-screen?)] (log/debug "Logged in: " address account) - (realm/change-account-realm address #(when (nil? %) - (initialize-account db account))))) + (realm/change-account-realm address new-account? + #(if (nil? %) + (initialize-account db account) + (log/debug "Error changing acount realm: " %))))) (register-handler :login-account (-> (fn [db [_ address password]] diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index ea9f1a361a..ef847e1748 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -40,8 +40,9 @@ :key row-id}])) (defn create-account [event] - ;(dispatch [:console-create-account]) (dispatch-sync [:reset-app]) + ; add accounts screen to history ( maybe there is a better way ? ) + (dispatch [:navigate-to-clean :accounts]) (dispatch [:navigate-to :chat "console"])) (defview accounts [] diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 51f4059906..e544d3b811 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -24,6 +24,7 @@ [status-im.profile.screen :refer [profile my-profile]] [status-im.utils.utils :refer [toast]] [status-im.utils.encryption] + status-im.persistence.realm.core [status-im.utils.logging :as log])) (defn init-back-button-handler! [] diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 86167112cb..84887faa34 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -61,8 +61,8 @@ :user-identity nil))) (register-handler :initialize-account-db - (fn [_ _] - (assoc app-db + (fn [db _] + (assoc db :signed-up (storage/get kv/kv-store :signed-up) :password (storage/get kv/kv-store :password)))) diff --git a/src/status_im/persistence/realm/core.cljs b/src/status_im/persistence/realm/core.cljs index 801e245409..8a8dbc1ff6 100644 --- a/src/status_im/persistence/realm/core.cljs +++ b/src/status_im/persistence/realm/core.cljs @@ -22,7 +22,7 @@ (when (cljs.core/exists? js/window) (realm-class. (clj->js base)))) -(def account-realm (atom nil)) +(def account-realm (atom (create-account-realm new-account-filename))) (defn is-new-account? [] (let [path (.-path @account-realm) @@ -50,18 +50,21 @@ (.write @account-realm #(.deleteAll @account-realm))) (defn move-file-handler [address err handler] + (log/debug "Moved file with error: " err address) (if err (log/error "Error moving account realm: " (.-message err)) (reset! account-realm (create-account-realm address))) (handler err)) -(defn change-account-realm [address handler] +(defn change-account-realm [address new-account? handler] (let [path (.-path @account-realm) - realm-file (str new-account-filename ".realm") - is-new-account? (str/ends-with? path realm-file)] + realm-file (str new-account-filename ".realm")] + (log/debug "closing account realm: " path) (close-account-realm) - (if is-new-account? + (log/debug "is new account? " new-account?) + (if new-account? (let [new-path (str/replace path realm-file (str address ".realm"))] + (log/debug "Moving file to " new-path) (fs/move-file path new-path #(move-file-handler address % handler))) (do (reset! account-realm (create-account-realm address))