From 3646b39d063313b49922a2bbe770ed35c2488659 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 12:58:30 -0700 Subject: [PATCH 01/56] trying to clean up auth and get it to work... --- .../ReactNativeBridgePrivyAuth.ts | 8 +++ .../ReactNativeBridgeRouter.tsx | 11 +--- .../ReactNativeBridgeUser.tsx | 11 +--- .../components/ReactNativeBridge/types.ts | 14 +++++ .../ReactNativeBridge/usePrivyAuthStatus.ts | 60 +++++++++++++++++++ .../components/ReactNativeBridge/utils.ts | 9 +++ 6 files changed, 93 insertions(+), 20 deletions(-) create mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts create mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/types.ts create mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts create mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/utils.ts diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts new file mode 100644 index 00000000000..429a86543ab --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts @@ -0,0 +1,8 @@ +import { usePrivyAuthStatus } from 'views/components/ReactNativeBridge/usePrivyAuthStatus'; + +/** + * The main bridge that handles the privy auth flow in the client. + */ +export const ReactNativeBridgePrivyAuth = () => { + const privyAuth = usePrivyAuthStatus(); +}; diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeRouter.tsx b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeRouter.tsx index 693167011c7..5555ccff770 100644 --- a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeRouter.tsx +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeRouter.tsx @@ -1,6 +1,7 @@ import type { ReactNativeWebView } from 'hooks/useReactNativeWebView'; import { useCallback, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; +import { messageToObject } from './utils'; declare global { interface Window { @@ -62,16 +63,6 @@ export const ReactNativeBridgeRouter = () => { return null; }; -function messageToObject(message: string | object): object | null { - try { - return typeof message === 'string' ? JSON.parse(message) : message; - } catch (e) { - // this could happen if another library is sending non-JSON data via - // postMessage - return null; - } -} - function getPathAndQuery(url: string): string { // only navigate with the path and query because we don't want to include // the host portion as a notification could be from the official common.xyz diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeUser.tsx b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeUser.tsx index 9aa7ccf5772..4fdf1160d65 100644 --- a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeUser.tsx +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgeUser.tsx @@ -2,16 +2,7 @@ import useUserStore from 'client/scripts/state/ui/user'; import { useReactNativeWebView } from 'hooks/useReactNativeWebView'; import { useEffect, useState } from 'react'; import { useDarkMode } from '../../../state/ui/darkMode/darkMode'; - -/** - * Typed message so that the react-native client knows how to handel this message. - * - * This is teh standard pattern of how to handle postMessage with multiple uses. - */ -type TypedData = { - type: string; - data: Data; -}; +import { TypedData } from './types'; /** * The actual user info that the client needs. diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/types.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/types.ts new file mode 100644 index 00000000000..97bd931c827 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/types.ts @@ -0,0 +1,14 @@ +/** + * Typed message so that the react-native client knows how to handel this message. + * + * This is teh standard pattern of how to handle postMessage with multiple uses. + */ +export type TypedData = { + type: string; + data: Data; +}; + +export interface ReactNativeWebView { + // allows us to send messages to ReactNative. + postMessage: (message: string) => void; +} diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts new file mode 100644 index 00000000000..aa5f74162d9 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts @@ -0,0 +1,60 @@ +import { WalletSsoSource } from '@hicommonwealth/shared'; +import { useCallback, useEffect, useState } from 'react'; +import { messageToObject } from './utils'; + +/** + * When the user is authenticated, this provides the data the user needs to + * authenticate. + */ +export interface UserAuth { + /** + * The privy id which we're providing for debug info. It's not normally used + * otherwise. + */ + id: string; + address: string | null; + identityToken: string; + ssoOAuthToken: string; + ssoProvider: WalletSsoSource; +} + +export interface IPrivyAuthStatus { + enabled: boolean; + authenticated: boolean; + userAuth: UserAuth | null; +} + +export function usePrivyAuthStatus(): IPrivyAuthStatus | null { + const [status, setStatus] = useState(null); + + const handleMessage = useCallback((message: MessageEvent) => { + const obj = messageToObject(message.data); + if (obj && typeof message.data === 'object') { + if (isPrivyAuthStatusMessage(obj)) { + setStatus(obj.data); + } + } + }, []); + + useEffect(() => { + window.addEventListener('message', handleMessage); + + return () => { + window.removeEventListener('message', handleMessage); + }; + }, [handleMessage]); + + return status; +} + +type PrivyAuthStatusMessage = { + type: 'privy.auth-status'; + data: IPrivyAuthStatus; +}; + +function isPrivyAuthStatusMessage( + data: object, +): data is PrivyAuthStatusMessage { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return !!data && (data as any).type === 'privy.auth-status'; +} diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/utils.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/utils.ts new file mode 100644 index 00000000000..314081ea7ef --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/utils.ts @@ -0,0 +1,9 @@ +export function messageToObject(message: string | object): object | null { + try { + return typeof message === 'string' ? JSON.parse(message) : message; + } catch (e) { + // this could happen if another library is sending non-JSON data via + // postMessage + return null; + } +} From fa78c9d1c76886a1927406b5d5037e3dfd523fe0 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 13:33:28 -0700 Subject: [PATCH 02/56] ... basic layout for the privy auth, but I need to think through some things now. --- packages/commonwealth/client/scripts/App.tsx | 23 +++---- .../PrivyMobile/DebugPrivyMobile.tsx | 15 +++++ .../PrivyMobileAuthStatusProvider.ts | 51 ++++++++++++++++ .../PrivyMobile/PrivyMobileAuthenticator.tsx | 22 +++++++ .../views/components/PrivyMobile/types.ts | 23 +++++++ .../usePrivyMobileAuthStatusStore.tsx | 25 ++++++++ .../ReactNativeBridgePrivyAuth.ts | 8 --- .../ReactNativeBridge/usePrivyAuthStatus.ts | 60 ------------------- 8 files changed, 149 insertions(+), 78 deletions(-) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/types.ts create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatusStore.tsx delete mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts delete mode 100644 packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts diff --git a/packages/commonwealth/client/scripts/App.tsx b/packages/commonwealth/client/scripts/App.tsx index 8c900a80a34..ec0363d5028 100644 --- a/packages/commonwealth/client/scripts/App.tsx +++ b/packages/commonwealth/client/scripts/App.tsx @@ -12,6 +12,7 @@ import { queryClient } from 'state/api/config'; import { DefaultPrivyProvider } from 'views/components/DefaultPrivyProvider/DefaultPrivyProvider'; import { DisableMavaOnMobile } from 'views/components/DisableMavaOnMobile'; import ForceMobileAuth from 'views/components/ForceMobileAuth'; +import { PrivyMobileAuthStatusProvider } from 'views/components/PrivyMobile/PrivyMobileAuthStatusProvider'; import { ReactNativeBridgeUser } from 'views/components/ReactNativeBridge'; import { ReactNativeLogForwarder } from 'views/components/ReactNativeBridge/ReactNativeLogForwarder'; import { ReactNativeScrollToTopListener } from 'views/components/ReactNativeBridge/ReactNativeScrollToTopListener'; @@ -37,16 +38,18 @@ const App = () => { {isLoading ? ( ) : ( - - - - - - - - - - + + + + + + + + + + + + )} {import.meta.env.DEV && } diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx new file mode 100644 index 00000000000..a2b2cc41ae9 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; + +export const DebugPrivyMobile = () => { + const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + + return ( +
+
+ :privyMobileAuthStatus: +
+
{JSON.stringify(privyMobileAuthStatus, null, 2)}
+
+ ); +}; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts new file mode 100644 index 00000000000..8a25a7af572 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts @@ -0,0 +1,51 @@ +import { useCallback, useEffect } from 'react'; +import { IPrivyAuthStatus } from 'views/components/PrivyMobile/types'; +import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; +import { messageToObject } from '../ReactNativeBridge/utils'; + +type Props = { + children: React.ReactNode; +}; + +/** + * This keeps the privy auth state, from the mobile app, using mobile privy, + * available for use within the app. + */ +export const PrivyMobileAuthStatusProvider = (props: Props) => { + const { children } = props; + const { setState } = usePrivyMobileAuthStatusStore(); + + const handleMessage = useCallback( + (message: MessageEvent) => { + const obj = messageToObject(message.data); + if (obj && typeof message.data === 'object') { + if (isPrivyAuthStatusMessage(obj)) { + setState({ status: obj.data }); + } + } + }, + [setState], + ); + + useEffect(() => { + window.addEventListener('message', handleMessage); + + return () => { + window.removeEventListener('message', handleMessage); + }; + }, [handleMessage]); + + return children; +}; + +type PrivyAuthStatusMessage = { + type: 'privy.auth-status'; + data: IPrivyAuthStatus; +}; + +function isPrivyAuthStatusMessage( + data: object, +): data is PrivyAuthStatusMessage { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return !!data && (data as any).type === 'privy.auth-status'; +} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx new file mode 100644 index 00000000000..c41c8898a0d --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -0,0 +1,22 @@ +import React, { ReactNode } from 'react'; +import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; +import { LoadingIndicator } from 'views/components/react_quill_editor/loading_indicator'; + +type Props = { + children: ReactNode; +}; + +/** + * Triggers authentication when privy mobile is enabled. + */ +export const PrivyMobileAuthenticator = (props: Props) => { + const { children } = props; + const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + + if (privyMobileAuthStatus?.enabled) { + // the *client* doesn't have privy enabled so do not attempt to authenticate. + return children; + } + + return ; +}; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/types.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/types.ts new file mode 100644 index 00000000000..fdbf6ee83d7 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/types.ts @@ -0,0 +1,23 @@ +import { WalletSsoSource } from '@hicommonwealth/shared'; + +/** + * When the user is authenticated, this provides the data the user needs to + * authenticate. + */ +export interface UserAuth { + /** + * The privy id which we're providing for debug info. It's not normally used + * otherwise. + */ + id: string; + address: string | null; + identityToken: string; + ssoOAuthToken: string; + ssoProvider: WalletSsoSource; +} + +export interface IPrivyAuthStatus { + enabled: boolean; + authenticated: boolean; + userAuth: UserAuth | null; +} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatusStore.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatusStore.tsx new file mode 100644 index 00000000000..1555acd6da9 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatusStore.tsx @@ -0,0 +1,25 @@ +import { createBoundedUseStore } from 'state/ui/utils'; +import { IPrivyAuthStatus } from 'views/components/PrivyMobile/types'; +import { devtools } from 'zustand/middleware'; +import { createStore } from 'zustand/vanilla'; + +type InternalState = { + status: IPrivyAuthStatus | undefined; +}; + +type SMSDialogStore = InternalState & { + setState: (state: InternalState) => void; +}; + +export const privyMobileAuthStatusStore = createStore()( + devtools((set) => ({ + status: undefined, + setState: (newState: InternalState) => set(newState), + })), +); + +const usePrivyMobileAuthStatusStore = createBoundedUseStore( + privyMobileAuthStatusStore, +); + +export default usePrivyMobileAuthStatusStore; diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts deleted file mode 100644 index 429a86543ab..00000000000 --- a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/ReactNativeBridgePrivyAuth.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { usePrivyAuthStatus } from 'views/components/ReactNativeBridge/usePrivyAuthStatus'; - -/** - * The main bridge that handles the privy auth flow in the client. - */ -export const ReactNativeBridgePrivyAuth = () => { - const privyAuth = usePrivyAuthStatus(); -}; diff --git a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts b/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts deleted file mode 100644 index aa5f74162d9..00000000000 --- a/packages/commonwealth/client/scripts/views/components/ReactNativeBridge/usePrivyAuthStatus.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { WalletSsoSource } from '@hicommonwealth/shared'; -import { useCallback, useEffect, useState } from 'react'; -import { messageToObject } from './utils'; - -/** - * When the user is authenticated, this provides the data the user needs to - * authenticate. - */ -export interface UserAuth { - /** - * The privy id which we're providing for debug info. It's not normally used - * otherwise. - */ - id: string; - address: string | null; - identityToken: string; - ssoOAuthToken: string; - ssoProvider: WalletSsoSource; -} - -export interface IPrivyAuthStatus { - enabled: boolean; - authenticated: boolean; - userAuth: UserAuth | null; -} - -export function usePrivyAuthStatus(): IPrivyAuthStatus | null { - const [status, setStatus] = useState(null); - - const handleMessage = useCallback((message: MessageEvent) => { - const obj = messageToObject(message.data); - if (obj && typeof message.data === 'object') { - if (isPrivyAuthStatusMessage(obj)) { - setStatus(obj.data); - } - } - }, []); - - useEffect(() => { - window.addEventListener('message', handleMessage); - - return () => { - window.removeEventListener('message', handleMessage); - }; - }, [handleMessage]); - - return status; -} - -type PrivyAuthStatusMessage = { - type: 'privy.auth-status'; - data: IPrivyAuthStatus; -}; - -function isPrivyAuthStatusMessage( - data: object, -): data is PrivyAuthStatusMessage { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return !!data && (data as any).type === 'privy.auth-status'; -} From 28d99d5911d9264fa6e5374185008dadfa9886e7 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 13:43:07 -0700 Subject: [PATCH 03/56] ok... it won't login yet but I think we can get the domain status... --- .../client/scripts/navigation/CommonDomainRoutes.tsx | 7 +++++++ .../views/components/PrivyMobile/DebugPrivyMobile.tsx | 2 +- .../PrivyMobile/PrivyMobileAuthStatusProvider.ts | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx b/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx index 80f54525bcc..0f8484da436 100644 --- a/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx +++ b/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx @@ -1,6 +1,7 @@ import { Navigate } from 'navigation/helpers'; import React, { lazy } from 'react'; import { Route } from 'react-router-dom'; +import { DebugPrivyMobile } from 'views/components/PrivyMobile/DebugPrivyMobile'; import { SignIn } from 'views/components/SignIn/SignIn'; import { withLayout } from 'views/Layout'; import { MobileSignIn } from 'views/modals/MobileSignIn/MobileSignIn'; @@ -145,6 +146,12 @@ const newProposalViewPage = lazy( ); const CommonDomainRoutes = () => [ + } + />, + { return (
- :privyMobileAuthStatus: + privyMobileAuthStatus:
{JSON.stringify(privyMobileAuthStatus, null, 2)}
diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts index 8a25a7af572..85347dc62dd 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts @@ -20,6 +20,10 @@ export const PrivyMobileAuthStatusProvider = (props: Props) => { const obj = messageToObject(message.data); if (obj && typeof message.data === 'object') { if (isPrivyAuthStatusMessage(obj)) { + console.log( + 'Privy auth status message received', + JSON.stringify(obj, null, 2), + ); setState({ status: obj.data }); } } From e747d4f7194e115704e9363f933c11b7318c1067 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 14:07:44 -0700 Subject: [PATCH 04/56] ... hook to sign messages now.. --- .../PrivyMobile/usePrivyMobileSignMessage.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts new file mode 100644 index 00000000000..7b574bc888c --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts @@ -0,0 +1,19 @@ +import { execWithinMobileApp } from 'hooks/useReactNativeWebView'; +import { useCallback } from 'react'; + +type Opts = { + message: string; +}; + +/** + * Get privy to sign a message, in react-native, then return the message into + * the browser. + */ +export function usePrivyMobileSignMessage() { + return useCallback(async (opts: Opts) => { + return await execWithinMobileApp({ + type: 'privy.sign_message', + data: opts, + }); + }, []); +} From 7c1267f4061f3fd2b68956502794ce38344d1287 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 14:10:08 -0700 Subject: [PATCH 05/56] ok this should be all that we need now... --- .../components/PrivyMobile/DebugPrivyMobile.tsx | 17 +++++++++++++++++ .../PrivyMobile/usePrivyMobileSignMessage.ts | 8 ++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index e57d2811c10..714a36c18f1 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,14 +1,31 @@ import React from 'react'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; +import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; export const DebugPrivyMobile = () => { const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + const signMessage = usePrivyMobileSignMessage(); + + const handleSignMessage = () => { + async function doAsync() { + const result = await signMessage('hello'); + console.log(result); + } + + doAsync().catch(console.error); + }; + return (
privyMobileAuthStatus:
+ +
+ +
+
{JSON.stringify(privyMobileAuthStatus, null, 2)}
); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts index 7b574bc888c..c51126674ee 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts @@ -1,19 +1,15 @@ import { execWithinMobileApp } from 'hooks/useReactNativeWebView'; import { useCallback } from 'react'; -type Opts = { - message: string; -}; - /** * Get privy to sign a message, in react-native, then return the message into * the browser. */ export function usePrivyMobileSignMessage() { - return useCallback(async (opts: Opts) => { + return useCallback(async (message: string) => { return await execWithinMobileApp({ type: 'privy.sign_message', - data: opts, + data: { message }, }); }, []); } From 61ccc4e74a3770b718751462c6db35554f67a310 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 14:32:47 -0700 Subject: [PATCH 06/56] ... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index c41c8898a0d..dc2ee6dbe29 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -13,6 +13,11 @@ export const PrivyMobileAuthenticator = (props: Props) => { const { children } = props; const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + console.log( + 'PrivyMobileAuthenticator: Working with privyMobileAuthStatus:' + + JSON.stringify(privyMobileAuthStatus, null, 2), + ); + if (privyMobileAuthStatus?.enabled) { // the *client* doesn't have privy enabled so do not attempt to authenticate. return children; From 301e289d0d3cee208c3bee64a716bbd2c1cd9472 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 14:39:01 -0700 Subject: [PATCH 07/56] ... --- packages/commonwealth/client/scripts/App.tsx | 12 +++++++----- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/commonwealth/client/scripts/App.tsx b/packages/commonwealth/client/scripts/App.tsx index ec0363d5028..90559ee0913 100644 --- a/packages/commonwealth/client/scripts/App.tsx +++ b/packages/commonwealth/client/scripts/App.tsx @@ -11,8 +11,8 @@ import { ToastContainer } from 'react-toastify'; import { queryClient } from 'state/api/config'; import { DefaultPrivyProvider } from 'views/components/DefaultPrivyProvider/DefaultPrivyProvider'; import { DisableMavaOnMobile } from 'views/components/DisableMavaOnMobile'; -import ForceMobileAuth from 'views/components/ForceMobileAuth'; import { PrivyMobileAuthStatusProvider } from 'views/components/PrivyMobile/PrivyMobileAuthStatusProvider'; +import { PrivyMobileAuthenticator } from 'views/components/PrivyMobile/PrivyMobileAuthenticator'; import { ReactNativeBridgeUser } from 'views/components/ReactNativeBridge'; import { ReactNativeLogForwarder } from 'views/components/ReactNativeBridge/ReactNativeLogForwarder'; import { ReactNativeScrollToTopListener } from 'views/components/ReactNativeBridge/ReactNativeScrollToTopListener'; @@ -39,16 +39,18 @@ const App = () => { ) : ( - - + + + {/**/} - - + {/**/} + + )} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index dc2ee6dbe29..b86c0d57212 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -1,6 +1,5 @@ -import React, { ReactNode } from 'react'; +import { ReactNode } from 'react'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; -import { LoadingIndicator } from 'views/components/react_quill_editor/loading_indicator'; type Props = { children: ReactNode; @@ -23,5 +22,6 @@ export const PrivyMobileAuthenticator = (props: Props) => { return children; } - return ; + //return ; + return children; }; From b4a5bd683c31e6ad5b9154b8bd24ccdbd3e7219d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 15:30:37 -0700 Subject: [PATCH 08/56] record the signature now... --- .../views/components/PrivyMobile/DebugPrivyMobile.tsx | 7 ++++++- .../components/PrivyMobile/usePrivyMobileSignMessage.ts | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index 714a36c18f1..c6b97e4fba5 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,15 +1,18 @@ -import React from 'react'; +import React, { useState } from 'react'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; export const DebugPrivyMobile = () => { const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + const [signature, setSignature] = useState(); + const signMessage = usePrivyMobileSignMessage(); const handleSignMessage = () => { async function doAsync() { const result = await signMessage('hello'); + setSignature(result); console.log(result); } @@ -26,6 +29,8 @@ export const DebugPrivyMobile = () => { + {signature &&
signature: {signature}
} +
{JSON.stringify(privyMobileAuthStatus, null, 2)}
); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts index c51126674ee..54ffe617100 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts @@ -6,10 +6,11 @@ import { useCallback } from 'react'; * the browser. */ export function usePrivyMobileSignMessage() { - return useCallback(async (message: string) => { - return await execWithinMobileApp({ + return useCallback(async (message: string): Promise => { + const result = await execWithinMobileApp({ type: 'privy.sign_message', data: { message }, }); + return (result as any).signature; }, []); } From 90c165f1d417d239fa8a91506b121ae4c322f68e Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 16:11:31 -0700 Subject: [PATCH 09/56] more debug code... --- .../client/scripts/hooks/useReactNativeWebView.ts | 6 ++++-- .../views/components/PrivyMobile/DebugPrivyMobile.tsx | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts index 21d2cdb98a0..c9ef1aba9f3 100644 --- a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts +++ b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts @@ -74,6 +74,8 @@ export async function execWithinMobileApp< function handler(message: MessageEvent) { const dataObj = messageToObject(message.data); + console.log('FIXME.666: got message: ', JSON.stringify(dataObj, null, 2)); + if (dataObj.__requestID === __requestID) { latch.resolve(dataObj as Output); } @@ -90,11 +92,11 @@ export async function execWithinMobileApp< // the event listener we just registered will keep listening until the // latch is revolved and gets the response. - await latch.promise; + const output = await latch.promise; // now we have to remove the event listener before we return the latch and // clean up after ourselves. removeEventListener('message', handler); - return latch.promise; + return output; } diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index c6b97e4fba5..adb3329291c 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -12,6 +12,7 @@ export const DebugPrivyMobile = () => { const handleSignMessage = () => { async function doAsync() { const result = await signMessage('hello'); + console.log('FIXME.667', JSON.stringify(result)); setSignature(result); console.log(result); } From e4c69289e3df8aa5875c7d4bc55f350bf1fc8d82 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 5 May 2025 17:02:40 -0700 Subject: [PATCH 10/56] ... --- .../client/scripts/hooks/useReactNativeWebView.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts index c9ef1aba9f3..17715013b28 100644 --- a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts +++ b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts @@ -72,6 +72,7 @@ export async function execWithinMobileApp< // eslint-disable-next-line @typescript-eslint/no-explicit-any function handler(message: MessageEvent) { + console.log('FIXME execWithinMobileApp .111'); const dataObj = messageToObject(message.data); console.log('FIXME.666: got message: ', JSON.stringify(dataObj, null, 2)); @@ -81,6 +82,8 @@ export async function execWithinMobileApp< } } + console.log('FIXME execWithinMobileApp .112'); + addEventListener('message', handler); window.ReactNativeWebView!.postMessage( @@ -90,10 +93,14 @@ export async function execWithinMobileApp< }), ); + console.log('FIXME.112.1 execWithinMobileApp waiting fr resolution '); + // the event listener we just registered will keep listening until the // latch is revolved and gets the response. const output = await latch.promise; + console.log('FIXME.113 execWithinMobileApp RESOLVED!!! '); + // now we have to remove the event listener before we return the latch and // clean up after ourselves. removeEventListener('message', handler); From 5551f043efaa2479dd675ae01156ede187bb4170 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 08:53:14 -0700 Subject: [PATCH 11/56] test of post message. --- .../scripts/hooks/useReactNativeWebView.ts | 2 ++ .../PrivyMobile/DebugPostMessage.tsx | 22 +++++++++++++++ .../PrivyMobile/DebugPrivyMobile.tsx | 27 ++++++++++--------- 3 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx diff --git a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts index 17715013b28..5369d6e6779 100644 --- a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts +++ b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts @@ -75,6 +75,8 @@ export async function execWithinMobileApp< console.log('FIXME execWithinMobileApp .111'); const dataObj = messageToObject(message.data); + // FIXME: it's possible messageToObject could be throwing an error? + console.log('FIXME.666: got message: ', JSON.stringify(dataObj, null, 2)); if (dataObj.__requestID === __requestID) { diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx new file mode 100644 index 00000000000..32f48011824 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx @@ -0,0 +1,22 @@ +import React, { memo, useCallback } from 'react'; + +type Props = { + children: React.ReactNode; +}; + +export const DebugPostMessage = memo(function DebugPostMessage(props: Props) { + const { children } = props; + const handler = useCallback((message: MessageEvent) => { + console.log('GOT POST MESSAGE' + message.data); + }, []); + + useCallback(() => { + window.addEventListener('message', handler); + + return () => { + window.removeEventListener('message', handler); + }; + }, [handler]); + + return children; +}); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index adb3329291c..3e43a6cea76 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,8 +1,9 @@ -import React, { useState } from 'react'; +import React, { memo, useState } from 'react'; +import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; -export const DebugPrivyMobile = () => { +export const DebugPrivyMobile = memo(function DebugPrivyMobile() { const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); const [signature, setSignature] = useState(); @@ -21,18 +22,20 @@ export const DebugPrivyMobile = () => { }; return ( -
+
- privyMobileAuthStatus: -
+
+ privyMobileAuthStatus: +
-
- -
+
+ +
- {signature &&
signature: {signature}
} + {signature &&
signature: {signature}
} -
{JSON.stringify(privyMobileAuthStatus, null, 2)}
-
+
{JSON.stringify(privyMobileAuthStatus, null, 2)}
+ + ); -}; +}); From 116889024bdcd4491c39790c03c966baa173514f Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 09:29:03 -0700 Subject: [PATCH 12/56] had a bug in my debug code... --- .../scripts/hooks/useReactNativeWebView.ts | 19 ++++++++++++------- .../PrivyMobile/DebugPostMessage.tsx | 5 +++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts index 5369d6e6779..85c3b295085 100644 --- a/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts +++ b/packages/commonwealth/client/scripts/hooks/useReactNativeWebView.ts @@ -72,21 +72,26 @@ export async function execWithinMobileApp< // eslint-disable-next-line @typescript-eslint/no-explicit-any function handler(message: MessageEvent) { - console.log('FIXME execWithinMobileApp .111'); + console.log('FIXME execWithinMobileApp handler received message!'); const dataObj = messageToObject(message.data); // FIXME: it's possible messageToObject could be throwing an error? - console.log('FIXME.666: got message: ', JSON.stringify(dataObj, null, 2)); + console.log( + 'FIXME execWithinMobileApp: got message: ', + JSON.stringify(dataObj, null, 2), + ); if (dataObj.__requestID === __requestID) { latch.resolve(dataObj as Output); } } - console.log('FIXME execWithinMobileApp .112'); + console.log( + 'FIXME execWithinMobileApp adding event listener to listen for response message', + ); - addEventListener('message', handler); + window.addEventListener('message', handler); window.ReactNativeWebView!.postMessage( JSON.stringify({ @@ -95,17 +100,17 @@ export async function execWithinMobileApp< }), ); - console.log('FIXME.112.1 execWithinMobileApp waiting fr resolution '); + console.log('FIXME execWithinMobileApp waiting fr resolution '); // the event listener we just registered will keep listening until the // latch is revolved and gets the response. const output = await latch.promise; - console.log('FIXME.113 execWithinMobileApp RESOLVED!!! '); + console.log('FIXME execWithinMobileApp RESOLVED!!! '); // now we have to remove the event listener before we return the latch and // clean up after ourselves. - removeEventListener('message', handler); + window.removeEventListener('message', handler); return output; } diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx index 32f48011824..77850d7c383 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx @@ -1,4 +1,4 @@ -import React, { memo, useCallback } from 'react'; +import React, { memo, useCallback, useEffect } from 'react'; type Props = { children: React.ReactNode; @@ -10,7 +10,8 @@ export const DebugPostMessage = memo(function DebugPostMessage(props: Props) { console.log('GOT POST MESSAGE' + message.data); }, []); - useCallback(() => { + useEffect(() => { + console.log('Listening for all post messages'); window.addEventListener('message', handler); return () => { From bcc2de19b5998823c00476d2d817e852255741de Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 11:13:31 -0700 Subject: [PATCH 13/56] this shouldn't matter ... --- .../scripts/views/components/PrivyMobile/DebugPostMessage.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx index 77850d7c383..4f0fbe23019 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPostMessage.tsx @@ -7,7 +7,7 @@ type Props = { export const DebugPostMessage = memo(function DebugPostMessage(props: Props) { const { children } = props; const handler = useCallback((message: MessageEvent) => { - console.log('GOT POST MESSAGE' + message.data); + console.log('GOT POST MESSAGE' + JSON.stringify(message.data, null, 2)); }, []); useEffect(() => { @@ -15,6 +15,7 @@ export const DebugPostMessage = memo(function DebugPostMessage(props: Props) { window.addEventListener('message', handler); return () => { + console.log('Removing post message listener'); window.removeEventListener('message', handler); }; }, [handler]); From f96cc82f3ce008e2b34780201368e91decb847b7 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 14:06:19 -0700 Subject: [PATCH 14/56] ok v1 of the new sender/receiver RPC --- .../hooks/mobile/useMobileRPCSender.ts | 98 +++++++++++++++++++ .../PrivyMobile/usePrivyMobileSignMessage.ts | 11 +-- 2 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts new file mode 100644 index 00000000000..f49fc266b71 --- /dev/null +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -0,0 +1,98 @@ +import { useCallback } from 'react'; + +type ProtoError = { + message: string; +}; + +type ProtoRequestObject = { + $id: string; + type: string; + variant: 'request'; + data: Request; +}; + +/** + * Wraps a response so that it includes the error OR data. + */ +type ProtoResponseObject = { + $id: string; + type: string; + variant: 'response'; + data: Response | null; + error: ProtoError | null; +}; + +type Opts = { + type: string; +}; + +export function useMobileRPCSender(opts: Opts) { + return useCallback( + async (request: Request) => { + return new Promise((resolve, reject) => { + const $id = '' + Math.random() * 100000; + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + function handler(message: MessageEvent) { + const protoResponse = toProtoResponse( + opts.type, + message.data, + ); + + if (protoResponse?.$id === $id) { + console.log('Got proto response: ', protoResponse); + if (protoResponse.data) { + resolve(protoResponse.data); + } + + if (protoResponse.error) { + reject(protoResponse.error); + } + } + } + + window.addEventListener('message', handler); + + const requestObj: ProtoRequestObject = { + $id, + type: opts.type, + variant: 'request', + data: request, + }; + + window.ReactNativeWebView!.postMessage( + JSON.stringify({ + requestObj, + }), + ); + }); + }, + [opts.type], + ); +} + +function toProtoResponse( + type: string, + data: any, +): ProtoResponseObject | null { + const obj = messageToObject(data); + + if (obj && obj.type === type && obj.variant === 'response') { + return obj; + } + + return null; +} + +function messageToObject(message: string | any): any | null { + if (message === 'string') { + try { + return JSON.parse(message); + } catch (e) { + // this might be just a string sent with sendMessage + return null; + } + } + + return typeof message === 'string' ? JSON.parse(message) : message; +} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts index 54ffe617100..6dee18ca98b 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileSignMessage.ts @@ -1,16 +1,9 @@ -import { execWithinMobileApp } from 'hooks/useReactNativeWebView'; -import { useCallback } from 'react'; +import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; /** * Get privy to sign a message, in react-native, then return the message into * the browser. */ export function usePrivyMobileSignMessage() { - return useCallback(async (message: string): Promise => { - const result = await execWithinMobileApp({ - type: 'privy.sign_message', - data: { message }, - }); - return (result as any).signature; - }, []); + return useMobileRPCSender({ type: 'privy.signMessage' }); } From 36735849c5cd2509b1145d0ec020e90e2d8e0280 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 14:31:25 -0700 Subject: [PATCH 15/56] wrong object sent. --- .../client/scripts/hooks/mobile/useMobileRPCSender.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts index f49fc266b71..267653b4c58 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -53,18 +53,19 @@ export function useMobileRPCSender(opts: Opts) { window.addEventListener('message', handler); - const requestObj: ProtoRequestObject = { + const protoRequest: ProtoRequestObject = { $id, type: opts.type, variant: 'request', data: request, }; - window.ReactNativeWebView!.postMessage( - JSON.stringify({ - requestObj, - }), + console.log( + 'FIXME: useMobileRPCSender sending message: ', + JSON.stringify(protoRequest), ); + + window.ReactNativeWebView!.postMessage(JSON.stringify(protoRequest)); }); }, [opts.type], From c3a71a9f0684708b6ed1a6e52cb2edd8f228577d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 14:47:46 -0700 Subject: [PATCH 16/56] cleanup... --- .../client/scripts/hooks/mobile/useMobileRPCSender.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts index 267653b4c58..e2765a3c64d 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -60,11 +60,6 @@ export function useMobileRPCSender(opts: Opts) { data: request, }; - console.log( - 'FIXME: useMobileRPCSender sending message: ', - JSON.stringify(protoRequest), - ); - window.ReactNativeWebView!.postMessage(JSON.stringify(protoRequest)); }); }, From e97f322ca6799356a3a3e1dce69f1a2a3ee40a1d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 15:12:40 -0700 Subject: [PATCH 17/56] implemented logout now... --- .../PrivyMobile/DebugPrivyMobile.tsx | 18 +++++++++++++++--- .../PrivyMobile/usePrivyMobileLogout.ts | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index 3e43a6cea76..5ba5af0e2e1 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,6 +1,7 @@ import React, { memo, useState } from 'react'; import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; +import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; export const DebugPrivyMobile = memo(function DebugPrivyMobile() { @@ -9,13 +10,20 @@ export const DebugPrivyMobile = memo(function DebugPrivyMobile() { const [signature, setSignature] = useState(); const signMessage = usePrivyMobileSignMessage(); + const logout = usePrivyMobileLogout(); const handleSignMessage = () => { async function doAsync() { const result = await signMessage('hello'); - console.log('FIXME.667', JSON.stringify(result)); setSignature(result); - console.log(result); + } + + doAsync().catch(console.error); + }; + + const handleLogout = () => { + async function doAsync() { + await logout({}); } doAsync().catch(console.error); @@ -28,10 +36,14 @@ export const DebugPrivyMobile = memo(function DebugPrivyMobile() { privyMobileAuthStatus: -
+
+
+ +
+ {signature &&
signature: {signature}
}
{JSON.stringify(privyMobileAuthStatus, null, 2)}
diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts new file mode 100644 index 00000000000..497dadedfc5 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts @@ -0,0 +1,9 @@ +import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; + +/** + * Get privy to sign a message, in react-native, then return the message into + * the browser. + */ +export function usePrivyMobileLogout() { + return useMobileRPCSender<{}, {}>({ type: 'privy.logout' }); +} From 545485593927d30f6ee3accf2537eb8645306404 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 15:29:48 -0700 Subject: [PATCH 18/56] request now works... --- .../PrivyMobile/DebugPrivyMobile.tsx | 23 +++++++++++++++++++ .../components/PrivyMobile/usePrivyFoo.ts | 12 ++++++++++ 2 files changed, 35 insertions(+) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index 5ba5af0e2e1..40779f4f74b 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,5 +1,6 @@ import React, { memo, useState } from 'react'; import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; +import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyFoo'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; @@ -9,8 +10,11 @@ export const DebugPrivyMobile = memo(function DebugPrivyMobile() { const [signature, setSignature] = useState(); + const [accounts, setAccounts] = useState(); + const signMessage = usePrivyMobileSignMessage(); const logout = usePrivyMobileLogout(); + const ethereumWalletRequest = usePrivyEthereumWalletRequest(); const handleSignMessage = () => { async function doAsync() { @@ -29,6 +33,17 @@ export const DebugPrivyMobile = memo(function DebugPrivyMobile() { doAsync().catch(console.error); }; + const handleEthereumWalletRequest = () => { + async function doAsync() { + const tmp = await ethereumWalletRequest({ + method: 'eth_requestAccounts', + }); + setAccounts(tmp); + } + + doAsync().catch(console.error); + }; + return (
@@ -44,8 +59,16 @@ export const DebugPrivyMobile = memo(function DebugPrivyMobile() {
+
+ +
+ {signature &&
signature: {signature}
} + {accounts &&
accounts: {JSON.stringify(accounts, null, 2)}
} +
{JSON.stringify(privyMobileAuthStatus, null, 2)}
diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts new file mode 100644 index 00000000000..f0eb53fcea9 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts @@ -0,0 +1,12 @@ +import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; + +type RequestArguments = { + method: string; + params?: Array | undefined; +}; + +export function usePrivyEthereumWalletRequest() { + return useMobileRPCSender({ + type: 'privy.ethereumWalletRequest', + }); +} From eec183dcdcdbe6b3b2fb318894534eeee578e336 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 6 May 2025 16:13:24 -0700 Subject: [PATCH 19/56] cleanup... --- .../scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx | 2 +- .../{usePrivyFoo.ts => usePrivyEthereumWalletRequest.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/commonwealth/client/scripts/views/components/PrivyMobile/{usePrivyFoo.ts => usePrivyEthereumWalletRequest.ts} (100%) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx index 40779f4f74b..0ca2de409b5 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/DebugPrivyMobile.tsx @@ -1,6 +1,6 @@ import React, { memo, useState } from 'react'; import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; -import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyFoo'; +import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletRequest.ts similarity index 100% rename from packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyFoo.ts rename to packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletRequest.ts From 034ba258eeaf0b2973d1af3da7abc93b5745cb43 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 15:26:50 -0700 Subject: [PATCH 20/56] we should support mobile privy auth but I have to test first... --- .../scripts/views/components/Privy/helpers.ts | 22 +++-- .../scripts/views/components/Privy/types.ts | 21 ++--- .../PrivyMobileAuthStatusProvider.ts | 3 + .../PrivyMobile/PrivyMobileAuthenticator.tsx | 85 +++++++++++++++++-- .../PrivyMobile/usePrivyMobileAuthStatus.ts | 30 +++++++ 5 files changed, 135 insertions(+), 26 deletions(-) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts diff --git a/packages/commonwealth/client/scripts/views/components/Privy/helpers.ts b/packages/commonwealth/client/scripts/views/components/Privy/helpers.ts index 6249036e50e..018e4389299 100644 --- a/packages/commonwealth/client/scripts/views/components/Privy/helpers.ts +++ b/packages/commonwealth/client/scripts/views/components/Privy/helpers.ts @@ -1,14 +1,26 @@ -import { - OAuthProvider, - PrivySignInSSOProvider, -} from 'views/components/Privy/types'; +import { WalletSsoSource } from '@hicommonwealth/shared'; +import { PrivySignInSSOProvider } from 'views/components/Privy/types'; export function toSignInProvider( - provider: OAuthProvider, + provider: WalletSsoSource, ): PrivySignInSSOProvider { switch (provider) { case 'google': return 'google_oauth'; + case 'github': + return 'github_oauth'; + case 'discord': + return 'discord_oauth'; + case 'twitter': + return 'twitter_oauth'; + case 'apple': + return 'apple_oauth'; + case 'email': + return 'email'; + case 'farcaster': + return 'farcaster'; + case 'SMS': + return 'phone'; default: throw new Error('Not supported: ' + provider); } diff --git a/packages/commonwealth/client/scripts/views/components/Privy/types.ts b/packages/commonwealth/client/scripts/views/components/Privy/types.ts index 3270ba64eb3..0fe1d9ab641 100644 --- a/packages/commonwealth/client/scripts/views/components/Privy/types.ts +++ b/packages/commonwealth/client/scripts/views/components/Privy/types.ts @@ -1,4 +1,12 @@ -export type PrivySignInSSOProvider = 'email' | 'phone' | 'google_oauth'; +export type PrivySignInSSOProvider = + | 'google_oauth' + | 'github_oauth' + | 'discord_oauth' + | 'apple_oauth' + | 'twitter_oauth' + | 'phone' + | 'farcaster' + | 'email'; export type OAuthProvider = | 'google' @@ -6,14 +14,3 @@ export type OAuthProvider = | 'discord' | 'twitter' | 'apple'; - -export type PrivyOAuthProvider = - | 'google' - | 'discord' - | 'twitter' - | 'github' - | 'spotify' - | 'instagram' - | 'tiktok' - | 'linkedin' - | 'apple'; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts index 85347dc62dd..74d72cd5e38 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthStatusProvider.ts @@ -10,6 +10,9 @@ type Props = { /** * This keeps the privy auth state, from the mobile app, using mobile privy, * available for use within the app. + * + * @deprecated TODO we don't need this now. + * */ export const PrivyMobileAuthStatusProvider = (props: Props) => { const { children } = props; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index b86c0d57212..0c75ac0afbe 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -1,5 +1,18 @@ -import { ReactNode } from 'react'; -import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; +import { ChainBase, WalletId } from '@hicommonwealth/shared'; +import { PrivyEthereumWebWalletController } from 'controllers/app/webWallets/privy_ethereum_web_wallet'; +import { getSessionFromWallet } from 'controllers/server/sessions'; +import { ReactNode, useCallback, useEffect } from 'react'; +import { useSignIn } from 'state/api/user'; +import { toSignInProvider } from 'views/components/Privy/helpers'; +import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; +import { usePrivyMobileAuthStatus } from 'views/components/PrivyMobile/usePrivyMobileAuthStatus'; +import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; + +declare global { + interface Window { + PRIVY_MOBILE_ENABLED?: boolean; + } +} type Props = { children: ReactNode; @@ -10,18 +23,72 @@ type Props = { */ export const PrivyMobileAuthenticator = (props: Props) => { const { children } = props; - const { status: privyMobileAuthStatus } = usePrivyMobileAuthStatusStore(); + const getPrivyMobileAuthStatus = usePrivyMobileAuthStatus(); + const { signIn } = useSignIn(); + + const request = usePrivyEthereumWalletRequest(); + const signMessage = usePrivyMobileSignMessage(); - console.log( - 'PrivyMobileAuthenticator: Working with privyMobileAuthStatus:' + - JSON.stringify(privyMobileAuthStatus, null, 2), + const ethereumProvider = useCallback(async () => { + return { request }; + }, [request]); + + const signMessageProvider = useCallback( + async (message: string): Promise => { + return await signMessage(message); + }, + [signMessage], ); - if (privyMobileAuthStatus?.enabled) { - // the *client* doesn't have privy enabled so do not attempt to authenticate. + useEffect(() => { + async function doAsync() { + const privyMobileAuthStatus = await getPrivyMobileAuthStatus({}); + + if (!privyMobileAuthStatus.enabled) { + console.log('Privy mobile auth is not enabled'); + return; + } + + if ( + !privyMobileAuthStatus.authenticated || + !privyMobileAuthStatus.userAuth + ) { + console.log('Privy mobile not authenticated.'); + return; + } + + const webWallet = new PrivyEthereumWebWalletController( + ethereumProvider, + signMessageProvider, + ); + + await webWallet.enable(); + const session = await getSessionFromWallet(webWallet, { + newSession: true, + }); + + console.log('Going to sign in now with privy mobile.'); + + await signIn(session, { + address: privyMobileAuthStatus.userAuth.address, + community_id: ChainBase.Ethereum, + wallet_id: WalletId.Privy, + privy: { + identityToken: privyMobileAuthStatus.userAuth.identityToken, + ssoOAuthToken: privyMobileAuthStatus.userAuth.ssoOAuthToken, + ssoProvider: toSignInProvider( + privyMobileAuthStatus.userAuth.ssoProvider, + ), + }, + }); + } + + doAsync().catch(console.error); + }, [ethereumProvider, getPrivyMobileAuthStatus, signIn, signMessageProvider]); + + if (!window.PRIVY_MOBILE_ENABLED) { return children; } - //return ; return children; }; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts new file mode 100644 index 00000000000..986e354dffc --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts @@ -0,0 +1,30 @@ +import { WalletSsoSource } from '@hicommonwealth/shared'; +import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; + +/** + * When the user is authenticated, this provides the data the user needs to + * authenticate. + */ +export interface UserAuth { + /** + * The privy id which we're providing for debug info. It's not normally used + * otherwise. + */ + id: string; + address: string; + identityToken: string; + ssoOAuthToken: string; + ssoProvider: WalletSsoSource; +} + +export interface IPrivyMobileAuthStatus { + enabled: boolean; + authenticated: boolean; + userAuth: UserAuth | null; +} + +export function usePrivyMobileAuthStatus() { + return useMobileRPCSender<{}, IPrivyMobileAuthStatus>({ + type: 'privy.authStatus', + }); +} From a9aea63c64ff2d7119fa40acc41fdb42b9a214a3 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 15:53:27 -0700 Subject: [PATCH 21/56] ... --- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 0c75ac0afbe..d4875112949 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -44,8 +44,13 @@ export const PrivyMobileAuthenticator = (props: Props) => { async function doAsync() { const privyMobileAuthStatus = await getPrivyMobileAuthStatus({}); + console.log( + 'FIXME: privyMobileAuthStatus', + JSON.stringify(privyMobileAuthStatus, null, 2), + ); + if (!privyMobileAuthStatus.enabled) { - console.log('Privy mobile auth is not enabled'); + console.log('FIXME: Privy mobile auth is not enabled'); return; } @@ -53,7 +58,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { !privyMobileAuthStatus.authenticated || !privyMobileAuthStatus.userAuth ) { - console.log('Privy mobile not authenticated.'); + console.log('FIXME: Privy mobile not authenticated.'); return; } @@ -67,7 +72,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { newSession: true, }); - console.log('Going to sign in now with privy mobile.'); + console.log('FIXME: Going to sign in now with privy mobile.'); await signIn(session, { address: privyMobileAuthStatus.userAuth.address, @@ -87,8 +92,10 @@ export const PrivyMobileAuthenticator = (props: Props) => { }, [ethereumProvider, getPrivyMobileAuthStatus, signIn, signMessageProvider]); if (!window.PRIVY_MOBILE_ENABLED) { + console.log('FIXME: Privy mobile is not enabled.'); return children; } + console.log('FIXME: Privy mobile is ENABLED.'); return children; }; From d86ba4421e55c44f1da6ce2758c01fff3153cd34 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 16:10:13 -0700 Subject: [PATCH 22/56] ... --- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index d4875112949..3f36b9939fb 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -72,9 +72,14 @@ export const PrivyMobileAuthenticator = (props: Props) => { newSession: true, }); - console.log('FIXME: Going to sign in now with privy mobile.'); + console.log( + 'FIXME: Going to sign in now with privy mobile. session: ', + session, + ); - await signIn(session, { + console.log('FIXME: trying to sign in now... '); + + const auth = await signIn(session, { address: privyMobileAuthStatus.userAuth.address, community_id: ChainBase.Ethereum, wallet_id: WalletId.Privy, @@ -86,6 +91,8 @@ export const PrivyMobileAuthenticator = (props: Props) => { ), }, }); + + console.log('FIXME signIn result: ' + JSON.stringify(auth, null, 2)); } doAsync().catch(console.error); From 1ce55d64d20c4012cb2dc25fc1eeec9ed5745f06 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 17:04:58 -0700 Subject: [PATCH 23/56] more debug... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 3f36b9939fb..14739f250ac 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -62,12 +62,18 @@ export const PrivyMobileAuthenticator = (props: Props) => { return; } + console.log('FIXME: Privy mobile is authenticated so trying to sign in '); + const webWallet = new PrivyEthereumWebWalletController( ethereumProvider, signMessageProvider, ); + console.log('FIXME enable web wallet... ;'); + await webWallet.enable(); + + console.log('FIXME getting session now.;'); const session = await getSessionFromWallet(webWallet, { newSession: true, }); From 41b980f2bbcb5f8b9776362080f47fbfd27ee721 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 17:27:05 -0700 Subject: [PATCH 24/56] null is an acceptable result.. --- .../client/scripts/hooks/mobile/useMobileRPCSender.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts index e2765a3c64d..b2ebc8e12a5 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -41,13 +41,15 @@ export function useMobileRPCSender(opts: Opts) { if (protoResponse?.$id === $id) { console.log('Got proto response: ', protoResponse); - if (protoResponse.data) { - resolve(protoResponse.data); - } if (protoResponse.error) { reject(protoResponse.error); } + + // FIXME: this is the bug because some function can return null... + if (protoResponse.data) { + resolve(protoResponse.data); + } } } From 75ff16049e57706c81a36b03b3059171b60fa0af Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 17:31:37 -0700 Subject: [PATCH 25/56] null is an acceptable result.. --- .../hooks/mobile/useMobileRPCSender.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts index b2ebc8e12a5..d9c8eefbaeb 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -11,17 +11,29 @@ type ProtoRequestObject = { data: Request; }; +type ProtoResponseObjectSuccess = { + $id: string; + type: string; + variant: 'response'; + data: Response; + error: null; +}; + /** * Wraps a response so that it includes the error OR data. */ -type ProtoResponseObject = { +type ProtoResponseObjectFailure = { $id: string; type: string; variant: 'response'; - data: Response | null; - error: ProtoError | null; + data: null; + error: ProtoError; }; +type ProtoResponseObject = + | ProtoResponseObjectSuccess + | ProtoResponseObjectFailure; + type Opts = { type: string; }; @@ -44,10 +56,7 @@ export function useMobileRPCSender(opts: Opts) { if (protoResponse.error) { reject(protoResponse.error); - } - - // FIXME: this is the bug because some function can return null... - if (protoResponse.data) { + } else { resolve(protoResponse.data); } } From a9651d43fe11b99672b5ba1dd60f70f5268a4f50 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 17:55:35 -0700 Subject: [PATCH 26/56] ... --- packages/commonwealth/client/scripts/App.tsx | 30 ++++++++++--------- .../webWallets/privy_ethereum_web_wallet.ts | 14 +++++++++ .../PrivyMobile/PrivyMobileAuthenticator.tsx | 3 +- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/commonwealth/client/scripts/App.tsx b/packages/commonwealth/client/scripts/App.tsx index 90559ee0913..bf04cf10930 100644 --- a/packages/commonwealth/client/scripts/App.tsx +++ b/packages/commonwealth/client/scripts/App.tsx @@ -32,26 +32,28 @@ const App = () => { + {/*@ts-expect-error StrictNullChecks*/} {isLoading ? ( ) : ( - - - - {/**/} - - - - - - - {/**/} - - - + <> + + + + {/**/} + + + + + + {/**/} + + + + )} {import.meta.env.DEV && } diff --git a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts index e1814a1b861..2dee5d414a5 100644 --- a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts +++ b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts @@ -98,6 +98,7 @@ export class PrivyEthereumWebWalletController implements IWebWallet { public async enable(forceChainId?: string) { // TODO: use https://docs.metamask.io/guide/rpc-api.html#other-rpc-methods to switch active // chain according to currently active node, if one exists + console.log('FIXME: within enable... 1'); console.log('Attempting to enable Metamask'); this._enabling = true; try { @@ -108,6 +109,8 @@ export class PrivyEthereumWebWalletController implements IWebWallet { const Web3 = (await import('web3')).default; + console.log('FIXME: within enable... 2'); + let ethereum = await this.etheriumProvider(); if (ethereum.providers?.length) { @@ -117,6 +120,8 @@ export class PrivyEthereumWebWalletController implements IWebWallet { }); } + console.log('FIXME: within enable... 3'); + this._web3 = process.env.ETH_RPC !== 'e2e-test' ? { @@ -139,6 +144,8 @@ export class PrivyEthereumWebWalletController implements IWebWallet { if (!this._web3.givenProvider.request) throw new Error('No web3.givenProvider.request'); + console.log('FIXME: within enable... 4'); + await this._web3.givenProvider.request({ method: 'eth_requestAccounts', }); @@ -153,6 +160,8 @@ export class PrivyEthereumWebWalletController implements IWebWallet { }); } } catch (switchError) { + console.log('FIXME: within enable... 5'); + // This error code indicates that the chain has not been added to MetaMask. if (switchError.code === 4902) { const wsRpcUrl = app.chain?.meta?.ChainNode?.url ?? ''; @@ -188,6 +197,9 @@ export class PrivyEthereumWebWalletController implements IWebWallet { throw switchError; } } + + console.log('FIXME: within enable... 6'); + // fetch active accounts this._accounts = ( await this._web3.givenProvider.request({ @@ -201,6 +213,8 @@ export class PrivyEthereumWebWalletController implements IWebWallet { throw new Error('Metamask fetched no accounts'); } + console.log('FIXME: within enable... 7'); + await this.initAccountsChanged(); this._enabled = true; this._enabling = false; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 14739f250ac..8b0cae9bd6d 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -69,8 +69,9 @@ export const PrivyMobileAuthenticator = (props: Props) => { signMessageProvider, ); - console.log('FIXME enable web wallet... ;'); + console.log('FIXME enable web wallet... '); + // FIXME this is the bug now - it's not logging though await webWallet.enable(); console.log('FIXME getting session now.;'); From 93a53a113b2ecc55b971e175c700a42e0438ad37 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 7 May 2025 18:16:02 -0700 Subject: [PATCH 27/56] ... --- .../controllers/app/webWallets/privy_ethereum_web_wallet.ts | 3 +++ .../views/components/PrivyMobile/PrivyMobileAuthenticator.tsx | 2 ++ 2 files changed, 5 insertions(+) diff --git a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts index 2dee5d414a5..d07e2fce76a 100644 --- a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts +++ b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts @@ -231,6 +231,9 @@ export class PrivyEthereumWebWalletController implements IWebWallet { } public async initAccountsChanged() { + // FIXME: we don't have the 'on' event handler... + console.log('FIXME: within enable... 7'); + await this._web3.givenProvider.on( 'accountsChanged', async (accounts: string[]) => { diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 8b0cae9bd6d..d6ff24d38a8 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -111,5 +111,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { } console.log('FIXME: Privy mobile is ENABLED.'); + // FIXME: do not return until we've finished authenticating... + return children; }; From fd424a3c1632434c9a707149cf27d121a6eea483 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 07:50:10 -0700 Subject: [PATCH 28/56] ok both sides of the event updater have been worked on... --- .../hooks/mobile/useMobileRPCEventReceiver.ts | 78 +++++++++++++++++++ .../PrivyMobile/PrivyMobileAuthenticator.tsx | 1 + 2 files changed, 79 insertions(+) create mode 100644 packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts new file mode 100644 index 00000000000..6e361462270 --- /dev/null +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts @@ -0,0 +1,78 @@ +import { useCallback } from 'react'; +import { useReactNativeWebView } from '../useReactNativeWebView'; + +type EvenSubscribeMessage = { + $id: string; + type: string; + variant: 'event-subscribe'; +}; + +type EventUpdateMessage = { + $id: string; + type: string; + variant: 'event-update'; + data: EventData; +}; + +export function useMobileRPCEventReceiver(type: string) { + const reactNativeWebView = useReactNativeWebView(); + + return useCallback( + (listener: (update: EventData) => void) => { + const $id = '' + Math.random() * 100000; + + const subscription: EvenSubscribeMessage = { + $id, + type: type, + variant: 'event-subscribe', + }; + + if (!reactNativeWebView) { + return; + } + + reactNativeWebView.postMessage(JSON.stringify(subscription)); + + function handler(message: MessageEvent) { + const eventUpdateMessage = toEventUpdateMessage( + type, + message.data, + ); + + if (eventUpdateMessage?.$id === $id) { + console.log('Got event update: ', eventUpdateMessage); + listener(eventUpdateMessage.data); + } + } + + window.addEventListener('message', handler); + }, + [reactNativeWebView, type], + ); +} + +function toEventUpdateMessage( + type: string, + data: any, +): EventUpdateMessage | null { + const obj = messageToObject(data); + + if (obj && obj.type === type && obj.variant === 'event-update') { + return obj; + } + + return null; +} + +function messageToObject(message: string | any): any | null { + if (message === 'string') { + try { + return JSON.parse(message); + } catch (e) { + // this might be just a string sent with sendMessage + return null; + } + } + + return typeof message === 'string' ? JSON.parse(message) : message; +} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index d6ff24d38a8..a64913dfada 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -112,6 +112,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { console.log('FIXME: Privy mobile is ENABLED.'); // FIXME: do not return until we've finished authenticating... + // FIXME: can I use useUeerStore here ? return children; }; From 2a11ca3a500ff43a1dafe9ce725c14c6912bf583 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 07:57:40 -0700 Subject: [PATCH 29/56] now we're giving it the event name... --- .../client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts | 4 +++- .../views/components/PrivyMobile/usePrivyEthereumWalletOn.ts | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletOn.ts diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts index 6e361462270..ba94bd25355 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCEventReceiver.ts @@ -5,6 +5,7 @@ type EvenSubscribeMessage = { $id: string; type: string; variant: 'event-subscribe'; + eventName: string; }; type EventUpdateMessage = { @@ -18,12 +19,13 @@ export function useMobileRPCEventReceiver(type: string) { const reactNativeWebView = useReactNativeWebView(); return useCallback( - (listener: (update: EventData) => void) => { + (eventName: string, listener: (update: EventData) => void) => { const $id = '' + Math.random() * 100000; const subscription: EvenSubscribeMessage = { $id, type: type, + eventName, variant: 'event-subscribe', }; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletOn.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletOn.ts new file mode 100644 index 00000000000..d3e3bc6f681 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyEthereumWalletOn.ts @@ -0,0 +1,5 @@ +import { useMobileRPCEventReceiver } from 'hooks/mobile/useMobileRPCEventReceiver'; + +export function usePrivyEthereumWalletOn() { + return useMobileRPCEventReceiver('privy.ethereumWalletOn'); +} From 8e40b0af3a2d30c846694ff28541eccf6bb93c61 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 07:59:53 -0700 Subject: [PATCH 30/56] ok I think all the callbacks are in place... --- .../app/webWallets/privy_ethereum_web_wallet.ts | 4 ++++ .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts index d07e2fce76a..227e860af6e 100644 --- a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts +++ b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts @@ -237,6 +237,10 @@ export class PrivyEthereumWebWalletController implements IWebWallet { await this._web3.givenProvider.on( 'accountsChanged', async (accounts: string[]) => { + console.log( + 'FIXME: initAccounts got some accounts: ', + JSON.stringify(accounts, null, 2), + ); const updatedAddress = userStore .getState() .accounts.find((addr) => addr.address === accounts[0]); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index a64913dfada..76f2c265143 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -4,6 +4,7 @@ import { getSessionFromWallet } from 'controllers/server/sessions'; import { ReactNode, useCallback, useEffect } from 'react'; import { useSignIn } from 'state/api/user'; import { toSignInProvider } from 'views/components/Privy/helpers'; +import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyEthereumWalletOn'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import { usePrivyMobileAuthStatus } from 'views/components/PrivyMobile/usePrivyMobileAuthStatus'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; @@ -26,12 +27,13 @@ export const PrivyMobileAuthenticator = (props: Props) => { const getPrivyMobileAuthStatus = usePrivyMobileAuthStatus(); const { signIn } = useSignIn(); - const request = usePrivyEthereumWalletRequest(); + const walletRequest = usePrivyEthereumWalletRequest(); + const walletOn = usePrivyEthereumWalletOn(); const signMessage = usePrivyMobileSignMessage(); const ethereumProvider = useCallback(async () => { - return { request }; - }, [request]); + return { request: walletRequest, on: walletOn }; + }, [walletOn, walletRequest]); const signMessageProvider = useCallback( async (message: string): Promise => { From 56095a8200687b216b345647a56395d96047886a Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 11:17:38 -0700 Subject: [PATCH 31/56] client side is done now... --- .../useNotificationsGetPermissionsAsyncReceiver.ts | 11 +++++++++++ ...useNotificationsRequestPermissionsAsyncReceiver.ts | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver.ts create mode 100644 packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver.ts new file mode 100644 index 00000000000..e350b06f736 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver.ts @@ -0,0 +1,11 @@ +import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; + +type PermissionStatus = { + status: 'granted' | 'denied' | 'undetermined'; +}; + +export function useNotificationsGetPermissionsAsyncReceiver() { + return useMobileRPCSender<{}, PermissionStatus>({ + type: 'Notifications.getPermissionsAsync', + }); +} diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts new file mode 100644 index 00000000000..48ac6554169 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts @@ -0,0 +1,7 @@ +import { useMobileRPCSender } from 'client/scripts/hooks/mobile/useMobileRPCSender'; + +export function useNotificationsRequestPermissionsAsyncReceiver() { + return useMobileRPCSender<{}, {}>({ + type: 'Notifications.requestPermissionsAsync', + }); +} From aec25d3ade3fbef3391c736ef026c98b3c4541a2 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 12:56:40 -0700 Subject: [PATCH 32/56] changing this to a generic mobile debug component... --- .../client/scripts/navigation/CommonDomainRoutes.tsx | 6 +++--- .../DebugPrivyMobile.tsx => DebugMobile/DebugMobile.tsx} | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) rename packages/commonwealth/client/scripts/views/components/{PrivyMobile/DebugPrivyMobile.tsx => DebugMobile/DebugMobile.tsx} (95%) diff --git a/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx b/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx index 0f8484da436..336c156740b 100644 --- a/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx +++ b/packages/commonwealth/client/scripts/navigation/CommonDomainRoutes.tsx @@ -1,7 +1,7 @@ import { Navigate } from 'navigation/helpers'; import React, { lazy } from 'react'; import { Route } from 'react-router-dom'; -import { DebugPrivyMobile } from 'views/components/PrivyMobile/DebugPrivyMobile'; +import { DebugMobile } from 'views/components/DebugMobile/DebugMobile'; import { SignIn } from 'views/components/SignIn/SignIn'; import { withLayout } from 'views/Layout'; import { MobileSignIn } from 'views/modals/MobileSignIn/MobileSignIn'; @@ -148,8 +148,8 @@ const newProposalViewPage = lazy( const CommonDomainRoutes = () => [ } + path="/_internal/debug-mobile" + element={} />, (); From e83da9f389d16c1fc27f7e9fdfd6ebd75b834be8 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 13:11:39 -0700 Subject: [PATCH 33/56] ... --- .../components/DebugMobile/DebugMobile.tsx | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx index 19cc0324101..19f7531b0cd 100644 --- a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx @@ -1,5 +1,6 @@ import React, { memo, useState } from 'react'; import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; +import { useNotificationsGetPermissionsAsyncReceiver } from 'views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; @@ -14,11 +15,17 @@ export const DebugMobile = memo(function DebugMobile() { const [signature, setSignature] = useState(); const [accounts, setAccounts] = useState(); + const [notificationPermissions, setNotificationPermissions] = useState< + string | undefined + >(); const signMessage = usePrivyMobileSignMessage(); const logout = usePrivyMobileLogout(); const ethereumWalletRequest = usePrivyEthereumWalletRequest(); + const getNotificationsPermissions = + useNotificationsGetPermissionsAsyncReceiver(); + const handleSignMessage = () => { async function doAsync() { const result = await signMessage('hello'); @@ -47,6 +54,15 @@ export const DebugMobile = memo(function DebugMobile() { doAsync().catch(console.error); }; + const handleGetNotificationsPermissions = () => { + async function doAsync() { + const { status } = await getNotificationsPermissions({}); + setNotificationPermissions(status); + } + + doAsync().catch(console.error); + }; + return (
@@ -68,10 +84,20 @@ export const DebugMobile = memo(function DebugMobile() {
+
+ +
+ {signature &&
signature: {signature}
} {accounts &&
accounts: {JSON.stringify(accounts, null, 2)}
} + {notificationPermissions && ( +
notificationPermissions: {notificationPermissions}
+ )} +
{JSON.stringify(privyMobileAuthStatus, null, 2)}
From a66c20bca78940b72cdcd6c4217b1d08e01f2f4a Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 13:29:02 -0700 Subject: [PATCH 34/56] use request... --- .../views/components/DebugMobile/DebugMobile.tsx | 12 ++++++------ ...seNotificationsRequestPermissionsAsyncReceiver.ts | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx index 19f7531b0cd..9e5246104bb 100644 --- a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx @@ -1,10 +1,10 @@ import React, { memo, useState } from 'react'; import { DebugPostMessage } from 'views/components/PrivyMobile/DebugPostMessage'; -import { useNotificationsGetPermissionsAsyncReceiver } from 'views/components/PrivyMobile/useNotificationsGetPermissionsAsyncReceiver'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import usePrivyMobileAuthStatusStore from 'views/components/PrivyMobile/usePrivyMobileAuthStatusStore'; import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; +import { useNotificationsRequestPermissionsAsyncReceiver } from '../PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver'; /** * component to help debug mobile usage. @@ -23,8 +23,8 @@ export const DebugMobile = memo(function DebugMobile() { const logout = usePrivyMobileLogout(); const ethereumWalletRequest = usePrivyEthereumWalletRequest(); - const getNotificationsPermissions = - useNotificationsGetPermissionsAsyncReceiver(); + const requestNotificationsPermissions = + useNotificationsRequestPermissionsAsyncReceiver(); const handleSignMessage = () => { async function doAsync() { @@ -54,9 +54,9 @@ export const DebugMobile = memo(function DebugMobile() { doAsync().catch(console.error); }; - const handleGetNotificationsPermissions = () => { + const handleRequestNotificationsPermissions = () => { async function doAsync() { - const { status } = await getNotificationsPermissions({}); + const { status } = await requestNotificationsPermissions({}); setNotificationPermissions(status); } @@ -85,7 +85,7 @@ export const DebugMobile = memo(function DebugMobile() {
-
diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts index 48ac6554169..b3c5c77a9da 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver.ts @@ -1,7 +1,11 @@ import { useMobileRPCSender } from 'client/scripts/hooks/mobile/useMobileRPCSender'; +type PermissionStatus = { + status: 'granted' | 'denied' | 'undetermined'; +}; + export function useNotificationsRequestPermissionsAsyncReceiver() { - return useMobileRPCSender<{}, {}>({ + return useMobileRPCSender<{}, PermissionStatus>({ type: 'Notifications.requestPermissionsAsync', }); } From 7691a92db08caea670b1ac2f38e0e7f28a4ca786 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 14:24:16 -0700 Subject: [PATCH 35/56] request notifications.. not get.. --- .../client/scripts/views/components/DebugMobile/DebugMobile.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx index 9e5246104bb..e10b27c3766 100644 --- a/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx +++ b/packages/commonwealth/client/scripts/views/components/DebugMobile/DebugMobile.tsx @@ -86,7 +86,7 @@ export const DebugMobile = memo(function DebugMobile() {
From dcb85290eddcc0bd02bc22aaaad55d01f2cc16c6 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 8 May 2025 14:44:22 -0700 Subject: [PATCH 36/56] ok we fixed permission prompting. --- .../scripts/utils/MobileNotifications.ts | 9 +++++++++ .../useSubscriptionPreferenceSettingToggle.ts | 19 +++++++++++++++---- .../verifyMobileNotificationPermissions.ts | 3 +++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/commonwealth/client/scripts/utils/MobileNotifications.ts b/packages/commonwealth/client/scripts/utils/MobileNotifications.ts index 077bee419e4..ff8f66d8916 100644 --- a/packages/commonwealth/client/scripts/utils/MobileNotifications.ts +++ b/packages/commonwealth/client/scripts/utils/MobileNotifications.ts @@ -30,7 +30,13 @@ export interface PermissionResponse { status: PermissionStatus; } +/** + * @deprecated Not used any longer. We should remove. + */ export class MobileNotifications { + /** + * @deprecated + */ public static async getPermissionsAsync(): Promise { // eslint-disable-next-line @typescript-eslint/no-explicit-any const response = await execWithinMobileApp({ @@ -44,6 +50,9 @@ export class MobileNotifications { }; } + /** + * @deprecated + */ public static async requestPermissionsAsync(): Promise { // eslint-disable-next-line @typescript-eslint/no-explicit-any const response = await execWithinMobileApp({ diff --git a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/useSubscriptionPreferenceSettingToggle.ts b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/useSubscriptionPreferenceSettingToggle.ts index 7206ac35f71..ff3adebc2fb 100644 --- a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/useSubscriptionPreferenceSettingToggle.ts +++ b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/useSubscriptionPreferenceSettingToggle.ts @@ -6,13 +6,16 @@ import { useUpdateSubscriptionPreferencesMutation } from 'state/api/trpc/subscri // eslint-disable-next-line max-len import useUserStore from 'state/ui/user'; // eslint-disable-next-line max-len +import { useNotificationsRequestPermissionsAsyncReceiver } from 'views/components/PrivyMobile/useNotificationsRequestPermissionsAsyncReceiver'; import { SubscriptionPrefType } from 'views/pages/NotificationSettings/useSubscriptionPreferenceSetting'; -import { verifyMobileNotificationPermissions } from './verifyMobileNotificationPermissions'; export function useSubscriptionPreferenceSettingToggle( prefs: SubscriptionPrefType[], ) { const subscriptionPreferences = useSubscriptionPreferences(); + + const requestPermissions = useNotificationsRequestPermissionsAsyncReceiver(); + const { mutateAsync: updateSubscriptionPreferences } = useUpdateSubscriptionPreferencesMutation(); const user = useUserStore(); @@ -21,8 +24,10 @@ export function useSubscriptionPreferenceSettingToggle( async (activate: boolean) => { if (activate) { // *** we have to first request permissions if we're activating. - const verified = await verifyMobileNotificationPermissions(); - if (!verified) { + const { status: notificationPermissions } = await requestPermissions( + {}, + ); + if (notificationPermissions !== 'granted') { return; } } @@ -46,6 +51,12 @@ export function useSubscriptionPreferenceSettingToggle( await subscriptionPreferences.refetch(); }, - [prefs, subscriptionPreferences, updateSubscriptionPreferences, user.id], + [ + prefs, + requestPermissions, + subscriptionPreferences, + updateSubscriptionPreferences, + user.id, + ], ); } diff --git a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/verifyMobileNotificationPermissions.ts b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/verifyMobileNotificationPermissions.ts index 6d8d0478c52..a7f39b583e4 100644 --- a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/verifyMobileNotificationPermissions.ts +++ b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/verifyMobileNotificationPermissions.ts @@ -1,6 +1,9 @@ import { isMobileApp } from 'hooks/useReactNativeWebView'; import { MobileNotifications } from 'utils/MobileNotifications'; +/** + * @deprecated Not used any longer. We should remove. + */ export async function verifyMobileNotificationPermissions(): Promise { if (isMobileApp()) { const existingPermissions = await MobileNotifications.getPermissionsAsync(); From 8827f40455b99e596b9afe5ae39939cfec7f2bd0 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 09:58:01 -0700 Subject: [PATCH 37/56] trying to debug auth... it should work, but it's not... --- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 76f2c265143..fa591f5284d 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -81,14 +81,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { newSession: true, }); - console.log( - 'FIXME: Going to sign in now with privy mobile. session: ', - session, - ); - - console.log('FIXME: trying to sign in now... '); - - const auth = await signIn(session, { + const signInOpts = { address: privyMobileAuthStatus.userAuth.address, community_id: ChainBase.Ethereum, wallet_id: WalletId.Privy, @@ -99,7 +92,13 @@ export const PrivyMobileAuthenticator = (props: Props) => { privyMobileAuthStatus.userAuth.ssoProvider, ), }, - }); + }; + + console.log('FIXME: Trying to auth '); + console.log('FIXME: session: ' + session); + console.log('FIXME: signInOpts: ' + JSON.stringify(signInOpts, null, 2)); + + const auth = await signIn(session, signInOpts); console.log('FIXME signIn result: ' + JSON.stringify(auth, null, 2)); } From 41c72df6f9af7185a8f48e8919a7727d529a824d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 12:55:05 -0700 Subject: [PATCH 38/56] force logout on mobile... --- .../components/SublayoutHeader/useUserMenuItems.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/SublayoutHeader/useUserMenuItems.tsx b/packages/commonwealth/client/scripts/views/components/SublayoutHeader/useUserMenuItems.tsx index 5c6dcb8add7..21f7251fc8b 100644 --- a/packages/commonwealth/client/scripts/views/components/SublayoutHeader/useUserMenuItems.tsx +++ b/packages/commonwealth/client/scripts/views/components/SublayoutHeader/useUserMenuItems.tsx @@ -33,6 +33,7 @@ import useUserStore from 'state/ui/user'; import { PopoverMenuItem } from 'views/components/component_kit/CWPopoverMenu'; import { CWToggle } from 'views/components/component_kit/new_designs/cw_toggle'; import CWIconButton from 'views/components/component_kit/new_designs/CWIconButton'; +import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import useAuthentication from '../../modals/AuthModal/useAuthentication'; import { MobileTabType } from '../../pages/WalletPage/types'; import { mobileTabParam } from '../../pages/WalletPage/utils'; @@ -79,6 +80,7 @@ const useUserMenuItems = ({ const privyEnabled = useFlag('privy'); const { authenticated, logout } = usePrivy(); + const privyMobileLogout = usePrivyMobileLogout(); const userData = useUserStore(); const hasMagic = userData.hasMagicWallet; @@ -116,6 +118,11 @@ const useUserMenuItems = ({ if (privyEnabled && authenticated) { await logout(); } + + // it's ok to call this when running outside of the mobile app as nothing + // will happen. + privyMobileLogout({}).catch(console.error); + notifySuccess('Signed out'); darkModeStore.getState().setDarkMode(false); setLocalStorageItem(LocalStorageKeys.HasSeenNotifications, 'true'); @@ -124,7 +131,7 @@ const useUserMenuItems = ({ notifyError('Something went wrong during logging out.'); window.location.reload(); } - }, [authenticated, logout, privyEnabled]); + }, [authenticated, logout, privyEnabled, privyMobileLogout]); useEffect(() => { // if a user is in a stake enabled community without membership, set first user address as active that From cb777ac574c12404bd04fd6663ecd6ffa0e5586d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 13:31:24 -0700 Subject: [PATCH 39/56] trying to fix auth now... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index fa591f5284d..0aa07411899 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -81,6 +81,10 @@ export const PrivyMobileAuthenticator = (props: Props) => { newSession: true, }); + const ssoProvider = privyMobileAuthStatus.userAuth.ssoProvider + ? toSignInProvider(privyMobileAuthStatus.userAuth.ssoProvider) + : undefined; + const signInOpts = { address: privyMobileAuthStatus.userAuth.address, community_id: ChainBase.Ethereum, @@ -88,9 +92,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { privy: { identityToken: privyMobileAuthStatus.userAuth.identityToken, ssoOAuthToken: privyMobileAuthStatus.userAuth.ssoOAuthToken, - ssoProvider: toSignInProvider( - privyMobileAuthStatus.userAuth.ssoProvider, - ), + ssoProvider, }, }; From 4947d013606d91caa7b9240ec03ebe73c3a4fc5d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 13:32:42 -0700 Subject: [PATCH 40/56] Fixing types... --- .../views/components/PrivyMobile/usePrivyMobileAuthStatus.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts index 986e354dffc..bcd463666c1 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileAuthStatus.ts @@ -13,8 +13,8 @@ export interface UserAuth { id: string; address: string; identityToken: string; - ssoOAuthToken: string; - ssoProvider: WalletSsoSource; + ssoOAuthToken?: string; + ssoProvider?: WalletSsoSource; } export interface IPrivyMobileAuthStatus { From 14ac8ea1e5b70a503a03a8e1f0bf748f1b7e8f01 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 14:11:22 -0700 Subject: [PATCH 41/56] it requires one more load after signIn... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 0aa07411899..f2ef3c81304 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -103,6 +103,12 @@ export const PrivyMobileAuthenticator = (props: Props) => { const auth = await signIn(session, signInOpts); console.log('FIXME signIn result: ' + JSON.stringify(auth, null, 2)); + + const landingURL = new URL( + '/dashboard/for-you', + window.location.href, + ).toString(); + document.location.href = landingURL; } doAsync().catch(console.error); From 8853de6938d0ac4466a0fedc45acec45d942593d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 14:29:40 -0700 Subject: [PATCH 42/56] Fixed bug with auth loop... --- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index f2ef3c81304..ca47d28d224 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -3,6 +3,7 @@ import { PrivyEthereumWebWalletController } from 'controllers/app/webWallets/pri import { getSessionFromWallet } from 'controllers/server/sessions'; import { ReactNode, useCallback, useEffect } from 'react'; import { useSignIn } from 'state/api/user'; +import useUserStore from 'state/ui/user'; import { toSignInProvider } from 'views/components/Privy/helpers'; import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyEthereumWalletOn'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; @@ -27,6 +28,8 @@ export const PrivyMobileAuthenticator = (props: Props) => { const getPrivyMobileAuthStatus = usePrivyMobileAuthStatus(); const { signIn } = useSignIn(); + const user = useUserStore(); + const walletRequest = usePrivyEthereumWalletRequest(); const walletOn = usePrivyEthereumWalletOn(); const signMessage = usePrivyMobileSignMessage(); @@ -44,6 +47,11 @@ export const PrivyMobileAuthenticator = (props: Props) => { useEffect(() => { async function doAsync() { + if (user) { + // we're already authenticated so there's nothing to do... + return; + } + const privyMobileAuthStatus = await getPrivyMobileAuthStatus({}); console.log( @@ -112,7 +120,13 @@ export const PrivyMobileAuthenticator = (props: Props) => { } doAsync().catch(console.error); - }, [ethereumProvider, getPrivyMobileAuthStatus, signIn, signMessageProvider]); + }, [ + user, + ethereumProvider, + getPrivyMobileAuthStatus, + signIn, + signMessageProvider, + ]); if (!window.PRIVY_MOBILE_ENABLED) { console.log('FIXME: Privy mobile is not enabled.'); From 06c4ecadee0eb613af6bd7cc9e99ed43f1baa4c3 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 14:43:03 -0700 Subject: [PATCH 43/56] wrong logic... --- .../views/components/PrivyMobile/PrivyMobileAuthenticator.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index ca47d28d224..d15aa264b6b 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -47,7 +47,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { useEffect(() => { async function doAsync() { - if (user) { + if (user && user.isLoggedIn) { // we're already authenticated so there's nothing to do... return; } From 1bfa20643b48e82560f27553b3c93582101719e2 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Mon, 12 May 2025 14:46:58 -0700 Subject: [PATCH 44/56] cleanup --- .../webWallets/privy_ethereum_web_wallet.ts | 21 ------------------- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 11 ---------- 2 files changed, 32 deletions(-) diff --git a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts index 227e860af6e..2a6cf848cf8 100644 --- a/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts +++ b/packages/commonwealth/client/scripts/controllers/app/webWallets/privy_ethereum_web_wallet.ts @@ -98,8 +98,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { public async enable(forceChainId?: string) { // TODO: use https://docs.metamask.io/guide/rpc-api.html#other-rpc-methods to switch active // chain according to currently active node, if one exists - console.log('FIXME: within enable... 1'); - console.log('Attempting to enable Metamask'); this._enabling = true; try { // default to ETH @@ -109,8 +107,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { const Web3 = (await import('web3')).default; - console.log('FIXME: within enable... 2'); - let ethereum = await this.etheriumProvider(); if (ethereum.providers?.length) { @@ -120,8 +116,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { }); } - console.log('FIXME: within enable... 3'); - this._web3 = process.env.ETH_RPC !== 'e2e-test' ? { @@ -144,8 +138,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { if (!this._web3.givenProvider.request) throw new Error('No web3.givenProvider.request'); - console.log('FIXME: within enable... 4'); - await this._web3.givenProvider.request({ method: 'eth_requestAccounts', }); @@ -160,8 +152,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { }); } } catch (switchError) { - console.log('FIXME: within enable... 5'); - // This error code indicates that the chain has not been added to MetaMask. if (switchError.code === 4902) { const wsRpcUrl = app.chain?.meta?.ChainNode?.url ?? ''; @@ -198,8 +188,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { } } - console.log('FIXME: within enable... 6'); - // fetch active accounts this._accounts = ( await this._web3.givenProvider.request({ @@ -213,8 +201,6 @@ export class PrivyEthereumWebWalletController implements IWebWallet { throw new Error('Metamask fetched no accounts'); } - console.log('FIXME: within enable... 7'); - await this.initAccountsChanged(); this._enabled = true; this._enabling = false; @@ -231,16 +217,9 @@ export class PrivyEthereumWebWalletController implements IWebWallet { } public async initAccountsChanged() { - // FIXME: we don't have the 'on' event handler... - console.log('FIXME: within enable... 7'); - await this._web3.givenProvider.on( 'accountsChanged', async (accounts: string[]) => { - console.log( - 'FIXME: initAccounts got some accounts: ', - JSON.stringify(accounts, null, 2), - ); const updatedAddress = userStore .getState() .accounts.find((addr) => addr.address === accounts[0]); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index d15aa264b6b..53d09dd9295 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -104,8 +104,6 @@ export const PrivyMobileAuthenticator = (props: Props) => { }, }; - console.log('FIXME: Trying to auth '); - console.log('FIXME: session: ' + session); console.log('FIXME: signInOpts: ' + JSON.stringify(signInOpts, null, 2)); const auth = await signIn(session, signInOpts); @@ -128,14 +126,5 @@ export const PrivyMobileAuthenticator = (props: Props) => { signMessageProvider, ]); - if (!window.PRIVY_MOBILE_ENABLED) { - console.log('FIXME: Privy mobile is not enabled.'); - return children; - } - console.log('FIXME: Privy mobile is ENABLED.'); - - // FIXME: do not return until we've finished authenticating... - // FIXME: can I use useUeerStore here ? - return children; }; From f3020cd8e0fe0134de1ff1f0c72b71c881c75d3d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 13 May 2025 07:32:23 -0700 Subject: [PATCH 45/56] cleanup... also handle auth better. --- .../PrivyMobile/PrivyMobileAuthenticator.tsx | 34 ++++++++----------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 53d09dd9295..bf17688cbf7 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -1,7 +1,7 @@ import { ChainBase, WalletId } from '@hicommonwealth/shared'; import { PrivyEthereumWebWalletController } from 'controllers/app/webWallets/privy_ethereum_web_wallet'; import { getSessionFromWallet } from 'controllers/server/sessions'; -import { ReactNode, useCallback, useEffect } from 'react'; +import React, { ReactNode, useCallback, useEffect } from 'react'; import { useSignIn } from 'state/api/user'; import useUserStore from 'state/ui/user'; import { toSignInProvider } from 'views/components/Privy/helpers'; @@ -9,6 +9,7 @@ import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyE import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import { usePrivyMobileAuthStatus } from 'views/components/PrivyMobile/usePrivyMobileAuthStatus'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; +import { PageLoading } from 'views/pages/loading'; declare global { interface Window { @@ -47,20 +48,20 @@ export const PrivyMobileAuthenticator = (props: Props) => { useEffect(() => { async function doAsync() { - if (user && user.isLoggedIn) { + if (!window.PRIVY_MOBILE_ENABLED) { + // only attempt to authenticate when running in the mobile app and + // privy is enabled. + return; + } + + if (user.isLoggedIn) { // we're already authenticated so there's nothing to do... return; } const privyMobileAuthStatus = await getPrivyMobileAuthStatus({}); - console.log( - 'FIXME: privyMobileAuthStatus', - JSON.stringify(privyMobileAuthStatus, null, 2), - ); - if (!privyMobileAuthStatus.enabled) { - console.log('FIXME: Privy mobile auth is not enabled'); return; } @@ -68,23 +69,16 @@ export const PrivyMobileAuthenticator = (props: Props) => { !privyMobileAuthStatus.authenticated || !privyMobileAuthStatus.userAuth ) { - console.log('FIXME: Privy mobile not authenticated.'); return; } - console.log('FIXME: Privy mobile is authenticated so trying to sign in '); - const webWallet = new PrivyEthereumWebWalletController( ethereumProvider, signMessageProvider, ); - console.log('FIXME enable web wallet... '); - - // FIXME this is the bug now - it's not logging though await webWallet.enable(); - console.log('FIXME getting session now.;'); const session = await getSessionFromWallet(webWallet, { newSession: true, }); @@ -104,11 +98,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { }, }; - console.log('FIXME: signInOpts: ' + JSON.stringify(signInOpts, null, 2)); - - const auth = await signIn(session, signInOpts); - - console.log('FIXME signIn result: ' + JSON.stringify(auth, null, 2)); + await signIn(session, signInOpts); const landingURL = new URL( '/dashboard/for-you', @@ -126,5 +116,9 @@ export const PrivyMobileAuthenticator = (props: Props) => { signMessageProvider, ]); + if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { + return ; + } + return children; }; From 048cb685f8282aafc28197c86551357b3e8ecc43 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 13 May 2025 08:12:49 -0700 Subject: [PATCH 46/56] cleaning up this component because it was misnamed, and in the wrong place. --- .../DefaultPrivyProvider/WaitForPrivy.tsx | 4 ++-- .../LoadingIndicator/LoadingIndicator.scss} | 2 +- .../LoadingIndicator/LoadingIndicator.tsx | 21 +++++++++++++++++++ .../PrivyMobile/PrivyMobileAuthenticator.tsx | 4 ++-- .../Update/UpdateCommunityGroupPage.tsx | 4 ++-- .../Integrations/Discord/CallbackPage.tsx | 4 ++-- .../pages/GovernancePage/GovernancePage.tsx | 4 ++-- .../NewProposalViewPage.tsx | 4 ++-- .../pages/NotificationSettings/index.tsx | 6 +++--- .../views/pages/Redirects/GroupRedirect.tsx | 4 ++-- .../scripts/views/pages/comment_redirect.tsx | 4 ++-- .../views/pages/discussions_redirect.tsx | 4 ++-- .../views/pages/finish_social_login.tsx | 4 ++-- .../client/scripts/views/pages/loading.tsx | 21 ------------------- .../views/pages/new_proposal/index.tsx | 6 +++--- .../scripts/views/pages/profile_redirect.tsx | 4 ++-- .../client/scripts/views/pages/proposals.tsx | 4 ++-- .../scripts/views/pages/search/index.tsx | 4 ++-- .../pages/snapshot_proposal_link_redirect.tsx | 4 ++-- .../client/scripts/views/pages/stats.tsx | 4 ++-- .../scripts/views/pages/thread_redirect.tsx | 4 ++-- .../scripts/views/pages/topic_redirect.tsx | 4 ++-- .../views/pages/view_proposal/index.tsx | 8 +++---- 23 files changed, 66 insertions(+), 66 deletions(-) rename packages/commonwealth/client/scripts/views/{pages/loading.scss => components/LoadingIndicator/LoadingIndicator.scss} (92%) create mode 100644 packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.tsx delete mode 100644 packages/commonwealth/client/scripts/views/pages/loading.tsx diff --git a/packages/commonwealth/client/scripts/views/components/DefaultPrivyProvider/WaitForPrivy.tsx b/packages/commonwealth/client/scripts/views/components/DefaultPrivyProvider/WaitForPrivy.tsx index 581bb8cee02..83e428b43e8 100644 --- a/packages/commonwealth/client/scripts/views/components/DefaultPrivyProvider/WaitForPrivy.tsx +++ b/packages/commonwealth/client/scripts/views/components/DefaultPrivyProvider/WaitForPrivy.tsx @@ -1,6 +1,6 @@ import { usePrivy } from '@privy-io/react-auth'; import React, { memo } from 'react'; -import { PageLoading } from 'views/pages/loading'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import './WaitForPrivy.scss'; type WaitForPrivyProps = { @@ -17,7 +17,7 @@ export const WaitForPrivy = memo(function WaitForPrivy( if (!ready) { return (
- ; + ;
); } diff --git a/packages/commonwealth/client/scripts/views/pages/loading.scss b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.scss similarity index 92% rename from packages/commonwealth/client/scripts/views/pages/loading.scss rename to packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.scss index 6c87e5bcc2d..2c3ba37aff1 100644 --- a/packages/commonwealth/client/scripts/views/pages/loading.scss +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.scss @@ -1,4 +1,4 @@ -.LoadingPage { +.LoadingIndicator { align-items: center; display: flex; flex: 1; diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.tsx b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.tsx new file mode 100644 index 00000000000..5bbee446020 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/LoadingIndicator.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { CWText } from '../component_kit/cw_text'; +import CWCircleMultiplySpinner from '../component_kit/new_designs/CWCircleMultiplySpinner'; +import './LoadingIndicator.scss'; + +type LoadingIndicatorProps = { + message?: string; +}; + +export const LoadingIndicator = (props: LoadingIndicatorProps) => { + const { message } = props; + + return ( +
+
+ + {message} +
+
+ ); +}; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index bf17688cbf7..f154d5c2490 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -4,12 +4,12 @@ import { getSessionFromWallet } from 'controllers/server/sessions'; import React, { ReactNode, useCallback, useEffect } from 'react'; import { useSignIn } from 'state/api/user'; import useUserStore from 'state/ui/user'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import { toSignInProvider } from 'views/components/Privy/helpers'; import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyEthereumWalletOn'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import { usePrivyMobileAuthStatus } from 'views/components/PrivyMobile/usePrivyMobileAuthStatus'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; -import { PageLoading } from 'views/pages/loading'; declare global { interface Window { @@ -117,7 +117,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { ]); if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { - return ; + return ; } return children; diff --git a/packages/commonwealth/client/scripts/views/pages/CommunityGroupsAndMembers/Groups/Update/UpdateCommunityGroupPage.tsx b/packages/commonwealth/client/scripts/views/pages/CommunityGroupsAndMembers/Groups/Update/UpdateCommunityGroupPage.tsx index f2b87d93e53..5b58c1157f6 100644 --- a/packages/commonwealth/client/scripts/views/pages/CommunityGroupsAndMembers/Groups/Update/UpdateCommunityGroupPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/CommunityGroupsAndMembers/Groups/Update/UpdateCommunityGroupPage.tsx @@ -10,8 +10,8 @@ import useUserStore from 'state/ui/user'; import Permissions from 'utils/Permissions'; import { MixpanelPageViewEvent } from '../../../../../../../shared/analytics/types'; import useAppStatus from '../../../../../hooks/useAppStatus'; +import { LoadingIndicator } from '../../../../components/LoadingIndicator/LoadingIndicator'; import { PageNotFound } from '../../../404'; -import { PageLoading } from '../../../loading'; import { AMOUNT_CONDITIONS, chainTypes, @@ -77,7 +77,7 @@ const UpdateCommunityGroupPage = ({ groupId }: { groupId: string }) => { } if (isLoading) { - return ; + return ; } return ( diff --git a/packages/commonwealth/client/scripts/views/pages/CommunityManagement/Integrations/Discord/CallbackPage.tsx b/packages/commonwealth/client/scripts/views/pages/CommunityManagement/Integrations/Discord/CallbackPage.tsx index 63ac482855a..1be47040868 100644 --- a/packages/commonwealth/client/scripts/views/pages/CommunityManagement/Integrations/Discord/CallbackPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/CommunityManagement/Integrations/Discord/CallbackPage.tsx @@ -2,8 +2,8 @@ import useNecessaryEffect from 'hooks/useNecessaryEffect'; import { useCommonNavigate } from 'navigation/helpers'; import React, { useState } from 'react'; import { useSetDiscordBotConfigMutation } from 'state/api/discord'; +import { LoadingIndicator } from '../../../../components/LoadingIndicator/LoadingIndicator'; import { PageNotFound } from '../../../404'; -import { PageLoading } from '../../../loading'; const CallbackPage = () => { const navigate = useCommonNavigate(); @@ -59,7 +59,7 @@ const CallbackPage = () => { return failed ? ( ) : ( - + ); }; diff --git a/packages/commonwealth/client/scripts/views/pages/GovernancePage/GovernancePage.tsx b/packages/commonwealth/client/scripts/views/pages/GovernancePage/GovernancePage.tsx index e9d251127a2..b266328cc27 100644 --- a/packages/commonwealth/client/scripts/views/pages/GovernancePage/GovernancePage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/GovernancePage/GovernancePage.tsx @@ -9,8 +9,8 @@ import { } from 'client/scripts/state/api/proposals'; import React, { useEffect, useState } from 'react'; import CWPageLayout from '../../components/component_kit/new_designs/CWPageLayout'; +import { LoadingIndicator } from '../../components/LoadingIndicator/LoadingIndicator'; import { PageNotFound } from '../404'; -import { PageLoading } from '../loading'; import GovernanceCards from './GovernanceCards'; import GovernanceHeader from './GovernanceHeader/GovernanceHeader'; import './GovernancePage.scss'; @@ -60,7 +60,7 @@ const GovernancePage = () => { ); } - return ; + return ; } const activeProposalsCount = activeCosmosProposals?.length || 0; diff --git a/packages/commonwealth/client/scripts/views/pages/NewProposalViewPage/NewProposalViewPage.tsx b/packages/commonwealth/client/scripts/views/pages/NewProposalViewPage/NewProposalViewPage.tsx index 4fa7eb6efe2..7685134a486 100644 --- a/packages/commonwealth/client/scripts/views/pages/NewProposalViewPage/NewProposalViewPage.tsx +++ b/packages/commonwealth/client/scripts/views/pages/NewProposalViewPage/NewProposalViewPage.tsx @@ -10,6 +10,7 @@ import { useSearchParams } from 'react-router-dom'; import app from 'state'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; import useManageDocumentTitle from '../../../hooks/useManageDocumentTitle'; +import { LoadingIndicator } from '../../components/LoadingIndicator/LoadingIndicator'; import MarkdownViewerWithFallback from '../../components/MarkdownViewerWithFallback'; import CWAccordView from '../../components/component_kit/CWAccordView/CWAccordView'; import { CWContentPage } from '../../components/component_kit/CWContentPage'; @@ -24,7 +25,6 @@ import { VotingActions } from '../../components/proposals/voting_actions'; import { VotingResults } from '../../components/proposals/voting_results'; import { PageNotFound } from '../404'; import { SnapshotPollCardContainer } from '../Snapshots/ViewSnapshotProposal/SnapshotPollCard'; -import { PageLoading } from '../loading'; import { JSONDisplay } from '../view_proposal/JSONDisplay'; import ProposalVotesDrawer from './ProposalVotesDrawer/ProposalVotesDrawer'; import { useCosmosProposal } from './useCosmosProposal'; @@ -136,7 +136,7 @@ const NewProposalViewPage = ({ identifier, scope }: ViewProposalPageProps) => { }, [snapshotProposal, proposal, queryType]); if (isLoading || isSnapshotLoading) { - return ; + return ; } if (cosmosError) { diff --git a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/index.tsx b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/index.tsx index 91e580bf764..9ea50490919 100644 --- a/packages/commonwealth/client/scripts/views/pages/NotificationSettings/index.tsx +++ b/packages/commonwealth/client/scripts/views/pages/NotificationSettings/index.tsx @@ -2,12 +2,12 @@ import { CommunityAlert } from '@hicommonwealth/schemas'; import React, { useState } from 'react'; import { useCommunityAlertsQuery } from 'state/api/trpc/subscription/useCommunityAlertsQuery'; import useUserStore from 'state/ui/user'; -import ScrollContainer from 'views/components/ScrollContainer'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; import { CWTab, CWTabsRow, } from 'views/components/component_kit/new_designs/CWTabs'; +import ScrollContainer from 'views/components/ScrollContainer'; import { PageNotFound } from 'views/pages/404'; import { CommentSubscriptions } from 'views/pages/NotificationSettings/CommentSubscriptions'; import { CommunityEntry } from 'views/pages/NotificationSettings/CommunityEntry'; @@ -19,7 +19,7 @@ import { useSupportsPushNotifications } from 'views/pages/NotificationSettings/u import { useThreadSubscriptions } from 'views/pages/NotificationSettings/useThreadSubscriptions'; import { z } from 'zod'; import { CWText } from '../../components/component_kit/cw_text'; -import { PageLoading } from '../loading'; +import { LoadingIndicator } from '../../components/LoadingIndicator/LoadingIndicator'; import './index.scss'; type NotificationSection = @@ -42,7 +42,7 @@ const NotificationSettings = () => { useState('push-notifications'); if (threadSubscriptions.isLoading) { - return ; + return ; } else if (!user.isLoggedIn) { return ; } diff --git a/packages/commonwealth/client/scripts/views/pages/Redirects/GroupRedirect.tsx b/packages/commonwealth/client/scripts/views/pages/Redirects/GroupRedirect.tsx index 2b46505a281..764026becd8 100644 --- a/packages/commonwealth/client/scripts/views/pages/Redirects/GroupRedirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/Redirects/GroupRedirect.tsx @@ -2,7 +2,7 @@ import useRunOnceOnCondition from 'hooks/useRunOnceOnCondition'; import { useCommonNavigate } from 'navigation/helpers'; import React from 'react'; import { useFetchGroupsQuery } from 'state/api/groups'; -import { PageLoading } from '../loading'; +import { LoadingIndicator } from '../../components/LoadingIndicator/LoadingIndicator'; const GroupRedirect = ({ id }: { id: string }) => { const navigate = useCommonNavigate(); @@ -26,7 +26,7 @@ const GroupRedirect = ({ id }: { id: string }) => { shouldRun: !!(group || error), }); - return ; + return ; }; export default GroupRedirect; diff --git a/packages/commonwealth/client/scripts/views/pages/comment_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/comment_redirect.tsx index 47847faddd9..d8c1d3bb14a 100644 --- a/packages/commonwealth/client/scripts/views/pages/comment_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/comment_redirect.tsx @@ -2,7 +2,7 @@ import useRunOnceOnCondition from 'hooks/useRunOnceOnCondition'; import { useCommonNavigate } from 'navigation/helpers'; import React from 'react'; import { useFetchCommentsQuery } from 'state/api/comments'; -import { PageLoading } from './loading'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; const CommentRedirect = ({ identifier }: { identifier: string }) => { const navigate = useCommonNavigate(); @@ -32,7 +32,7 @@ const CommentRedirect = ({ identifier }: { identifier: string }) => { shouldRun: !!(foundComment || error), }); - return ; + return ; }; export default CommentRedirect; diff --git a/packages/commonwealth/client/scripts/views/pages/discussions_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/discussions_redirect.tsx index bf0169031b9..1d9849e5f3e 100644 --- a/packages/commonwealth/client/scripts/views/pages/discussions_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/discussions_redirect.tsx @@ -5,7 +5,7 @@ import { NavigateOptions, useLocation } from 'react-router-dom'; import { DefaultPage } from '@hicommonwealth/shared'; import { useCommonNavigate } from 'navigation/helpers'; import app from 'state'; -import { PageLoading } from './loading'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; export default function DiscussionsRedirect() { const navigate = useCommonNavigate(); @@ -40,5 +40,5 @@ export default function DiscussionsRedirect() { } }, [navigate, location.search]); - return ; + return ; } diff --git a/packages/commonwealth/client/scripts/views/pages/finish_social_login.tsx b/packages/commonwealth/client/scripts/views/pages/finish_social_login.tsx index 098e8288907..3aad87ffa4f 100644 --- a/packages/commonwealth/client/scripts/views/pages/finish_social_login.tsx +++ b/packages/commonwealth/client/scripts/views/pages/finish_social_login.tsx @@ -5,8 +5,8 @@ import React, { useEffect, useState } from 'react'; import { initAppState } from 'state'; import { useFetchCustomDomainQuery } from 'state/api/configuration'; import useUserStore from 'state/ui/user'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import ErrorPage from 'views/pages/error'; -import { PageLoading } from 'views/pages/loading'; const validate = async ( setRoute: (route: string) => void, @@ -102,7 +102,7 @@ const FinishSocialLogin = () => { if (validationError) { return ; } else { - return ; + return ; } }; diff --git a/packages/commonwealth/client/scripts/views/pages/loading.tsx b/packages/commonwealth/client/scripts/views/pages/loading.tsx deleted file mode 100644 index 9e518af4744..00000000000 --- a/packages/commonwealth/client/scripts/views/pages/loading.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react'; -import { CWText } from '../components/component_kit/cw_text'; -import CWCircleMultiplySpinner from '../components/component_kit/new_designs/CWCircleMultiplySpinner'; -import './loading.scss'; - -type PageLoadingProps = { - message?: string; -}; - -export const PageLoading = (props: PageLoadingProps) => { - const { message } = props; - - return ( -
-
- - {message} -
-
- ); -}; diff --git a/packages/commonwealth/client/scripts/views/pages/new_proposal/index.tsx b/packages/commonwealth/client/scripts/views/pages/new_proposal/index.tsx index a1f5faf1d68..845f4474f08 100644 --- a/packages/commonwealth/client/scripts/views/pages/new_proposal/index.tsx +++ b/packages/commonwealth/client/scripts/views/pages/new_proposal/index.tsx @@ -4,7 +4,7 @@ import React, { useEffect, useState } from 'react'; import app from 'state'; import { userStore } from 'state/ui/user'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; -import { PageLoading } from 'views/pages/loading'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import { CWText } from '../../components/component_kit/cw_text'; import { PageNotFound } from '../404'; import { CosmosProposalForm } from './cosmos_proposal_form'; @@ -34,7 +34,7 @@ const NewProposalPage = () => { } if (!app.chain || !isLoaded || !app.chain.meta) { - return ; + return ; } // special case for initializing cosmos governance @@ -48,7 +48,7 @@ const NewProposalPage = () => { app.chainModuleReady.emit('ready'); }); } - return ; + return ; } } else { return ; diff --git a/packages/commonwealth/client/scripts/views/pages/profile_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/profile_redirect.tsx index d262050c6ff..feffa6cf595 100644 --- a/packages/commonwealth/client/scripts/views/pages/profile_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/profile_redirect.tsx @@ -5,8 +5,8 @@ import { useCommonNavigate } from 'navigation/helpers'; import app from 'state'; import { useFetchProfilesByAddressesQuery } from 'state/api/profiles'; import useUserStore from 'state/ui/user'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; import { PageNotFound } from './404'; -import { PageLoading } from './loading'; type ProfileRedirectProps = { address: string; @@ -41,7 +41,7 @@ const ProfileRedirect = (props: ProfileRedirectProps) => { }, [isError, users]); if (isLoading) { - return ; + return ; } if (isError) { diff --git a/packages/commonwealth/client/scripts/views/pages/proposals.tsx b/packages/commonwealth/client/scripts/views/pages/proposals.tsx index 7ed9f6b39bb..aab0158ad64 100644 --- a/packages/commonwealth/client/scripts/views/pages/proposals.tsx +++ b/packages/commonwealth/client/scripts/views/pages/proposals.tsx @@ -11,10 +11,10 @@ import { useActiveCosmosProposalsQuery, useCompletedCosmosProposalsQuery, } from 'state/api/proposals'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import { ProposalCard } from 'views/components/ProposalCard'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; import { PageNotFound } from 'views/pages/404'; -import { PageLoading } from 'views/pages/loading'; import useManageDocumentTitle from '../../hooks/useManageDocumentTitle'; import { CardsCollection } from '../components/cards_collection'; import { CWText } from '../components/component_kit/cw_text'; @@ -76,7 +76,7 @@ const ProposalsPage = () => { ); } - return ; + return ; } const activeProposalContent = isLoadingCosmosActiveProposals ? ( diff --git a/packages/commonwealth/client/scripts/views/pages/search/index.tsx b/packages/commonwealth/client/scripts/views/pages/search/index.tsx index a5c60b0448d..456db9a8309 100644 --- a/packages/commonwealth/client/scripts/views/pages/search/index.tsx +++ b/packages/commonwealth/client/scripts/views/pages/search/index.tsx @@ -16,7 +16,7 @@ import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'; import app from 'state'; import { useFetchCustomDomainQuery } from 'state/api/configuration'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; -import { PageLoading } from 'views/pages/loading'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import { APIOrderBy, APIOrderDirection, @@ -309,7 +309,7 @@ const SearchPage = () => { {sharedQueryOptions?.searchTerm?.length > 0 && ( <> {isLoading ? ( - + ) : ( <> diff --git a/packages/commonwealth/client/scripts/views/pages/snapshot_proposal_link_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/snapshot_proposal_link_redirect.tsx index afee64842a9..f376a0fde1e 100644 --- a/packages/commonwealth/client/scripts/views/pages/snapshot_proposal_link_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/snapshot_proposal_link_redirect.tsx @@ -2,7 +2,7 @@ import useNecessaryEffect from 'hooks/useNecessaryEffect'; import { useCommonNavigate } from 'navigation/helpers'; import React from 'react'; import { getSnapshotProposalQuery } from 'state/api/snapshots'; -import { PageLoading } from './loading'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; type SnapshotProposalLinkRedirectProps = { identifier: string; @@ -41,7 +41,7 @@ const SnapshotProposalLinkRedirect = ({ fetchSnapshotData(); }, [navigate]); - return ; + return ; }; export default SnapshotProposalLinkRedirect; diff --git a/packages/commonwealth/client/scripts/views/pages/stats.tsx b/packages/commonwealth/client/scripts/views/pages/stats.tsx index 692e631d527..8722ec90239 100644 --- a/packages/commonwealth/client/scripts/views/pages/stats.tsx +++ b/packages/commonwealth/client/scripts/views/pages/stats.tsx @@ -5,8 +5,8 @@ import app from 'state'; import { SERVER_URL } from 'state/api/config'; import useUserStore, { userStore } from 'state/ui/user'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import ErrorPage from 'views/pages/error'; -import { PageLoading } from 'views/pages/loading'; import { CWText } from '../components/component_kit/cw_text'; import { PageNotFound } from './404'; import './stats.scss'; @@ -155,7 +155,7 @@ const StatsPage = () => { } if (!batchedData) { - return ; + return ; } else if (error) { return ; } diff --git a/packages/commonwealth/client/scripts/views/pages/thread_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/thread_redirect.tsx index b841d05f770..bee38ec94e8 100644 --- a/packages/commonwealth/client/scripts/views/pages/thread_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/thread_redirect.tsx @@ -2,7 +2,7 @@ import useRunOnceOnCondition from 'hooks/useRunOnceOnCondition'; import { useCommonNavigate } from 'navigation/helpers'; import React from 'react'; import { useGetThreadsByIdQuery } from 'state/api/threads'; -import { PageLoading } from './loading'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; const ThreadRedirect = ({ identifier }: { identifier: string }) => { const navigate = useCommonNavigate(); @@ -27,7 +27,7 @@ const ThreadRedirect = ({ identifier }: { identifier: string }) => { shouldRun: !!(foundThread || error), }); - return ; + return ; }; export default ThreadRedirect; diff --git a/packages/commonwealth/client/scripts/views/pages/topic_redirect.tsx b/packages/commonwealth/client/scripts/views/pages/topic_redirect.tsx index f397effe8bd..44dab210446 100644 --- a/packages/commonwealth/client/scripts/views/pages/topic_redirect.tsx +++ b/packages/commonwealth/client/scripts/views/pages/topic_redirect.tsx @@ -3,7 +3,7 @@ import useRunOnceOnCondition from 'hooks/useRunOnceOnCondition'; import { useCommonNavigate } from 'navigation/helpers'; import React from 'react'; import { useGetTopicByIdQuery } from 'state/api/topics'; -import { PageLoading } from './loading'; +import { LoadingIndicator } from '../components/LoadingIndicator/LoadingIndicator'; const ThreadRedirect = ({ id }: { id: number }) => { const navigate = useCommonNavigate(); @@ -46,7 +46,7 @@ const ThreadRedirect = ({ id }: { id: number }) => { shouldRun: !!(topic || error), }); - return ; + return ; }; export default ThreadRedirect; diff --git a/packages/commonwealth/client/scripts/views/pages/view_proposal/index.tsx b/packages/commonwealth/client/scripts/views/pages/view_proposal/index.tsx index 214e9e765df..a37a337c535 100644 --- a/packages/commonwealth/client/scripts/views/pages/view_proposal/index.tsx +++ b/packages/commonwealth/client/scripts/views/pages/view_proposal/index.tsx @@ -16,15 +16,15 @@ import { useCosmosProposalVotesQuery, } from 'state/api/proposals'; import CWPageLayout from 'views/components/component_kit/new_designs/CWPageLayout'; -import { PageLoading } from 'views/pages/loading'; +import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; import useManageDocumentTitle from '../../../hooks/useManageDocumentTitle'; import type { AnyProposal } from '../../../models/types'; -import MarkdownViewerWithFallback from '../../components/MarkdownViewerWithFallback'; -import { Skeleton } from '../../components/Skeleton'; import CWAccordView from '../../components/component_kit/CWAccordView/CWAccordView'; import { CWContentPage } from '../../components/component_kit/CWContentPage'; +import MarkdownViewerWithFallback from '../../components/MarkdownViewerWithFallback'; import TimeLineCard from '../../components/proposals/TimeLineCard'; import { VotingResults } from '../../components/proposals/voting_results'; +import { Skeleton } from '../../components/Skeleton'; import { PageNotFound } from '../404'; import { JSONDisplay } from './JSONDisplay'; import { ProposalSubheader } from './proposal_components'; @@ -95,7 +95,7 @@ const ViewProposalPage = ({ identifier }: ViewProposalPageAttrs) => { }, [isAdapterLoaded, proposalId]); if (isFetchingProposal || !isAdapterLoaded) { - return ; + return ; } if (cosmosError) { From d51bb2088f725bc7b686d73f4dc75fdee8a241ca Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 13 May 2025 08:13:45 -0700 Subject: [PATCH 47/56] ... --- .../client/scripts/views/components/LoadingIndicator/index.tsx | 1 + 1 file changed, 1 insertion(+) create mode 100644 packages/commonwealth/client/scripts/views/components/LoadingIndicator/index.tsx diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicator/index.tsx b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/index.tsx new file mode 100644 index 00000000000..266c417377e --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicator/index.tsx @@ -0,0 +1 @@ +export * from './LoadingIndicator'; From aae3d363b850f366353796ff561f570d91ccb02d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 13 May 2025 08:18:07 -0700 Subject: [PATCH 48/56] new loading indicator screen... --- .../LoadingIndicatorScreen.scss | 6 ++++++ .../LoadingIndicatorScreen.tsx | 14 ++++++++++++++ .../components/LoadingIndicatorScreen/index.tsx | 1 + 3 files changed, 21 insertions(+) create mode 100644 packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.scss create mode 100644 packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx create mode 100644 packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/index.tsx diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.scss b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.scss new file mode 100644 index 00000000000..44738d2df1e --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.scss @@ -0,0 +1,6 @@ +.LoadingIndicatorScreen { + display: flex; + justify-content: center; + align-items: center; + height: 100vh; +} diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx new file mode 100644 index 00000000000..a91185752b2 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { LoadingIndicator } from 'views/components/LoadingIndicator'; +import './LoadingIndicatorScreen.scss'; + +/** + * A full screen loading indicator. + */ +export const LoadingIndicatorScreen = () => { + return ( +
+ +
+ ); +}; diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/index.tsx b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/index.tsx new file mode 100644 index 00000000000..6abba5ece93 --- /dev/null +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/index.tsx @@ -0,0 +1 @@ +export * from './LoadingIndicatorScreen'; From c7ae5c485d48c09ece00a3ee8940743d29bb7bd5 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Tue, 13 May 2025 08:18:51 -0700 Subject: [PATCH 49/56] cleanup... --- .../views/components/PrivyMobile/PrivyMobileAuthenticator.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index f154d5c2490..e3c505f36c9 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -4,7 +4,7 @@ import { getSessionFromWallet } from 'controllers/server/sessions'; import React, { ReactNode, useCallback, useEffect } from 'react'; import { useSignIn } from 'state/api/user'; import useUserStore from 'state/ui/user'; -import { LoadingIndicator } from 'views/components/LoadingIndicator/LoadingIndicator'; +import { LoadingIndicatorScreen } from 'views/components/LoadingIndicatorScreen'; import { toSignInProvider } from 'views/components/Privy/helpers'; import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyEthereumWalletOn'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; @@ -117,7 +117,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { ]); if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { - return ; + return ; } return children; From 6446605c306c81af31f62e99eb0e170c98d7676c Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 14 May 2025 10:08:27 -0700 Subject: [PATCH 50/56] perform logout if there's an error during auth... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index e3c505f36c9..ab0aaa20163 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -9,6 +9,7 @@ import { toSignInProvider } from 'views/components/Privy/helpers'; import { usePrivyEthereumWalletOn } from 'views/components/PrivyMobile/usePrivyEthereumWalletOn'; import { usePrivyEthereumWalletRequest } from 'views/components/PrivyMobile/usePrivyEthereumWalletRequest'; import { usePrivyMobileAuthStatus } from 'views/components/PrivyMobile/usePrivyMobileAuthStatus'; +import { usePrivyMobileLogout } from 'views/components/PrivyMobile/usePrivyMobileLogout'; import { usePrivyMobileSignMessage } from 'views/components/PrivyMobile/usePrivyMobileSignMessage'; declare global { @@ -27,6 +28,8 @@ type Props = { export const PrivyMobileAuthenticator = (props: Props) => { const { children } = props; const getPrivyMobileAuthStatus = usePrivyMobileAuthStatus(); + const privyMobileLogout = usePrivyMobileLogout(); + const { signIn } = useSignIn(); const user = useUserStore(); @@ -107,13 +110,17 @@ export const PrivyMobileAuthenticator = (props: Props) => { document.location.href = landingURL; } - doAsync().catch(console.error); + doAsync().catch((err) => { + console.error('Could not perform authentication: ', err); + privyMobileLogout({}).catch(console.error); + }); }, [ user, ethereumProvider, getPrivyMobileAuthStatus, signIn, signMessageProvider, + privyMobileLogout, ]); if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { From 49481099441b574d3b5ca1df49e730104b799a78 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 14 May 2025 12:50:14 -0700 Subject: [PATCH 51/56] more logging so I can debug the authentication process... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index ab0aaa20163..bc1e6648695 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -101,6 +101,10 @@ export const PrivyMobileAuthenticator = (props: Props) => { }, }; + console.log( + 'Going to authenticate with signInOpts: ' + + JSON.stringify(signInOpts, null, 2), + ); await signIn(session, signInOpts); const landingURL = new URL( @@ -111,7 +115,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { } doAsync().catch((err) => { - console.error('Could not perform authentication: ', err); + console.error('Could not perform authentication: ' + err.message, err); privyMobileLogout({}).catch(console.error); }); }, [ From 0c1cfcc35629d869682a825803981e0951957e49 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Wed, 14 May 2025 15:13:06 -0700 Subject: [PATCH 52/56] ... --- .../views/components/PrivyMobile/PrivyMobileAuthenticator.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index bc1e6648695..b7eec661750 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -116,7 +116,8 @@ export const PrivyMobileAuthenticator = (props: Props) => { doAsync().catch((err) => { console.error('Could not perform authentication: ' + err.message, err); - privyMobileLogout({}).catch(console.error); + // FIXME enable this again once we have reliable authentication working... + //privyMobileLogout({}).catch(console.error); }); }, [ user, From 3cbb1902f2fa2903c6033ec6b407fc88caf47119 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 15 May 2025 12:00:16 -0700 Subject: [PATCH 53/56] more debug code... --- .../client/scripts/hooks/mobile/useMobileRPCSender.ts | 5 ++++- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts index d9c8eefbaeb..359818edc5a 100644 --- a/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts +++ b/packages/commonwealth/client/scripts/hooks/mobile/useMobileRPCSender.ts @@ -52,7 +52,10 @@ export function useMobileRPCSender(opts: Opts) { ); if (protoResponse?.$id === $id) { - console.log('Got proto response: ', protoResponse); + console.log( + 'Got proto response: ', + JSON.stringify(protoResponse, null, 2), + ); if (protoResponse.error) { reject(protoResponse.error); diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index b7eec661750..cd614b4c7c2 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -90,6 +90,15 @@ export const PrivyMobileAuthenticator = (props: Props) => { ? toSignInProvider(privyMobileAuthStatus.userAuth.ssoProvider) : undefined; + // FIXME: the bug is that userAuth , computed in the mobile app, doesn't include the ssoProvider... + + if (!ssoProvider) { + console.warn( + 'Unable to compute the sign in ssoProvider for ' + + privyMobileAuthStatus.userAuth.ssoProvider, + ); + } + const signInOpts = { address: privyMobileAuthStatus.userAuth.address, community_id: ChainBase.Ethereum, From d084fdf41d6c69250defccbf5f61cd833e63d110 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 15 May 2025 15:19:54 -0700 Subject: [PATCH 54/56] support error messages now... --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 4 +++- .../views/components/PrivyMobile/usePrivyMobileLogout.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index cd614b4c7c2..cf53506be69 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -126,7 +126,9 @@ export const PrivyMobileAuthenticator = (props: Props) => { doAsync().catch((err) => { console.error('Could not perform authentication: ' + err.message, err); // FIXME enable this again once we have reliable authentication working... - //privyMobileLogout({}).catch(console.error); + privyMobileLogout({ + error: err.message ?? undefined, + }).catch(console.error); }); }, [ user, diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts index 497dadedfc5..e6b647ac542 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/usePrivyMobileLogout.ts @@ -1,9 +1,13 @@ import { useMobileRPCSender } from 'hooks/mobile/useMobileRPCSender'; +type Input = { + error?: string; +}; + /** * Get privy to sign a message, in react-native, then return the message into * the browser. */ export function usePrivyMobileLogout() { - return useMobileRPCSender<{}, {}>({ type: 'privy.logout' }); + return useMobileRPCSender({ type: 'privy.logout' }); } From 3a1b67116be626654144172bf97e8bd1c2bfe8c2 Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Thu, 15 May 2025 15:42:50 -0700 Subject: [PATCH 55/56] keeping track of what we're waiting for. --- .../LoadingIndicatorScreen/LoadingIndicatorScreen.tsx | 8 ++++++-- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx index a91185752b2..34b18cb0503 100644 --- a/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx +++ b/packages/commonwealth/client/scripts/views/components/LoadingIndicatorScreen/LoadingIndicatorScreen.tsx @@ -2,13 +2,17 @@ import React from 'react'; import { LoadingIndicator } from 'views/components/LoadingIndicator'; import './LoadingIndicatorScreen.scss'; +type LoadingIndicatorScreenProps = { + message?: string; +}; + /** * A full screen loading indicator. */ -export const LoadingIndicatorScreen = () => { +export const LoadingIndicatorScreen = (props: LoadingIndicatorScreenProps) => { return (
- +
); }; diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index cf53506be69..72fe41ebe53 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -140,7 +140,9 @@ export const PrivyMobileAuthenticator = (props: Props) => { ]); if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { - return ; + return ( + + ); } return children; From b0f8a561118d3a21338e3078589a2de48931879d Mon Sep 17 00:00:00 2001 From: Kevin Burton Date: Fri, 16 May 2025 12:09:19 -0700 Subject: [PATCH 56/56] removing FIXME statements. --- .../components/PrivyMobile/PrivyMobileAuthenticator.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx index 72fe41ebe53..23f5559ab6a 100644 --- a/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx +++ b/packages/commonwealth/client/scripts/views/components/PrivyMobile/PrivyMobileAuthenticator.tsx @@ -90,8 +90,6 @@ export const PrivyMobileAuthenticator = (props: Props) => { ? toSignInProvider(privyMobileAuthStatus.userAuth.ssoProvider) : undefined; - // FIXME: the bug is that userAuth , computed in the mobile app, doesn't include the ssoProvider... - if (!ssoProvider) { console.warn( 'Unable to compute the sign in ssoProvider for ' + @@ -125,7 +123,6 @@ export const PrivyMobileAuthenticator = (props: Props) => { doAsync().catch((err) => { console.error('Could not perform authentication: ' + err.message, err); - // FIXME enable this again once we have reliable authentication working... privyMobileLogout({ error: err.message ?? undefined, }).catch(console.error); @@ -140,9 +137,7 @@ export const PrivyMobileAuthenticator = (props: Props) => { ]); if (!user.isLoggedIn && window.PRIVY_MOBILE_ENABLED) { - return ( - - ); + return ; } return children;