-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
6 changed files
with
151 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
packages/features/src/settings/routes/authorized-zkapps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
69
packages/features/src/settings/views/authorized-zkapps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters