Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/feat/privCred-presentation' in…
Browse files Browse the repository at this point in the history
…to feat/privCred-presentation
  • Loading branch information
martonmoro committed Nov 27, 2024
2 parents 7ed5f31 + 334566a commit 7d99301
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 18 deletions.
30 changes: 17 additions & 13 deletions packages/features/.ladle/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
import { ThemeProvider } from "next-themes"
import React, { useEffect } from "react"
import { ErrorBoundary } from "react-error-boundary"
import { I18nextProvider } from "react-i18next"
import { MemoryRouter } from "react-router-dom"
import { i18n } from "../src/lib/i18n"

export const Provider: GlobalProvider = ({ children }) => {
const { dispatch } = useLadleContext()
Expand All @@ -17,18 +19,20 @@ export const Provider: GlobalProvider = ({ children }) => {
dispatch({ type: ActionType.UpdateTheme, value: ThemeState.Dark })
}, [])
return (
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<MemoryRouter>
<ErrorBoundary
fallbackRender={({ error }) => (
<div>
{JSON.stringify(error, Object.getOwnPropertyNames(error))}
</div>
)}
>
{children}
</ErrorBoundary>
</MemoryRouter>
</ThemeProvider>
<I18nextProvider i18n={i18n}>
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
<MemoryRouter>
<ErrorBoundary
fallbackRender={({ error }) => (
<div>
{JSON.stringify(error, Object.getOwnPropertyNames(error))}
</div>
)}
>
{children}
</ErrorBoundary>
</MemoryRouter>
</ThemeProvider>
</I18nextProvider>
)
}
5 changes: 2 additions & 3 deletions packages/features/.ladle/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ export default {
width: {
enabled: true,
options: {
xsmall: 370,
xsmall: 480,
small: 640,
medium: 768,
large: 1024,
},
defaultState: 370,
defaultState: 480,
},
},
appendToHead: `<style>
.ladle-iframe { max-height: 600px; }
.frame-content { display: flex; flex-direction: column; min-height: 100vh; }
</style>`,
}
2 changes: 0 additions & 2 deletions packages/features/.ladle/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineConfig } from "vite"
import { nodePolyfills } from "vite-plugin-node-polyfills"
import svgr from "vite-plugin-svgr"
import topLevelAwait from "vite-plugin-top-level-await"

const env = (import.meta as any).env

Expand All @@ -12,7 +11,6 @@ export default defineConfig({
"process.env": {},
},
plugins: [
topLevelAwait(),
svgr(),
nodePolyfills({ protocolImports: true, globals: { Buffer: true } }),
],
Expand Down
8 changes: 8 additions & 0 deletions packages/features/src/components/menu-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export const MenuDrawer = () => {
>
{t("components.staking")}
</button>
<button
type="button"
className="text-3xl text-left"
onClick={() => navigate("/credentials")}
data-testid="menu/credentials"
>
{t("credentials.credentials")}
</button>
<button
type="button"
className="text-3xl text-left"
Expand Down
11 changes: 11 additions & 0 deletions packages/features/src/credentials/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { StoryDefault } from "@ladle/react"
import { CredentialDetailsRoute } from "./routes/credential-details"
import { CredentialsRoute } from "./routes/credentials"

export const Credentials = () => <CredentialsRoute />

export const CredentialDetails = () => <CredentialDetailsRoute />

export default {
title: "Credentials",
} satisfies StoryDefault
29 changes: 29 additions & 0 deletions packages/features/src/credentials/routes/credential-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type CredentialId, useVault } from "@palladco/vault"
import { useNavigate, useParams } from "react-router"
import { CredentialDetailsView } from "../views/credential-details"

export const CredentialDetailsRoute = () => {
const navigate = useNavigate()
const { id } = useParams()
const credential = useVault((state) =>
JSON.stringify(state.getObject(id as CredentialId), null, "\t"),
)
const removeObject = useVault((state) => state.removeObject)
const onCredentialDelete = () => {
const result = window.confirm(
"Are you sure you want to delete this credential?",
)
if (!result) return
removeObject(id as CredentialId)
return navigate("/credentials")
}
if (!id) return null
return (
<CredentialDetailsView
id={id}
credential={credential}
onGoBack={() => navigate("/credentials")}
onDelete={onCredentialDelete}
/>
)
}
7 changes: 7 additions & 0 deletions packages/features/src/credentials/routes/credentials.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { useVault } from "@palladco/vault"
import { CredentialsView } from "../views/credentials"

export const CredentialsRoute = () => {
const credentials = useVault((store) => Object.entries(store.objects))
return <CredentialsView credentials={credentials} />
}
33 changes: 33 additions & 0 deletions packages/features/src/credentials/views/credential-details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AppLayout } from "@/components/app-layout"
import { MenuBar } from "@/components/menu-bar"
import { useTranslation } from "react-i18next"

export type CredentialDetailsViewProps = {
id: string
credential: string
onGoBack: () => void
onDelete: () => void
}

export const CredentialDetailsView = ({
id,
credential,
onGoBack,
onDelete,
}: CredentialDetailsViewProps) => {
const { t } = useTranslation()
return (
<AppLayout>
<MenuBar variant="back" onBackClicked={onGoBack} />
<section className="flex flex-col flex-1 justify-between px-8 pb-8 gap-8">
<h1 className="text-3xl w-full">{id}</h1>
<div className="break-all flex-1 p-4 bg-secondary rounded-xl whitespace-pre-wrap overflow-y-scroll">
{credential}
</div>
<button type="button" className="btn btn-error" onClick={onDelete}>
{t("credentials.delete")}
</button>
</section>
</AppLayout>
)
}
38 changes: 38 additions & 0 deletions packages/features/src/credentials/views/credentials.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { AppLayout } from "@/components/app-layout"
import { MenuBar } from "@/components/menu-bar"
import type { Json } from "@mina-js/utils"
import { KeyRound } from "lucide-react"
import { useTranslation } from "react-i18next"
import { Link } from "react-router-dom"

type CredentialsViewProps = {
credentials: [string, Json][]
}

export const CredentialsView = ({ credentials }: CredentialsViewProps) => {
const { t } = useTranslation()
return (
<AppLayout>
<MenuBar variant="dashboard" />
<section className="flex flex-col gap-4 px-8">
<h1 className="text-3xl w-full">{t("credentials.credentials")}</h1>
<div className="flex flex-col gap-2">
{credentials.map(([id]) => (
<Link
key={id}
to={`/credentials/${id}`}
className="p-4 flex items-center space-x-4 bg-secondary rounded-2xl"
>
<div className="flex items-center justify-center w-12 h-12 rounded-full bg-neutral">
<KeyRound />
</div>
<div>
<p>{id}</p>
</div>
</Link>
))}
</div>
</section>
</AppLayout>
)
}
4 changes: 4 additions & 0 deletions packages/features/src/lib/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@
"deny": "Deny",
"sign": "Sign",
"reject": "Reject"
},
"credentials": {
"credentials": "Credentials",
"delete": "Delete"
}
}
4 changes: 4 additions & 0 deletions packages/features/src/lib/locales/tr/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,9 @@
"deny": "Reddet",
"sign": "İmzala",
"reject": "Reddet"
},
"credentials": {
"credentials": "Kimlik",
"delete": "Silmek"
}
}
6 changes: 6 additions & 0 deletions packages/features/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { I18nextProvider } from "react-i18next"
import { Toaster } from "sonner"
import { AddressBookRoute } from "./address-book/routes/address-book"
import { NewAddressRoute } from "./address-book/routes/new-address"
import { CredentialDetailsRoute } from "./credentials/routes/credential-details"
import { CredentialsRoute } from "./credentials/routes/credentials"
import { ErrorView } from "./error-renderer/views/error"
import { i18n } from "./lib/i18n"
import { UnlockWalletRoute } from "./lock/routes/unlock-wallet"
Expand Down Expand Up @@ -122,6 +124,10 @@ export const Router = () => {
/>
<Route path="privacy" element={<PrivacyRoute />} />
</Route>
<Route path="credentials" element={<Outlet />}>
<Route path="" element={<CredentialsRoute />} />
<Route path=":id" element={<CredentialDetailsRoute />} />
</Route>
<Route path="/*" element={<NotFoundRoute />} />
</Routes>
</MemoryRouter>
Expand Down

0 comments on commit 7d99301

Please sign in to comment.