From 0c53b0059287f2f0b370805deb628bf1107dd829 Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Wed, 29 Jul 2020 09:40:32 -0400 Subject: [PATCH] clean up account profile loguc --- src/actions/profilesActions.ts | 84 ++++++++++--------- src/actions/web3Actions.ts | 1 + src/components/Account/AccountProfilePage.tsx | 26 ++++-- 3 files changed, 65 insertions(+), 46 deletions(-) diff --git a/src/actions/profilesActions.ts b/src/actions/profilesActions.ts index 03b6c7ea7..d74fde6b7 100644 --- a/src/actions/profilesActions.ts +++ b/src/actions/profilesActions.ts @@ -121,61 +121,63 @@ export function getProfile(accountAddress: string, currentAccount = false): (dispatch: Redux.Dispatch, _getState: () => IRootState) => Promise { return async (dispatch: Redux.Dispatch, _getState: () => IRootState): Promise => { - 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, - }); } }; } diff --git a/src/actions/web3Actions.ts b/src/actions/web3Actions.ts index 5ec18667a..1483065b1 100644 --- a/src/actions/web3Actions.ts +++ b/src/actions/web3Actions.ts @@ -11,6 +11,7 @@ export type ConnectAction = IAsyncAction<"WEB3_CONNECT", void, IWeb3State>; export function setCurrentAccount(accountAddress: string): (dispatch: Redux.Dispatch, _getState: unknown) => Promise { + return async (dispatch: Redux.Dispatch, _getState: unknown) => { const payload = { currentAccountAddress: accountAddress?.toLowerCase(), diff --git a/src/components/Account/AccountProfilePage.tsx b/src/components/Account/AccountProfilePage.tsx index 300b5de99..241752db7 100644 --- a/src/components/Account/AccountProfilePage.tsx +++ b/src/components/Account/AccountProfilePage.tsx @@ -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"; @@ -35,6 +35,7 @@ interface IStateProps { accountProfile?: IProfileState; currentAccountAddress: string; daoAvatarAddress: string; + isConnected: boolean; threeBox: any; } @@ -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, }; }; @@ -93,7 +95,7 @@ class AccountProfilePage extends React.Component { }; } - public async componentDidMount(): Promise { + public componentDidMount(): void { const { accountAddress, getProfile, accountProfile} = this.props; if (!accountProfile) { @@ -118,6 +120,7 @@ class AccountProfilePage extends React.Component { public handleFormSubmit = async (values: IFormValues, { _props, setSubmitting, _setErrors }: any): Promise => { 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"))) { @@ -129,6 +132,10 @@ class AccountProfilePage extends React.Component { setSubmitting(false); } + public handleConnect = () => { + enableWalletProvider({ showNotification }); + } + private closeThreeboxModal = (_e: any): void => { this.setState({ showThreeBoxModal: false }); } @@ -142,8 +149,9 @@ class AccountProfilePage extends React.Component { return ; } - // 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, @@ -252,7 +260,7 @@ class AccountProfilePage extends React.Component {
@@ -295,6 +303,14 @@ class AccountProfilePage extends React.Component { {accountAddress.substr(0, 20)}... + {(canEdit && !editing) ? +
+ +
+ : "" + }