Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Commit

Permalink
refactor: update core/class, change open/close dialog
Browse files Browse the repository at this point in the history
BREAKING CHANGE: change open/close dialog flow
  • Loading branch information
dudiq authored and Alex committed Mar 27, 2019
1 parent 6fbff8f commit 8a894dd
Show file tree
Hide file tree
Showing 29 changed files with 430 additions and 880 deletions.
2 changes: 1 addition & 1 deletion env/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
local = require('./local');
} catch (e) {}

const getEnv = (env = 'development') => {
const getEnv = (env) => {
switch ((env || '').toLowerCase()) {
case 'production':
return prod;
Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@endpass/connect",
"version": "0.16.1-beta",
"authVersion": "0.2",
"version": "0.17.0-beta",
"authVersion": "0.3",
"main": "./dist/endpass-connect.min.js",
"module": "./dist/endpass-connect.esm.js",
"description": "",
Expand Down Expand Up @@ -67,34 +67,34 @@
}
},
"dependencies": {
"@endpass/class": "^0.9.4",
"@endpass/class": "^0.10.0",
"lodash.get": "^4.4.2",
"utility-types": "^3.4.1",
"web3-providers-http": "1.0.0-beta.33"
},
"devDependencies": {
"@babel/core": "^7.3.4",
"@babel/parser": "^7.3.4",
"@babel/core": "^7.4.0",
"@babel/parser": "^7.4.2",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/preset-env": "^7.3.4",
"@babel/plugin-transform-runtime": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-typescript": "^7.3.3",
"@babel/runtime": "^7.3.4",
"@babel/runtime": "^7.4.2",
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/git": "^7.0.8",
"@types/lodash": "^4.14.122",
"@types/lodash.get": "^4.4.6",
"@types/node": "^11.10.5",
"@types/node": "^11.11.6",
"@types/web3": "^1.0.18",
"@typescript-eslint/eslint-plugin": "^1.4.2",
"@typescript-eslint/parser": "^1.4.2",
"@typescript-eslint/eslint-plugin": "^1.5.0",
"@typescript-eslint/parser": "^1.5.0",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"commitizen": "^3.0.7",
"cz-conventional-changelog": "^2.1.0",
"eslint": "^5.14.1",
"eslint": "^5.15.3",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
"eslint-multiple-parsers": "^1.0.1",
Expand All @@ -103,20 +103,20 @@
"gh-pages": "^2.0.1",
"husky": "^1.3.1",
"jest": "^24.5.0",
"lint-staged": "^8.1.4",
"lint-staged": "^8.1.5",
"prettier": "^1.16.4",
"regenerator-runtime": "^0.13.1",
"regenerator-runtime": "^0.13.2",
"rimraf": "^2.6.3",
"rollup": "^1.4.0",
"rollup": "^1.7.3",
"rollup-plugin-alias": "^1.5.1",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-commonjs": "^9.2.2",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^4.0.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-replace": "^2.1.1",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-typescript": "^1.0.0",
"rollup-plugin-visualizer": "^1.0.2",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-visualizer": "^1.1.0",
"semantic-release": "^15.13.3",
"typescript": "^3.3.3333"
}
Expand Down
4 changes: 1 addition & 3 deletions src/Connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import privateFields from '@/privateFields';
import Queue from '@/Queue';
import { METHODS } from '@/constants';
import middleware from '@/middleware';
import Dialog from '@/class/Dialog';

import pkg from '../package.json';

Expand Down Expand Up @@ -94,10 +93,9 @@ export default class Connect {
async openAccount() {
const context = this[privateFields.context];

const params = Dialog.createParams({
const res = await context.askDialog({
method: METHODS.ACCOUNT,
});
const res = await context.askDialog(params);

if (!res.status) throw new Error(res.error || 'Account updating failed!');
const { type, settings } = res.payload;
Expand Down
17 changes: 6 additions & 11 deletions src/Context.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CrossWindowMessenger, Network } from '@endpass/class';
import Network from '@endpass/class/Network';
import CrossWindowMessenger from '@endpass/class/CrossWindowMessenger';
import { Emmiter, InpageProvider, Bridge, ProviderFactory } from '@/class';
import {
INPAGE_EVENTS,
METHODS,
DEFAULT_AUTH_URL,
DIRECTION,
} from '@/constants';
import Dialog from './class/Dialog';

export default class Context {
/**
Expand All @@ -20,7 +20,7 @@ export default class Context {

this.authUrl = `${authUrl}${ENV.authVersion}`;

this.namespace = options.namespace;
this.namespace = options.namespace || '';

this.haveDemoData = !!options.demoData;

Expand Down Expand Up @@ -66,16 +66,12 @@ export default class Context {
}

async askDialog(params) {
const { method, route, payload } = params;
const { method, payload } = params;

const bridge = this.getBridge();

await bridge.openDialog({ route });

const res = await bridge.ask(method, payload);

bridge.closeDialog();

return res;
}

Expand All @@ -96,13 +92,12 @@ export default class Context {
* know about result
*/
async auth(redirectUrl) {
const params = Dialog.createParams({
const res = await this.askDialog({
method: METHODS.AUTH,
payload: {
redirectUrl: redirectUrl || null,
},
});
const res = await this.askDialog(params);

if (!res.status) throw new Error(res.error || 'Authentificaton error!');
this.isServerLogin = true;
Expand Down Expand Up @@ -155,7 +150,7 @@ export default class Context {
activeNet: settings.net || Network.NET_ID.MAIN,
};
} catch (err) {
throw new Error('User not autorized!');
throw new Error('User not authorized!');
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Queue/Queue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @ts-check
import { INPAGE_EVENTS } from '@/constants';
import { AsyncQueue } from '@/class';

// @ts-ignore
import QueueAsync from '@endpass/class/QueueAsync';
import itemStates from './itemStates';

// eslint-disable-next-line no-unused-vars
Expand All @@ -18,7 +20,7 @@ export default class Queue {
this.handleRequest = this.handleRequest.bind(this);

// Setup net requests queue
this.queue = new AsyncQueue();
this.queue = new QueueAsync();

// start queue
this.setupEventEmitter();
Expand Down
11 changes: 0 additions & 11 deletions src/class/ArrayQueue.js

This file was deleted.

86 changes: 0 additions & 86 deletions src/class/AsyncQueue.js

This file was deleted.

23 changes: 3 additions & 20 deletions src/class/Bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ export default class Bridge {

/** @type Resolvers */
this.readyResolvers = [];
const messenger = this.context.getMessenger();

this.context.getMessenger().subscribe(METHODS.INITIATE, (payload, req) => {
messenger.subscribe(METHODS.INITIATE, (payload, req) => {
req.answer(this.initialPayload);
});

this.context.getMessenger().subscribe(METHODS.READY_STATE_BRIDGE, () => {
messenger.subscribe(METHODS.READY_STATE_BRIDGE, () => {
this.ready = true;
this.readyResolvers.forEach(item => item(true));
this.readyResolvers.length = 0;
Expand All @@ -52,24 +53,6 @@ export default class Bridge {
});
}

/**
*
* @param {{}} params for dialog
* @return {Promise<void>}
*/
async openDialog(params) {
await this.checkReadyState();

await this.dialog.open(params);
}

/**
* Close dialog
*/
closeDialog() {
this.dialog.close();
}

/**
* Wrapper on sendMessage and awaitMessage methods
* Send message with given payload and awaits answer on it
Expand Down
Loading

0 comments on commit 8a894dd

Please sign in to comment.