MyCrypto/common/sagas/ens.js

42 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-06-26 22:27:55 +00:00
// @flow
import { takeEvery, call, put, select } from 'redux-saga/effects';
import { delay } from 'redux-saga';
2017-09-04 16:30:31 +00:00
2017-06-26 22:27:55 +00:00
import { cacheEnsAddress } from 'actions/ens';
import type { ResolveEnsNameAction } from 'actions/ens';
2017-09-04 16:30:31 +00:00
2017-06-26 22:27:55 +00:00
import { getEnsAddress } from 'selectors/ens';
import { donationAddressMap } from 'config/data';
2017-06-26 22:27:55 +00:00
2017-09-04 16:30:31 +00:00
import type { Yield, Return, Next } from 'sagas/types';
function* resolveEns(
action?: ResolveEnsNameAction
): Generator<Yield, Return, Next> {
2017-07-04 03:21:19 +00:00
if (!action) return;
2017-07-02 05:49:06 +00:00
const ensName = action.payload;
// FIXME Add resolve logic
//// _ens.getAddress(scope.addressDrtv.ensAddressField, function(data) {
// if (data.error) uiFuncs.notifier.danger(data.msg);
// else if (data.data == '0x0000000000000000000000000000000000000000' || data.data == '0x') {
// setValue('0x0000000000000000000000000000000000000000');
// scope.addressDrtv.derivedAddress = '0x0000000000000000000000000000000000000000';
// scope.addressDrtv.showDerivedAddress = true;
// } else {
// setValue(data.data);
// scope.addressDrtv.derivedAddress = ethUtil.toChecksumAddress(data.data);
// scope.addressDrtv.showDerivedAddress = true;
2017-06-26 22:27:55 +00:00
2017-07-02 05:49:06 +00:00
const cachedEnsAddress = yield select(getEnsAddress, ensName);
2017-06-26 22:27:55 +00:00
2017-07-02 05:49:06 +00:00
if (cachedEnsAddress) {
return;
}
yield call(delay, 1000);
yield put(cacheEnsAddress(ensName, donationAddressMap.ETH));
2017-06-26 22:27:55 +00:00
}
2017-09-04 16:30:31 +00:00
export default function* notificationsSaga(): Generator<Yield, Return, Next> {
2017-07-02 05:49:06 +00:00
yield takeEvery('ENS_RESOLVE', resolveEns);
2017-06-26 22:27:55 +00:00
}