MyCrypto/common/sagas/wallet.js

27 lines
805 B
JavaScript
Raw Normal View History

2017-06-30 03:03:11 +04:00
// @flow
import { takeEvery, call, put, select } from 'redux-saga/effects';
2017-07-04 03:59:27 +04:00
import type { Effect } from 'redux-saga/effects';
2017-06-30 03:03:11 +04:00
import { delay } from 'redux-saga';
2017-07-04 03:59:27 +04:00
import { saveWallet, initWallet } from 'actions/wallet';
2017-06-30 03:03:11 +04:00
import type { UnlockPrivateKeyAction } from 'actions/wallet';
import PrivKeyWallet from 'libs/wallet/privkey';
2017-07-04 03:59:27 +04:00
function* init() {
2017-07-03 22:21:19 -05:00
yield put(initWallet());
// const node = select(getNode);
// yield call();
// fetch balance,
// fetch tokens
yield delay(100);
2017-07-04 03:59:27 +04:00
}
function* unlockPrivateKey(action?: UnlockPrivateKeyAction) {
2017-07-03 22:21:19 -05:00
if (!action) return;
yield put(saveWallet(new PrivKeyWallet(action.payload)));
yield call(init);
2017-06-30 03:03:11 +04:00
}
2017-07-04 03:59:27 +04:00
export default function* notificationsSaga(): Generator<Effect, void, any> {
2017-07-03 22:21:19 -05:00
yield takeEvery('WALLET_UNLOCK_PRIVATE_KEY', unlockPrivateKey);
2017-06-30 03:03:11 +04:00
}