Commit e590bbe8 authored by / /\ / /\/'s avatar / /\ / /\/
Browse files

Revert "wip error handling on community creation"

This reverts commit c8fe3dc1.
parent c8fe3dc1
......@@ -8,19 +8,30 @@ import { key_utils } from '@steemit/steem-js/lib/auth/ecc';
class CreateCommunity extends React.Component {
constructor() {
super();
this.state = { error: false, errorMessage: '' }; // Component error state refers to account creation ops. For errors in custom ops, see the communityHivemindOperationError prop.
this.state = { error: false, errorMessage: '' };
}
componentDidUpdate(prevProps, prevState) {
if (this.props.hasTransactionError && !prevProps.hasTransactionError) {
this.setState({
errorMessage: 'There was a transaction error.',
});
}
if (this.props.loginError && !prevProps.loginError) {
this.setState({
errorMessage: 'There was a credentials error.',
});
}
}
render() {
const errorCB = () => {
this.setState({ error: true });
};
const successCB = () => {
this.setState({ error: false, errorMessage: '' });
};
const {
accountName,
communityCreateError,
communityCreatePending,
communityCreateSuccess,
createCommunity,
......@@ -36,7 +47,9 @@ class CreateCommunity extends React.Component {
updateCommunityOwnerWifPassword,
communityHivemindOperationPending,
communityHivemindOperationError,
communityAccountCreated, // If the community account was successfully created, but the hivemind ops to assign the currently-logged in user as community account admin fail, the next time the user attempts to create the community, the account-creation step will be skipped.
loginError,
transactionState,
hasTransactionError,
} = this.props;
const handleCommunityTitleInput = e => {
......@@ -65,12 +78,7 @@ class CreateCommunity extends React.Component {
communityOwnerName,
communityOwnerWifPassword,
};
createCommunity(
createCommunitypayload,
successCB,
errorCB,
communityAccountCreated
);
createCommunity(createCommunitypayload, errorCB);
this.setState({ error: false, errorMessage: '' });
};
......@@ -138,25 +146,9 @@ class CreateCommunity extends React.Component {
<input type="submit" value="Submit" />
);
const createCommunityAccountSuccessMessage = (
<div>
Community was successfully created on the blockchain, now
broadcasting custom operations...
</div>
);
const createCommunityCustomOpsErrorMessage = (
<div>
There was a problem with that operation, please try again.
</div>
);
const createCommunitySuccessMessage = (
<div>
<p>
Your community was created! And your user assigned the admin
role!
</p>
<p>Your community was created!</p>
<a
href={`https://steemitdev.com/trending/${communityOwnerName}`}
>
......@@ -238,10 +230,6 @@ class CreateCommunity extends React.Component {
return (
<div className="row">
<div className="column large-6 small-12">
{communityAccountCreated &&
createCommunityAccountSuccessMessage}
{communityHivemindOperationError &&
createCommunityCustomOpsErrorMessage}
{this.state.error && createCommunityErrorMessage}
{this.state.error && createCommunityForm}
{!communityCreatePending &&
......@@ -253,6 +241,7 @@ class CreateCommunity extends React.Component {
{communityHivemindOperationPending &&
createCommunityCustomOpsPendingMessage}
{communityCreateSuccess && createCommunitySuccessMessage}
{communityCreateError && createCommunityErrorMessage}
</div>
</div>
);
......@@ -267,6 +256,13 @@ export default connect(
const current = state.user.get('current');
// get userLogin error
console.log('userState', state.user.toJS());
console.log('transactionState', state.transaction.toJS());
const loginError = state.user.toJS().login_error;
const transactionState = state.transaction.toJS();
const hasTransactionError =
Object.values(state.transaction.toJS().errors).filter(v => !!v)
.length > 0;
console.log('There was a transaction error:', hasTransactionError);
const username = current && current.get('username');
const isMyAccount = username === accountName;
return {
......@@ -275,6 +271,8 @@ export default connect(
isMyAccount,
accountName,
loginError,
transactionState,
hasTransactionError,
};
},
// mapDispatchToProps
......@@ -299,21 +297,13 @@ export default connect(
communityActions.setCommunityOwnerWifPassword(password)
);
},
createCommunity: (
createCommunityPayload,
successCB,
errorCB,
skipAccountCreate
) => {
const successCallback = () => {
successCB();
return dispatch(
communityActions.setCommunityAccountCreated(true),
createCommunity: (createCommunityPayload, errorCB) => {
const successCallback = () =>
dispatch(
communityActions.communityHivemindOperation(
createCommunityPayload
)
);
};
const errorCallback = () => {
errorCB();
};
......@@ -322,15 +312,7 @@ export default connect(
errorCallback: errorCallback,
...createCommunityPayload,
};
if (skipAccountCreate) {
dispatch(communityActions.createCommunity(payload));
} else {
dispatch(
communityActions.communityHivemindOperation(
createCommunityPayload
)
);
}
dispatch(communityActions.createCommunity(payload));
},
};
}
......
......@@ -26,7 +26,7 @@
"community_password_is": "Your password is",
"community_creating": "Your community is being created...",
"community_create_password_error":
"Unable to create a new account - there was a problem with your credentials:",
"There was a problem with your credentials:",
"community_create_try_again": "Please try again:",
"community_broadcasting_custom_ops": "Making",
"community_broadcasting_custom_ops_1": "administrator of the",
......
......@@ -9,14 +9,13 @@ const SET_COMMUNITY_OWNER_ACCOUNT_NAME =
'community/SET_COMMUNITY_OWNER_ACCOUNT_NAME';
const SET_COMMUNITY_OWNER_WIF_PASSWORD =
'community/SET_COMMUNITY_OWNER_MASTER_PASSWORD';
export const SET_COMMUNITY_ACCOUNT_CREATED =
'community/SET_COMMUNITY_ACCOUNT_CREATED';
export const CREATE_COMMUNITY_ACCOUNT = 'community/CREATE_COMMUNITY_ACCOUNT'; // Has saga.
export const CREATE_COMMUNITY_ACCOUNT_PENDING =
'community/CREATE_COMMUNITY_ACCOUNT_PENDING';
export const CREATE_COMMUNITY_ACCOUNT_ERROR =
'community/CREATE_COMMUNITY_ACCOUNT_ERROR';
export const CREATE_COMMUNITY_ERROR = 'community/CREATE_COMMUNITY_ERROR';
export const CREATE_COMMUNITY_SUCCESS = 'community/CREATE_COMMUNITY_SUCCESS';
export const COMMUNITY_HIVEMIND_OPERATION =
'community/COMMUNITY_HIVEMIND_OPERATION'; // Has saga.
......@@ -33,10 +32,10 @@ const defaultState = fromJS({
communityOwnerName: '',
communityOwnerWifPassword: '',
communityCreatePending: false,
communityCreateSuccess: false,
communityCreateError: false,
communityHivemindOperationPending: false,
communityHivemindOperationError: false,
communityAccountCreated: false,
communityCreateSuccess: false,
});
export default function reducer(state = defaultState, action) {
......@@ -62,10 +61,6 @@ export default function reducer(state = defaultState, action) {
const password = fromJS(payload);
return state.merge({ communityOwnerWifPassword: password });
}
case SET_COMMUNITY_ACCOUNT_CREATED: {
const creationSuccess = fromJS(payload);
return state.merge({ communityAccountCreated: creationSuccess });
}
// Has a saga watcher.
case CREATE_COMMUNITY_ACCOUNT: {
return state;
......@@ -78,6 +73,10 @@ export default function reducer(state = defaultState, action) {
const pending = fromJS(payload);
return state.merge({ communityCreatePending: pending });
}
case CREATE_COMMUNITY_ERROR: {
const err = fromJS(payload);
return state.merge({ communityCreateError: err });
}
case CREATE_COMMUNITY_SUCCESS: {
const success = fromJS(payload);
return state.merge({ communityCreateSuccess: success });
......@@ -116,11 +115,6 @@ export const setCommunityNSFW = payload => ({
payload,
});
export const setCommunityAccountCreated = payload => ({
type: SET_COMMUNITY_ACCOUNT_CREATED,
payload,
});
export const setCommunityOwnerAccountName = payload => ({
type: SET_COMMUNITY_OWNER_ACCOUNT_NAME,
payload,
......
......@@ -34,7 +34,21 @@ export const communityWatches = [
createCommunityAccount
),
takeLatest(communityActions.COMMUNITY_HIVEMIND_OPERATION, customOps),
takeLatest(
communityActions.CREATE_COMMUNITY_ACCOUNT_ERROR,
createAccountError
),
];
export function* createAccountError(action) {
yield put({
type: communityActions.CREATE_COMMUNITY_ACCOUNT_PENDING,
payload: false,
});
yield put({
type: communityActions.CREATE_COMMUNITY_ERROR,
payload: true,
});
}
export function* customOps(action) {
yield put({
......@@ -49,10 +63,6 @@ export function* customOps(action) {
communityOwnerName,
communityOwnerWifPassword,
} = action.payload;
yield put({
type: communityActions.COMMUNITY_HIVEMIND_OPERATION_ERROR,
payload: false,
});
// The client cannot submit custom_json and account_create in the same block. The easiest way around this, for now, is to pause for 3 seconds after the account is created before submitting the ops.
yield call(wait, 4000);
try {
......@@ -106,8 +116,9 @@ export function* customOps(action) {
payload: true,
});
} catch (error) {
console.log(error);
yield put({
type: communityActions.COMMUNITY_HIVEMIND_OPERATION_ERROR,
type: communityActions.CREATE_COMMUNITY_ERROR,
payload: true,
});
}
......@@ -166,28 +177,24 @@ export function* createCommunityAccount(createCommunityAction) {
json_metadata: '',
};
const communityAccountAlreadyCreated = yield select(
state => state.community.toJS().communityAccountCreated
yield put(
transactionActions.broadcastOperation({
type: 'account_create',
confirm: 'Are you sure?',
operation: op,
successCallback: res => {
successCallback();
},
errorCallback: res => {
errorCallback(res);
},
})
);
if (communityAccountAlreadyCreated) {
successCallback();
} else {
yield put(
transactionActions.broadcastOperation({
type: 'account_create',
confirm: 'Are you sure?',
operation: op,
successCallback: res => {
successCallback();
},
errorCallback: res => {
errorCallback(res);
},
})
);
}
} catch (error) {
// Technically this code will not be reached because of the errorCallback in the broadcastOperation
yield put({
type: communityActions.CREATE_COMMUNITY_ERROR,
payload: true,
});
yield put({
type: communityActions.CREATE_COMMUNITY_ACCOUNT_PENDING,
payload: false,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment