Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
added few views and some code for communication with reduces
Browse files Browse the repository at this point in the history
  • Loading branch information
Andriy Tkachyshyn authored and Andriy Tkachyshyn committed Jul 7, 2018
1 parent 2dd69b8 commit 5a43693
Show file tree
Hide file tree
Showing 45 changed files with 1,221 additions and 492 deletions.
88 changes: 88 additions & 0 deletions app/actions/accounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// @flow
import * as types from './types';

import eos from './helpers/eos';

export function getAccounts(publicKey) {
return (dispatch: () => void, getState) => {
dispatch({
type: types.GET_ACCOUNTS_REQUEST
});

const {
connection
} = getState();

const modified = {
...connection,
sign: false
};

eos(modified).getKeyAccounts(publicKey).then((result) => dispatch({
type: types.GET_ACCOUNTS_SUCCESS,
accounts: result.account_names
})).catch((err) => dispatch({
type: types.GET_ACCOUNTS_REQUEST,
err
}));
};
}

export function getAccount(name) {
return (dispatch: () => void, getState) => {
dispatch({
type: types.GET_ACCOUNT_REQUEST
});
const { connection } = getState();

const modified = {
...connection,
sign: false
};

eos(modified).getAccount(name).then((result) => {
dispatch({
type: types.GET_ACCOUNT_SUCCESS,
account: result
});
}).catch((err) => {
dispatch({
type: types.GET_ACCOUNT_FAILURE,
err
});
});
};
}

export function getActions(name) {
return (dispatch: () => void, getState) => {
dispatch({
type: types.GET_ACTIONS_REQUEST
});

const { connection } = getState();

const modified = {
...connection,
sign: false
};

eos(modified).getActions(name).then((result) => {
dispatch({
type: types.GET_ACTIONS_SUCCESS,
actions: result
});
}).catch((err) => {
dispatch({
type: types.GET_ACTIONS_FAILURE,
err
});
});

};
}

export default {
getAccounts,
getAccount
}
75 changes: 75 additions & 0 deletions app/actions/connection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @flow
import * as types from './types';
import { getAccounts } from './accounts';

import eos from './helpers/eos';

export function test(url) {
return function(dispatch) {
dispatch({
type: 'dfgdfgdgdgdf'
});
}
};

export function createConnection(url) {
return (dispatch: () => void, getState) => {
dispatch({
type: types.CREATE_CONNECTION_PENDING,
url
});

if (!url || url.length === 0) {
return;
}

try {
const {
connection
} = getState();

let { host, protocol, path } = new URL(url);
if (`${protocol}${path}` === url) {
host = url;
protocol = 'http:';
}
const httpEndpoint = `${protocol}//${host}`;

const modified = {
...connection,
httpEndpoint,
sign: false
};

eos(modified).getInfo({}).then((result) => {
if (result.head_block_num > 0) {
dispatch({
type: types.CREATE_CONNECTION_SUCCESS,
httpEndpoint
});

return dispatch(getAccounts(getState().ledger.publicKey))
}
return dispatch({
type: types.CREATE_CONNECTION_FAILURE
});
}).catch((err) => {
dispatch({
type: types.CREATE_CONNECTION_FAILURE,
err
});
});

} catch (err) {
return dispatch({
type: types.CREATE_CONNECTION_FAILURE,
err
});
}
};
}

export default {
createConnection,
test
}
44 changes: 0 additions & 44 deletions app/actions/counter.js

This file was deleted.

140 changes: 90 additions & 50 deletions app/actions/ledger.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,110 @@

// @flow
import * as types from './types';

const Api = require('./helpers/eosledjer').default;
const Transport = require("@ledgerhq/hw-transport-node-hid").default;

export function startListen() {
return (dispatch: () => void) => {
dispatch({
type: types.START_LISTEN_DEVICE_EVENTS
});
};
}

export function stopListen() {
return (dispatch: () => void) => {
return (dispatch: () => void, getState) => {
var currentState = getState();

dispatch({
type: types.STOP_LISTEN_DEVICE_EVENTS
type: types.APP_LEDGER_CONNECTION_STATUS,
deviceConnected: !!currentState.ledger.publicKey
});
};
}

export function getPublicKey(device) {
return (dispatch: () => void) => {
dispatch({
type: types.GET_PUBLIC_KEY_REQUEST
});

// const api = new Api(device);
device.getPublicKey("44'/194'/0'/0/0", false, false).then(result => {
dispatch({

if (getState().ledger.subscriber !== null) {
if (!currentState.states.deviceConnected){
getState().ledger.subscriber();
}

return;
}

const subscriber = () => {
dispatch({
type: types.GET_PUBLIC_KEY_SUCCESS,
publicKey: result
});
return result;
}).catch((err) => {
console.log(err);
dispatch({
type: types.GET_PUBLIC_KEY_FAILURE,
statusCode: err.statusCode
publicKey: 'EOS8ddPoePGrH4x1mha1RHcbjU1cAWWFLWqBQF6Q35RrTsZdLouCm'
});
});
}
}

export function getAppConfiguration(device) {
return (dispatch: () => void) => {
dispatch(startListen());
}

// const subscriber = Transport.listen({
// next: (event) => {
// if (event.type === 'add') {
// if (getState().ledger.devicePath === null) {
//
// if (getState().ledger.devicePath !== event.device.path && getState().ledger.publicKey === null) {
// dispatch(stopListen());
//
// Transport.open(event.device.path).then((transport) => {
// transport.setDebugMode(true);
// const api = new Api(transport);
// api.getPublicKey("44'/194'/0'/0/0").then((result) => {
// transport.close();
//
// dispatch({
// type: types.GET_PUBLIC_KEY_SUCCESS,
// publicKey: result
// });
//
// dispatch(startListen());
// return result;
// }).catch((err) => {
// transport.close();
//
// dispatch({
// type: types.GET_PUBLIC_KEY_FAILURE,
// publicKey: null,
// err
// });
//
// dispatch(startListen());
// });
// return transport;
// }).catch((err) => {
// console.log(err);
// dispatch(startListen());
// });
// }
//
// dispatch({
// type: types.DEVICE_CONNECTED,
// devicePath: event.device.path
// });
// }
//
//
// } else if (event.type === 'remove') {
// dispatch({ type: types.DEVICE_DISCONNECTED});
// }
// }
// });

dispatch({
type: types.GET_APP_INFO_REQUEST
type: types.START_LISTEN_DEVICE_EVENTS,
subscriber
});

dispatch(startListen());
};
}

const api = new Api(device);
api.getAppConfiguration().then(result => {
dispatch({
type: types.GET_APP_INFO_SUCCESS
});
return result;
}).catch((err) => {
console.log(err);
export function stopListen() {
return (dispatch: () => void, getState) => {
const { ledger } = getState();
if (ledger.subscriber !== null) {
ledger.subscriber.unsubscribe();

dispatch({
type: types.GET_APP_INFO_FAILURE,
statusCode: err.statusCode
type: types.STOP_LISTEN_DEVICE_EVENTS
});
});
}
}
};
}

export default {
getPublicKey
startListen,
stopListen
};
Loading

0 comments on commit 5a43693

Please sign in to comment.