Skip to content

Commit

Permalink
fix: network switch, another great ux improvement (#4608)
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Feb 7, 2024
2 parents 843d739 + a706155 commit 29944a3
Show file tree
Hide file tree
Showing 25 changed files with 42 additions and 152 deletions.
7 changes: 1 addition & 6 deletions apps/web/src/components/Composer/NewPublication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import { useState } from 'react';
import toast from 'react-hot-toast';
import useCreatePoll from 'src/hooks/useCreatePoll';
import useCreatePublication from 'src/hooks/useCreatePublication';
import useHandleWrongNetwork from 'src/hooks/useHandleWrongNetwork';
import usePublicationMetadata from 'src/hooks/usePublicationMetadata';
import { useCollectModuleStore } from 'src/store/non-persisted/publication/useCollectModuleStore';
import { useOpenActionStore } from 'src/store/non-persisted/publication/useOpenActionStore';
Expand Down Expand Up @@ -180,6 +179,7 @@ const NewPublication: FC<NewPublicationProps> = ({ publication }) => {
const resetLiveVideoConfig = usePublicationLiveStore(
(state) => state.resetLiveVideoConfig
);

const setLicense = usePublicationLicenseStore((state) => state.setLicense);

// Collect module store
Expand Down Expand Up @@ -207,7 +207,6 @@ const NewPublication: FC<NewPublicationProps> = ({ publication }) => {
const [editor] = useLexicalComposerContext();
const createPoll = useCreatePoll();
const getMetadata = usePublicationMetadata();
const handleWrongNetwork = useHandleWrongNetwork();

const { canUseLensManager, isSponsored } =
checkDispatcherPermissions(currentProfile);
Expand Down Expand Up @@ -354,10 +353,6 @@ const NewPublication: FC<NewPublicationProps> = ({ publication }) => {
toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

if (isComment && publication.momoka?.proof && !isSponsored) {
return toast.error(
'Momoka is currently in beta - during this time certain actions are not available to all profiles.'
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/Publication/Actions/Share/Mirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const Mirror: FC<MirrorProps> = ({ isLoading, publication, setIsLoading }) => {
isMomokaPublication = false
) => {
const { id, typedData } = generatedData;
await handleWrongNetwork();

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -227,10 +228,6 @@ const Mirror: FC<MirrorProps> = ({ isLoading, publication, setIsLoading }) => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

if (publication.momoka?.proof && !isSponsored) {
return toast.error(
'Momoka is currently in beta - during this time certain actions are not available to all profiles.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const CollectAction: FC<CollectActionProps> = ({

const typedDataGenerator = async (generatedData: any) => {
const { id, typedData } = generatedData;
await handleWrongNetwork();

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -335,10 +336,6 @@ const CollectAction: FC<CollectActionProps> = ({
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
if (isLegacyCollectModule) {
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/Settings/Account/SuperFollow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const SuperFollow: FC = () => {
const { followModule, followModuleInitData, profileId } =
typedData.value;
const args = [profileId, followModule, followModuleInitData];
await handleWrongNetwork();

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -158,10 +159,6 @@ const SuperFollow: FC = () => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
return await createSetFollowModuleTypedData({
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/Settings/Allowance/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ const AllowanceButton: FC<AllowanceButtonProps> = ({
value: string,
selectedModule: string
) => {
if (handleWrongNetwork()) {
return;
}

try {
const isUnknownModule =
module.moduleName === OpenActionModuleType.UnknownOpenActionModule;
Expand All @@ -107,6 +103,7 @@ const AllowanceButton: FC<AllowanceButtonProps> = ({
}
}
});
await handleWrongNetwork();

return sendTransaction?.({
account: data?.generateModuleCurrencyApprovalData.from,
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/components/Settings/Danger/Delete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ const DeleteSettings: FC = () => {
});
};

const handleDelete = () => {
const handleDelete = async () => {
if (!currentProfile) {
return toast.error(Errors.SignWallet);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
await handleWrongNetwork();
return write({ args: [currentProfile?.id] });
} catch (error) {
onError(error);
Expand Down
7 changes: 2 additions & 5 deletions apps/web/src/components/Settings/Danger/Guardian.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ const GuardianSettings: FC = () => {
});
};

const handleDisable = () => {
const handleDisable = async () => {
if (!currentProfile) {
return toast.error(Errors.SignWallet);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
await handleWrongNetwork();
return write();
} catch (error) {
onError(error);
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/Settings/Handles/LinkHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const LinkHandle: FC = () => {
onCompleted: async ({ createLinkHandleToProfileTypedData }) => {
const { id, typedData } = createLinkHandleToProfileTypedData;
const signature = await signTypedDataAsync(getSignature(typedData));
await handleWrongNetwork();
setLensHubOnchainSigNonce(lensHubOnchainSigNonce + 1);

if (canBroadcast) {
Expand Down Expand Up @@ -145,10 +146,6 @@ const LinkHandle: FC = () => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

const confirmation = confirm('Are you sure you want to link this handle?');

if (!confirmation) {
Expand Down
5 changes: 1 addition & 4 deletions apps/web/src/components/Settings/Handles/UnlinkHandle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const UnlinkHandle: FC = () => {
useCreateUnlinkHandleFromProfileTypedDataMutation({
onCompleted: async ({ createUnlinkHandleFromProfileTypedData }) => {
const { id, typedData } = createUnlinkHandleFromProfileTypedData;
await handleWrongNetwork();

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -135,10 +136,6 @@ const UnlinkHandle: FC = () => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setUnlinking(true);
const request: UnlinkHandleFromProfileRequest = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
useCreateChangeProfileManagersTypedDataMutation({
onCompleted: async ({ createChangeProfileManagersTypedData }) => {
const { id, typedData } = createChangeProfileManagersTypedData;
const signature = await signTypedDataAsync(getSignature(typedData));
const {
approvals,
configNumber,
Expand All @@ -109,8 +108,10 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
configNumber,
switchToGivenConfig
];
await handleWrongNetwork();

if (!isTba && canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
const { data } = await broadcastOnchain({
variables: { request: { id, signature } }
});
Expand All @@ -130,10 +131,6 @@ const ToggleLensManager: FC<ToggleLensManagerProps> = ({
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
return await createChangeProfileManagersTypedData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ const AddProfileManager: FC<AddProfileManagerProps> = ({
configNumber,
switchToGivenConfig
];
await handleWrongNetwork();

try {
if (!isTba && canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -144,10 +146,6 @@ const AddProfileManager: FC<AddProfileManagerProps> = ({
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
return await createChangeProfileManagersTypedData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ const List: FC = () => {
useCreateChangeProfileManagersTypedDataMutation({
onCompleted: async ({ createChangeProfileManagersTypedData }) => {
const { id, typedData } = createChangeProfileManagersTypedData;
const signature = await signTypedDataAsync(getSignature(typedData));
setLensHubOnchainSigNonce(lensHubOnchainSigNonce + 1);
const {
approvals,
configNumber,
Expand All @@ -108,8 +106,11 @@ const List: FC = () => {
configNumber,
switchToGivenConfig
];
await handleWrongNetwork();
setLensHubOnchainSigNonce(lensHubOnchainSigNonce + 1);

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
const { data } = await broadcastOnchain({
variables: { request: { id, signature } }
});
Expand All @@ -129,10 +130,6 @@ const List: FC = () => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setRemovingAddress(address);
return await createChangeProfileManagersTypedData({
Expand Down
13 changes: 1 addition & 12 deletions apps/web/src/components/Settings/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ const ProfileSettingsForm: FC = () => {
onCompleted: async ({ createOnchainSetProfileMetadataTypedData }) => {
const { id, typedData } = createOnchainSetProfileMetadataTypedData;
const { metadataURI, profileId } = typedData.value;
await handleWrongNetwork();

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
Expand Down Expand Up @@ -231,10 +232,6 @@ const ProfileSettingsForm: FC = () => {
return toast.error(Errors.Suspended);
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
const otherAttributes =
Expand Down Expand Up @@ -300,14 +297,6 @@ const ProfileSettingsForm: FC = () => {
};

const uploadAndSave = async (type: 'avatar' | 'cover') => {
if (!currentProfile) {
return toast.error(Errors.SignWallet);
}

if (handleWrongNetwork()) {
return;
}

try {
const croppedImage = await getCroppedImg(
type === 'avatar' ? profilePictureSrc : coverPictureSrc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ const BlockOrUnBlockProfile: FC = () => {

const typedDataGenerator = async (generatedData: any) => {
const { id, typedData } = generatedData;
const signature = await signTypedDataAsync(getSignature(typedData));
await handleWrongNetwork();
setLensHubOnchainSigNonce(lensHubOnchainSigNonce + 1);

if (canBroadcast) {
const signature = await signTypedDataAsync(getSignature(typedData));
const { data } = await broadcastOnchain({
variables: { request: { id, signature } }
});
Expand Down Expand Up @@ -176,10 +177,6 @@ const BlockOrUnBlockProfile: FC = () => {
return;
}

if (handleWrongNetwork()) {
return;
}

try {
setIsLoading(true);
const request: BlockRequest | UnblockRequest = {
Expand Down
29 changes: 0 additions & 29 deletions apps/web/src/components/Shared/Auth/WrongNetwork.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,13 @@ const ProtectProfile: FC = () => {
).toISOString();
const isCoolOffPassed = new Date(coolOffDate).getTime() < Date.now();

const handleProtect = () => {
const handleProtect = async () => {
if (!currentProfile) {
return toast.error(Errors.SignWallet);
}

if (handleWrongNetwork()) {
return;
}

try {
await handleWrongNetwork();
return write();
} catch (error) {
onError(error);
Expand Down

1 comment on commit 29944a3

@vercel
Copy link

@vercel vercel bot commented on 29944a3 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

web – ./apps/web

heyxyz.vercel.app
web-heyxyz.vercel.app
web-git-main-heyxyz.vercel.app
hey.xyz

Please sign in to comment.