Add actions/api/reducers/sagas

This commit is contained in:
Anthony Laibe 2018-08-13 12:08:59 +01:00 committed by Pascal Precht
parent 83d6130259
commit b6156e7632
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 48 additions and 7 deletions

View File

@ -132,6 +132,21 @@ export const messageListen = {
failure: (error) => action(MESSAGE_LISTEN[FAILURE], {error})
};
export const ENS_RECORD = createRequestTypes('ENS_RECORD');
export const ensRecord = {
resolve: (name) => action(ENS_RECORD[REQUEST], {name}),
lookup: (address) => action(ENS_RECORD[REQUEST], {address}),
success: (record, payload) => action(ENS_RECORD[SUCCESS], {ensRecords: [Object.assign(payload, record)]}),
failure: (error) => action(ENS_RECORD[FAILURE], {error})
};
export const ENS_RECORDS = createRequestTypes('ENS_RECORDS');
export const ensRecords = {
post: (name, address) => action(ENSENS_RECORDS_RECORD[REQUEST], {name, address}),
success: (_record, payload) => action(ENS_RECORDS[SUCCESS], {ensRecords: [{name: payload.name, address: payload.address}]}),
failure: (error) => action(ENS_RECORDS[FAILURE], {error})
};
// Web Socket
export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS';
export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS';

View File

@ -80,14 +80,26 @@ export function sendMessage(payload) {
return post(`/communication/sendMessage`, payload.body);
}
export function listenToChannel(channel) {
return new WebSocket(`${constants.wsEndpoint}/communication/listenTo/${channel}`);
}
export function fetchContractProfile(payload) {
return get(`/profiler/${payload.contractName}`);
}
export function fetchENSRecord(payload) {
if (payload.name) {
return get('/ens/resolve', {params: payload});
} else {
return get('/ens/lookup', {params: payload});
}
}
export function postENSRecord(payload) {
return post('/ens/register', payload);
}
export function listenToChannel(channel) {
return new WebSocket(`${constants.wsEndpoint}/communication/listenTo/${channel}`);
}
export function webSocketProcess(processName) {
return new WebSocket(constants.wsEndpoint + '/process-logs/' + processName);
}

View File

@ -17,7 +17,8 @@ const entitiesDefaultState = {
messageChannels: [],
fiddle: null,
versions: [],
plugins: []
plugins: [],
ensRecords: []
};
const sorter = {

View File

@ -4,7 +4,8 @@ import {eventChannel} from 'redux-saga';
import {all, call, fork, put, takeEvery, take} from 'redux-saga/effects';
const {account, accounts, block, blocks, transaction, transactions, processes, commands, processLogs,
contracts, contract, contractProfile, messageSend, versions, plugins, messageListen, fiddle} = actions;
contracts, contract, contractProfile, messageSend, versions, plugins, messageListen, fiddle,
ensRecord, ensRecords} = actions;
function *doRequest(entity, apiFn, payload) {
const {response, error} = yield call(apiFn, payload);
@ -32,6 +33,8 @@ export const fetchContract = doRequest.bind(null, contract, api.fetchContract);
export const fetchContractProfile = doRequest.bind(null, contractProfile, api.fetchContractProfile);
export const fetchFiddle = doRequest.bind(null, fiddle, api.fetchFiddle);
export const sendMessage = doRequest.bind(null, messageSend, api.sendMessage);
export const fetchENSRecord = doRequest.bind(null, ensRecord, api.fetchENSRecord);
export const postENSRecord = doRequest.bind(null, ensRecords, api.postENSRecord);
export function *watchFetchTransaction() {
yield takeEvery(actions.TRANSACTION[actions.REQUEST], fetchTransaction);
@ -97,6 +100,14 @@ export function *watchSendMessage() {
yield takeEvery(actions.MESSAGE_SEND[actions.REQUEST], sendMessage);
}
export function *watchFetchENSRecord() {
yield takeEvery(actions.ENS_RECORD[actions.REQUEST], fetchENSRecord);
}
export function *watchPostENSRecords() {
yield takeEvery(actions.ENS_RECORDS[actions.REQUEST], postENSRecord);
}
function createChannel(socket) {
return eventChannel(emit => {
socket.onmessage = ((message) => {
@ -192,6 +203,8 @@ export default function *root() {
fork(watchFetchContract),
fork(watchFetchTransaction),
fork(watchFetchContractProfile),
fork(watchFetchFiddle)
fork(watchFetchFiddle),
fork(watchFetchENSRecord),
fork(watchPostENSRecords)
]);
}