Skip to content

Commit

Permalink
clean up account profile loguc
Browse files Browse the repository at this point in the history
  • Loading branch information
dkent600 committed Jul 29, 2020
1 parent 41c165a commit 0c53b00
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
84 changes: 43 additions & 41 deletions src/actions/profilesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,61 +121,63 @@ export function getProfile(accountAddress: string, currentAccount = false):
(dispatch: Redux.Dispatch<any, any>, _getState: () => IRootState) => Promise<void> {

return async (dispatch: Redux.Dispatch<any, any>, _getState: () => IRootState): Promise<void> => {
try {
if (accountAddress) {
try {
/**
* Get profile data for this account.
* Note accountAddress is case insensitive to `Box.getProfile`, but
* we need to cast to lower because state.currentAccountAddress is cast to lower, thus
* facilitating address comparisons, and array key matching.
*/
accountAddress = accountAddress.toLowerCase();
const profile: any = await Box.getProfile(accountAddress);

if (profile) {
profile.ethereumAccountAddress = accountAddress;
profile.socialURLs = await Box.getVerifiedAccounts(profile);
const space = await Box.getSpace(accountAddress, spaceName);
await space.syncDone;

if (space.follows) {
profile.follows = space.follows;
} else {
profile.follows = {
daos: [],
proposals: [],
users: [],
};
}

dispatch({
type: ActionTypes.GET_PROFILE_DATA,
sequence: AsyncActionSequence.Success,
payload: { profiles: { [accountAddress]: profile } },
});
accountAddress = accountAddress.toLowerCase();
const profile: any = await Box.getProfile(accountAddress);

if (profile) {
profile.ethereumAccountAddress = accountAddress;
profile.socialURLs = await Box.getVerifiedAccounts(profile);
const space = await Box.getSpace(accountAddress, spaceName);
await space.syncDone;

if (space.follows) {
profile.follows = space.follows;
} else {
profile.follows = {
daos: [],
proposals: [],
users: [],
};
}

dispatch({
type: ActionTypes.GET_PROFILE_DATA,
sequence: AsyncActionSequence.Success,
payload: { profiles: { [accountAddress]: profile } },
});

if (currentAccount) {
if (currentAccount) {
// If getting profile for the current account then update our analytics services with the profile data
Analytics.people.set({
Name: profile.name,
Description: profile.description,
Analytics.people.set({
Name: profile.name,
Description: profile.description,
});
}
} else {
// Setup blank profile for the account
dispatch({
type: ActionTypes.GET_PROFILE_DATA,
sequence: AsyncActionSequence.Success,
payload: { profiles: { [accountAddress]: newProfile(accountAddress) } },
});
}
} else {
// Setup blank profile for the account
} catch (e) {
// eslint-disable-next-line no-console
console.error("Error getting profile from 3box", e);
dispatch({
type: ActionTypes.GET_PROFILE_DATA,
sequence: AsyncActionSequence.Success,
payload: { profiles: { [accountAddress]: newProfile(accountAddress) } },
sequence: AsyncActionSequence.Failure,
payload: e.message,
});
}
} catch (e) {
// eslint-disable-next-line no-console
console.error("Error getting profile from 3box", e);
dispatch({
type: ActionTypes.GET_PROFILE_DATA,
sequence: AsyncActionSequence.Failure,
payload: e.message,
});
}
};
}
Expand Down
1 change: 1 addition & 0 deletions src/actions/web3Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConnectAction = IAsyncAction<"WEB3_CONNECT", void, IWeb3State>;

export function setCurrentAccount(accountAddress: string):
(dispatch: Redux.Dispatch<any, any>, _getState: unknown) => Promise<void> {

return async (dispatch: Redux.Dispatch<any, any>, _getState: unknown) => {
const payload = {
currentAccountAddress: accountAddress?.toLowerCase(),
Expand Down
26 changes: 21 additions & 5 deletions src/components/Account/AccountProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

import BN = require("bn.js");
import { getProfile, updateProfile } from "actions/profilesActions";
import { enableWalletProvider, getArc } from "arc";
import { enableWalletProvider, getArc, getAccountIsEnabled } from "arc";
import classNames from "classnames";
import AccountImage from "components/Account/AccountImage";
import Reputation from "components/Account/Reputation";
Expand Down Expand Up @@ -35,6 +35,7 @@ interface IStateProps {
accountProfile?: IProfileState;
currentAccountAddress: string;
daoAvatarAddress: string;
isConnected: boolean;
threeBox: any;
}

Expand All @@ -58,6 +59,7 @@ const mapStateToProps = (state: IRootState, ownProps: IExternalProps): IExternal
accountProfile: state.profiles[accountAddress],
currentAccountAddress: state.web3.currentAccountAddress,
daoAvatarAddress,
isConnected: getAccountIsEnabled(),
threeBox: state.profiles.threeBox,
};
};
Expand Down Expand Up @@ -93,7 +95,7 @@ class AccountProfilePage extends React.Component<IProps, IState> {
};
}

public async componentDidMount(): Promise<void> {
public componentDidMount(): void {
const { accountAddress, getProfile, accountProfile} = this.props;

if (!accountProfile) {
Expand All @@ -118,6 +120,7 @@ class AccountProfilePage extends React.Component<IProps, IState> {
public handleFormSubmit = async (values: IFormValues, { _props, setSubmitting, _setErrors }: any): Promise<void> => {
const { currentAccountAddress, showNotification, updateProfile } = this.props;

// hopefully this isn't necessasry at this point
if (!await enableWalletProvider({ showNotification })) { setSubmitting(false); return; }

if (this.props.threeBox || parseInt(localStorage.getItem("dontShowThreeboxModal"))) {
Expand All @@ -129,6 +132,10 @@ class AccountProfilePage extends React.Component<IProps, IState> {
setSubmitting(false);
}

public handleConnect = () => {
enableWalletProvider({ showNotification });
}

private closeThreeboxModal = (_e: any): void => {
this.setState({ showThreeBoxModal: false });
}
Expand All @@ -142,8 +149,9 @@ class AccountProfilePage extends React.Component<IProps, IState> {
return <Loading/>;
}

// TODO: dont show profile until loaded from 3box
const editing = currentAccountAddress && accountAddress === currentAccountAddress;
// TODO: dont show profile until loaded from 3box and we are fully in sync with the actual current account
const canEdit = !currentAccountAddress || (accountAddress === currentAccountAddress);
const editing = currentAccountAddress && (accountAddress === currentAccountAddress) && this.props.isConnected;

const profileContainerClass = classNames({
[css.profileContainer]: true,
Expand Down Expand Up @@ -252,7 +260,7 @@ class AccountProfilePage extends React.Component<IProps, IState> {
<div className={css.saveProfile}>
<button className={css.submitButton} type="submit" disabled={isSubmitting}>
<img className={css.loading} src="/assets/images/Icon/Loading-black.svg" />
SUBMIT
Submit
</button>
</div>
</div>
Expand Down Expand Up @@ -295,6 +303,14 @@ class AccountProfilePage extends React.Component<IProps, IState> {
<span>{accountAddress.substr(0, 20)}...</span>
<CopyToClipboard value={accountAddress} color={IconColor.Black}/>
</div>
{(canEdit && !editing) ?
<div className={css.saveProfile}>
<button className={css.submitButton} type="button" onClick={this.handleConnect}>
{currentAccountAddress ? "Edit" : "Try Edit"}
</button>
</div>
: ""
}
</div>
</div>
</form>
Expand Down

0 comments on commit 0c53b00

Please sign in to comment.