Skip to content

Commit bac33dc

Browse files
authored
Merge pull request #386 from LIT-Protocol/feat/faster-app-connecting
feat(dashboard): faster app connections
2 parents 6288c46 + 2c1b215 commit bac33dc

File tree

9 files changed

+84
-71
lines changed

9 files changed

+84
-71
lines changed

packages/apps/app-dashboard/src/components/user-dashboard/connect/ConnectPage.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
2020
import { BigNumber } from 'ethers';
2121
import { addPayee } from '@/utils/user-dashboard/addPayee';
2222
import { usePendingAppConnectPkp } from '@/hooks/user-dashboard/connect/usePendingAppConnectPkp';
23+
import { wait } from '@/lib/utils';
2324

2425
interface ConnectPageProps {
2526
connectInfoMap: ConnectInfoMap;
@@ -67,23 +68,20 @@ export function ConnectPage({
6768
// Handle redirect when JWT is ready
6869
useEffect(() => {
6970
if (redirectUrl && !localSuccess) {
70-
setLocalSuccess('Success! Redirecting to app...');
71-
setTimeout(() => {
71+
(async () => {
72+
setLocalSuccess('Success! Redirecting to app...');
73+
await wait(1000);
7274
executeRedirect();
73-
}, 2000);
75+
})();
7476
}
7577
}, [redirectUrl, localSuccess, executeRedirect]);
7678

7779
// Generate JWT when agentPKP is set and permissions are granted
7880
useEffect(() => {
7981
if (agentPKP && localSuccess === 'Permissions granted successfully!') {
80-
const timer = setTimeout(async () => {
81-
setLocalSuccess(null);
82-
await generateJWT(connectInfoMap.app, connectInfoMap.app.activeVersion!);
83-
}, 1000);
84-
return () => clearTimeout(timer);
82+
setLocalSuccess(null);
83+
generateJWT(connectInfoMap.app, connectInfoMap.app.activeVersion!);
8584
}
86-
return undefined;
8785
}, [agentPKP, localSuccess, generateJWT, connectInfoMap.app]);
8886

8987
const handleSubmit = useCallback(async () => {

packages/apps/app-dashboard/src/components/user-dashboard/connect/EditPermissionsCard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1919
import { useFormatUserPermissions } from '@/hooks/user-dashboard/dashboard/useFormatUserPermissions';
2020
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
2121
import { litNodeClient } from '@/utils/user-dashboard/lit';
22+
import { wait } from '@/lib/utils';
2223

2324
interface EditPermissionsCardProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -57,10 +58,11 @@ export function EditPermissionsCard({
5758
// Handle redirect when JWT is ready
5859
useEffect(() => {
5960
if (redirectUrl && !localSuccess) {
60-
setLocalSuccess('Success! Redirecting to app...');
61-
setTimeout(() => {
61+
(async () => {
62+
setLocalSuccess('Success! Redirecting to app...');
63+
await wait(1000);
6264
executeRedirect();
63-
}, 2000);
65+
})();
6466
}
6567
}, [redirectUrl, localSuccess, executeRedirect]);
6668

packages/apps/app-dashboard/src/components/user-dashboard/connect/RepermitConnect.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ActionButtons } from './ui/ActionButtons';
1414
import { theme } from './ui/theme';
1515
import { InfoBanner } from './ui/InfoBanner';
1616
import { App } from '@/types/developer-dashboard/appTypes';
17+
import { wait } from '@/lib/utils';
1718

1819
interface RepermitConnectProps {
1920
appData: App;
@@ -44,22 +45,21 @@ export function RepermitConnect({
4445
// Handle redirect when JWT is ready
4546
useEffect(() => {
4647
if (redirectUrl && localSuccess !== 'Success! Redirecting to app...') {
47-
setLocalSuccess('Success! Redirecting to app...');
48-
setTimeout(() => {
48+
(async () => {
49+
setLocalSuccess('Success! Redirecting to app...');
50+
await wait(1000);
4951
executeRedirect();
50-
}, 2000);
52+
})();
5153
}
5254
}, [redirectUrl, localSuccess, executeRedirect]);
5355

5456
// Generate JWT when re-permitting is successful
5557
useEffect(() => {
5658
if (localSuccess === 'App re-permitted successfully!') {
57-
const timer = setTimeout(async () => {
59+
(async () => {
5860
await generateJWT(appData, appData.activeVersion!);
59-
}, 1000);
60-
return () => clearTimeout(timer);
61+
})();
6162
}
62-
return undefined;
6363
}, [localSuccess, generateJWT, appData]);
6464

6565
const handleSubmit = useCallback(async () => {

packages/apps/app-dashboard/src/components/user-dashboard/connect/ReturningUserConnect.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useCanGoBack } from '@/hooks/user-dashboard/connect/useCanGoBack';
1212
import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1313
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
1414
import { App, AppVersion } from '@/types/developer-dashboard/appTypes';
15+
import { wait } from '@/lib/utils';
1516

1617
type ReturningUserConnectProps = {
1718
appData: App;
@@ -46,10 +47,11 @@ export function ReturningUserConnect({
4647
// Handle redirect when JWT is ready
4748
useEffect(() => {
4849
if (redirectUrl && !localSuccess) {
49-
setLocalSuccess('Success! Redirecting to app...');
50-
setTimeout(() => {
50+
(async () => {
51+
setLocalSuccess('Success! Redirecting to app...');
52+
await wait(1000);
5153
executeRedirect();
52-
}, 2000);
54+
})();
5355
}
5456
}, [redirectUrl, localSuccess, executeRedirect]);
5557

packages/apps/app-dashboard/src/components/user-dashboard/connect/UpdateVersionCard.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { useConnectFormData } from '@/hooks/user-dashboard/connect/useConnectFor
2020
import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
2121
import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
2222
import { litNodeClient } from '@/utils/user-dashboard/lit';
23+
import { wait } from '@/lib/utils';
2324

2425
interface UpdateVersionCardProps {
2526
connectInfoMap: ConnectInfoMap;
@@ -56,10 +57,11 @@ export function UpdateVersionCard({
5657
// Handle redirect when JWT is ready
5758
useEffect(() => {
5859
if (redirectUrl && !localSuccess) {
59-
setLocalSuccess('Success! Redirecting to app...');
60-
setTimeout(() => {
60+
(async () => {
61+
setLocalSuccess('Success! Redirecting to app...');
62+
await wait(1000);
6163
executeRedirect();
62-
}, 2000);
64+
})();
6365
}
6466
}, [redirectUrl, localSuccess, executeRedirect]);
6567

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/RepermitConnectPage.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { ConnectAppHeader } from '../connect/ui/ConnectAppHeader';
1616
import { PageHeader } from './ui/PageHeader';
1717
import { ActionButtons } from '../connect/ui/ActionButtons';
1818
import { Breadcrumb } from '@/components/shared/ui/Breadcrumb';
19+
import { wait } from '@/lib/utils';
1920

2021
interface RepermitConnectPageProps {
2122
appData: App;
@@ -55,10 +56,11 @@ export function RepermitConnectPage({
5556
// Handle redirect when JWT is ready
5657
useEffect(() => {
5758
if (redirectUrl && !localSuccess) {
58-
setLocalSuccess('Success! Redirecting to app...');
59-
setTimeout(() => {
59+
(async () => {
60+
setLocalSuccess('Success! Redirecting to app...');
61+
await wait(1000);
6062
executeRedirect();
61-
}, 2000);
63+
})();
6264
}
6365
}, [redirectUrl, localSuccess, executeRedirect]);
6466

@@ -94,17 +96,16 @@ export function RepermitConnectPage({
9496
setIsConnectProcessing(false);
9597
setLocalSuccess('App re-permitted successfully!');
9698

97-
// Generate JWT for redirect after short delay
98-
setTimeout(async () => {
99-
setLocalSuccess(null);
100-
// Only generate JWT if there's an effectiveRedirectUri (for app redirects)
101-
if (effectiveRedirectUri) {
102-
await generateJWT(appData, appData.activeVersion!);
103-
} else {
104-
// Navigate to the app permissions page with full refresh to update sidebar
105-
window.location.href = `/user/appId/${appData.appId}`;
106-
}
107-
}, 3000);
99+
// Generate JWT for redirect or navigate after showing success message
100+
await wait(2000);
101+
setLocalSuccess(null);
102+
// Only generate JWT if there's an effectiveRedirectUri (for app redirects)
103+
if (effectiveRedirectUri) {
104+
await generateJWT(appData, appData.activeVersion!);
105+
} else {
106+
// Navigate to the app permissions page with full refresh to update sidebar
107+
window.location.href = `/user/appId/${appData.appId}`;
108+
}
108109
} catch (error) {
109110
setLocalError(error instanceof Error ? error.message : 'Failed to re-permit app');
110111
setIsConnectProcessing(false);

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/UpdateVersionPage.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { useJwtRedirect } from '@/hooks/user-dashboard/connect/useJwtRedirect';
1919
import { useUrlRedirectUri } from '@/hooks/user-dashboard/connect/useUrlRedirectUri';
2020
import { ActionButtons } from '@/components/user-dashboard/connect/ui/ActionButtons';
2121
import { Breadcrumb } from '@/components/shared/ui/Breadcrumb';
22+
import { wait } from '@/lib/utils';
2223

2324
interface UpdateVersionPageProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -53,10 +54,11 @@ export function UpdateVersionPage({
5354
// Handle redirect when JWT is ready
5455
useEffect(() => {
5556
if (redirectUrl && !localSuccess) {
56-
setLocalSuccess('Success! Redirecting to app...');
57-
setTimeout(() => {
57+
(async () => {
58+
setLocalSuccess('Success! Redirecting to app...');
59+
await wait(1000);
5860
executeRedirect();
59-
}, 2000);
61+
})();
6062
}
6163
}, [redirectUrl, localSuccess, executeRedirect]);
6264

@@ -120,18 +122,17 @@ export function UpdateVersionPage({
120122
});
121123

122124
setLocalStatus(null);
123-
// Show success state for 3 seconds, then redirect or reload
125+
// Show success state then redirect or reload
124126
setLocalSuccess('Version updated successfully!');
125-
setTimeout(async () => {
126-
setLocalSuccess(null);
127-
// Only generate JWT if there's a redirectUri (for app redirects)
128-
if (redirectUri) {
129-
await generateJWT(connectInfoMap.app, connectInfoMap.app.activeVersion!);
130-
} else {
131-
// Navigate to the app permissions page with full refresh to update sidebar
132-
window.location.href = `/user/appId/${connectInfoMap.app.appId}`;
133-
}
134-
}, 3000);
127+
await wait(2000);
128+
setLocalSuccess(null);
129+
// Only generate JWT if there's a redirectUri (for app redirects)
130+
if (redirectUri) {
131+
await generateJWT(connectInfoMap.app, connectInfoMap.app.activeVersion!);
132+
} else {
133+
// Navigate to the app permissions page with full refresh to update sidebar
134+
window.location.href = `/user/appId/${connectInfoMap.app.appId}`;
135+
}
135136
} catch (error) {
136137
setLocalError(error instanceof Error ? error.message : 'Failed to update version');
137138
setLocalStatus(null);

packages/apps/app-dashboard/src/components/user-dashboard/dashboard/UserPermissionPage.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ReadAuthInfo } from '@/hooks/user-dashboard/useAuthInfo';
1919
import { AppVersion } from '@/types/developer-dashboard/appTypes';
2020
import { hasConfigurablePolicies } from '@/utils/user-dashboard/hasConfigurablePolicies';
2121
import { litNodeClient } from '@/utils/user-dashboard/lit';
22+
import { wait } from '@/lib/utils';
2223

2324
interface AppPermissionPageProps {
2425
connectInfoMap: ConnectInfoMap;
@@ -65,10 +66,11 @@ export function AppPermissionPage({
6566
// Handle redirect when JWT is ready
6667
useEffect(() => {
6768
if (redirectUrl && !localSuccess) {
68-
setLocalSuccess('Success! Redirecting to app...');
69-
setTimeout(() => {
69+
(async () => {
70+
setLocalSuccess('Success! Redirecting to app...');
71+
await wait(1000);
7072
executeRedirect();
71-
}, 2000);
73+
})();
7274
}
7375
}, [redirectUrl, localSuccess, executeRedirect]);
7476

@@ -176,9 +178,8 @@ export function AppPermissionPage({
176178
if (!hasAnyChanges) {
177179
setLocalStatus(null);
178180
setLocalSuccess('Permissions are up to date.');
179-
setTimeout(() => {
180-
setLocalSuccess(null);
181-
}, 3000);
181+
await wait(2000);
182+
setLocalSuccess(null);
182183
return;
183184
}
184185

@@ -211,17 +212,16 @@ export function AppPermissionPage({
211212
console.log('[UserPermissionPage] setAbilityPolicyParameters result:', result);
212213

213214
setLocalStatus(null);
214-
// Show success state for 3 seconds, then handle redirect or clear success
215+
// Show success state then handle redirect or clear success
215216
setLocalSuccess('Permissions granted successfully!');
216217

217218
// Generate JWT for redirect (useJwtRedirect will handle if there's a redirectUri)
218-
setTimeout(async () => {
219-
setLocalSuccess(null);
220-
// Only generate JWT if there's a redirectUri (for app redirects)
221-
if (redirectUri) {
222-
await generateJWT(connectInfoMap.app, Number(permittedVersion));
223-
}
224-
}, 3000);
219+
await wait(2000);
220+
setLocalSuccess(null);
221+
// Only generate JWT if there's a redirectUri (for app redirects)
222+
if (redirectUri) {
223+
await generateJWT(connectInfoMap.app, Number(permittedVersion));
224+
}
225225
} catch (error) {
226226
setLocalError(error instanceof Error ? error.message : 'Failed to permit app');
227227
setLocalStatus(null);
@@ -279,10 +279,9 @@ export function AppPermissionPage({
279279
setLocalStatus(null);
280280
// Show success state until redirect
281281
setLocalSuccess('App unpermitted successfully!');
282-
setTimeout(() => {
283-
// Force the refresh for the sidebar to update
284-
window.location.href = `/user/apps`;
285-
}, 3000);
282+
// Force the refresh for the sidebar to update after showing success message
283+
await wait(2000);
284+
window.location.href = `/user/apps`;
286285
} catch (error) {
287286
setLocalError(error instanceof Error ? error.message : 'Failed to unpermit app');
288287
setLocalStatus(null);

packages/apps/app-dashboard/src/lib/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,11 @@ import { twMerge } from 'tailwind-merge';
44
export function cn(...inputs: ClassValue[]) {
55
return twMerge(clsx(inputs));
66
}
7+
8+
/**
9+
* Utility function to wait for a specified amount of time
10+
* @param time Time to wait in milliseconds (default: 3000ms)
11+
*/
12+
export async function wait(time = 3_000): Promise<void> {
13+
await new Promise((resolve) => setTimeout(resolve, time));
14+
}

0 commit comments

Comments
 (0)