Skip to content

Commit

Permalink
Merge pull request steemit#2944 from steemit/revert-2898-2835-wipe-au…
Browse files Browse the repository at this point in the history
…to-vests

Revert "reset outgoing auto-vesting-routes on account recovery"
  • Loading branch information
bnchdrff authored Jul 16, 2018
2 parents df50049 + a7dcd5b commit 42a0b34
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 271 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"react-timeago": "3.4.3",
"redux": "3.7.2",
"redux-form": "5.3.4",
"redux-saga": "0.16.0",
"redux-saga": "0.9.5",
"remarkable": "1.7.1",
"sanitize-html": "1.14.1",
"sass-loader": "6.0.6",
Expand Down Expand Up @@ -175,7 +175,6 @@
"react-test-renderer": "15.6.2",
"react-transform-catch-errors": "1.0.2",
"react-transform-hmr": "1.0.4",
"redux-devtools-extension": "2.13.5",
"redux-mock-store": "1.5.1",
"regenerator-runtime": "0.11.1",
"sinon": "1.17.7",
Expand Down
11 changes: 7 additions & 4 deletions src/app/redux/AuthSaga.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { call, put, select, takeEvery } from 'redux-saga/effects';
import { takeEvery } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';
import { Set, Map, fromJS, List } from 'immutable';
import { api } from '@steemit/steem-js';
import { PrivateKey } from '@steemit/steem-js/lib/auth/ecc';
Expand All @@ -13,9 +14,11 @@ const postingOps = Set(
.split(/,\s*/)
);

export const authWatches = [
takeEvery('user/ACCOUNT_AUTH_LOOKUP', accountAuthLookup),
];
export const authWatches = [watchForAuth];

function* watchForAuth() {
yield* takeEvery('user/ACCOUNT_AUTH_LOOKUP', accountAuthLookup);
}

export function* accountAuthLookup({
payload: { account, private_keys, login_owner_pubkey },
Expand Down
40 changes: 27 additions & 13 deletions src/app/redux/FetchDataSaga.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import {
call,
put,
select,
fork,
takeLatest,
takeEvery,
} from 'redux-saga/effects';
import { takeLatest, takeEvery } from 'redux-saga';
import { call, put, select, fork } from 'redux-saga/effects';
import { loadFollows, fetchFollowCount } from 'app/redux/FollowSaga';
import { getContent } from 'app/redux/SagaShared';
import * as globalActions from './GlobalReducer';
Expand All @@ -19,13 +13,21 @@ const GET_CONTENT = 'fetchDataSaga/GET_CONTENT';
const FETCH_STATE = 'fetchDataSaga/FETCH_STATE';

export const fetchDataWatches = [
takeLatest(REQUEST_DATA, fetchData),
takeEvery(GET_CONTENT, getContentCaller),
takeLatest('@@router/LOCATION_CHANGE', fetchState),
takeLatest(FETCH_STATE, fetchState),
takeEvery('global/FETCH_JSON', fetchJson),
watchLocationChange,
watchDataRequests,
watchFetchJsonRequests,
watchFetchState,
watchGetContent,
];

export function* watchDataRequests() {
yield* takeLatest(REQUEST_DATA, fetchData);
}

export function* watchGetContent() {
yield* takeEvery(GET_CONTENT, getContentCaller);
}

export function* getContentCaller(action) {
yield getContent(action.payload);
}
Expand Down Expand Up @@ -118,6 +120,14 @@ function* getAccounts(usernames) {
yield put(globalActions.receiveAccounts({ accounts }));
}

export function* watchLocationChange() {
yield* takeLatest('@@router/LOCATION_CHANGE', fetchState);
}

export function* watchFetchState() {
yield* takeLatest(FETCH_STATE, fetchState);
}

export function* fetchData(action) {
const { order, author, permlink, accountname } = action.payload;
let { category } = action.payload;
Expand Down Expand Up @@ -357,6 +367,10 @@ export function* fetchMeta({ payload: { id, link } }) {
}
}

export function* watchFetchJsonRequests() {
yield* takeEvery('global/FETCH_JSON', fetchJson);
}

/**
@arg {string} id unique key for result global['fetchJson_' + id]
@arg {string} url
Expand Down
21 changes: 17 additions & 4 deletions src/app/redux/MarketSaga.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { call, put, takeLatest } from 'redux-saga/effects';
import { takeLatest } from 'redux-saga';
import { call, put } from 'redux-saga/effects';
import { api } from '@steemit/steem-js';

import * as marketActions from './MarketReducer';
Expand All @@ -7,9 +8,9 @@ import * as userActions from './UserReducer';
import { getAccount } from './SagaShared';

export const marketWatches = [
takeLatest(userActions.SET_USER, fetchOpenOrders),
takeLatest('@@router/LOCATION_CHANGE', fetchMarket),
takeLatest(marketActions.UPDATE_MARKET, reloadMarket),
watchLocationChange,
watchUserLogin,
watchMarketUpdate,
];

const wait = ms =>
Expand Down Expand Up @@ -85,3 +86,15 @@ export function* reloadMarket(reload_action) {
yield fetchMarket(reload_action);
yield fetchOpenOrders(reload_action);
}

export function* watchUserLogin() {
yield* takeLatest(userActions.SET_USER, fetchOpenOrders);
}

export function* watchLocationChange() {
yield* takeLatest('@@router/LOCATION_CHANGE', fetchMarket);
}

export function* watchMarketUpdate() {
yield* takeLatest(marketActions.UPDATE_MARKET, reloadMarket);
}
34 changes: 23 additions & 11 deletions src/app/redux/SagaShared.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fromJS } from 'immutable';
import { call, put, select, takeEvery, takeLatest } from 'redux-saga/effects';
import { call, put, select } from 'redux-saga/effects';
import { takeEvery, takeLatest } from 'redux-saga';
import tt from 'counterpart';
import { api } from '@steemit/steem-js';
import * as globalActions from './GlobalReducer';
Expand All @@ -13,16 +14,9 @@ const wait = ms =>
});

export const sharedWatches = [
takeEvery(globalActions.GET_STATE, getState),
takeLatest(
[
appActions.SET_USER_PREFERENCES,
appActions.TOGGLE_NIGHTMODE,
appActions.TOGGLE_BLOGMODE,
],
saveUserPreferences
),
takeEvery('transaction/ERROR', showTransactionErrorNotification),
watchGetState,
watchTransactionErrors,
watchUserSettingsUpdates,
];

export function* getAccount(username, force = false) {
Expand All @@ -39,6 +33,9 @@ export function* getAccount(username, force = false) {
return account;
}

export function* watchGetState() {
yield* takeEvery(globalActions.GET_STATE, getState);
}
/** Manual refreshes. The router is in FetchDataSaga. */
export function* getState({ payload: { url } }) {
try {
Expand All @@ -50,6 +47,10 @@ export function* getState({ payload: { url } }) {
}
}

export function* watchTransactionErrors() {
yield* takeEvery('transaction/ERROR', showTransactionErrorNotification);
}

function* showTransactionErrorNotification() {
const errors = yield select(state => state.transaction.get('errors'));
for (const [key, message] of errors) {
Expand Down Expand Up @@ -93,3 +94,14 @@ function* saveUserPreferences({ payload }) {
const prefs = yield select(state => state.app.get('user_preferences'));
yield setUserPreferences(prefs.toJS());
}

function* watchUserSettingsUpdates() {
yield* takeLatest(
[
appActions.SET_USER_PREFERENCES,
appActions.TOGGLE_NIGHTMODE,
appActions.TOGGLE_BLOGMODE,
],
saveUserPreferences
);
}
53 changes: 26 additions & 27 deletions src/app/redux/TransactionSaga.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { call, put, select, all, takeEvery } from 'redux-saga/effects';
import { takeEvery } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';
import { fromJS, Set, Map } from 'immutable';
import tt from 'counterpart';
import getSlug from 'speakingurl';
Expand All @@ -17,12 +18,28 @@ import { DEBT_TICKER } from 'app/client_config';
import { serverApiRecordEvent } from 'app/utils/ServerApiClient';

export const transactionWatches = [
takeEvery(transactionActions.BROADCAST_OPERATION, broadcastOperation),
takeEvery(transactionActions.UPDATE_AUTHORITIES, updateAuthorities),
takeEvery(transactionActions.UPDATE_META, updateMeta),
takeEvery(transactionActions.RECOVER_ACCOUNT, recoverAccount),
watchForBroadcast,
watchForUpdateAuthorities,
watchForUpdateMeta,
watchForRecoverAccount,
];

export function* watchForBroadcast() {
yield* takeEvery(
transactionActions.BROADCAST_OPERATION,
broadcastOperation
);
}
export function* watchForUpdateAuthorities() {
yield* takeEvery(transactionActions.UPDATE_AUTHORITIES, updateAuthorities);
}
export function* watchForUpdateMeta() {
yield* takeEvery(transactionActions.UPDATE_META, updateMeta);
}
export function* watchForRecoverAccount() {
yield* takeEvery(transactionActions.RECOVER_ACCOUNT, recoverAccount);
}

const hook = {
preBroadcast_comment,
preBroadcast_transfer,
Expand Down Expand Up @@ -164,7 +181,7 @@ function* error_account_witness_vote({
}

/** Keys, username, and password are not needed for the initial call. This will check the login and may trigger an action to prompt for the password / key. */
export function* broadcastOperation({
function* broadcastOperation({
payload: {
type,
operation,
Expand Down Expand Up @@ -680,7 +697,7 @@ function slug(text) {
const pwPubkey = (name, pw, role) =>
auth.wifToPublic(auth.toWif(name, pw.trim(), role));

export function* recoverAccount({
function* recoverAccount({
payload: {
account_to_recover,
old_password,
Expand All @@ -693,7 +710,6 @@ export function* recoverAccount({
[api, api.getAccountsAsync],
[account_to_recover]
);

if (!account) {
onError('Unknown account ' + account);
return;
Expand Down Expand Up @@ -744,7 +760,6 @@ export function* recoverAccount({
};

try {
// TODO: Investigate wrapping in a redux-saga call fn, so it can be tested!.
yield broadcast.sendAsync(
{
extensions: [],
Expand All @@ -765,7 +780,6 @@ export function* recoverAccount({
// change password
// change password probably requires a separate transaction (single trx has not been tested)
const { json_metadata } = account;
// TODO: Investigate wrapping in a redux-saga call fn, so it can be tested!
yield broadcast.sendAsync(
{
extensions: [],
Expand All @@ -792,21 +806,6 @@ export function* recoverAccount({
},
[newOwnerPrivate]
);
// Reset all outgoing auto-vesting routes for this user. Condenser - #2835
const outgoingAutoVestingRoutes = yield call(
[api, api.getWithdrawRoutes],
[account.name, 'outgoing']
);
if (outgoingAutoVestingRoutes && outgoingAutoVestingRoutes.length > 0) {
yield all(
outgoingAutoVestingRoutes.map(ovr => {
return call(
[broadcast, broadcast.setWithdrawVestingRoute],
[newActive, ovr.from_account, ovr.to_account, 0, true]
);
})
);
}
if (onSuccess) onSuccess();
} catch (error) {
console.error('Recover account', error);
Expand All @@ -816,7 +815,7 @@ export function* recoverAccount({

/** auths must start with most powerful key: owner for example */
// const twofaAccount = 'steem'
export function* updateAuthorities({
function* updateAuthorities({
payload: { accountName, signingKey, auths, twofa, onSuccess, onError },
}) {
// Be sure this account is up-to-date (other required fields are sent in the update)
Expand Down Expand Up @@ -956,7 +955,7 @@ export function* updateAuthorities({

/** auths must start with most powerful key: owner for example */
// const twofaAccount = 'steem'
export function* updateMeta(params) {
function* updateMeta(params) {
// console.log('params', params)
const {
meta,
Expand Down
Loading

0 comments on commit 42a0b34

Please sign in to comment.