Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove processSubscription, now we got id from faucet #51

Merged
merged 2 commits into from
Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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