diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 1424cfb2..6f603860 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -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'; diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 4dc9dc2d..615f97ed 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -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); } diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 315ce094..626794cc 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -17,7 +17,8 @@ const entitiesDefaultState = { messageChannels: [], fiddle: null, versions: [], - plugins: [] + plugins: [], + ensRecords: [] }; const sorter = { diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 74b0348b..5e23a5d7 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -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) ]); }