Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ERC20 Launchpad] - Endpoint integration for Community information step #9230

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface CreateCommunityProps {
socialLinks: string[];
userAddress: string;
isPWA?: boolean;
tokenName?: string;
}

export const buildCreateCommunityInput = ({
Expand All @@ -23,6 +24,7 @@ export const buildCreateCommunityInput = ({
iconUrl,
socialLinks,
userAddress,
tokenName,
chainNodeId,
}: CreateCommunityProps) => {
const nameToSymbol = name.toUpperCase().slice(0, 4);
Expand All @@ -36,6 +38,7 @@ export const buildCreateCommunityInput = ({
user_address: userAddress,
type: ChainType.Offchain,
default_symbol: nameToSymbol,
token_name: tokenName,
chain_node_id: chainNodeId,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const CommunityInformationForm = ({
isCreatingCommunity,
submitBtnLabel,
}: CommunityInformationFormProps) => {
const [communityName, setCommunityName] = useState('');
const [communityName, setCommunityName] = useState(
initialValues?.communityName || '',
);
const [isProcessingProfileImage, setIsProcessingProfileImage] =
useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const LaunchToken = () => {
const {
createTokenCommunityStep,
onChangeStep,
createdTokenInfo,
selectedAddress,
setSelectedAddress,
createdTokenInfo,
setCreatedTokenInfo,
} = useCreateCommunity();

Expand Down Expand Up @@ -60,6 +60,7 @@ const LaunchToken = () => {
handleGoBack={() => onChangeStep(false)}
handleContinue={() => onChangeStep(true)}
tokenInfo={createdTokenInfo}
selectedAddress={selectedAddress}
/>
);
case CreateTokenCommunityStep.SignatureLaunch:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,98 @@
import { ChainBase, commonProtocol } from '@hicommonwealth/shared';
import { notifyError } from 'controllers/app/notifications';
import useAppStatus from 'hooks/useAppStatus';
import { useBrowserAnalyticsTrack } from 'hooks/useBrowserAnalyticsTrack';
import AddressInfo from 'models/AddressInfo';
import React from 'react';
import {
BaseMixpanelPayload,
MixpanelCommunityCreationEvent,
MixpanelLoginPayload,
} from 'shared/analytics/types';
import useCreateCommunityMutation, {
buildCreateCommunityInput,
} from 'state/api/communities/createCommunity';
import { fetchCachedNodes } from 'state/api/nodes';
import CommunityInformationForm from 'views/components/CommunityInformationForm/CommunityInformationForm';
import { CommunityInformationFormSubmitValues } from 'views/components/CommunityInformationForm/types';
import { CWText } from 'views/components/component_kit/cw_text';
import CWBanner from 'views/components/component_kit/new_designs/CWBanner';
import { openConfirmation } from 'views/modals/confirmation_modal';
import { TokenInfo } from '../../types';
import './CommunityInformationStep.scss';
import { generateCommunityNameFromToken } from './utils';

interface CommunityInformationStepProps {
handleGoBack: () => void;
handleContinue: () => void;
tokenInfo?: TokenInfo;
selectedAddress?: AddressInfo;
}

const CommunityInformationStep = ({
handleGoBack,
handleContinue,
tokenInfo,
selectedAddress,
}: CommunityInformationStepProps) => {
const { isAddedToHomeScreen } = useAppStatus();

const initialValues = {
communityName: generateCommunityNameFromToken({
tokenName: tokenInfo?.name || '',
tokenSymbol: tokenInfo?.symbol || '',
}),
communityDescription: tokenInfo?.description || '',
communityProfileImageURL: tokenInfo?.imageURL || '',
};

const { trackAnalytics } = useBrowserAnalyticsTrack<
MixpanelLoginPayload | BaseMixpanelPayload
>({
onAction: true,
});

const handleSubmit = async (values: unknown) => {
// TODO 8706: integrate endpoint
console.log('values => ', values);
await new Promise((r) => setTimeout(r, 10));
handleContinue();
const {
mutateAsync: createCommunityMutation,
isLoading: createCommunityLoading,
} = useCreateCommunityMutation();

const handleSubmit = async (
values: CommunityInformationFormSubmitValues & { communityId: string },
) => {
// this condition will never be fulfilled but adding this to avoid typescript errors
mzparacha marked this conversation as resolved.
Show resolved Hide resolved
if (!selectedAddress) {
notifyError('No address selected');
return;
}

const nodes = fetchCachedNodes();
const baseNode = nodes?.find(
(n) => n.ethChainId === commonProtocol.ValidChains.Base,
);
if (!baseNode || !baseNode.ethChainId) {
notifyError('Could not find base chain node');
return;
}

try {
const input = buildCreateCommunityInput({
id: values.communityId,
name: values.communityName,
chainBase: ChainBase.Ethereum,
description: values.communityDescription,
iconUrl: values.communityProfileImageURL,
socialLinks: values.links ?? [],
userAddress: selectedAddress.address,
chainNodeId: baseNode.ethChainId,
isPWA: isAddedToHomeScreen,
tokenName: tokenInfo?.name || '',
});
await createCommunityMutation(input);
handleContinue();
} catch (err) {
notifyError(err.message);
}
};

const handleCancel = () => {
Expand Down Expand Up @@ -81,9 +138,10 @@ const CommunityInformationStep = ({
<CommunityInformationForm
onSubmit={handleSubmit}
onCancel={handleCancel}
isCreatingCommunity={false}
isCreatingCommunity={createCommunityLoading}
submitBtnLabel="Next"
withSocialLinks={true}
initialValues={initialValues}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const generateCommunityNameFromToken = ({
tokenName,
tokenSymbol,
}: {
tokenName: string;
tokenSymbol: string;
}) => {
return `${tokenName} (${tokenSymbol}) Community`;
};
Loading