Skip to content

Commit

Permalink
Merge pull request #51 from TrustyFund/fix-registration-subscription
Browse files Browse the repository at this point in the history
Remove processSubscription, now we got id from faucet
  • Loading branch information
roma219 authored Apr 2, 2018
2 parents 3a39d73 + a0f811c commit 6b71b6a
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 38 deletions.
8 changes: 2 additions & 6 deletions src/actions/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PrivateKey, key, Aes } from 'bitsharesjs';
import * as types from '../mutations';
// import { getAccountIdByOwnerPubkey, getAccount } from '../services/wallet.js';
import API from '../services/api';
import Subscriptions from '../services/api/subscriptions';
import PersistentStorage from '../services/persistent-storage';

const OWNER_KEY_INDEX = 1;
Expand Down Expand Up @@ -71,18 +70,15 @@ export const signup = async (state, { name, password, dictionary }) => {
const { commit } = state;
commit(types.ACCOUNT_SIGNUP_REQUEST);
const brainkey = API.Account.suggestBrainkey(dictionary);
console.log(brainkey);
const result = await API.Account.createAccount({
name,
activeKey: key.get_brainPrivateKey(brainkey, ACTIVE_KEY_INDEX),
ownerKey: key.get_brainPrivateKey(brainkey, OWNER_KEY_INDEX),
});
console.log('Account created : ', result.success);
console.log('Account created : ', result);
if (result.success) {
const signUpSubscription = new Subscriptions.SignUp({ name });
const userId = await API.ChainListener.processSubscription(signUpSubscription);
const userId = result.id;
const wallet = createWallet({ password, brainkey });
console.log(userId);
commit(types.ACCOUNT_SIGNUP_COMPLETE, { wallet, userId });
PersistentStorage.saveUserData({
id: userId,
Expand Down
5 changes: 3 additions & 2 deletions src/services/api/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ export const createAccount = async ({ name, activeKey, ownerKey }) => {
const result = await response.json();
if (result.result === 'OK') {
return {
success: true
success: true,
id: result.id
};
}
return {
success: false,
error: 'Account creation error'
error: result.result
};
} catch (error) {
return {
Expand Down
11 changes: 0 additions & 11 deletions src/services/api/chain-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ class ChainListener {
});
}

processSubscription(subscription) {
return new Promise((resolve) => {
const wrapped = (result) => {
this.deleteSubscription(subscription.getType());
resolve(result);
};
subscription.setCallback(wrapped);
this._subscribers.push(subscription);
});
}

addSubscription(subscription) {
this._subscribers.push(subscription);
return true;
Expand Down
19 changes: 0 additions & 19 deletions src/services/api/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,6 @@ class Markets extends Subscription {
}
}

class SignUp extends Subscription {
constructor({ name }) {
super('userSignUp');
this.name = name;
}

notify(operation) {
if (operation.id && operation.id.startsWith(history_prefix)
&& operation.op[0] === ChainTypes.operations.account_create) {
const payload = operation.op[1];
const { name } = payload;
if (this.name === name) {
this._callback(operation.result[1]);
}
}
}
}

class UserOperations extends Subscription {
constructor({ userId, callback }) {
super('userOperation');
Expand Down Expand Up @@ -117,7 +99,6 @@ class UserOperations extends Subscription {

const Subscriptions = {
Markets,
SignUp,
UserOperations
};

Expand Down

0 comments on commit 6b71b6a

Please sign in to comment.