Skip to content

Commit

Permalink
prep and clean up for sendtag checkout (#602)
Browse files Browse the repository at this point in the history
* fix sign-in.anon.spec
* clean up useProfileLookup and tsconfigs
* add playwright record option
* only wait 10 seconds for send account create request
* app: estimate call gas limit
  • Loading branch information
0xBigBoss authored Jul 17, 2024
1 parent 44ef187 commit 411cc52
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 45 deletions.
2 changes: 2 additions & 0 deletions .env.local.template
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ SUPABASE_SERVICE_ROLE=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZ
# NEXT_PUBLIC_ENABLE_QUERY_DEV_TOOLS=1
# Enables more logging for sendapp
# DEBUG="api:*,app:*,test:*,-test:fixtures:snaplet:*"
# Record your playwright tests
# PLAYWRIGHT_RECORD=1
5 changes: 4 additions & 1 deletion packages/app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"jest.setup-after-env.ts",
"__mocks__",
"tamagui.config.ts",
"./.eslintrc.cjs"
"./.eslintrc.cjs",
"../../supabase"
],
"exclude": ["coverage"],
"compilerOptions": {
Expand All @@ -32,6 +33,8 @@
"@my/wagmi": ["../wagmi/src"],
"@my/wagmi/*": ["../wagmi/src/*"],
"@my/contracts/out/*": ["../contracts/out/*"],
"@my/supabase": ["../../supabase"],
"@my/supabase/*": ["../../supabase/*"],
"@daimo/expo-passkeys/*": ["../daimo-expo-passkeys/src/*"]
}
},
Expand Down
50 changes: 38 additions & 12 deletions packages/app/utils/useProfileLookup.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
import { type UseQueryResult, useQuery } from '@tanstack/react-query'
import { type UseQueryResult, queryOptions, useQuery } from '@tanstack/react-query'
import { useSupabase } from './supabase/useSupabase'
import type { Functions, Database } from '@my/supabase/database.types'
import type { PostgrestError } from '@supabase/supabase-js'
import type { SupabaseClient } from '@supabase/supabase-js'
import { assert } from './assert'

export function useProfileLookup(
lookup_type: Database['public']['Enums']['lookup_type_enum'],
export function fetchProfile({
supabase,
lookup_type,
identifier,
}: {
supabase: SupabaseClient<Database>
lookup_type: Database['public']['Enums']['lookup_type_enum']
identifier: string
): UseQueryResult<Functions<'profile_lookup'>[number], PostgrestError> {
const supabase = useSupabase()
return useQuery({
queryKey: ['profile', lookup_type, identifier],
queryFn: async () => {
}) {
return supabase.rpc('profile_lookup', { lookup_type: lookup_type, identifier: identifier })
}

export function profileLookupQueryOptions({
supabase,
lookup_type,
identifier,
}: {
supabase: SupabaseClient<Database>
lookup_type: Database['public']['Enums']['lookup_type_enum'] | undefined
identifier: string | undefined
}) {
return queryOptions({
queryKey: ['profile', { lookup_type, identifier, supabase }] as const,
queryFn: async ({ queryKey: [, { supabase, lookup_type, identifier }] }) => {
assert(!!lookup_type, 'lookup_type is required')
assert(!!identifier, 'identifier is required')
const { data, error } = await supabase
.rpc('profile_lookup', { lookup_type: lookup_type, identifier: identifier })
.maybeSingle()
const { data, error } = await fetchProfile({
supabase,
lookup_type,
identifier,
}).maybeSingle()
if (error) {
if (error.code === 'PGRST116') {
// no rows found
Expand All @@ -29,3 +47,11 @@ export function useProfileLookup(
enabled: !!lookup_type && !!identifier,
})
}

export function useProfileLookup(
lookup_type: Database['public']['Enums']['lookup_type_enum'],
identifier: string
): UseQueryResult<Functions<'profile_lookup'>[number] | null, Error> {
const supabase = useSupabase()
return useQuery(profileLookupQueryOptions({ supabase, lookup_type, identifier }))
}
10 changes: 9 additions & 1 deletion packages/app/utils/userop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { signWithPasskey } from '@daimo/expo-passkeys'
import {
baseMainnetBundlerClient,
entryPointAddress,
sendAccountAbi,
sendTokenAbi,
Expand Down Expand Up @@ -279,6 +280,7 @@ function userOpQueryOptions({
functionName: 'executeBatch',
args: [calls],
})

const paymaster = tokenPaymasterAddress[chainId]
const userOp: UserOperation<'v0.7'> = {
...defaultUserOp,
Expand All @@ -291,7 +293,13 @@ function userOpQueryOptions({
paymasterData: '0x',
signature: '0x',
}
return userOp

// only estimate the gas for the call
const { callGasLimit } = await baseMainnetBundlerClient.estimateUserOperationGas({
userOperation: userOp,
})

return { ...userOp, callGasLimit }
},
})
}
Expand Down
12 changes: 8 additions & 4 deletions packages/playwright/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ export default defineConfig({
trace: 'on-first-retry',

/* Configure the video recording. */
// video: {
// size: { width: 1366, height: 768 },
// mode: 'on',
// },
...(process.env.PLAYWRIGHT_RECORD
? {
video: {
size: { width: 1366, height: 768 },
mode: 'on',
},
}
: undefined),
},

/* Configure projects for major browsers */
Expand Down
29 changes: 16 additions & 13 deletions packages/playwright/tests/fixtures/send-accounts/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,22 @@ export class OnboardingPage {
}
return false
})
const response = this.page.waitForEvent('response', async (response) => {
if (response.url().includes('/api/trpc/sendAccount.create')) {
const json = await response.json()
expect(json.data?.[0]?.error).toBeFalsy()
this.log?.(
'sendAccount.create response',
response.url(),
response.status(),
JSON.stringify(json)
)
return true
}
return false
const response = this.page.waitForEvent('response', {
predicate: async (response) => {
if (response.url().includes('/api/trpc/sendAccount.create')) {
const json = await response.json()
expect(json.data?.[0]?.error).toBeFalsy()
this.log?.(
'sendAccount.create response',
response.url(),
response.status(),
JSON.stringify(json)
)
return true
}
return false
},
timeout: 10_000,
})

await this.page.getByRole('button', { name: 'Create Passkey' }).click()
Expand Down
6 changes: 5 additions & 1 deletion packages/playwright/tests/sign-in.anon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ test('redirect on sign-in', async ({ page, pg }) => {
// ensure use can log in with passkey
await page.context().clearCookies()
await page.goto('/send')
await page.waitForURL(/auth\/sign-in/)
// redirect to send after user is logged in
await expect(page).toHaveURL('/auth/sign-in?redirectUri=/send')
await expect(page).toHaveURL(`/auth/sign-in?redirectUri=${encodeURIComponent('/send')}`)
const signInButton = page.getByRole('button', { name: 'Sign In' })
await expect(signInButton).toBeVisible()
await signInButton.click()
Expand Down Expand Up @@ -56,6 +57,7 @@ test('redirect to send confirm page on sign-in', async ({ page, seed, pg }) => {

// naive but go to home page to see if user is logged in
await page.goto('/auth/sign-up')
await page.waitForURL(/auth\/sign-up/)
await expect(page).toHaveURL('/auth/sign-up')

try {
Expand All @@ -66,6 +68,7 @@ test('redirect to send confirm page on sign-in', async ({ page, seed, pg }) => {
await page.goto(
`/send/confirm?idType=tag&recipient=${tag?.name}&amount=1&sendToken=${sendToken.address}`
)
await page.waitForURL(/auth\/sign-in/)
const beforeRedirectUrl = new URL(page.url())
expect(Object.fromEntries(beforeRedirectUrl.searchParams.entries())).toMatchObject({
redirectUri: `/send/confirm?idType=tag&recipient=${tag?.name}&amount=1&sendToken=${sendToken.address}`,
Expand All @@ -74,6 +77,7 @@ test('redirect to send confirm page on sign-in', async ({ page, seed, pg }) => {
const signInButton = page.getByRole('button', { name: 'Sign In' })
await expect(signInButton).toBeVisible()
await signInButton.click()
await page.waitForURL(/send\/confirm/)
//@todo: find a way to wait for the new url and check query params like above
// Checking the url strimg is not sturdy because it cares about the query params order
await expect(page).toHaveURL(
Expand Down
7 changes: 5 additions & 2 deletions packages/playwright/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"../app",
"../wagmi",
"../contracts",
"../webauthn-authenticator"
"../webauthn-authenticator",
"../../supabase"
],
"compilerOptions": {
"noEmit": true,
Expand All @@ -22,7 +23,9 @@
"@my/playwright/*": ["./tests/*"],
"@my/snaplet/*": ["../snaplet/src/*"],
"@0xsend/webauthn-authenticator": ["../webauthn-authenticator/src"],
"@0xsend/webauthn-authenticator/*": ["../webauthn-authenticator/src/*"]
"@0xsend/webauthn-authenticator/*": ["../webauthn-authenticator/src/*"],
"@my/supabase": ["../../supabase"],
"@my/supabase/*": ["../../supabase/*"]
}
},
"references": []
Expand Down
23 changes: 12 additions & 11 deletions supabase/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import type { PostgrestError } from '@supabase/supabase-js'
* @see https://www.postgresql.org/docs/16/functions-binarystring.html#ENCODE-FORMAT-HEX
**/
export type PgBytea = `\\x${string}`
type Hex = `0x${string}`

type ProfileLookupRow =
DatabaseGenerated['public']['Functions']['profile_lookup']['Returns'][number]
type ProfileLookup = {
[K in keyof ProfileLookupRow]: ProfileLookupRow[K] | null | undefined
[K in keyof ProfileLookupRow]: K extends 'address' ? Hex | null : ProfileLookupRow[K] | null
}

export type Database = MergeDeep<
Expand All @@ -21,24 +22,24 @@ export type Database = MergeDeep<
Tables: {
chain_addresses: {
Row: {
address: `0x${string}`
address: Hex
}
Insert: {
address: `0x${string}`
address: Hex
}
Update: {
address: `0x${string}`
address: Hex
}
}
distribution_shares: {
Row: {
address: `0x${string}`
address: Hex
}
Insert: {
address: `0x${string}`
address: Hex
}
Update: {
address: `0x${string}`
address: Hex
}
}
webauthn_credentials: {
Expand All @@ -60,23 +61,23 @@ export type Database = MergeDeep<
}
send_accounts: {
Row: {
address: `0x${string}`
address: Hex
init_code: PgBytea
}
Insert: {
address: `0x${string}`
address: Hex
init_code: PgBytea
}
Update: {
address: `0x${string}`
address: Hex
init_code: PgBytea
}
}
}
Functions: {
distribution_hodler_addresses: {
Returns: {
address: `0x${string}`
address: Hex
created_at: string
user_id: string
}[]
Expand Down

0 comments on commit 411cc52

Please sign in to comment.