Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
raducristianpopa committed Sep 16, 2024
1 parent 4987cc6 commit 4507237
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
2 changes: 2 additions & 0 deletions docker/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ services:
RATE_API_KEY: ${RATE_API_KEY}
REDIS_URL: redis://redis:6379/0
KRATOS_ADMIN_URL: 'http://kratos:4434/admin'
GATEHUB_ACCESS_KEY: ${GATEHUB_ACCESS_KEY}
GATEHUB_SECRET_KEY: ${GATEHUB_SECRET_KEY}
restart: always
networks:
- testnet
Expand Down
8 changes: 8 additions & 0 deletions packages/wallet/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export class App {
const knex = await this.container.resolve('knex')
const socketService = await this.container.resolve('socketService')

logger.debug(
JSON.stringify(
{ gh0: env.GATEHUB_ACCESS_KEY, gh1: env.GATEHUB_SECRET_KEY },
null,
2
)
)

await knex.migrate.latest({
directory: __dirname + '/../migrations'
})
Expand Down
23 changes: 7 additions & 16 deletions packages/wallet/frontend/src/lib/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../httpClient'
import { UserResponse, ValidTokenResponse } from '@wallet/shared'
import { emailSchema } from '@wallet/shared/src'
import { IFRAME_TYPE, IframeResponse } from '@wallet/shared'

const isValidPassword = (password: string): boolean => {
if (typeof password !== 'string') return false
Expand Down Expand Up @@ -143,10 +144,6 @@ export const changePasswordSchema = z
}
})

const getIframeSrcSchema = z.object({
type: z.enum(['onboarding', 'ramp'])
})

type SignUpArgs = z.infer<typeof signUpSchema>
type SignUpError = ErrorResponse<SignUpArgs | undefined>
type SignUpResponse = SuccessResponse | SignUpError
Expand Down Expand Up @@ -191,14 +188,8 @@ type ChangePasswordArgs = z.infer<typeof changePasswordSchema>
type ChangePasswordError = ErrorResponse<ChangePasswordArgs | undefined>
type ChangePasswordResponse = SuccessResponse | ChangePasswordError

type GetGateHubIframeSrcArgs = z.infer<typeof getIframeSrcSchema>
type GetGateHubIframeSrcResult = SuccessResponse<{ url: string }>
type GetGateHubIframeSrcError = ErrorResponse<
GetGateHubIframeSrcArgs | undefined
>
type GetGateHubIframeSrcResponse =
| GetGateHubIframeSrcResult
| GetGateHubIframeSrcError
type GetGateHubIframeSrcResult = SuccessResponse<IframeResponse>
type GetGateHubIframeSrcResponse = GetGateHubIframeSrcResult | ErrorResponse

interface UserService {
signUp: (args: SignUpArgs) => Promise<SignUpResponse>
Expand All @@ -215,7 +206,7 @@ interface UserService {
args: ResendVerificationEmailArgs
) => Promise<ResendVerificationEmailResponse>
getGateHubIframeSrc: (
args: GetGateHubIframeSrcArgs,
type: IFRAME_TYPE,
cookies?: string
) => Promise<GetGateHubIframeSrcResponse>
}
Expand Down Expand Up @@ -392,18 +383,18 @@ const createUserService = (): UserService => ({
}
},

async getGateHubIframeSrc(args, cookies) {
async getGateHubIframeSrc(type, cookies) {
try {
const response = await httpClient
.get(`gatehub/token/${args.type}`, {
.get(`iframe-urls/${type}`, {
headers: {
...(cookies ? { Cookie: cookies } : {})
}
})
.json<GetGateHubIframeSrcResult>()
return response
} catch (error) {
return getError<GetGateHubIframeSrcArgs>(
return getError(
error,
// TODO: Better error message
'Something went wrong. Please try again.'
Expand Down
15 changes: 8 additions & 7 deletions packages/wallet/frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function middleware(req: NextRequest) {
`${cookieName}=${req.cookies.get(cookieName)?.value}`
)

// TODO: Update middleware as well
// Success TRUE - the user is logged in
if (response.success) {
// If the user is logged in and has not completed KYC, redirect to KYC page.
Expand All @@ -41,13 +42,13 @@ export async function middleware(req: NextRequest) {

// If KYC is completed and the user tries to navigate to the page, redirect
// to homepage.
if (
!response.result?.needsIDProof &&
!response.result?.needsWallet &&
req.nextUrl.pathname.startsWith('/kyc')
) {
return NextResponse.redirect(new URL('/', req.url))
}
// if (
// !response.result?.needsIDProof &&
// !response.result?.needsWallet &&
// req.nextUrl.pathname.startsWith('/kyc')
// ) {
// return NextResponse.redirect(new URL('/', req.url))
// }

if (isPublic) {
return NextResponse.redirect(new URL('/', req.url))
Expand Down
3 changes: 2 additions & 1 deletion packages/wallet/frontend/src/pages/kyc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export const getServerSideProps: GetServerSideProps<{
url: string
}> = async (ctx) => {
const response = await userService.getGateHubIframeSrc(
{ type: 'onboarding' },
'onboarding',
ctx.req.headers.cookie
)
console.log(response)

if (!response.success || !response.result) {
return {
Expand Down

0 comments on commit 4507237

Please sign in to comment.