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