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

chore: fix dashboard bug for invalid token, added dev mode for captcha #3410

Merged
merged 6 commits into from
Oct 27, 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
9 changes: 7 additions & 2 deletions apps/consent/app/components/captcha-challenge/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
"use client"
import { memo, useCallback, useEffect } from "react"

import { toast } from "react-toastify"

import { sendPhoneCode } from "@/app/login/phone/server-actions"
declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
initGeetest: (options: any, callback: (captchaObj: any) => void) => void
}
}

const CaptchaChallengeComponent: React.FC<{
id: string
Expand All @@ -14,7 +21,6 @@ const CaptchaChallengeComponent: React.FC<{
}
}> = ({ id, challenge, formData }) => {
const captchaHandler = useCallback(
/* eslint @typescript-eslint/ban-ts-comment: "off" */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(captchaObj: any) => {
const onSuccess = async () => {
Expand All @@ -38,7 +44,6 @@ const CaptchaChallengeComponent: React.FC<{
)

useEffect(() => {
// @ts-ignore-next-line error
window.initGeetest(
{
gt: id,
Expand Down
18 changes: 18 additions & 0 deletions apps/consent/app/login/phone/server-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GetCaptchaChallengeResponse, SendPhoneCodeResponse } from "./phone-logi
import { LoginType, SubmitValue } from "@/app/index.types"
import authApi from "@/services/galoy-auth"
import { hydraClient } from "@/services/hydra"
import { env } from "@/env"

export const getCaptchaChallenge = async (
_prevState: unknown,
Expand Down Expand Up @@ -64,6 +65,23 @@ export const getCaptchaChallenge = async (
const res = await authApi.requestPhoneCaptcha(customHeaders)
const id = res.id
const challenge = res.challengeCode

if (env.NODE_ENV === "development") {
const params = new URLSearchParams({
login_challenge,
})
cookies().set(
login_challenge,
JSON.stringify({
loginType: LoginType.phone,
value: phone,
remember: remember,
}),
{ secure: true },
)
redirect(`/login/verification?${params}`)
}

return {
error: false,
message: "success",
Expand Down
2 changes: 2 additions & 0 deletions apps/consent/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ export const env = createEnv({
GRAPHQL_ENDPOINT: z.string().default("http://localhost:4455/graphql"),
OTEL_EXPORTER_OTLP_ENDPOINT: z.string().default("http://localhost:4318"),
TRACING_SERVICE_NAME: z.string().default("consent"),
NODE_ENV: z.string(),
},
runtimeEnv: {
CORE_AUTH_URL: process.env.CORE_AUTH_URL,
HYDRA_ADMIN_URL: process.env.HYDRA_ADMIN_URL,
GRAPHQL_ENDPOINT: process.env.GRAPHQL_ENDPOINT,
OTEL_EXPORTER_OTLP_ENDPOINT: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
TRACING_SERVICE_NAME: process.env.TRACING_SERVICE_NAME,
NODE_ENV: process.env.NODE_ENV,
},
})
5 changes: 4 additions & 1 deletion apps/dashboard/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { redirect } from "next/navigation"
import type { Metadata } from "next"
import { getServerSession } from "next-auth"

Expand All @@ -19,7 +20,9 @@ export const metadata: Metadata = {

export default async function RootLayout({ children }: { children: React.ReactNode }) {
const session = await getServerSession(authOptions)

if (!session || !session?.userData || !session?.accessToken) {
redirect("/api/auth/signin")
}
return (
<html lang="en">
<body>
Expand Down
76 changes: 58 additions & 18 deletions apps/dashboard/components/price-container/price-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react"
import { Box } from "@mui/joy"

import PriceContainerCard from "./price-card-container"

export interface WalletData {
__typename: string
accountId: string
Expand All @@ -15,6 +16,23 @@ export interface PriceContainerProps {
walletDetails: ReadonlyArray<WalletData>
}

const formatBalance = (
balance: number,
walletCurrency: "BTC" | "USD",
): [number, string] => {
if (walletCurrency === "BTC") {
const btcBalance = balance / 100000000
if (btcBalance < 0.00001) {
return [balance, "sats"]
} else {
return [btcBalance, "BTC"]
}
} else {
const usdBalance = balance / 100
return [usdBalance, "USD"]
}
}

const PriceContainer: React.FC<PriceContainerProps> = ({ walletDetails }) => {
const btcWallet = walletDetails.find((wallet) => wallet.walletCurrency === "BTC")
const usdWallet = walletDetails.find((wallet) => wallet.walletCurrency === "USD")
Expand All @@ -34,24 +52,46 @@ const PriceContainer: React.FC<PriceContainerProps> = ({ walletDetails }) => {
flexWrap: "wrap",
}}
>
{btcWallet && (
<PriceContainerCard
id={btcWallet.id}
walletCurrency={btcWallet.walletCurrency}
balance={btcWallet.balance / 100000000}
pendingIncomingBalance={btcWallet.pendingIncomingBalance / 100000000}
currencySymbol="BTC"
/>
)}
{usdWallet && (
<PriceContainerCard
id={usdWallet.id}
walletCurrency={usdWallet.walletCurrency}
balance={usdWallet.balance / 100}
pendingIncomingBalance={usdWallet.pendingIncomingBalance / 100}
currencySymbol="USD"
/>
)}
{btcWallet &&
(() => {
const [balance, currencySymbol] = formatBalance(
btcWallet.balance,
btcWallet.walletCurrency,
)
const [pendingBalance] = formatBalance(
btcWallet.pendingIncomingBalance,
btcWallet.walletCurrency,
)
return (
<PriceContainerCard
id={btcWallet.id}
walletCurrency={btcWallet.walletCurrency}
balance={balance}
pendingIncomingBalance={pendingBalance}
currencySymbol={currencySymbol}
/>
)
})()}
{usdWallet &&
(() => {
const [balance, currencySymbol] = formatBalance(
usdWallet.balance,
usdWallet.walletCurrency,
)
const [pendingBalance] = formatBalance(
usdWallet.pendingIncomingBalance,
usdWallet.walletCurrency,
)
return (
<PriceContainerCard
id={usdWallet.id}
walletCurrency={usdWallet.walletCurrency}
balance={balance}
pendingIncomingBalance={pendingBalance}
currencySymbol={currencySymbol}
/>
)
})()}
</Box>
</Box>
)
Expand Down
Loading