Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix(passport): web3 auth lazy load back #2345

Merged
merged 19 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/btoa-npm-1.2.1-be4637c301-afbf004fb1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/flat-npm-5.0.2-12748102a5-12a1536ac7.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ws-npm-7.5.3-3a046a0b1a-423dc0d859.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion apps/console/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ export default function handleRequest(
(nonce, dev) =>
getCSP({
directives: {
'default-src': [SELF],
'default-src': [
SELF,
'https://verify.walletconnect.com'
],
'connect-src': [
SELF,
'*.google-analytics.com',
'wss://relay.walletconnect.com',
'https://*.g.alchemy.com',
'https://upload.imagedelivery.net',
// Used for Remix WebSocket Live Reaload
...(dev ? ['ws://localhost:*/socket'] : []),
Expand Down
11 changes: 11 additions & 0 deletions apps/console/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export type LoaderData = {
ENV: {
INTERNAL_GOOGLE_ANALYTICS_TAG: string
REMIX_DEV_SERVER_WS_PORT?: number
WALLET_CONNECT_PROJECT_ID: string,
}
}

Expand Down Expand Up @@ -124,6 +125,15 @@ export const loader: LoaderFunction = getRollupReqFunctionErrorWrapper(
console.error('Could not retrieve profile image.', e)
}

console.log({
INTERNAL_GOOGLE_ANALYTICS_TAG,
REMIX_DEV_SERVER_WS_PORT:
process.env.NODE_ENV === 'development'
? +process.env.REMIX_DEV_SERVER_WS_PORT!
: undefined,
WALLET_CONNECT_PROJECT_ID,
})

return json<LoaderData>({
apps: reshapedApps,
avatarUrl,
Expand All @@ -134,6 +144,7 @@ export const loader: LoaderFunction = getRollupReqFunctionErrorWrapper(
process.env.NODE_ENV === 'development'
? +process.env.REMIX_DEV_SERVER_WS_PORT!
: undefined,
WALLET_CONNECT_PROJECT_ID,
},
displayName,
})
Expand Down
122 changes: 59 additions & 63 deletions apps/console/app/routes/apps/$clientId/designer.beta.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useLoaderData,
useOutletContext,
} from '@remix-run/react'
import { ReactNode, useContext, useEffect, useRef, useState } from 'react'
import { ReactNode, Suspense, lazy, useContext, useEffect, useRef, useState } from 'react'
import { IconType } from 'react-icons'
import { HiCog, HiOutlineCog, HiOutlineMail } from 'react-icons/hi'
import { DocumentationBadge } from '~/components/DocumentationBadge'
Expand All @@ -16,8 +16,6 @@ import Authentication, {
AuthenticationScreenDefaults,
} from '@proofzero/design-system/src/templates/authentication/Authentication'

import { createClient } from 'wagmi'
import { getDefaultClient } from 'connectkit'
import { Avatar } from '@proofzero/packages/design-system/src/atoms/profile/avatar/Avatar'
import IconPicker from '~/components/IconPicker'
import { Loader } from '@proofzero/design-system/src/molecules/loader/Loader'
Expand Down Expand Up @@ -63,11 +61,10 @@ import { GetEmailOTPThemeResult } from '@proofzero/platform/starbase/src/jsonrpc
import { getRollupReqFunctionErrorWrapper } from '@proofzero/utils/errors'
import { getEmailIcon, adjustAddressTypeToDisplay } from '@proofzero/utils/getNormalisedConnectedAccounts'

const client = createClient(
// @ts-ignore
getDefaultClient({
appName: 'Rollup',
})
const LazyAuth = lazy(() =>
import('../../../web3/lazyAuth').then((module) => ({
default: module.LazyAuth,
}))
)

const getRGBColor = (hex: string, type: string) => {
Expand All @@ -90,9 +87,8 @@ const DesignerTab = ({
selected: boolean
}) => (
<div
className={`box-border -mb-0.5 mr-8 pb-4 px-1 flex flex-row items-center gap-2 border-b-2 ${
selected ? 'border-indigo-600' : 'border-transparent'
}`}
className={`box-border -mb-0.5 mr-8 pb-4 px-1 flex flex-row items-center gap-2 border-b-2 ${selected ? 'border-indigo-600' : 'border-transparent'
}`}
>
<Icon
className={`w-5 h-5 ${selected ? 'text-indigo-600' : 'text-gray-500'}`}
Expand Down Expand Up @@ -182,9 +178,8 @@ const RadiusButton = ({
return (
<button
type="button"
className={`w-full py-1.5 px-2.5 rounded-md ${
selected ? 'bg-indigo-500' : ''
}`}
className={`w-full py-1.5 px-2.5 rounded-md ${selected ? 'bg-indigo-500' : ''
}`}
onClick={(e) => {
e.preventDefault()
setRadius(radius)
Expand Down Expand Up @@ -330,10 +325,10 @@ const AuthPanel = ({
}[]
>(
appTheme?.providers ??
AuthenticationScreenDefaults.knownKeys.map((k) => ({
key: k,
enabled: true,
}))
AuthenticationScreenDefaults.knownKeys.map((k) => ({
key: k,
enabled: true,
}))
)
const [providerModalOpen, setProviderModalOpen] = useState<boolean>(false)

Expand Down Expand Up @@ -549,7 +544,7 @@ const AuthPanel = ({
minWidth={720}
minHeight={1080}
id="image"
setIsFormChanged={(val) => {}}
setIsFormChanged={(val) => { }}
setIsImgUploading={(val) => {
setLoading(val)
}}
Expand Down Expand Up @@ -630,40 +625,41 @@ const AuthPanel = ({
<Tab.Group>
<Tab.Panels className="pointer-events-auto">
<Tab.Panel>
<Authentication
Header={
<>
<Avatar
src={AuthenticationScreenDefaults.defaultLogoURL}
size="sm"
></Avatar>
<div className={'flex flex-col items-center gap-2'}>
<h1
className={'font-semibold text-xl dark:text-white'}
>
{heading ??
AuthenticationScreenDefaults.defaultHeading}
</h1>

<h2
style={{ color: '#6B7280' }}
className={'font-medium text-base'}
>
{AuthenticationScreenDefaults.defaultSubheading}
</h2>
</div>
</>
}
displayKeys={providers
.filter((p) => p.enabled)
.map((p) => p.key)}
mapperArgs={{
clientId: 'Foo',
wagmiClient: client,
signData: null,
}}
radius={radius}
/>
<LazyAuth>
<Authentication
Header={
<>
<Avatar
src={AuthenticationScreenDefaults.defaultLogoURL}
size="sm"
></Avatar>
<div className={'flex flex-col items-center gap-2'}>
<h1
className={'font-semibold text-xl dark:text-white'}
>
{heading ??
AuthenticationScreenDefaults.defaultHeading}
</h1>

<h2
style={{ color: '#6B7280' }}
className={'font-medium text-base'}
>
{AuthenticationScreenDefaults.defaultSubheading}
</h2>
</div>
</>
}
displayKeys={providers
.filter((p) => p.enabled)
.map((p) => p.key)}
mapperArgs={{
clientId: 'Foo',
signData: null,
}}
radius={radius}
/>
</LazyAuth>
</Tab.Panel>
<Tab.Panel>
<Authorization
Expand Down Expand Up @@ -695,8 +691,8 @@ const AuthPanel = ({
'urn:rollupid:address/0xc2b930f1fc2a55ddc1bf99e8844ca0479567ac44f3e2eea58216660e26947686',
},
]}
selectEmailCallback={() => {}}
addNewEmailCallback={() => {}}
selectEmailCallback={() => { }}
addNewEmailCallback={() => { }}
connectedAccounts={[
{
title: 'email@example.com',
Expand Down Expand Up @@ -728,8 +724,8 @@ const AuthPanel = ({
selectAllSmartWalletsCallback={() => { }}
// disableAuthorize={true}
transitionState={'idle'}
cancelCallback={() => {}}
authorizeCallback={() => {}}
cancelCallback={() => { }}
authorizeCallback={() => { }}
radius={radius}
/>
</Tab.Panel>
Expand Down Expand Up @@ -821,7 +817,7 @@ const EmailPanel = ({
height: 1,
}}
id="logoURL"
setIsFormChanged={(val) => {}}
setIsFormChanged={(val) => { }}
setIsImgUploading={(val) => {
setLoading(val)
}}
Expand Down Expand Up @@ -1031,9 +1027,9 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
color:
color && colorDark
? {
light: color,
dark: colorDark,
}
light: color,
dark: colorDark,
}
: theme?.color,
graphicURL: graphicURL ?? theme?.graphicURL,
providers: providers ?? theme?.providers,
Expand Down Expand Up @@ -1139,7 +1135,7 @@ export default () => {
const [loading, setLoading] = useState<boolean>(false)

return (
<>
<Suspense fallback={<Loader />}>
{loading && <Loader />}

<Form method="post">
Expand Down Expand Up @@ -1211,6 +1207,6 @@ export default () => {
</Tab.Panels>
</Tab.Group>
</Form>
</>
</Suspense>
)
}
32 changes: 32 additions & 0 deletions apps/console/app/web3/lazyAuth.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { getDefaultConfig, ConnectKitProvider } from 'connectkit'
import { Suspense } from 'react'
import { useHydrated } from 'remix-utils'
import { createConfig, WagmiConfig } from 'wagmi'

export function LazyAuth({
autoConnect = false,
children
}: {
context?: any
autoConnect?: boolean
children: JSX.Element,
}) {
const hydrated = useHydrated()
if (!hydrated) return <>Loading...</>

const config = createConfig(
getDefaultConfig({
appName: 'Rollup',
autoConnect,
walletConnectProjectId:
window.ENV.WALLET_CONNECT_PROJECT_ID,
})
)
return (
<WagmiConfig config={config}>
<ConnectKitProvider>
{children}
</ConnectKitProvider>
</WagmiConfig>
)
}
1 change: 1 addition & 0 deletions apps/console/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ declare global {

const INTERNAL_CLOUDFLARE_ZONE_ID: string
const TOKEN_CLOUDFLARE_API: string
const WALLET_CONNECT_PROJECT_ID: string
}
5 changes: 3 additions & 2 deletions apps/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@remix-run/react": "1.14.0",
"@tailwindcss/forms": "0.5.3",
"bcryptjs": "2.4.3",
"connectkit": "1.2.0",
"connectkit": "1.4.0",
"cross-env": "7.0.3",
"ethers": "5.7.2",
"flowbite": "1.6.5",
Expand All @@ -44,7 +44,8 @@
"react-helmet": "6.1.0",
"react-icons": "4.8.0",
"tiny-invariant": "1.3.1",
"wagmi": "0.11.7"
"viem": "0.3.41",
"wagmi": "1.0.9"
},
"devDependencies": {
"@babel/core": "7.20.2",
Expand Down
4 changes: 4 additions & 0 deletions apps/console/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ STORAGE_NAMESPACE = "console"
INTERNAL_GOOGLE_ANALYTICS_TAG = "G-NHNH4KRWC3"
PROFILE_APP_URL = "http://localhost:10003"
COOKIE_DOMAIN = "localhost"
WALLET_CONNECT_PROJECT_ID = "36efbf71d7586e254d72041a15a42078"

# Site
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -77,6 +78,7 @@ COOKIE_DOMAIN = "rollup.id"
STORAGE_NAMESPACE = "console"
INTERNAL_GOOGLE_ANALYTICS_TAG = "G-NHNH4KRWC3"
PROFILE_APP_URL = "https://my-dev.rollup.id"
WALLET_CONNECT_PROJECT_ID = "249578b973e49826abb32d2ad263e2a3"

# Environment: next
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -107,6 +109,7 @@ COOKIE_DOMAIN = "rollup.id"
STORAGE_NAMESPACE = "console"
INTERNAL_GOOGLE_ANALYTICS_TAG = "G-X7ZN16M4NB"
PROFILE_APP_URL = "https://my-next.rollup.id"
WALLET_CONNECT_PROJECT_ID = "7bce942e261433eb70c2a72d555dd61f"

# Environment: current
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -138,3 +141,4 @@ COOKIE_DOMAIN = "rollup.id"
STORAGE_NAMESPACE = "console"
INTERNAL_GOOGLE_ANALYTICS_TAG = "G-675VJMWSRY"
PROFILE_APP_URL = "https://my.rollup.id"
WALLET_CONNECT_PROJECT_ID = "6f2ebc8aa6a1d5c4d4ac1e700294e35f"
7 changes: 6 additions & 1 deletion apps/passport/app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ export default function handleRequest(
(nonce, dev) =>
getCSP({
directives: {
'default-src': [SELF],
'default-src': [
SELF,
'https://verify.walletconnect.com',
],
'connect-src': [
SELF,
'wss://*.bridge.walletconnect.org',
'wss://relay.walletconnect.com',
'https://*.g.alchemy.com',
'*.alchemyapi.io',
'*.google-analytics.com',
// Used for Remix WebSocket Live Reaload
Expand Down
3 changes: 2 additions & 1 deletion apps/passport/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ export const loader: LoaderFunction = getRollupReqFunctionErrorWrapper(
PROFILE_APP_URL: context.env.PROFILE_APP_URL,
INTERNAL_GOOGLE_ANALYTICS_TAG:
context.env.INTERNAL_GOOGLE_ANALYTICS_TAG,
APIKEY_ALCHEMY_PUBLIC: context.env.APIKEY_ALCHEMY_PUBLIC,
REMIX_DEV_SERVER_WS_PORT:
process.env.NODE_ENV === 'development'
? process.env.REMIX_DEV_SERVER_WS_PORT
: undefined,
WALLET_CONNECT_PROJECT_ID: context.env.WALLET_CONNECT_PROJECT_ID,
APIKEY_ALCHEMY_PUBLIC: context.env.APIKEY_ALCHEMY_PUBLIC,
},
},
{
Expand Down
Loading