Skip to content

Commit

Permalink
add authorized zkapps page (#206)
Browse files Browse the repository at this point in the history
* feat(extension): add authorized zkapps page

* feat (extension): move data logic for authorized zkapp to route

* feat: update .all-contributorsrc and README.md for new code contributors
  • Loading branch information
Myestery authored Aug 30, 2024
1 parent bc7ee21 commit 2753d11
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 24 deletions.
28 changes: 7 additions & 21 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"files": [
"README.md"
],
"files": ["README.md"],
"imageSize": 100,
"commit": false,
"commitType": "docs",
Expand All @@ -12,54 +10,42 @@
"name": "Tomek Marciniak",
"avatar_url": "https://avatars.githubusercontent.com/u/16132011?v=4",
"profile": "https://github.com/mrcnk",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "teddyjfpender",
"name": "Teddy Pender",
"avatar_url": "https://avatars.githubusercontent.com/u/92999717?v=4",
"profile": "https://github.com/teddyjfpender",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "rago4",
"name": "Rafał Goławski",
"avatar_url": "https://avatars.githubusercontent.com/u/19167236?v=4",
"profile": "https://dev.to/rgolawski",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "mich3lang3lo",
"name": "Mariusz",
"avatar_url": "https://avatars.githubusercontent.com/u/164676295?v=4",
"profile": "https://github.com/mich3lang3lo",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "aliraza556",
"name": "Ali Raza",
"avatar_url": "https://avatars.githubusercontent.com/u/87068339?v=4",
"profile": "https://github.com/aliraza556",
"contributions": [
"code"
]
"contributions": ["code"]
},
{
"login": "yaodingyd",
"name": "Yao Ding",
"avatar_url": "https://avatars.githubusercontent.com/u/11392695?v=4",
"profile": "https://yaodingyd.github.io/",
"contributions": [
"code"
]
"contributions": ["code"]
}
],
"contributorsPerLine": 7,
Expand Down
9 changes: 7 additions & 2 deletions packages/features/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { MemoryRouter, Outlet, Route, Routes } from "react-router-dom"

import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime"
import { ErrorBoundary } from "react-error-boundary"
import { MixpanelProvider } from "react-mixpanel-browser"
import { MemoryRouter, Outlet, Route, Routes } from "react-router-dom"
import { Toaster } from "sonner"

import { AddressBookRoute } from "./address-book/routes/address-book"
import { NewAddressRoute } from "./address-book/routes/new-address"
import { useAppStore } from "./common/store/app"
Expand All @@ -26,6 +26,7 @@ import { TransactionErrorRoute } from "./send/routes/transaction-error"
import { TransactionSuccessRoute } from "./send/routes/transaction-success"
import { TransactionSummaryRoute } from "./send/routes/transaction-summary"
import { AboutRoute } from "./settings/routes/about"
import { AuthorizedZkAppsRoute } from "./settings/routes/authorized-zkapps"
import { CurrencyRoute } from "./settings/routes/currency"
import { DisplayRoute } from "./settings/routes/display"
import { LanguageRoute } from "./settings/routes/language"
Expand Down Expand Up @@ -123,6 +124,10 @@ export const Router = () => {
<Route path="language" element={<LanguageRoute />} />
<Route path="currency" element={<CurrencyRoute />} />
</Route>
<Route
path="authorized-zkapps"
element={<AuthorizedZkAppsRoute />}
/>
<Route path="privacy" element={<PrivacyRoute />} />
</Route>
<Route path="/*" element={<NotFoundRoute />} />
Expand Down
4 changes: 4 additions & 0 deletions packages/features/src/settings/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { action } from "@ladle/react"
import type { StoryDefault } from "@ladle/react"

import { AboutView } from "./views/about"
import { AuthorizedZkAppsView } from "./views/authorized-zkapps"
import { CurrencyView } from "./views/currency"
import { DisplayView } from "./views/display"
import { LanguageView } from "./views/language"
Expand All @@ -18,6 +19,9 @@ export const Settings = () => (
)

export const About = () => <AboutView onCloseClicked={action("Go Back")} />
export const AuthorizedZkApps = () => (
<AuthorizedZkAppsView onCloseClicked={action("Go Back")} />
)

export const Support = () => <SupportView onCloseClicked={action("Go Back")} />

Expand Down
56 changes: 56 additions & 0 deletions packages/features/src/settings/routes/authorized-zkapps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { useEffect, useState } from "react"

import { fetcher } from "@/common/lib/fetch"
import { useNavigate } from "react-router-dom"
import { AuthorizedZkAppsView } from "../views/authorized-zkapps"

export type ZkApp = {
title: string
description: string
image: string
url: string
}
export const AuthorizedZkAppsRoute = () => {
const navigate = useNavigate()
const [connectedApps, setConnectedApps] = useState([] as ZkApp[])

useEffect(() => {
fetchConnectedApps()
}, [])

const fetchConnectedApps = async () => {
const { permissions } = (await chrome.storage.local.get({
permissions: [],
})) as Record<string, "ALLOWED">
// https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
const URLRegex =
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
const appsWithMetadata = await Promise.all(
Object.keys(permissions)
.filter((key) => URLRegex.test(key))
.map(async (url) => {
const metadata = (await fetcher(
`https://api.dub.co/metatags?url=${url}`,
)) as Omit<ZkApp, "url">
return { url, ...metadata }
}),
)
setConnectedApps(appsWithMetadata)
}

const handleDeleteApp = async (appToDelete: ZkApp) => {
const filteredApps = connectedApps.filter(
(app) => app.url !== appToDelete.url,
)
await chrome.storage.local.set({ permissions: filteredApps })
setConnectedApps(filteredApps)
}

return (
<AuthorizedZkAppsView
handleDeleteApp={handleDeleteApp}
apps={connectedApps}
onCloseClicked={() => navigate(-1)}
/>
)
}
69 changes: 69 additions & 0 deletions packages/features/src/settings/views/authorized-zkapps.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { AppWindowMac, X } from "lucide-react"

import { truncateString } from "@/common/lib/string"
import { AppLayout } from "@/components/app-layout"
import { SettingsPageLayout } from "@/components/settings-page-layout"
import type { ZkApp } from "../routes/authorized-zkapps"

type AuthorizedZkAppsViewProps = {
onCloseClicked: () => void
apps: ZkApp[]
handleDeleteApp: (appToDelete: ZkApp) => void
}

export const AuthorizedZkAppsView = ({
onCloseClicked,
handleDeleteApp,
apps: connectedApps,
}: AuthorizedZkAppsViewProps) => {
return (
<AppLayout>
<SettingsPageLayout
title="Authorized zkApps"
onCloseClicked={onCloseClicked}
>
{connectedApps.map((app) => (
<div
key={app.url}
className="p-4 flex items-center justify-between bg-secondary rounded-2xl mb-4"
>
<div className="flex gap-3">
{app.image ? (
<img
src={app.image}
alt={app.title}
className="w-8 h-8 pt-1 rounded"
/>
) : (
<div className="pt-1 w-8 h-8 rounded">
<AppWindowMac size={32} />
</div>
)}
<div>
<p>
{truncateString({
value: app.title,
firstCharCount: 20,
endCharCount: 2,
})}
</p>
<p className="text-sm">
{truncateString({
value: app.url,
firstCharCount: 20,
endCharCount: 2,
})}
</p>
</div>
</div>
<div>
<button type="button" onClick={() => handleDeleteApp(app)}>
<X />
</button>
</div>
</div>
))}
</SettingsPageLayout>
</AppLayout>
)
}
9 changes: 8 additions & 1 deletion packages/features/src/settings/views/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AppWindowMac, Eye, Info } from "lucide-react"

import { AppLayout } from "@/components/app-layout"
import { SettingsPageLayout } from "@/components/settings-page-layout"
import { Eye, Info } from "lucide-react"
import { Link } from "react-router-dom"

const Links = [
Expand All @@ -11,6 +12,12 @@ const Links = [
// href: "/settings/wallet",
// Icon: WalletMinimal,
// },
{
label: "Authorized zkApps",
description: "zkApps connected to your wallet",
href: "/settings/authorized-zkapps",
Icon: AppWindowMac,
},
{
label: "Privacy",
description: "Data sharing",
Expand Down

0 comments on commit 2753d11

Please sign in to comment.