changed add account flow to use new binding system
Former-commit-id: ec9cfe8f8c
This commit is contained in:
parent
5a1c2c9bb3
commit
232259c4ba
|
@ -132,8 +132,8 @@ dependencies {
|
||||||
compile project(':ReactNativeAndroidSmsListener')
|
compile project(':ReactNativeAndroidSmsListener')
|
||||||
compile project(':react-native-camera')
|
compile project(':react-native-camera')
|
||||||
compile project(':react-native-orientation')
|
compile project(':react-native-orientation')
|
||||||
// compile(name:'geth', ext:'aar')
|
compile(name:'statusgo-android-16', ext:'aar')
|
||||||
compile(group: 'status-im', name: 'status-go', version: '0.1.0-test-callback', ext: 'aar')
|
//compile(group: 'status-im', name: 'status-go', version: '0.1.0-test-callback', ext: 'aar')
|
||||||
|
|
||||||
compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"])
|
compile fileTree(dir: "node_modules/realm/android/libs", include: ["*.jar"])
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,7 @@
|
||||||
<service
|
<service
|
||||||
android:name=".geth.service.GethService"
|
android:name=".geth.service.GethService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="true"
|
android:exported="true"/>
|
||||||
android:process=":geth_process"/>
|
|
||||||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,15 @@ import com.statusim.geth.service.ConnectorHandler;
|
||||||
import com.statusim.geth.service.GethConnector;
|
import com.statusim.geth.service.GethConnector;
|
||||||
import com.statusim.geth.service.GethMessages;
|
import com.statusim.geth.service.GethMessages;
|
||||||
import com.statusim.geth.service.GethService;
|
import com.statusim.geth.service.GethService;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class GethModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler {
|
public class GethModule extends ReactContextBaseJavaModule implements LifecycleEventListener, ConnectorHandler {
|
||||||
|
|
||||||
|
private static final String TAG = "GethModule";
|
||||||
|
|
||||||
protected GethConnector geth = null;
|
protected GethConnector geth = null;
|
||||||
protected String handlerIdentifier = createIdentifier();
|
protected String handlerIdentifier = createIdentifier();
|
||||||
|
|
||||||
|
@ -81,15 +84,20 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
@Override
|
@Override
|
||||||
public boolean handleMessage(Message message) {
|
public boolean handleMessage(Message message) {
|
||||||
|
|
||||||
|
Log.d(TAG, "Received message: " + message.toString());
|
||||||
boolean isClaimed = true;
|
boolean isClaimed = true;
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER);
|
String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER);
|
||||||
|
Log.d(TAG, "callback identifier: " + callbackIdentifier);
|
||||||
Callback callback = null;
|
Callback callback = null;
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case GethMessages.MSG_NODE_STARTED:
|
case GethMessages.MSG_NODE_STARTED:
|
||||||
|
Log.d(TAG, "handle startNodeCallbacks size: " + startNodeCallbacks.size());
|
||||||
callback = startNodeCallbacks.remove(callbackIdentifier);
|
callback = startNodeCallbacks.remove(callbackIdentifier);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.invoke(null);
|
callback.invoke(true);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "Could not find callback: " + callbackIdentifier);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GethMessages.MSG_NODE_STOPPED:
|
case GethMessages.MSG_NODE_STOPPED:
|
||||||
|
@ -97,7 +105,7 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
case GethMessages.MSG_ACCOUNT_CREATED:
|
case GethMessages.MSG_ACCOUNT_CREATED:
|
||||||
callback = createAccountCallbacks.remove(callbackIdentifier);
|
callback = createAccountCallbacks.remove(callbackIdentifier);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.invoke(null, "{ \"address\": \"" + data.getString("address") + "\"}");
|
callback.invoke(data.getString("data"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GethMessages.MSG_ACCOUNT_ADDED:
|
case GethMessages.MSG_ACCOUNT_ADDED:
|
||||||
|
@ -106,7 +114,7 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
callback.invoke(null, "{ \"address\": \"" + data.getString("address") + "\"}");
|
callback.invoke(null, "{ \"address\": \"" + data.getString("address") + "\"}");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GethMessages.MSG_ACCOUNT_UNLOCKED:
|
case GethMessages.MSG_LOGGED_IN:
|
||||||
callback = unlockAccountCallbacks.remove(callbackIdentifier);
|
callback = unlockAccountCallbacks.remove(callbackIdentifier);
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
callback.invoke(null, "{ \"result\": \"" + data.getString("result") + "\"}");
|
callback.invoke(null, "{ \"result\": \"" + data.getString("result") + "\"}");
|
||||||
|
@ -135,13 +143,15 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
}
|
}
|
||||||
|
|
||||||
String callbackIdentifier = createIdentifier();
|
String callbackIdentifier = createIdentifier();
|
||||||
|
Log.d(TAG, "Created callback identifier: " + callbackIdentifier);
|
||||||
startNodeCallbacks.put(callbackIdentifier, callback);
|
startNodeCallbacks.put(callbackIdentifier, callback);
|
||||||
|
Log.d(TAG, "startNodeCallbacks size: " + startNodeCallbacks.size());
|
||||||
|
|
||||||
geth.startNode(callbackIdentifier);
|
geth.startNode(callbackIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void unlockAccount(String address, String password, Callback callback) {
|
public void login(String address, String password, Callback callback) {
|
||||||
|
|
||||||
Activity currentActivity = getCurrentActivity();
|
Activity currentActivity = getCurrentActivity();
|
||||||
|
|
||||||
|
@ -158,11 +168,11 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
String callbackIdentifier = createIdentifier();
|
String callbackIdentifier = createIdentifier();
|
||||||
unlockAccountCallbacks.put(callbackIdentifier, callback);
|
unlockAccountCallbacks.put(callbackIdentifier, callback);
|
||||||
|
|
||||||
geth.unlockAccount(callbackIdentifier, address, password);
|
geth.login(callbackIdentifier, address, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void createAccount(Callback callback) {
|
public void createAccount(String password, Callback callback) {
|
||||||
|
|
||||||
Activity currentActivity = getCurrentActivity();
|
Activity currentActivity = getCurrentActivity();
|
||||||
|
|
||||||
|
@ -179,7 +189,7 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
|
||||||
String callbackIdentifier = createIdentifier();
|
String callbackIdentifier = createIdentifier();
|
||||||
createAccountCallbacks.put(callbackIdentifier, callback);
|
createAccountCallbacks.put(callbackIdentifier, callback);
|
||||||
|
|
||||||
geth.createAccount(callbackIdentifier);
|
geth.createAccount(callbackIdentifier, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
|
|
|
@ -42,13 +42,13 @@ public class GethConnector extends ServiceConnector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unlockAccount(String callbackIdentifier, String address, String password) {
|
public void login(String callbackIdentifier, String address, String password) {
|
||||||
|
|
||||||
if (checkBound()) {
|
if (checkBound()) {
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putString("address", address);
|
data.putString("address", address);
|
||||||
data.putString("password", password);
|
data.putString("password", password);
|
||||||
Message msg = createMessage(callbackIdentifier, GethMessages.MSG_UNLOCK_ACCOUNT, data);
|
Message msg = createMessage(callbackIdentifier, GethMessages.MSG_LOGIN, data);
|
||||||
try {
|
try {
|
||||||
serviceMessenger.send(msg);
|
serviceMessenger.send(msg);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -57,10 +57,12 @@ public class GethConnector extends ServiceConnector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createAccount(String callbackIdentifier) {
|
public void createAccount(String callbackIdentifier, String password) {
|
||||||
|
|
||||||
if (checkBound()) {
|
if (checkBound()) {
|
||||||
Message msg = createMessage(callbackIdentifier, GethMessages.MSG_CREATE_ACCOUNT, null);
|
Bundle data = new Bundle();
|
||||||
|
data.putString("password", password);
|
||||||
|
Message msg = createMessage(callbackIdentifier, GethMessages.MSG_CREATE_ACCOUNT, data);
|
||||||
try {
|
try {
|
||||||
serviceMessenger.send(msg);
|
serviceMessenger.send(msg);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
|
@ -95,6 +97,7 @@ public class GethConnector extends ServiceConnector {
|
||||||
|
|
||||||
protected Message createMessage(String callbackIdentifier, int idMessage, Bundle data) {
|
protected Message createMessage(String callbackIdentifier, int idMessage, Bundle data) {
|
||||||
|
|
||||||
|
Log.d(TAG, "Client messenger: " + clientMessenger.toString());
|
||||||
Message msg = Message.obtain(null, idMessage, 0, 0);
|
Message msg = Message.obtain(null, idMessage, 0, 0);
|
||||||
msg.replyTo = clientMessenger;
|
msg.replyTo = clientMessenger;
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
|
|
|
@ -26,12 +26,12 @@ public class GethMessages {
|
||||||
/**
|
/**
|
||||||
* Unlock an account
|
* Unlock an account
|
||||||
*/
|
*/
|
||||||
public static final int MSG_UNLOCK_ACCOUNT = 5;
|
public static final int MSG_LOGIN = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account unlocked event
|
* Account unlocked event
|
||||||
*/
|
*/
|
||||||
public static final int MSG_ACCOUNT_UNLOCKED = 6;
|
public static final int MSG_LOGGED_IN = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an account
|
* Create an account
|
||||||
|
|
|
@ -20,6 +20,8 @@ public class GethService extends Service {
|
||||||
private static boolean isGethInitialized = false;
|
private static boolean isGethInitialized = false;
|
||||||
private final Handler handler = new Handler();
|
private final Handler handler = new Handler();
|
||||||
|
|
||||||
|
private static String dataFolder;
|
||||||
|
|
||||||
static class IncomingHandler extends Handler {
|
static class IncomingHandler extends Handler {
|
||||||
|
|
||||||
private final WeakReference<GethService> service;
|
private final WeakReference<GethService> service;
|
||||||
|
@ -80,6 +82,7 @@ public class GethService extends Service {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
|
|
||||||
case GethMessages.MSG_START_NODE:
|
case GethMessages.MSG_START_NODE:
|
||||||
|
Log.d(TAG, "Received start node message." + message.toString());
|
||||||
startNode(message);
|
startNode(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -95,8 +98,8 @@ public class GethService extends Service {
|
||||||
addAccount(message);
|
addAccount(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GethMessages.MSG_UNLOCK_ACCOUNT:
|
case GethMessages.MSG_LOGIN:
|
||||||
unlockAccount(message);
|
login(message);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -109,16 +112,22 @@ public class GethService extends Service {
|
||||||
protected void startNode(Message message) {
|
protected void startNode(Message message) {
|
||||||
if (!isGethInitialized) {
|
if (!isGethInitialized) {
|
||||||
isGethInitialized = true;
|
isGethInitialized = true;
|
||||||
new StartTask(message).execute();
|
Log.d(TAG, "Client messenger1: " + message.replyTo.toString());
|
||||||
|
Bundle data = message.getData();
|
||||||
|
String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER);
|
||||||
|
Log.d(TAG, "Callback identifier: " + callbackIdentifier);
|
||||||
|
new StartTask(message.replyTo, callbackIdentifier).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class StartTask extends AsyncTask<Void, Void, Void> {
|
protected class StartTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
protected Message message;
|
protected String callbackIdentifier;
|
||||||
|
protected Messenger messenger;
|
||||||
|
|
||||||
public StartTask(Message message) {
|
public StartTask(Messenger messenger, String callbackIdentifier) {
|
||||||
this.message = message;
|
this.messenger = messenger;
|
||||||
|
this.callbackIdentifier = callbackIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Void doInBackground(Void... args) {
|
protected Void doInBackground(Void... args) {
|
||||||
|
@ -127,30 +136,41 @@ public class GethService extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Void results) {
|
protected void onPostExecute(Void results) {
|
||||||
onGethStarted(message);
|
onGethStarted(messenger, callbackIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onGethStarted(Message message) {
|
protected void onGethStarted(Messenger messenger, String callbackIdentifier) {
|
||||||
Log.d(TAG, "Geth Service started");
|
Log.d(TAG, "Geth Service started");
|
||||||
isGethStarted = true;
|
isGethStarted = true;
|
||||||
|
Message replyMessage = Message.obtain(null, GethMessages.MSG_NODE_STARTED, 0, 0, null);
|
||||||
sendReply(message, GethMessages.MSG_NODE_STARTED, null);
|
Bundle replyData = new Bundle();
|
||||||
|
Log.d(TAG, "Callback identifier: " + callbackIdentifier);
|
||||||
|
replyData.putString(GethConnector.CALLBACK_IDENTIFIER, callbackIdentifier);
|
||||||
|
replyMessage.setData(replyData);
|
||||||
|
sendReply(messenger, replyMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startGeth() {
|
protected void startGeth() {
|
||||||
Log.d(TAG, "Starting background Geth Service");
|
|
||||||
|
|
||||||
File extStore = Environment.getExternalStorageDirectory();
|
File extStore = Environment.getExternalStorageDirectory();
|
||||||
|
|
||||||
final String dataFolder = extStore.exists() ?
|
dataFolder = extStore.exists() ?
|
||||||
extStore.getAbsolutePath() :
|
extStore.getAbsolutePath() + "/ethereum" :
|
||||||
getApplicationInfo().dataDir;
|
getApplicationInfo().dataDir + "/ethereum";
|
||||||
|
Log.d(TAG, "Starting background Geth Service in folder: " + dataFolder);
|
||||||
|
try {
|
||||||
|
final File newFile = new File(dataFolder);
|
||||||
|
newFile.mkdir();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "error making folder: " + dataFolder, e);
|
||||||
|
}
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
Statusgo.doStartNode(dataFolder);
|
Statusgo.StartNode(dataFolder);
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
@ -158,19 +178,20 @@ public class GethService extends Service {
|
||||||
protected void stopNode(Message message) {
|
protected void stopNode(Message message) {
|
||||||
// TODO: stop node
|
// TODO: stop node
|
||||||
|
|
||||||
sendReply(message, GethMessages.MSG_NODE_STOPPED, null);
|
createAndSendReply(message, GethMessages.MSG_NODE_STOPPED, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createAccount(Message message) {
|
protected void createAccount(Message message) {
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
String password = data.getString("password");
|
String password = data.getString("password");
|
||||||
// TODO: remove second argument
|
// TODO: remove second argument
|
||||||
String address = Statusgo.doCreateAccount(password, "");
|
Log.d(TAG, "Creating account: " + password + " - " + dataFolder);
|
||||||
Log.d(TAG, "Created account: " + address);
|
String jsonData = Statusgo.CreateAccount(password, dataFolder);
|
||||||
|
Log.d(TAG, "Created account: " + jsonData);
|
||||||
|
|
||||||
Bundle replyData = new Bundle();
|
Bundle replyData = new Bundle();
|
||||||
replyData.putString("address", address);
|
replyData.putString("data", jsonData);
|
||||||
sendReply(message, GethMessages.MSG_ACCOUNT_CREATED, replyData);
|
createAndSendReply(message, GethMessages.MSG_ACCOUNT_CREATED, replyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addAccount(Message message) {
|
protected void addAccount(Message message) {
|
||||||
|
@ -184,27 +205,27 @@ public class GethService extends Service {
|
||||||
|
|
||||||
Bundle replyData = new Bundle();
|
Bundle replyData = new Bundle();
|
||||||
replyData.putString("address", address);
|
replyData.putString("address", address);
|
||||||
sendReply(message, GethMessages.MSG_ACCOUNT_ADDED, replyData);
|
createAndSendReply(message, GethMessages.MSG_ACCOUNT_ADDED, replyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void unlockAccount(Message message) {
|
protected void login(Message message) {
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
String address = data.getString("address");
|
String address = data.getString("address");
|
||||||
String password = data.getString("password");
|
String password = data.getString("password");
|
||||||
// TODO: remove third argument
|
// TODO: remove third argument
|
||||||
String result = Statusgo.doUnlockAccount(address, password, 0);
|
String result = Statusgo.Login(address, password);
|
||||||
Log.d(TAG, "Unlocked account: " + result);
|
Log.d(TAG, "Unlocked account: " + result);
|
||||||
|
|
||||||
Bundle replyData = new Bundle();
|
Bundle replyData = new Bundle();
|
||||||
replyData.putString("result", result);
|
replyData.putString("result", result);
|
||||||
sendReply(message, GethMessages.MSG_ACCOUNT_UNLOCKED, replyData);
|
createAndSendReply(message, GethMessages.MSG_LOGGED_IN, replyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRunning() {
|
public static boolean isRunning() {
|
||||||
return isGethInitialized;
|
return isGethInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendReply(Message message, int replyIdMessage, Bundle replyData) {
|
protected void createAndSendReply(Message message, int replyIdMessage, Bundle replyData) {
|
||||||
|
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -214,14 +235,21 @@ public class GethService extends Service {
|
||||||
replyData = new Bundle();
|
replyData = new Bundle();
|
||||||
}
|
}
|
||||||
Bundle data = message.getData();
|
Bundle data = message.getData();
|
||||||
String callbackIdentifier = data.getString("callbackIdentifier");
|
String callbackIdentifier = data.getString(GethConnector.CALLBACK_IDENTIFIER);
|
||||||
replyData.putString("callbackIdentifier", callbackIdentifier);
|
Log.d(TAG, "Callback identifier: " + callbackIdentifier);
|
||||||
|
replyData.putString(GethConnector.CALLBACK_IDENTIFIER, callbackIdentifier);
|
||||||
replyMessage.setData(replyData);
|
replyMessage.setData(replyData);
|
||||||
|
|
||||||
|
sendReply(message.replyTo, replyMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendReply(Messenger messenger, Message message) {
|
||||||
try {
|
try {
|
||||||
message.replyTo.send(replyMessage);
|
messenger.send(message);
|
||||||
} catch (RemoteException e) {
|
|
||||||
Log.e(TAG, "Exception sending message id: " + replyIdMessage, e);
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
Log.e(TAG, "Exception sending message id: " + message.what, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,17 +52,17 @@ public class ServiceConnector {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
|
|
||||||
boolean isClaimed = false;
|
boolean isClaimed = false;
|
||||||
if (message.obj != null) {
|
//if (message.obj != null) {
|
||||||
String identifier = ((Bundle) message.obj).getString("identifier");
|
// String identifier = ((Bundle) message.obj).getString("identifier");
|
||||||
if (identifier != null) {
|
//if (identifier != null) {
|
||||||
|
|
||||||
for (ConnectorHandler handler : handlers) {
|
for (ConnectorHandler handler : handlers) {
|
||||||
if (identifier.equals(handler.getID())) {
|
// if (identifier.equals(handler.getID())) {
|
||||||
isClaimed = handler.handleMessage(message);
|
isClaimed = handler.handleMessage(message);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
if (!isClaimed) {
|
if (!isClaimed) {
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,10 @@
|
||||||
(defn init []
|
(defn init []
|
||||||
(dispatch-sync [:initialize-db])
|
(dispatch-sync [:initialize-db])
|
||||||
(dispatch [:initialize-crypt])
|
(dispatch [:initialize-crypt])
|
||||||
|
(dispatch [:initialize-geth])
|
||||||
(dispatch [:initialize-chats])
|
(dispatch [:initialize-chats])
|
||||||
(dispatch [:initialize-protocol])
|
;protocol must be initialized after user enters password and we create account
|
||||||
|
;(dispatch [:initialize-protocol])
|
||||||
(dispatch [:load-user-phone-number])
|
(dispatch [:load-user-phone-number])
|
||||||
(dispatch [:load-contacts])
|
(dispatch [:load-contacts])
|
||||||
;; load commands from remote server (todo: uncomment)
|
;; load commands from remote server (todo: uncomment)
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
[status-im.handlers.content-suggestions :refer [get-content-suggestions]]
|
||||||
[status-im.utils.phone-number :refer [format-phone-number]]
|
[status-im.utils.phone-number :refer [format-phone-number]]
|
||||||
[status-im.utils.datetime :as time]
|
[status-im.utils.datetime :as time]
|
||||||
|
[status-im.components.react :refer [geth]]
|
||||||
|
[status-im.utils.logging :as log]
|
||||||
|
[status-im.utils.types :refer [json->clj]]
|
||||||
[status-im.chat.handlers.animation :refer [update-response-height
|
[status-im.chat.handlers.animation :refer [update-response-height
|
||||||
get-response-height]]))
|
get-response-height]]))
|
||||||
|
|
||||||
|
@ -259,6 +262,11 @@
|
||||||
|
|
||||||
(register-handler :save-password
|
(register-handler :save-password
|
||||||
(fn [db [_ password]]
|
(fn [db [_ password]]
|
||||||
|
(.createAccount geth password (fn [result]
|
||||||
|
(let [data (json->clj result)
|
||||||
|
public-key (:pubkey data)]
|
||||||
|
(log/debug "Created account: " result)
|
||||||
|
(when (not (str/blank? public-key)) (dispatch [:initialize-protocol public-key])))))
|
||||||
(sign-up-service/save-password password)
|
(sign-up-service/save-password password)
|
||||||
(assoc db :password-saved true)))
|
(assoc db :password-saved true)))
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[status-im.utils.logging :as log]
|
[status-im.utils.logging :as log]
|
||||||
[status-im.utils.crypt :refer [gen-random-bytes]]
|
[status-im.utils.crypt :refer [gen-random-bytes]]
|
||||||
[status-im.utils.handlers :as u]
|
[status-im.utils.handlers :as u]
|
||||||
|
[status-im.components.react :refer [geth]]
|
||||||
status-im.chat.handlers
|
status-im.chat.handlers
|
||||||
status-im.group-settings.handlers
|
status-im.group-settings.handlers
|
||||||
status-im.navigation.handlers
|
status-im.navigation.handlers
|
||||||
|
@ -74,6 +75,11 @@
|
||||||
(.toBits (.. js/ecc -sjcl -codec -hex))
|
(.toBits (.. js/ecc -sjcl -codec -hex))
|
||||||
(.addEntropy (.. js/ecc -sjcl -random)))
|
(.addEntropy (.. js/ecc -sjcl -random)))
|
||||||
(dispatch [:crypt-initialized]))))))))
|
(dispatch [:crypt-initialized]))))))))
|
||||||
|
(register-handler :initialize-geth
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ _]
|
||||||
|
(log/debug "Starting node")
|
||||||
|
(.startNode geth (fn [result] (log/debug "Started Node: " result))))))
|
||||||
|
|
||||||
(register-handler :crypt-initialized
|
(register-handler :crypt-initialized
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
|
|
||||||
(register-handler :initialize-protocol
|
(register-handler :initialize-protocol
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [db [_]]
|
(fn [db [_ public-key]]
|
||||||
(init-protocol (make-handler db)))))
|
(init-protocol public-key (make-handler db)))))
|
||||||
|
|
||||||
(register-handler :protocol-initialized
|
(register-handler :protocol-initialized
|
||||||
(fn [db [_ identity]]
|
(fn [db [_ identity]]
|
||||||
|
|
Loading…
Reference in New Issue