Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80d5595e7f | ||
|
|
d0bbbfd39d | ||
|
|
e26d81ce1d | ||
|
|
be3316ec1b | ||
|
|
872369770f | ||
|
|
3d48826928 | ||
|
|
fa640ad64b | ||
|
|
eb1a9c3c3e | ||
|
|
a54c1aba35 | ||
|
|
bea4f01742 | ||
|
|
e19f7a21ad | ||
|
|
c37af4f191 | ||
|
|
f964b8aaff | ||
|
|
424e6b8f9b | ||
|
|
763d3de5a8 | ||
|
|
f6f138ccbc | ||
|
|
f5d5e73e57 | ||
|
|
673e51b11c | ||
|
|
282edf7ccb | ||
|
|
a87e91b99c | ||
|
|
0e630c4550 | ||
|
|
11c7bf0955 | ||
|
|
c9e430d092 | ||
|
|
1f440d0c97 | ||
|
|
3a0aac4393 | ||
|
|
7b13015053 | ||
|
|
7f081618e1 | ||
|
|
881c7a96f7 | ||
|
|
ad68969559 | ||
|
|
915d955da1 | ||
|
|
7da16cff2f | ||
|
|
f0edc0f253 | ||
|
|
0a2d269782 | ||
|
|
3d996d1d23 | ||
|
|
40781b8170 | ||
|
|
d907017217 | ||
|
|
cf53c2d7f1 | ||
|
|
207cb9dbeb | ||
|
|
b4d365bdc0 | ||
|
|
ea4e2fe376 | ||
|
|
1d54cff7b4 | ||
|
|
fd04eefea9 | ||
|
|
4cc68310dc | ||
|
|
ccdce496e0 | ||
|
|
2725f337f8 | ||
|
|
2c6ea3e6dd | ||
|
|
219fc69d72 | ||
|
|
8d17685683 | ||
|
|
8ef418c543 | ||
|
|
b88f75b494 | ||
|
|
c83f1c6f7a | ||
|
|
bc0295487b | ||
|
|
90b779107d | ||
|
|
afe187de95 | ||
|
|
759b93beff | ||
|
|
8e357b3cb3 | ||
|
|
6c318f83d6 | ||
|
|
f790c9fae9 | ||
|
|
bcbb3f540a | ||
|
|
931c730a08 | ||
|
|
e0c83121c2 | ||
|
|
a82a31e5ad | ||
|
|
3d235e218a | ||
|
|
c08fb1356e | ||
|
|
68cca6f992 | ||
|
|
e0abf2b273 | ||
|
|
abf0bbaf35 | ||
|
|
23cb3bd98c | ||
|
|
dcef3f4fe7 | ||
|
|
bf46520a6b | ||
|
|
7defce7264 | ||
|
|
ae3a122cf1 | ||
|
|
2412a6958c | ||
|
|
bfd3be764c | ||
|
|
46b9d2dd82 | ||
|
|
3e9eb49787 | ||
|
|
630edadcec | ||
|
|
f757e60846 | ||
|
|
d5d593956e | ||
|
|
9a4b1cb147 | ||
|
|
85fe9491cd | ||
|
|
899051f788 | ||
|
|
5828b9bd45 | ||
|
|
2b68a32eaa | ||
|
|
66ae33ee8b | ||
|
|
e9788096d6 | ||
|
|
706d696434 | ||
|
|
c36cfbb5c7 | ||
|
|
93a9ba9121 | ||
|
|
6a7b556d75 |
@@ -188,9 +188,16 @@ jobs:
|
|||||||
- name: Build Packages
|
- name: Build Packages
|
||||||
run: pnpm build
|
run: pnpm build
|
||||||
|
|
||||||
- name: Report bundle size
|
- name: Report bundle size (thirdweb)
|
||||||
uses: andresz1/size-limit-action@94bc357df29c36c8f8d50ea497c3e225c3c95d1d # v1.8.0
|
uses: andresz1/size-limit-action@94bc357df29c36c8f8d50ea497c3e225c3c95d1d # v1.8.0
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
package_manager: pnpm
|
package_manager: pnpm
|
||||||
directory: packages/thirdweb
|
directory: packages/thirdweb
|
||||||
|
|
||||||
|
- name: Report bundle size (nexus)
|
||||||
|
uses: andresz1/size-limit-action@94bc357df29c36c8f8d50ea497c3e225c3c95d1d # v1.8.0
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
package_manager: pnpm
|
||||||
|
directory: packages/nexus
|
||||||
@@ -18,7 +18,7 @@ Welcome, AI copilots! This guide captures the coding standards, architectural de
|
|||||||
2. Formatting & Linting
|
2. Formatting & Linting
|
||||||
|
|
||||||
- Biome governs formatting and linting; its rules live in biome.json.
|
- Biome governs formatting and linting; its rules live in biome.json.
|
||||||
- Run pnpm biome check --apply before committing.
|
- Run `pnpm fix` & `pnpm lint` before committing, make sure there are no linting errors.
|
||||||
- Avoid editor‑specific configs; rely on the shared settings.
|
- Avoid editor‑specific configs; rely on the shared settings.
|
||||||
- make sure everything builds after each file change by running `pnpm build`
|
- make sure everything builds after each file change by running `pnpm build`
|
||||||
|
|
||||||
@@ -136,7 +136,7 @@ export function reportContractDeployed(properties: {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Client-side only**: never import `posthog-js` in server components.
|
- **Client-side only**: never import `posthog-js` in server components.
|
||||||
- **Housekeeping**: Inform **#eng-core-services** before renaming or removing an existing event.
|
- **Housekeeping**: Inform **#eng-core-services** before renaming or removing an existing event.
|
||||||
|
|
||||||
⸻
|
⸻
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ module.exports = [
|
|||||||
"/wallets",
|
"/wallets",
|
||||||
"/account-abstraction",
|
"/account-abstraction",
|
||||||
"/payments",
|
"/payments",
|
||||||
"/payments/x402",
|
"/x402",
|
||||||
"/nexus",
|
"/nexus",
|
||||||
"/auth",
|
"/auth",
|
||||||
"/in-app-wallets",
|
"/in-app-wallets",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.9.1",
|
"@hookform/resolvers": "^3.9.1",
|
||||||
"@marsidev/react-turnstile": "^1.1.0",
|
"@marsidev/react-turnstile": "^1.1.0",
|
||||||
|
"@number-flow/react": "^0.5.10",
|
||||||
"@radix-ui/react-accordion": "^1.2.11",
|
"@radix-ui/react-accordion": "^1.2.11",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.14",
|
"@radix-ui/react-alert-dialog": "^1.1.14",
|
||||||
"@radix-ui/react-avatar": "^1.1.10",
|
"@radix-ui/react-avatar": "^1.1.10",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
@@ -479,6 +479,11 @@ async function redirects() {
|
|||||||
destination: "/tokens",
|
destination: "/tokens",
|
||||||
permanent: false,
|
permanent: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
source: "/payments/x402",
|
||||||
|
destination: "/x402",
|
||||||
|
permanent: false,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import type {
|
|||||||
WalletStats,
|
WalletStats,
|
||||||
WebhookLatencyStats,
|
WebhookLatencyStats,
|
||||||
WebhookSummaryStats,
|
WebhookSummaryStats,
|
||||||
|
X402QueryParams,
|
||||||
|
X402SettlementStats,
|
||||||
} from "@/types/analytics";
|
} from "@/types/analytics";
|
||||||
import { getChains } from "./chain";
|
import { getChains } from "./chain";
|
||||||
|
|
||||||
@@ -184,7 +186,7 @@ const cached_getInAppWalletUsage = unstable_cache(
|
|||||||
if (res?.status !== 200) {
|
if (res?.status !== 200) {
|
||||||
const reason = await res?.text();
|
const reason = await res?.text();
|
||||||
console.error(
|
console.error(
|
||||||
`Failed to fetch in-app wallet usage, ${res?.status} - ${res.statusText} - ${reason}`,
|
`Failed to fetch user wallets usage, ${res?.status} - ${res.statusText} - ${reason}`,
|
||||||
);
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -906,3 +908,43 @@ export function getInsightUsage(
|
|||||||
) {
|
) {
|
||||||
return cached_getInsightUsage(normalizedParams(params), authToken);
|
return cached_getInsightUsage(normalizedParams(params), authToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cached_getX402Settlements = unstable_cache(
|
||||||
|
async (
|
||||||
|
params: X402QueryParams,
|
||||||
|
authToken: string,
|
||||||
|
): Promise<X402SettlementStats[]> => {
|
||||||
|
const searchParams = buildSearchParams(params);
|
||||||
|
|
||||||
|
if (params.groupBy) {
|
||||||
|
searchParams.append("groupBy", params.groupBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await fetchAnalytics({
|
||||||
|
authToken,
|
||||||
|
url: `v2/x402/settlements?${searchParams.toString()}`,
|
||||||
|
init: {
|
||||||
|
method: "GET",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res?.status !== 200) {
|
||||||
|
const reason = await res?.text();
|
||||||
|
console.error(
|
||||||
|
`Failed to fetch x402 settlements: ${res?.status} - ${res.statusText} - ${reason}`,
|
||||||
|
);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
return json.data as X402SettlementStats[];
|
||||||
|
},
|
||||||
|
["getX402Settlements"],
|
||||||
|
{
|
||||||
|
revalidate: 60 * 60, // 1 hour
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export function getX402Settlements(params: X402QueryParams, authToken: string) {
|
||||||
|
return cached_getX402Settlements(normalizedParams(params), authToken);
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ export type AuthOption =
|
|||||||
| "steam"
|
| "steam"
|
||||||
| "apple"
|
| "apple"
|
||||||
| "coinbase"
|
| "coinbase"
|
||||||
| "line";
|
| "line"
|
||||||
|
| "epic";
|
||||||
|
|
||||||
export type Ecosystem = {
|
export type Ecosystem = {
|
||||||
name: string;
|
name: string;
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ function SkeletonBarChart(props: {
|
|||||||
fill={`url(#${fillAreaSkeletonId})`}
|
fill={`url(#${fillAreaSkeletonId})`}
|
||||||
radius={8}
|
radius={8}
|
||||||
stroke="hsl(var(--muted-foreground))"
|
stroke="hsl(var(--muted-foreground))"
|
||||||
type="natural"
|
type="monotone"
|
||||||
/>
|
/>
|
||||||
</AreaChart>
|
</AreaChart>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ export function ThirdwebAreaChart<TConfig extends ChartConfig>(
|
|||||||
key={key}
|
key={key}
|
||||||
stackId={props.variant !== "stacked" ? undefined : "a"}
|
stackId={props.variant !== "stacked" ? undefined : "a"}
|
||||||
stroke={`var(--color-${key})`}
|
stroke={`var(--color-${key})`}
|
||||||
type="natural"
|
type="monotone"
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ type ShadcnSidebarBaseLink = {
|
|||||||
isActive?: (pathname: string) => boolean;
|
isActive?: (pathname: string) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ShadcnSidebarLink =
|
export type ShadcnSidebarLink =
|
||||||
| ShadcnSidebarBaseLink
|
| ShadcnSidebarBaseLink
|
||||||
| {
|
| {
|
||||||
group: string;
|
group: string;
|
||||||
links: ShadcnSidebarBaseLink[];
|
links: ShadcnSidebarLink[];
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
separator: true;
|
separator: true;
|
||||||
@@ -97,10 +97,7 @@ export function FullWidthSidebarLayout(props: {
|
|||||||
|
|
||||||
function MobileSidebarTrigger(props: { links: ShadcnSidebarLink[] }) {
|
function MobileSidebarTrigger(props: { links: ShadcnSidebarLink[] }) {
|
||||||
const activeLink = useActiveShadcnSidebarLink(props.links);
|
const activeLink = useActiveShadcnSidebarLink(props.links);
|
||||||
const parentSubNav = props.links.find(
|
const parentSubNav = findParentSubmenu(props.links, activeLink?.href);
|
||||||
(link) =>
|
|
||||||
"subMenu" in link && link.links.some((l) => l.href === activeLink?.href),
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-3 border-b px-4 py-4 lg:hidden">
|
<div className="flex items-center gap-3 border-b px-4 py-4 lg:hidden">
|
||||||
@@ -109,7 +106,7 @@ function MobileSidebarTrigger(props: { links: ShadcnSidebarLink[] }) {
|
|||||||
className="h-4 bg-muted-foreground/50"
|
className="h-4 bg-muted-foreground/50"
|
||||||
orientation="vertical"
|
orientation="vertical"
|
||||||
/>
|
/>
|
||||||
{parentSubNav && "subMenu" in parentSubNav && (
|
{parentSubNav && (
|
||||||
<>
|
<>
|
||||||
<span className="text-sm">{parentSubNav.subMenu.label}</span>
|
<span className="text-sm">{parentSubNav.subMenu.label}</span>
|
||||||
<ChevronRightIcon className="size-4 text-muted-foreground/50 -mx-1.5" />
|
<ChevronRightIcon className="size-4 text-muted-foreground/50 -mx-1.5" />
|
||||||
@@ -131,24 +128,65 @@ function useActiveShadcnSidebarLink(links: ShadcnSidebarLink[]) {
|
|||||||
return pathname?.startsWith(link.href);
|
return pathname?.startsWith(link.href);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const link of links) {
|
function walk(
|
||||||
if ("links" in link) {
|
navLinks: ShadcnSidebarLink[],
|
||||||
for (const subLink of link.links) {
|
): ShadcnSidebarBaseLink | undefined {
|
||||||
if (isActive(subLink)) {
|
for (const link of navLinks) {
|
||||||
return subLink;
|
if ("subMenu" in link) {
|
||||||
|
for (const subLink of link.links) {
|
||||||
|
if (isActive(subLink)) {
|
||||||
|
return subLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if ("href" in link) {
|
||||||
|
if (isActive(link)) {
|
||||||
|
return link;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("href" in link) {
|
|
||||||
if (isActive(link)) {
|
if ("links" in link && !("subMenu" in link)) {
|
||||||
return link;
|
const nested = walk(link.links);
|
||||||
|
if (nested) {
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return walk(links);
|
||||||
}, [links, pathname]);
|
}, [links, pathname]);
|
||||||
|
|
||||||
return activeLink;
|
return activeLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findParentSubmenu(
|
||||||
|
links: ShadcnSidebarLink[],
|
||||||
|
activeHref: string | undefined,
|
||||||
|
): Extract<ShadcnSidebarLink, { subMenu: unknown }> | undefined {
|
||||||
|
if (!activeHref) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const link of links) {
|
||||||
|
if ("subMenu" in link) {
|
||||||
|
if (link.links.some((subLink) => subLink.href === activeHref)) {
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("links" in link && !("subMenu" in link)) {
|
||||||
|
const nested = findParentSubmenu(link.links, activeHref);
|
||||||
|
if (nested) {
|
||||||
|
return nested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function useIsSubnavActive(links: ShadcnSidebarBaseLink[]) {
|
function useIsSubnavActive(links: ShadcnSidebarBaseLink[]) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,6 @@ import {
|
|||||||
type ProjectPageProps = {
|
type ProjectPageProps = {
|
||||||
header: ProjectPageHeaderProps;
|
header: ProjectPageHeaderProps;
|
||||||
footer?: ProjectPageFooterProps;
|
footer?: ProjectPageFooterProps;
|
||||||
/**
|
|
||||||
* @deprecated only for legacy pages where we still need internal tabs for the moment, currently:
|
|
||||||
* - /webhooks
|
|
||||||
*/
|
|
||||||
tabs?: TabPathLink[];
|
tabs?: TabPathLink[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -51,17 +51,12 @@ export function WalletAddressUI(
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
// default back to zero address if no address provided
|
const address = props.address || ZERO_ADDRESS;
|
||||||
const address = useMemo(() => props.address || ZERO_ADDRESS, [props.address]);
|
|
||||||
|
|
||||||
const [shortenedAddress, _lessShortenedAddress] = useMemo(() => {
|
const shortenedAddress =
|
||||||
return [
|
props.shortenAddress !== false
|
||||||
props.shortenAddress !== false
|
? `${address.slice(0, 6)}...${address.slice(-4)}`
|
||||||
? `${address.slice(0, 6)}...${address.slice(-4)}`
|
: address;
|
||||||
: address,
|
|
||||||
`${address.slice(0, 14)}...${address.slice(-12)}`,
|
|
||||||
];
|
|
||||||
}, [address, props.shortenAddress]);
|
|
||||||
|
|
||||||
if (!isAddress(address)) {
|
if (!isAddress(address)) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
+1
-1
@@ -337,7 +337,7 @@ export function InAppWalletUsersPageContent(
|
|||||||
isFetched={walletsQuery.isFetched}
|
isFetched={walletsQuery.isFetched}
|
||||||
isPending={walletsQuery.isPending}
|
isPending={walletsQuery.isPending}
|
||||||
tableContainerClassName="rounded-none border-x-0 border-b-0"
|
tableContainerClassName="rounded-none border-x-0 border-b-0"
|
||||||
title="in-app wallets"
|
title="User wallets"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex justify-center gap-3 border-t bg-card p-6">
|
<div className="flex justify-center gap-3 border-t bg-card p-6">
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import Link from "next/link";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
import { useLocalStorage } from "@/hooks/useLocalStorage";
|
||||||
|
|
||||||
// biome-ignore lint/correctness/noUnusedVariables: banner is toggled on-demand via API content changes
|
|
||||||
function AnnouncementBannerUI(props: {
|
function AnnouncementBannerUI(props: {
|
||||||
href: string;
|
href: string;
|
||||||
label: string;
|
label: string;
|
||||||
@@ -45,12 +44,11 @@ function AnnouncementBannerUI(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function AnnouncementBanner() {
|
export function AnnouncementBanner() {
|
||||||
// return (
|
return (
|
||||||
// <AnnouncementBannerUI
|
<AnnouncementBannerUI
|
||||||
// href="https://blog.thirdweb.com/the-fastest-way-to-build-web3-applications/"
|
href="https://blog.thirdweb.com/changelog/project-view-update-wallets/"
|
||||||
// label="We have re-branded our Engine, Payments, and Connect products. Please read the full blog post for details on changes"
|
label="Project View Update - Wallets"
|
||||||
// trackingLabel="product-rebrand"
|
trackingLabel="project-view-update-wallets"
|
||||||
// />
|
/>
|
||||||
// );
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const siwaExamplePrompts = [
|
export const siwaExamplePrompts = [
|
||||||
"How do I add in-app wallet with sign in with google to my react app?",
|
"How do I add user wallet with sign in with google to my react app?",
|
||||||
"How do I send a transaction in Unity?",
|
"How do I send a transaction in Unity?",
|
||||||
"What does this contract revert error mean?",
|
"What does this contract revert error mean?",
|
||||||
"I see thirdweb support id in my console log, can you help me?",
|
"I see thirdweb support id in my console log, can you help me?",
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ export function teamSubscriptionsStub(
|
|||||||
// In-App Wallets
|
// In-App Wallets
|
||||||
{
|
{
|
||||||
amount: usage.inAppWalletAmount?.amount || 0,
|
amount: usage.inAppWalletAmount?.amount || 0,
|
||||||
description: `${usage.inAppWalletAmount?.quantity || 0} x In-App Wallets (Tier 1 at $0.00 / month)`,
|
description: `${usage.inAppWalletAmount?.quantity || 0} x User Wallets (Tier 1 at $0.00 / month)`,
|
||||||
thirdwebSku: "usage:in_app_wallet",
|
thirdwebSku: "usage:in_app_wallet",
|
||||||
},
|
},
|
||||||
// AA Sponsorship
|
// AA Sponsorship
|
||||||
|
|||||||
@@ -94,3 +94,62 @@ export interface AnalyticsQueryParams {
|
|||||||
period?: "day" | "week" | "month" | "year" | "all";
|
period?: "day" | "week" | "month" | "year" | "all";
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface X402SettlementsOverall {
|
||||||
|
date: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface X402SettlementsByChainId {
|
||||||
|
date: string;
|
||||||
|
chainId: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface X402SettlementsByPayer {
|
||||||
|
date: string;
|
||||||
|
payer: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface X402SettlementsByReceiver {
|
||||||
|
date: string;
|
||||||
|
receiver: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface X402SettlementsByResource {
|
||||||
|
date: string;
|
||||||
|
resource: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface X402SettlementsByAsset {
|
||||||
|
date: string;
|
||||||
|
asset: string;
|
||||||
|
totalRequests: number;
|
||||||
|
totalValue: number;
|
||||||
|
totalValueUSD: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type X402SettlementStats =
|
||||||
|
| X402SettlementsOverall
|
||||||
|
| X402SettlementsByChainId
|
||||||
|
| X402SettlementsByPayer
|
||||||
|
| X402SettlementsByReceiver
|
||||||
|
| X402SettlementsByResource
|
||||||
|
| X402SettlementsByAsset;
|
||||||
|
|
||||||
|
export interface X402QueryParams extends AnalyticsQueryParams {
|
||||||
|
groupBy?: "overall" | "chainId" | "payer" | "resource" | "asset" | "receiver";
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ const customClaimAmounts: Record<number, number> = {
|
|||||||
631571: 0.1,
|
631571: 0.1,
|
||||||
// Sophon testnet
|
// Sophon testnet
|
||||||
531050104: 5,
|
531050104: 5,
|
||||||
|
// Arc testnet
|
||||||
|
5042002: 1,
|
||||||
|
// Injective testnet
|
||||||
|
1439: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultClaimAmount = 0.01;
|
const defaultClaimAmount = 0.01;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const usdCurrencyFormatter = new Intl.NumberFormat("en-US", {
|
const usdCurrencyFormatter = new Intl.NumberFormat("en-US", {
|
||||||
currency: "USD",
|
currency: "USD",
|
||||||
maximumFractionDigits: 2, // prefix with $
|
maximumFractionDigits: 6, // prefix with $
|
||||||
minimumFractionDigits: 0, // don't show decimal places if value is a whole number
|
minimumFractionDigits: 0, // don't show decimal places if value is a whole number
|
||||||
notation: "compact", // at max 2 decimal places
|
notation: "compact", // at max 2 decimal places
|
||||||
roundingMode: "halfEven", // round to nearest even number, standard practice for financial calculations
|
roundingMode: "halfEven", // round to nearest even number, standard practice for financial calculations
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const TEAM_PLANS: Record<
|
|||||||
features: [
|
features: [
|
||||||
"Email Support",
|
"Email Support",
|
||||||
"48hr Guaranteed Response",
|
"48hr Guaranteed Response",
|
||||||
"Custom In-App Wallet Auth",
|
"Custom User Wallet Auth",
|
||||||
],
|
],
|
||||||
price: 99,
|
price: 99,
|
||||||
subTitle: "Everything in Starter, plus:",
|
subTitle: "Everything in Starter, plus:",
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ export function getSDKTheme(theme: "light" | "dark"): Theme {
|
|||||||
primaryButtonText: "hsl(var(--inverted-foreground))",
|
primaryButtonText: "hsl(var(--inverted-foreground))",
|
||||||
primaryText: "hsl(var(--foreground))",
|
primaryText: "hsl(var(--foreground))",
|
||||||
scrollbarBg: "hsl(var(--muted))",
|
scrollbarBg: "hsl(var(--muted))",
|
||||||
secondaryButtonBg: "hsl(var(--secondary))",
|
secondaryButtonBg: "hsl(var(--secondary)/70%)",
|
||||||
secondaryButtonHoverBg: "hsl(var(--secondary)/80%)",
|
secondaryButtonHoverBg: "hsl(var(--secondary))",
|
||||||
secondaryButtonText: "hsl(var(--secondary-foreground))",
|
secondaryButtonText: "hsl(var(--secondary-foreground))",
|
||||||
secondaryIconColor: "hsl(var(--secondary-foreground))",
|
secondaryIconColor: "hsl(var(--secondary-foreground))",
|
||||||
secondaryIconHoverBg: "hsl(var(--accent))",
|
secondaryIconHoverBg: "hsl(var(--accent))",
|
||||||
@@ -33,7 +33,7 @@ export function getSDKTheme(theme: "light" | "dark"): Theme {
|
|||||||
separatorLine: "hsl(var(--border))",
|
separatorLine: "hsl(var(--border))",
|
||||||
skeletonBg: "hsl(var(--secondary-foreground)/15%)",
|
skeletonBg: "hsl(var(--secondary-foreground)/15%)",
|
||||||
success: "hsl(var(--success-text))",
|
success: "hsl(var(--success-text))",
|
||||||
tertiaryBg: "hsl(var(--muted)/30%)",
|
tertiaryBg: "hsl(var(--muted)/50%)",
|
||||||
tooltipBg: "hsl(var(--popover))",
|
tooltipBg: "hsl(var(--popover))",
|
||||||
tooltipText: "hsl(var(--popover-foreground))",
|
tooltipText: "hsl(var(--popover-foreground))",
|
||||||
},
|
},
|
||||||
|
|||||||
+16
-9
@@ -225,6 +225,10 @@ export const InstallModuleForm = (props: InstallModuleFormProps) => {
|
|||||||
moduleInfo: {
|
moduleInfo: {
|
||||||
bytecodeUri: selectedModule.metadata.bytecodeUri,
|
bytecodeUri: selectedModule.metadata.bytecodeUri,
|
||||||
},
|
},
|
||||||
|
isStylus:
|
||||||
|
(selectedModule.metadata.compilers?.stylus &&
|
||||||
|
selectedModule.metadata.compilers?.stylus?.length > 0) ||
|
||||||
|
false,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
queryKey: [
|
queryKey: [
|
||||||
@@ -432,6 +436,7 @@ async function isModuleCompatible(options: {
|
|||||||
moduleInfo: {
|
moduleInfo: {
|
||||||
bytecodeUri: string;
|
bytecodeUri: string;
|
||||||
};
|
};
|
||||||
|
isStylus: boolean;
|
||||||
client: ThirdwebClient;
|
client: ThirdwebClient;
|
||||||
}) {
|
}) {
|
||||||
// 1. get module's bytecode
|
// 1. get module's bytecode
|
||||||
@@ -444,15 +449,17 @@ async function isModuleCompatible(options: {
|
|||||||
|
|
||||||
// 2. check compatibility with core and installed modules
|
// 2. check compatibility with core and installed modules
|
||||||
try {
|
try {
|
||||||
const isCompatible = await checkModulesCompatibility({
|
const isCompatible =
|
||||||
chain: options.contractInfo.chain,
|
options.isStylus ||
|
||||||
client: options.client,
|
(await checkModulesCompatibility({
|
||||||
coreBytecode: options.contractInfo.bytecode,
|
chain: options.contractInfo.chain,
|
||||||
moduleBytecodes: [
|
client: options.client,
|
||||||
moduleBytecode,
|
coreBytecode: options.contractInfo.bytecode,
|
||||||
...options.contractInfo.installedModuleBytecodes,
|
moduleBytecodes: [
|
||||||
],
|
moduleBytecode,
|
||||||
});
|
...options.contractInfo.installedModuleBytecodes,
|
||||||
|
],
|
||||||
|
}));
|
||||||
|
|
||||||
return isCompatible;
|
return isCompatible;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
+10
-4
@@ -10,7 +10,11 @@ import {
|
|||||||
CircleXIcon,
|
CircleXIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { NATIVE_TOKEN_ADDRESS, type ThirdwebClient } from "thirdweb";
|
import {
|
||||||
|
getAddress,
|
||||||
|
NATIVE_TOKEN_ADDRESS,
|
||||||
|
type ThirdwebClient,
|
||||||
|
} from "thirdweb";
|
||||||
import type { Status, Token } from "thirdweb/bridge";
|
import type { Status, Token } from "thirdweb/bridge";
|
||||||
import { status } from "thirdweb/bridge";
|
import { status } from "thirdweb/bridge";
|
||||||
import { toTokens } from "thirdweb/utils";
|
import { toTokens } from "thirdweb/utils";
|
||||||
@@ -123,6 +127,8 @@ function TokenInfo(props: {
|
|||||||
const isNativeToken =
|
const isNativeToken =
|
||||||
props.token.address.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase();
|
props.token.address.toLowerCase() === NATIVE_TOKEN_ADDRESS.toLowerCase();
|
||||||
|
|
||||||
|
const tokenAddress = getAddress(props.token.address);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 pt-10 pb-9 px-6 lg:px-8">
|
<div className="flex-1 pt-10 pb-9 px-6 lg:px-8">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
@@ -206,7 +212,7 @@ function TokenInfo(props: {
|
|||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<p className="text-sm text-foreground ">{props.addressLabel}</p>
|
<p className="text-sm text-foreground ">{props.addressLabel}</p>
|
||||||
<WalletAddress
|
<WalletAddress
|
||||||
address={props.walletAddress}
|
address={getAddress(props.walletAddress)}
|
||||||
client={props.client}
|
client={props.client}
|
||||||
className="py-0.5 h-auto text-sm [&>*]:!font-sans tabular-nums [&>*]:font-normal text-muted-foreground hover:text-foreground"
|
className="py-0.5 h-auto text-sm [&>*]:!font-sans tabular-nums [&>*]:font-normal text-muted-foreground hover:text-foreground"
|
||||||
iconClassName="size-3"
|
iconClassName="size-3"
|
||||||
@@ -222,8 +228,8 @@ function TokenInfo(props: {
|
|||||||
? `/${chainQuery.data?.slug || props.token.chainId}`
|
? `/${chainQuery.data?.slug || props.token.chainId}`
|
||||||
: `/${chainQuery.data?.slug || props.token.chainId}/${props.token.address}`
|
: `/${chainQuery.data?.slug || props.token.chainId}/${props.token.address}`
|
||||||
}
|
}
|
||||||
textToShow={props.token.address}
|
textToShow={tokenAddress}
|
||||||
textToCopy={props.token.address}
|
textToCopy={tokenAddress}
|
||||||
copyTooltip="Copy Token Address"
|
copyTooltip="Copy Token Address"
|
||||||
className="-translate-x-1"
|
className="-translate-x-1"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
Clock4Icon,
|
Clock4Icon,
|
||||||
InfoIcon,
|
InfoIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { toTokens } from "thirdweb";
|
import { getAddress, toTokens } from "thirdweb";
|
||||||
import { status } from "thirdweb/bridge";
|
import { status } from "thirdweb/bridge";
|
||||||
import type { ChainMetadata } from "thirdweb/chains";
|
import type { ChainMetadata } from "thirdweb/chains";
|
||||||
import {
|
import {
|
||||||
@@ -153,6 +153,9 @@ function GeneericTxDetails(props: {
|
|||||||
|
|
||||||
const timestamp = getDatefromTimestamp(block.timestamp);
|
const timestamp = getDatefromTimestamp(block.timestamp);
|
||||||
|
|
||||||
|
const fromAddress = getAddress(transaction.from);
|
||||||
|
const toAddress = transaction.to ? getAddress(transaction.to) : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border rounded-xl p-4 lg:p-6 bg-card">
|
<div className="border rounded-xl p-4 lg:p-6 bg-card">
|
||||||
{/* section 1 */}
|
{/* section 1 */}
|
||||||
@@ -216,8 +219,8 @@ function GeneericTxDetails(props: {
|
|||||||
<section className="border-b py-6 space-y-5 lg:space-y-3">
|
<section className="border-b py-6 space-y-5 lg:space-y-3">
|
||||||
<GridItem label="From" tooltip="The sending party of the transaction.">
|
<GridItem label="From" tooltip="The sending party of the transaction.">
|
||||||
<CopyTextButton
|
<CopyTextButton
|
||||||
textToCopy={transaction.from}
|
textToCopy={fromAddress}
|
||||||
textToShow={transaction.from}
|
textToShow={fromAddress}
|
||||||
tooltip="Copy from address"
|
tooltip="Copy from address"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
copyIconPosition="right"
|
copyIconPosition="right"
|
||||||
@@ -225,14 +228,14 @@ function GeneericTxDetails(props: {
|
|||||||
/>
|
/>
|
||||||
</GridItem>
|
</GridItem>
|
||||||
|
|
||||||
{transaction.to && (
|
{toAddress && (
|
||||||
<GridItem
|
<GridItem
|
||||||
label="Interacted with (To)"
|
label="Interacted with (To)"
|
||||||
tooltip="The receiving party of the transaction (could be a contract address)."
|
tooltip="The receiving party of the transaction (could be a contract address)."
|
||||||
>
|
>
|
||||||
<CopyTextButton
|
<CopyTextButton
|
||||||
textToCopy={transaction.to}
|
textToCopy={toAddress}
|
||||||
textToShow={transaction.to}
|
textToShow={toAddress}
|
||||||
tooltip="Copy to address"
|
tooltip="Copy to address"
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
copyIconPosition="right"
|
copyIconPosition="right"
|
||||||
|
|||||||
@@ -183,13 +183,64 @@ const STYLUS = {
|
|||||||
],
|
],
|
||||||
description:
|
description:
|
||||||
"Airdrop your NFTs or tokens to a large number of recipients. Built with Arbitrum Stylus.",
|
"Airdrop your NFTs or tokens to a large number of recipients. Built with Arbitrum Stylus.",
|
||||||
displayName: "Arbitrum Stylus Contracts",
|
displayName: "Airdrop - Arbitrum Stylus",
|
||||||
id: "stylus",
|
id: "stylus",
|
||||||
name: "Stylus",
|
name: "Stylus",
|
||||||
showInExplore: true,
|
showInExplore: true,
|
||||||
isBeta: true,
|
isBeta: true,
|
||||||
} satisfies ExploreCategory;
|
} satisfies ExploreCategory;
|
||||||
|
|
||||||
|
const MODULAR_CONTRACTS_STYLUS = {
|
||||||
|
contracts: [
|
||||||
|
// erc721 token
|
||||||
|
[
|
||||||
|
"thirdweb.eth/ERC721CoreInitializable",
|
||||||
|
[
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusMintableERC721",
|
||||||
|
"deployer.thirdweb.eth/BatchMetadataERC721",
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusTransferableERC721",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
description: "ERC721 NFTs that only owners can mint.",
|
||||||
|
title: "Modular NFT Collection",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// erc1155 token
|
||||||
|
[
|
||||||
|
"thirdweb.eth/ERC1155CoreInitializable",
|
||||||
|
[
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusMintableERC1155",
|
||||||
|
"deployer.thirdweb.eth/BatchMetadataERC1155",
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusTransferableERC1155",
|
||||||
|
"deployer.thirdweb.eth/SequentialTokenIdERC1155",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
description: "ERC1155 NFTs that only owners can mint.",
|
||||||
|
title: "Modular Edition",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
// erc20 token
|
||||||
|
[
|
||||||
|
"thirdweb.eth/ERC20CoreInitializable",
|
||||||
|
[
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusMintableERC20",
|
||||||
|
"0x6453a486d52e0eb6e79ec4491038e2522a926936/StylusTransferableERC20",
|
||||||
|
],
|
||||||
|
{
|
||||||
|
description: "ERC20 Tokens that only owners can mint.",
|
||||||
|
title: "Modular Token",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
description:
|
||||||
|
"Collection of highly customizable and upgradeable smart contracts built with the modular contracts framework.",
|
||||||
|
displayName: "Modular Contracts - Arbitrum Stylus",
|
||||||
|
id: "modular-contracts",
|
||||||
|
name: "modular",
|
||||||
|
showInExplore: true,
|
||||||
|
isBeta: true,
|
||||||
|
} satisfies ExploreCategory;
|
||||||
|
|
||||||
const CATEGORIES: Record<string, ExploreCategory> = {
|
const CATEGORIES: Record<string, ExploreCategory> = {
|
||||||
[POPULAR.id]: POPULAR,
|
[POPULAR.id]: POPULAR,
|
||||||
[NFTS.id]: NFTS,
|
[NFTS.id]: NFTS,
|
||||||
@@ -203,6 +254,7 @@ const CATEGORIES: Record<string, ExploreCategory> = {
|
|||||||
[COMMERCE.id]: COMMERCE,
|
[COMMERCE.id]: COMMERCE,
|
||||||
[STAKING.id]: STAKING,
|
[STAKING.id]: STAKING,
|
||||||
[GOVERNANCE.id]: GOVERNANCE,
|
[GOVERNANCE.id]: GOVERNANCE,
|
||||||
|
[MODULAR_CONTRACTS_STYLUS.id]: MODULAR_CONTRACTS_STYLUS,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getCategory(id: string) {
|
export function getCategory(id: string) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { Metadata } from "next";
|
|||||||
import { unstable_cache } from "next/cache";
|
import { unstable_cache } from "next/cache";
|
||||||
import { Bridge } from "thirdweb";
|
import { Bridge } from "thirdweb";
|
||||||
import { serverThirdwebClient } from "@/constants/thirdweb-client.server";
|
import { serverThirdwebClient } from "@/constants/thirdweb-client.server";
|
||||||
|
import { bridgeStats } from "../../../bridge/data";
|
||||||
import { PageHeader } from "./components/header";
|
import { PageHeader } from "./components/header";
|
||||||
import { TokenPage } from "./components/token-page";
|
import { TokenPage } from "./components/token-page";
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ export default async function Page() {
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
85+ chains, 4500+ tokens and 9+ million routes supported
|
{bridgeStats.supportedChains} chains, {bridgeStats.supportedTokens}{" "}
|
||||||
|
tokens and {bridgeStats.supportedRoutes} routes supported
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export function TeamSidebarLayout(props: {
|
|||||||
label: "Documentation",
|
label: "Documentation",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "https://playground.thirdweb.com/connect/sign-in/button",
|
href: "https://playground.thirdweb.com/wallets/sign-in/button",
|
||||||
icon: BoxIcon,
|
icon: BoxIcon,
|
||||||
label: "Playground",
|
label: "Playground",
|
||||||
},
|
},
|
||||||
|
|||||||
+1
@@ -58,6 +58,7 @@ const authOptions = [
|
|||||||
"apple",
|
"apple",
|
||||||
"coinbase",
|
"coinbase",
|
||||||
"line",
|
"line",
|
||||||
|
"epic",
|
||||||
] as const satisfies AuthOption[];
|
] as const satisfies AuthOption[];
|
||||||
|
|
||||||
type AuthOptionsFormData = {
|
type AuthOptionsFormData = {
|
||||||
|
|||||||
+2
-2
@@ -6,9 +6,9 @@ export const SmartWalletsBillingAlert = (props: { teamSlug: string }) => {
|
|||||||
return (
|
return (
|
||||||
<Alert variant="warning">
|
<Alert variant="warning">
|
||||||
<CircleAlertIcon className="size-5" />
|
<CircleAlertIcon className="size-5" />
|
||||||
<AlertTitle>Account Abstraction on Mainnet</AlertTitle>
|
<AlertTitle>Gas Sponsorship on Mainnet</AlertTitle>
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
To enable AA on mainnet chains,{" "}
|
To enable Gas Sponsorship on mainnet chains,{" "}
|
||||||
<UnderlineLink href={`/team/${props.teamSlug}/~/billing`}>
|
<UnderlineLink href={`/team/${props.teamSlug}/~/billing`}>
|
||||||
subscribe to a billing plan.
|
subscribe to a billing plan.
|
||||||
</UnderlineLink>
|
</UnderlineLink>
|
||||||
|
|||||||
-8
@@ -14,7 +14,6 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow,
|
TableRow,
|
||||||
} from "@/components/ui/table";
|
} from "@/components/ui/table";
|
||||||
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
|
||||||
|
|
||||||
export function DefaultFactoriesSection() {
|
export function DefaultFactoriesSection() {
|
||||||
const data = [
|
const data = [
|
||||||
@@ -38,13 +37,6 @@ export function DefaultFactoriesSection() {
|
|||||||
</h3>
|
</h3>
|
||||||
<p className="text-muted-foreground text-sm">
|
<p className="text-muted-foreground text-sm">
|
||||||
Ready to use account factories that are pre-deployed on each chain.{" "}
|
Ready to use account factories that are pre-deployed on each chain.{" "}
|
||||||
<UnderlineLink
|
|
||||||
href="https://playground.thirdweb.com/connect/account-abstraction/connect"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
Learn how to use these in your apps
|
|
||||||
</UnderlineLink>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
+6
-158
@@ -1,163 +1,11 @@
|
|||||||
import type { Metadata } from "next";
|
import { redirect } from "next/navigation";
|
||||||
import { notFound, redirect } from "next/navigation";
|
|
||||||
import type { SearchParams } from "nuqs/server";
|
|
||||||
import { getUserOpUsage } from "@/api/analytics";
|
|
||||||
import { getAuthToken } from "@/api/auth-token";
|
|
||||||
import { getProject } from "@/api/project/projects";
|
|
||||||
import { getTeamBySlug } from "@/api/team/get-team";
|
|
||||||
import {
|
|
||||||
getLastNDaysRange,
|
|
||||||
type Range,
|
|
||||||
} from "@/components/analytics/date-range-selector";
|
|
||||||
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { SmartAccountIcon } from "@/icons/SmartAccountIcon";
|
|
||||||
import { getAbsoluteUrl } from "@/utils/vercel";
|
|
||||||
import { AccountAbstractionSummary } from "./AccountAbstractionAnalytics/AccountAbstractionSummary";
|
|
||||||
import { SmartWalletsBillingAlert } from "./Alerts";
|
|
||||||
import { AccountAbstractionAnalytics } from "./aa-analytics";
|
|
||||||
import { searchParamLoader } from "./search-params";
|
|
||||||
|
|
||||||
interface PageParams {
|
|
||||||
team_slug: string;
|
|
||||||
project_slug: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Redirect old Account Abstraction page to new Sponsored Gas Overview
|
||||||
export default async function Page(props: {
|
export default async function Page(props: {
|
||||||
params: Promise<PageParams>;
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
searchParams: Promise<SearchParams>;
|
|
||||||
children: React.ReactNode;
|
|
||||||
}) {
|
}) {
|
||||||
const [params, searchParams, authToken] = await Promise.all([
|
const params = await props.params;
|
||||||
props.params,
|
redirect(
|
||||||
searchParamLoader(props.searchParams),
|
`/team/${params.team_slug}/${params.project_slug}/wallets/sponsored-gas`,
|
||||||
getAuthToken(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!authToken) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const [team, project] = await Promise.all([
|
|
||||||
getTeamBySlug(params.team_slug),
|
|
||||||
getProject(params.team_slug, params.project_slug),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!team) {
|
|
||||||
redirect("/team");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!project) {
|
|
||||||
redirect(`/team/${params.team_slug}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const interval = searchParams.interval ?? "week";
|
|
||||||
const rangeType = searchParams.range || "last-120";
|
|
||||||
|
|
||||||
const range: Range = {
|
|
||||||
from:
|
|
||||||
rangeType === "custom"
|
|
||||||
? searchParams.from
|
|
||||||
: getLastNDaysRange(rangeType).from,
|
|
||||||
to:
|
|
||||||
rangeType === "custom"
|
|
||||||
? searchParams.to
|
|
||||||
: getLastNDaysRange(rangeType).to,
|
|
||||||
type: rangeType,
|
|
||||||
};
|
|
||||||
|
|
||||||
const userOpStats = await getUserOpUsage(
|
|
||||||
{
|
|
||||||
from: range.from,
|
|
||||||
period: interval,
|
|
||||||
projectId: project.id,
|
|
||||||
teamId: project.teamId,
|
|
||||||
to: range.to,
|
|
||||||
},
|
|
||||||
authToken,
|
|
||||||
);
|
|
||||||
|
|
||||||
const client = getClientThirdwebClient({
|
|
||||||
jwt: authToken,
|
|
||||||
teamId: project.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isBundlerServiceEnabled = !!project.services.find(
|
|
||||||
(s) => s.name === "bundler",
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasSmartWalletsWithoutBilling =
|
|
||||||
isBundlerServiceEnabled &&
|
|
||||||
team.billingStatus !== "validPayment" &&
|
|
||||||
team.billingStatus !== "pastDue";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProjectPage
|
|
||||||
header={{
|
|
||||||
icon: SmartAccountIcon,
|
|
||||||
client,
|
|
||||||
title: "Account Abstraction",
|
|
||||||
description:
|
|
||||||
"Integrate EIP-7702 and EIP-4337 compliant smart accounts for gasless sponsorships and more.",
|
|
||||||
actions: null,
|
|
||||||
settings: {
|
|
||||||
href: `/team/${params.team_slug}/${params.project_slug}/settings/account-abstraction`,
|
|
||||||
},
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
type: "docs",
|
|
||||||
href: "https://portal.thirdweb.com/transactions/sponsor",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "playground",
|
|
||||||
href: "https://playground.thirdweb.com/account-abstraction/eip-7702",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{hasSmartWalletsWithoutBilling && (
|
|
||||||
<>
|
|
||||||
<SmartWalletsBillingAlert teamSlug={params.team_slug} />
|
|
||||||
<div className="h-10" />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
<div className="flex grow flex-col gap-10">
|
|
||||||
<AccountAbstractionSummary
|
|
||||||
projectId={project.id}
|
|
||||||
teamId={project.teamId}
|
|
||||||
authToken={authToken}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<AccountAbstractionAnalytics
|
|
||||||
client={client}
|
|
||||||
projectId={project.id}
|
|
||||||
teamId={project.teamId}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
userOpStats={userOpStats}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</ProjectPage>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const seo = {
|
|
||||||
desc: "Add account abstraction to your web3 app & unlock powerful features for seamless onboarding, customizable transactions, & maximum security. Get started.",
|
|
||||||
title: "The Complete Account Abstraction Toolkit | thirdweb",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
|
||||||
description: seo.desc,
|
|
||||||
openGraph: {
|
|
||||||
description: seo.desc,
|
|
||||||
images: [
|
|
||||||
{
|
|
||||||
alt: seo.title,
|
|
||||||
height: 630,
|
|
||||||
url: `${getAbsoluteUrl()}/assets/og-image/dashboard-wallets-smart-wallet.png`,
|
|
||||||
width: 1200,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
title: seo.title,
|
|
||||||
},
|
|
||||||
title: seo.title,
|
|
||||||
};
|
|
||||||
|
|||||||
+1
-1
@@ -371,7 +371,7 @@ export function AccountAbstractionSettingsPage(
|
|||||||
of the{" "}
|
of the{" "}
|
||||||
<UnderlineLink
|
<UnderlineLink
|
||||||
className="text-primary-500"
|
className="text-primary-500"
|
||||||
href="https://portal.thirdweb.com/wallets/smart-wallet/infrastructure#supported-chains"
|
href="https://thirdweb.com/chainlist?service=account-abstraction"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ export default async function Page(props: {
|
|||||||
icon: <WebhookIcon className="size-3.5 text-muted-foreground" />,
|
icon: <WebhookIcon className="size-3.5 text-muted-foreground" />,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
settings: {
|
||||||
|
href: `/team/${params.team_slug}/${params.project_slug}/settings/payments`,
|
||||||
|
},
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
type: "docs",
|
type: "docs",
|
||||||
|
|||||||
+6
-2
@@ -4,9 +4,14 @@ import { ProjectFTUX } from "./ProjectFTUX";
|
|||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
component: ProjectFTUX,
|
component: ProjectFTUX,
|
||||||
|
parameters: {
|
||||||
|
nextjs: {
|
||||||
|
appDirectory: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
decorators: [
|
decorators: [
|
||||||
(Story) => (
|
(Story) => (
|
||||||
<div className="container py-8 pb-20">
|
<div className="container py-8 pb-20 max-w-7xl">
|
||||||
<Story />
|
<Story />
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
@@ -31,6 +36,5 @@ export const Default: Story = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
teamSlug: "bar",
|
teamSlug: "bar",
|
||||||
managementAccessToken: undefined,
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-80
@@ -15,33 +15,12 @@ import { UnrealIcon } from "@/icons/brand-icons/UnrealIcon";
|
|||||||
import { ContractIcon } from "@/icons/ContractIcon";
|
import { ContractIcon } from "@/icons/ContractIcon";
|
||||||
import { InsightIcon } from "@/icons/InsightIcon";
|
import { InsightIcon } from "@/icons/InsightIcon";
|
||||||
import { PayIcon } from "@/icons/PayIcon";
|
import { PayIcon } from "@/icons/PayIcon";
|
||||||
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
|
||||||
import { getProjectWalletLabel } from "@/lib/project-wallet";
|
|
||||||
import {
|
|
||||||
getProjectWallet,
|
|
||||||
type ProjectWalletSummary,
|
|
||||||
} from "@/lib/server/project-wallet";
|
|
||||||
import { ClientIDSection } from "./ClientIDSection";
|
import { ClientIDSection } from "./ClientIDSection";
|
||||||
import { ProjectWalletControls } from "./ProjectWalletControls.client";
|
|
||||||
import { ProjectWalletSetup } from "./ProjectWalletSetup.client";
|
|
||||||
import { SecretKeySection } from "./SecretKeySection";
|
import { SecretKeySection } from "./SecretKeySection";
|
||||||
|
|
||||||
export async function ProjectFTUX(props: {
|
export function ProjectFTUX(props: { project: Project; teamSlug: string }) {
|
||||||
project: Project;
|
|
||||||
teamSlug: string;
|
|
||||||
wallet?: ProjectWalletSummary | undefined;
|
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
}) {
|
|
||||||
const projectWallet = props.wallet ?? (await getProjectWallet(props.project));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-10">
|
<div className="flex flex-col gap-10">
|
||||||
<ProjectWalletSection
|
|
||||||
project={props.project}
|
|
||||||
teamSlug={props.teamSlug}
|
|
||||||
wallet={projectWallet}
|
|
||||||
managementAccessToken={props.managementAccessToken}
|
|
||||||
/>
|
|
||||||
<IntegrateAPIKeySection project={props.project} />
|
<IntegrateAPIKeySection project={props.project} />
|
||||||
<ProductsSection
|
<ProductsSection
|
||||||
projectSlug={props.project.slug}
|
projectSlug={props.project.slug}
|
||||||
@@ -53,64 +32,6 @@ export async function ProjectFTUX(props: {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ProjectWalletSection(props: {
|
|
||||||
project: Project;
|
|
||||||
teamSlug: string;
|
|
||||||
wallet: ProjectWalletSummary | undefined;
|
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
}) {
|
|
||||||
const defaultLabel = getProjectWalletLabel(props.project.name);
|
|
||||||
const walletAddress = props.wallet?.address;
|
|
||||||
const label = props.wallet?.label ?? defaultLabel;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section>
|
|
||||||
<div className="rounded-lg border border-border bg-card p-4">
|
|
||||||
<div className="flex flex-col gap-4">
|
|
||||||
<div className="flex items-center gap-3">
|
|
||||||
<div className="rounded-full border border-border bg-background p-2">
|
|
||||||
<WalletProductIcon className="size-5 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<p className="font-semibold text-lg tracking-tight">
|
|
||||||
Project Wallet
|
|
||||||
</p>
|
|
||||||
<p className="text-muted-foreground text-sm">
|
|
||||||
Use it for deployments, payments, and API integrations.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{walletAddress ? (
|
|
||||||
<>
|
|
||||||
<ProjectWalletControls
|
|
||||||
label={label}
|
|
||||||
project={props.project}
|
|
||||||
walletAddress={walletAddress}
|
|
||||||
/>
|
|
||||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-end">
|
|
||||||
<Link
|
|
||||||
className="inline-flex items-center gap-1 text-sm font-medium text-primary hover:underline"
|
|
||||||
href={`/team/${props.teamSlug}/${props.project.slug}/transactions`}
|
|
||||||
>
|
|
||||||
View Transactions
|
|
||||||
<ChevronRightIcon className="size-4" />
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<ProjectWalletSetup
|
|
||||||
managementAccessToken={props.managementAccessToken}
|
|
||||||
project={props.project}
|
|
||||||
teamSlug={props.teamSlug}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Integrate API key section ------------------------------------------------------------
|
// Integrate API key section ------------------------------------------------------------
|
||||||
|
|
||||||
function IntegrateAPIKeySection({ project }: { project: Project }) {
|
function IntegrateAPIKeySection({ project }: { project: Project }) {
|
||||||
|
|||||||
-747
@@ -1,747 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import {
|
|
||||||
EllipsisVerticalIcon,
|
|
||||||
RefreshCcwIcon,
|
|
||||||
SendIcon,
|
|
||||||
ShuffleIcon,
|
|
||||||
WalletIcon,
|
|
||||||
} from "lucide-react";
|
|
||||||
import { useEffect, useMemo, useState } from "react";
|
|
||||||
import { useForm } from "react-hook-form";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { toWei } from "thirdweb";
|
|
||||||
import { useWalletBalance } from "thirdweb/react";
|
|
||||||
import { isAddress } from "thirdweb/utils";
|
|
||||||
import { z } from "zod";
|
|
||||||
import { listProjectServerWallets } from "@/actions/project-wallet/list-server-wallets";
|
|
||||||
import { sendProjectWalletTokens } from "@/actions/project-wallet/send-tokens";
|
|
||||||
import type { Project } from "@/api/project/projects";
|
|
||||||
import { FundWalletModal } from "@/components/blocks/fund-wallets-modal";
|
|
||||||
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
|
|
||||||
import { WalletAddress } from "@/components/blocks/wallet-address";
|
|
||||||
import { Badge } from "@/components/ui/badge";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogFooter,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from "@/components/ui/dialog";
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from "@/components/ui/dropdown-menu";
|
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormDescription,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from "@/components/ui/form";
|
|
||||||
import { Input } from "@/components/ui/input";
|
|
||||||
import { Spinner } from "@/components/ui/Spinner";
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
|
|
||||||
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
|
||||||
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
|
|
||||||
import { cn } from "@/lib/utils";
|
|
||||||
import { updateDefaultProjectWallet } from "../../transactions/lib/vault.client";
|
|
||||||
|
|
||||||
type ProjectWalletControlsProps = {
|
|
||||||
walletAddress: string;
|
|
||||||
label: string;
|
|
||||||
project: Pick<
|
|
||||||
Project,
|
|
||||||
"id" | "publishableKey" | "teamId" | "services" | "name"
|
|
||||||
>;
|
|
||||||
defaultChainId?: number;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function ProjectWalletControls(props: ProjectWalletControlsProps) {
|
|
||||||
const { walletAddress, label, project, defaultChainId } = props;
|
|
||||||
const [isSendOpen, setIsSendOpen] = useState(false);
|
|
||||||
const [isReceiveOpen, setIsReceiveOpen] = useState(false);
|
|
||||||
const [selectedChainId, setSelectedChainId] = useState(defaultChainId ?? 1);
|
|
||||||
const [isChangeWalletOpen, setIsChangeWalletOpen] = useState(false);
|
|
||||||
const [selectedWalletId, setSelectedWalletId] = useState<string | undefined>(
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const client = useMemo(() => getClientThirdwebClient(), []);
|
|
||||||
const chain = useV5DashboardChain(selectedChainId);
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const router = useDashboardRouter();
|
|
||||||
|
|
||||||
const engineCloudService = useMemo(
|
|
||||||
() => project.services?.find((service) => service.name === "engineCloud"),
|
|
||||||
[project.services],
|
|
||||||
);
|
|
||||||
const managementAccessToken =
|
|
||||||
engineCloudService?.managementAccessToken ?? undefined;
|
|
||||||
const isManagedVault = !!engineCloudService?.encryptedAdminKey;
|
|
||||||
|
|
||||||
const serverWalletsQuery = useQuery({
|
|
||||||
enabled: !!managementAccessToken,
|
|
||||||
queryFn: async () => {
|
|
||||||
if (!managementAccessToken) {
|
|
||||||
return [] as ProjectWalletSummary[];
|
|
||||||
}
|
|
||||||
|
|
||||||
return listProjectServerWallets({
|
|
||||||
managementAccessToken,
|
|
||||||
projectId: project.id,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
queryKey: ["project", project.id, "server-wallets", managementAccessToken],
|
|
||||||
staleTime: 60_000,
|
|
||||||
});
|
|
||||||
|
|
||||||
const serverWallets = serverWalletsQuery.data ?? [];
|
|
||||||
const currentWalletAddressLower = walletAddress.toLowerCase();
|
|
||||||
const otherWallets = useMemo(() => {
|
|
||||||
return serverWallets.filter((wallet) => {
|
|
||||||
return wallet.address.toLowerCase() !== currentWalletAddressLower;
|
|
||||||
});
|
|
||||||
}, [serverWallets, currentWalletAddressLower]);
|
|
||||||
|
|
||||||
const canChangeWallet = otherWallets.length > 0;
|
|
||||||
|
|
||||||
const handleOpenChangeWallet = () => {
|
|
||||||
const currentWallet = serverWallets.find(
|
|
||||||
(wallet) => wallet.address.toLowerCase() === currentWalletAddressLower,
|
|
||||||
);
|
|
||||||
|
|
||||||
const nextWalletId =
|
|
||||||
otherWallets[0]?.id ?? currentWallet?.id ?? serverWallets[0]?.id;
|
|
||||||
|
|
||||||
setSelectedWalletId(nextWalletId);
|
|
||||||
setIsChangeWalletOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCloseChangeWallet = () => {
|
|
||||||
setIsChangeWalletOpen(false);
|
|
||||||
setSelectedWalletId(undefined);
|
|
||||||
};
|
|
||||||
|
|
||||||
const selectedWallet = useMemo(() => {
|
|
||||||
if (!selectedWalletId) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return serverWallets.find((wallet) => wallet.id === selectedWalletId);
|
|
||||||
}, [selectedWalletId, serverWallets]);
|
|
||||||
|
|
||||||
const isSelectionDifferent = Boolean(
|
|
||||||
selectedWallet &&
|
|
||||||
selectedWallet.address.toLowerCase() !== currentWalletAddressLower,
|
|
||||||
);
|
|
||||||
|
|
||||||
const changeWalletMutation = useMutation({
|
|
||||||
mutationFn: async (wallet: ProjectWalletSummary) => {
|
|
||||||
await updateDefaultProjectWallet({
|
|
||||||
project: project as Project,
|
|
||||||
projectWalletAddress: wallet.address,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
const message =
|
|
||||||
error instanceof Error
|
|
||||||
? error.message
|
|
||||||
: "Failed to update project wallet";
|
|
||||||
toast.error(message);
|
|
||||||
},
|
|
||||||
onSuccess: async (_, wallet) => {
|
|
||||||
const descriptionLabel = wallet.label ?? wallet.address;
|
|
||||||
toast.success("Project wallet updated", {
|
|
||||||
description: `Now pointing to ${descriptionLabel}`,
|
|
||||||
});
|
|
||||||
await queryClient.invalidateQueries({
|
|
||||||
queryKey: [
|
|
||||||
"project",
|
|
||||||
project.id,
|
|
||||||
"server-wallets",
|
|
||||||
managementAccessToken,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
handleCloseChangeWallet();
|
|
||||||
router.refresh();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const balanceQuery = useWalletBalance({
|
|
||||||
address: walletAddress,
|
|
||||||
chain,
|
|
||||||
client,
|
|
||||||
});
|
|
||||||
|
|
||||||
const balanceDisplay = balanceQuery.data
|
|
||||||
? `${balanceQuery.data.displayValue} ${balanceQuery.data.symbol}`
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-5">
|
|
||||||
<div className="rounded-lg border border-border bg-background p-3">
|
|
||||||
<div className="flex flex-col gap-4">
|
|
||||||
<div className="flex flex-col gap-3 lg:flex-row">
|
|
||||||
<div className="flex-1">
|
|
||||||
<p className="text-muted-foreground text-xs">Address</p>
|
|
||||||
<WalletAddress address={walletAddress} client={client} />
|
|
||||||
</div>
|
|
||||||
<div className="flex-1">
|
|
||||||
<p className="text-muted-foreground text-xs">Label</p>
|
|
||||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
|
||||||
<p className="font-mono text-sm break-all py-2 sm:py-0">
|
|
||||||
{label}
|
|
||||||
</p>
|
|
||||||
{canChangeWallet && (
|
|
||||||
<Button
|
|
||||||
className="h-8 gap-1 sm:ml-4"
|
|
||||||
onClick={handleOpenChangeWallet}
|
|
||||||
size="sm"
|
|
||||||
disabled={serverWalletsQuery.isLoading}
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<ShuffleIcon className="size-3.5" />
|
|
||||||
Change default
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
|
|
||||||
<div className="flex-1 flex-col">
|
|
||||||
<p className="text-xs text-muted-foreground pb-2">Balance</p>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WalletIcon className="size-4 text-muted-foreground" />
|
|
||||||
{balanceQuery.isLoading ? (
|
|
||||||
<Spinner className="size-4" />
|
|
||||||
) : balanceDisplay ? (
|
|
||||||
<span className="text-md tracking-tight">
|
|
||||||
{balanceDisplay}
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<span className="text-muted-foreground text-sm">N/A</span>
|
|
||||||
)}
|
|
||||||
<Button
|
|
||||||
aria-label="Refresh balance"
|
|
||||||
className="h-8 w-8 p-0"
|
|
||||||
disabled={balanceQuery.isFetching}
|
|
||||||
onClick={() => balanceQuery.refetch()}
|
|
||||||
size="icon"
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<RefreshCcwIcon
|
|
||||||
className={cn(
|
|
||||||
"size-4",
|
|
||||||
balanceQuery.isFetching && "animate-spin",
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Button>
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button
|
|
||||||
aria-label="Open wallet actions"
|
|
||||||
className="h-9 w-9"
|
|
||||||
size="icon"
|
|
||||||
variant="outline"
|
|
||||||
>
|
|
||||||
<EllipsisVerticalIcon className="size-4" />
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end" className="w-48 rounded-xl">
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="flex items-center gap-2"
|
|
||||||
onSelect={() => setIsSendOpen(true)}
|
|
||||||
>
|
|
||||||
<SendIcon className="size-4 text-muted-foreground" />
|
|
||||||
Send funds
|
|
||||||
</DropdownMenuItem>
|
|
||||||
<DropdownMenuItem
|
|
||||||
className="flex items-center gap-2"
|
|
||||||
onSelect={() => setIsReceiveOpen(true)}
|
|
||||||
>
|
|
||||||
<WalletIcon className="size-4 text-muted-foreground" />
|
|
||||||
Receive funds
|
|
||||||
</DropdownMenuItem>
|
|
||||||
</DropdownMenuContent>
|
|
||||||
</DropdownMenu>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div className="flex-col flex-1">
|
|
||||||
<p className="text-xs text-muted-foreground pb-2">Network</p>
|
|
||||||
<SingleNetworkSelector
|
|
||||||
chainId={selectedChainId}
|
|
||||||
className="max-w-xs rounded-lg"
|
|
||||||
client={client}
|
|
||||||
disableDeprecated
|
|
||||||
disableChainId
|
|
||||||
onChange={setSelectedChainId}
|
|
||||||
placeholder="Select network"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<SendProjectWalletModal
|
|
||||||
chainId={selectedChainId}
|
|
||||||
client={client}
|
|
||||||
isManagedVault={isManagedVault}
|
|
||||||
label={label}
|
|
||||||
onClose={() => setIsSendOpen(false)}
|
|
||||||
onSuccess={() => balanceQuery.refetch()}
|
|
||||||
open={isSendOpen}
|
|
||||||
publishableKey={project.publishableKey}
|
|
||||||
teamId={project.teamId}
|
|
||||||
walletAddress={walletAddress}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FundWalletModal
|
|
||||||
checkoutWidgetTitle={`Fund ${label}`}
|
|
||||||
client={client}
|
|
||||||
defaultChainId={selectedChainId}
|
|
||||||
description="Use your card or crypto to deposit into this server wallet"
|
|
||||||
onOpenChange={setIsReceiveOpen}
|
|
||||||
open={isReceiveOpen}
|
|
||||||
recipientAddress={walletAddress}
|
|
||||||
title="Fund project wallet"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Dialog
|
|
||||||
onOpenChange={(nextOpen) => {
|
|
||||||
if (!nextOpen) {
|
|
||||||
handleCloseChangeWallet();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
open={isChangeWalletOpen}
|
|
||||||
>
|
|
||||||
<DialogContent className="gap-0 p-0">
|
|
||||||
<DialogHeader className="p-4 lg:p-6">
|
|
||||||
<DialogTitle>Change default wallet</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Choose another server wallet to use as the default for this
|
|
||||||
project.
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div className="px-4 pb-8 lg:px-6">
|
|
||||||
{serverWalletsQuery.isLoading ? (
|
|
||||||
<div className="flex justify-center py-6">
|
|
||||||
<Spinner className="size-5" />
|
|
||||||
</div>
|
|
||||||
) : serverWallets.length <= 1 ? (
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
You need at least two server wallets to pick a different
|
|
||||||
default.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<div className="flex flex-col gap-3">
|
|
||||||
<Select
|
|
||||||
onValueChange={(value) => setSelectedWalletId(value)}
|
|
||||||
value={selectedWalletId ?? ""}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-full">
|
|
||||||
<SelectValue placeholder="Select server wallet">
|
|
||||||
{selectedWallet ? (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WalletAddress
|
|
||||||
address={selectedWallet.address}
|
|
||||||
client={client}
|
|
||||||
/>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="text-sm text-foreground">
|
|
||||||
{selectedWallet.label ?? "Unnamed server wallet"}
|
|
||||||
</span>
|
|
||||||
{selectedWallet.address.toLowerCase() ===
|
|
||||||
currentWalletAddressLower && (
|
|
||||||
<Badge variant="success" className="text-xs">
|
|
||||||
current
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
"Select server wallet"
|
|
||||||
)}
|
|
||||||
</SelectValue>
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{serverWallets.map((wallet) => {
|
|
||||||
const isCurrent =
|
|
||||||
wallet.address.toLowerCase() ===
|
|
||||||
currentWalletAddressLower;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SelectItem key={wallet.id} value={wallet.id}>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WalletAddress
|
|
||||||
address={wallet.address}
|
|
||||||
client={client}
|
|
||||||
/>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span className="text-sm text-foreground">
|
|
||||||
{wallet.label ?? "Unnamed server wallet"}
|
|
||||||
</span>
|
|
||||||
{isCurrent && (
|
|
||||||
<Badge variant="success" className="text-xs">
|
|
||||||
current
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<DialogFooter className="flex justify-end gap-3 border-t bg-card p-4 lg:p-6">
|
|
||||||
<Button
|
|
||||||
onClick={handleCloseChangeWallet}
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
disabled={changeWalletMutation.isPending}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
disabled={
|
|
||||||
!selectedWallet ||
|
|
||||||
!isSelectionDifferent ||
|
|
||||||
changeWalletMutation.isPending
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
if (selectedWallet) {
|
|
||||||
changeWalletMutation.mutate(selectedWallet);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{changeWalletMutation.isPending && (
|
|
||||||
<Spinner className="mr-2 size-4" />
|
|
||||||
)}
|
|
||||||
Save default
|
|
||||||
</Button>
|
|
||||||
</DialogFooter>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const createSendFormSchema = (secretKeyLabel: string) =>
|
|
||||||
z.object({
|
|
||||||
chainId: z.number({
|
|
||||||
required_error: "Select a network",
|
|
||||||
}),
|
|
||||||
toAddress: z
|
|
||||||
.string()
|
|
||||||
.trim()
|
|
||||||
.min(1, "Destination address is required")
|
|
||||||
.refine((value) => Boolean(isAddress(value)), {
|
|
||||||
message: "Enter a valid wallet address",
|
|
||||||
}),
|
|
||||||
amount: z.string().trim().min(1, "Amount is required"),
|
|
||||||
secretKey: z.string().trim().min(1, `${secretKeyLabel} is required`),
|
|
||||||
vaultAccessToken: z.string().trim(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const SECRET_KEY_LABEL = "Project secret key";
|
|
||||||
|
|
||||||
type SendFormValues = z.infer<ReturnType<typeof createSendFormSchema>>;
|
|
||||||
|
|
||||||
function SendProjectWalletModal(props: {
|
|
||||||
open: boolean;
|
|
||||||
onClose: () => void;
|
|
||||||
onSuccess: () => void;
|
|
||||||
walletAddress: string;
|
|
||||||
publishableKey: string;
|
|
||||||
teamId: string;
|
|
||||||
chainId: number;
|
|
||||||
label: string;
|
|
||||||
client: ReturnType<typeof getClientThirdwebClient>;
|
|
||||||
isManagedVault: boolean;
|
|
||||||
}) {
|
|
||||||
const {
|
|
||||||
open,
|
|
||||||
onClose,
|
|
||||||
onSuccess,
|
|
||||||
walletAddress,
|
|
||||||
publishableKey,
|
|
||||||
teamId,
|
|
||||||
chainId,
|
|
||||||
label,
|
|
||||||
client,
|
|
||||||
isManagedVault,
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
const secretKeyLabel = SECRET_KEY_LABEL;
|
|
||||||
const secretKeyPlaceholder = "Enter your project secret key";
|
|
||||||
const secretKeyHelper =
|
|
||||||
"Your project secret key was generated when you created your project. If you lost it, regenerate one from Project settings.";
|
|
||||||
const vaultAccessTokenHelper =
|
|
||||||
"Vault access tokens are optional credentials with server wallet permissions. Manage them in Vault settings.";
|
|
||||||
|
|
||||||
const formSchema = useMemo(() => createSendFormSchema(SECRET_KEY_LABEL), []);
|
|
||||||
|
|
||||||
const form = useForm<SendFormValues>({
|
|
||||||
defaultValues: {
|
|
||||||
amount: "0",
|
|
||||||
chainId,
|
|
||||||
secretKey: "",
|
|
||||||
vaultAccessToken: "",
|
|
||||||
toAddress: "",
|
|
||||||
},
|
|
||||||
mode: "onChange",
|
|
||||||
resolver: zodResolver(formSchema),
|
|
||||||
});
|
|
||||||
|
|
||||||
const selectedChain = useV5DashboardChain(form.watch("chainId"));
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax -- form submission chainId must track selector state
|
|
||||||
useEffect(() => {
|
|
||||||
form.setValue("chainId", chainId);
|
|
||||||
}, [chainId, form]);
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax -- reset cached inputs when modal closes to avoid leaking state
|
|
||||||
useEffect(() => {
|
|
||||||
if (!open) {
|
|
||||||
const currentValues = form.getValues();
|
|
||||||
form.reset({
|
|
||||||
amount: "0",
|
|
||||||
chainId,
|
|
||||||
secretKey: currentValues.secretKey ?? "",
|
|
||||||
vaultAccessToken: currentValues.vaultAccessToken ?? "",
|
|
||||||
toAddress: "",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [open, chainId, form]);
|
|
||||||
|
|
||||||
const sendMutation = useMutation({
|
|
||||||
mutationFn: async (values: SendFormValues) => {
|
|
||||||
const quantityWei = toWei(values.amount).toString();
|
|
||||||
const secretKeyValue = values.secretKey.trim();
|
|
||||||
const vaultAccessTokenValue = values.vaultAccessToken.trim();
|
|
||||||
|
|
||||||
const result = await sendProjectWalletTokens({
|
|
||||||
chainId: values.chainId,
|
|
||||||
publishableKey,
|
|
||||||
quantityWei,
|
|
||||||
recipientAddress: values.toAddress,
|
|
||||||
teamId,
|
|
||||||
walletAddress,
|
|
||||||
secretKey: secretKeyValue,
|
|
||||||
...(vaultAccessTokenValue
|
|
||||||
? { vaultAccessToken: vaultAccessTokenValue }
|
|
||||||
: {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result.ok) {
|
|
||||||
const errorMessage =
|
|
||||||
typeof result.error === "string"
|
|
||||||
? result.error
|
|
||||||
: "Failed to send funds";
|
|
||||||
throw new Error(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.transactionIds;
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
toast.error(error.message);
|
|
||||||
},
|
|
||||||
onSuccess: (transactionIds) => {
|
|
||||||
toast.success("Transfer submitted", {
|
|
||||||
description:
|
|
||||||
transactionIds && transactionIds.length > 0
|
|
||||||
? `Transaction ID: ${transactionIds[0]}`
|
|
||||||
: undefined,
|
|
||||||
});
|
|
||||||
onSuccess();
|
|
||||||
onClose();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog
|
|
||||||
onOpenChange={(nextOpen) => {
|
|
||||||
if (!nextOpen) {
|
|
||||||
onClose();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
open={open}
|
|
||||||
>
|
|
||||||
<DialogContent className="gap-0 p-0">
|
|
||||||
<DialogHeader className="p-4 lg:p-6">
|
|
||||||
<DialogTitle>Send from {label}</DialogTitle>
|
|
||||||
<DialogDescription>
|
|
||||||
Execute a one-off transfer using your server wallet.
|
|
||||||
</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<Form {...form}>
|
|
||||||
<form
|
|
||||||
onSubmit={form.handleSubmit((values) => {
|
|
||||||
void sendMutation.mutateAsync(values);
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div className="space-y-4 px-4 pb-8 lg:px-6">
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="chainId"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Network</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<SingleNetworkSelector
|
|
||||||
chainId={field.value}
|
|
||||||
className="bg-card"
|
|
||||||
client={client}
|
|
||||||
disableDeprecated
|
|
||||||
onChange={(nextChainId) => {
|
|
||||||
field.onChange(nextChainId);
|
|
||||||
}}
|
|
||||||
placeholder="Select network"
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="toAddress"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Send to</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
autoComplete="off"
|
|
||||||
placeholder="0x..."
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="amount"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>Amount</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
inputMode="decimal"
|
|
||||||
min="0"
|
|
||||||
step="any"
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormDescription>
|
|
||||||
Sending native token
|
|
||||||
{selectedChain?.nativeCurrency?.symbol
|
|
||||||
? ` (${selectedChain.nativeCurrency.symbol})`
|
|
||||||
: ""}
|
|
||||||
</FormDescription>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="secretKey"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>{secretKeyLabel}</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
autoComplete="off"
|
|
||||||
autoCorrect="off"
|
|
||||||
placeholder={secretKeyPlaceholder}
|
|
||||||
spellCheck={false}
|
|
||||||
type="password"
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormDescription>{secretKeyHelper}</FormDescription>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{!isManagedVault && (
|
|
||||||
<FormField
|
|
||||||
control={form.control}
|
|
||||||
name="vaultAccessToken"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel>
|
|
||||||
Vault access token
|
|
||||||
<span className="text-muted-foreground">
|
|
||||||
{" "}
|
|
||||||
(optional)
|
|
||||||
</span>
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<Input
|
|
||||||
autoComplete="off"
|
|
||||||
autoCorrect="off"
|
|
||||||
placeholder="Enter a vault access token (optional)"
|
|
||||||
spellCheck={false}
|
|
||||||
type="password"
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormDescription>
|
|
||||||
{vaultAccessTokenHelper}
|
|
||||||
</FormDescription>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex justify-end gap-3 border-t bg-card p-4 lg:p-6">
|
|
||||||
<Button onClick={onClose} type="button" variant="outline">
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
className="gap-2"
|
|
||||||
disabled={!form.formState.isValid || sendMutation.isPending}
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
{sendMutation.isPending && <Spinner className="size-4" />}
|
|
||||||
Submit transfer
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</Form>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
-215
@@ -1,215 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
||||||
import { CircleAlertIcon } from "lucide-react";
|
|
||||||
import { useMemo, useState } from "react";
|
|
||||||
import { toast } from "sonner";
|
|
||||||
import { listProjectServerWallets } from "@/actions/project-wallet/list-server-wallets";
|
|
||||||
import type { Project } from "@/api/project/projects";
|
|
||||||
import { WalletAddress } from "@/components/blocks/wallet-address";
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Spinner } from "@/components/ui/Spinner";
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
|
||||||
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
|
|
||||||
import { updateDefaultProjectWallet } from "../../transactions/lib/vault.client";
|
|
||||||
import CreateServerWallet from "../../transactions/server-wallets/components/create-server-wallet.client";
|
|
||||||
|
|
||||||
export function ProjectWalletSetup(props: {
|
|
||||||
project: Project;
|
|
||||||
teamSlug: string;
|
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
}) {
|
|
||||||
const { project, teamSlug, managementAccessToken } = props;
|
|
||||||
const router = useDashboardRouter();
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
const client = useMemo(() => getClientThirdwebClient(), []);
|
|
||||||
const [selectedWalletId, setSelectedWalletId] = useState<string | undefined>(
|
|
||||||
undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
const serverWalletsQuery = useQuery({
|
|
||||||
enabled: Boolean(managementAccessToken),
|
|
||||||
queryFn: async () => {
|
|
||||||
if (!managementAccessToken) {
|
|
||||||
return [] as ProjectWalletSummary[];
|
|
||||||
}
|
|
||||||
|
|
||||||
return listProjectServerWallets({
|
|
||||||
managementAccessToken,
|
|
||||||
projectId: project.id,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
queryKey: ["project", project.id, "server-wallets", managementAccessToken],
|
|
||||||
staleTime: 60_000,
|
|
||||||
});
|
|
||||||
|
|
||||||
const serverWallets = serverWalletsQuery.data ?? [];
|
|
||||||
|
|
||||||
const effectiveSelectedWalletId = useMemo(() => {
|
|
||||||
if (
|
|
||||||
selectedWalletId &&
|
|
||||||
serverWallets.some((wallet) => wallet.id === selectedWalletId)
|
|
||||||
) {
|
|
||||||
return selectedWalletId;
|
|
||||||
}
|
|
||||||
|
|
||||||
return serverWallets[0]?.id;
|
|
||||||
}, [selectedWalletId, serverWallets]);
|
|
||||||
|
|
||||||
const selectedWallet = useMemo(() => {
|
|
||||||
if (!effectiveSelectedWalletId) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return serverWallets.find(
|
|
||||||
(wallet) => wallet.id === effectiveSelectedWalletId,
|
|
||||||
);
|
|
||||||
}, [effectiveSelectedWalletId, serverWallets]);
|
|
||||||
|
|
||||||
const setDefaultWalletMutation = useMutation({
|
|
||||||
mutationFn: async (wallet: ProjectWalletSummary) => {
|
|
||||||
await updateDefaultProjectWallet({
|
|
||||||
project,
|
|
||||||
projectWalletAddress: wallet.address,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
const message =
|
|
||||||
error instanceof Error
|
|
||||||
? error.message
|
|
||||||
: "Failed to update project wallet";
|
|
||||||
toast.error(message);
|
|
||||||
},
|
|
||||||
onSuccess: async (_, wallet) => {
|
|
||||||
const descriptionLabel = wallet.label ?? wallet.address;
|
|
||||||
toast.success("Project wallet updated", {
|
|
||||||
description: `Now pointing to ${descriptionLabel}`,
|
|
||||||
});
|
|
||||||
await queryClient.invalidateQueries({
|
|
||||||
queryKey: [
|
|
||||||
"project",
|
|
||||||
project.id,
|
|
||||||
"server-wallets",
|
|
||||||
managementAccessToken,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
router.refresh();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const canSelectExisting =
|
|
||||||
Boolean(managementAccessToken) && serverWallets.length > 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Alert variant="info">
|
|
||||||
<CircleAlertIcon className="size-5" />
|
|
||||||
<AlertTitle>No project wallet set</AlertTitle>
|
|
||||||
<AlertDescription>
|
|
||||||
Set a project wallet to use for dashboard and API integrations.
|
|
||||||
</AlertDescription>
|
|
||||||
|
|
||||||
<div className="mt-4 space-y-5">
|
|
||||||
{serverWalletsQuery.isLoading ? (
|
|
||||||
<div className="flex items-center gap-2 text-sm text-muted-foreground">
|
|
||||||
<Spinner className="size-4" />
|
|
||||||
<span>Loading existing server wallets…</span>
|
|
||||||
</div>
|
|
||||||
) : canSelectExisting ? (
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<p className="text-sm font-medium text-foreground">
|
|
||||||
Choose an existing server wallet
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
These wallets were already created for this project. Pick one to
|
|
||||||
set as the default.
|
|
||||||
</p>
|
|
||||||
<Select
|
|
||||||
onValueChange={(value) => setSelectedWalletId(value)}
|
|
||||||
value={effectiveSelectedWalletId ?? ""}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-full">
|
|
||||||
<SelectValue placeholder="Select server wallet">
|
|
||||||
{selectedWallet ? (
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WalletAddress
|
|
||||||
address={selectedWallet.address}
|
|
||||||
client={client}
|
|
||||||
/>
|
|
||||||
<span className="text-muted-foreground text-sm">
|
|
||||||
{selectedWallet.label ?? "Unnamed server wallet"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
"Select server wallet"
|
|
||||||
)}
|
|
||||||
</SelectValue>
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{serverWallets.map((wallet) => (
|
|
||||||
<SelectItem key={wallet.id} value={wallet.id}>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<WalletAddress
|
|
||||||
address={wallet.address}
|
|
||||||
client={client}
|
|
||||||
/>
|
|
||||||
<span className="text-muted-foreground text-sm">
|
|
||||||
{wallet.label ?? "Unnamed server wallet"}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex flex-wrap items-center gap-3">
|
|
||||||
<Button
|
|
||||||
disabled={!selectedWallet || setDefaultWalletMutation.isPending}
|
|
||||||
onClick={() => {
|
|
||||||
if (selectedWallet) {
|
|
||||||
setDefaultWalletMutation.mutate(selectedWallet);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{setDefaultWalletMutation.isPending && (
|
|
||||||
<Spinner className="mr-2 size-4" />
|
|
||||||
)}
|
|
||||||
Set as project wallet
|
|
||||||
</Button>
|
|
||||||
<CreateServerWallet
|
|
||||||
managementAccessToken={managementAccessToken}
|
|
||||||
project={project}
|
|
||||||
teamSlug={teamSlug}
|
|
||||||
setAsProjectWallet
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="space-y-3 text-sm text-muted-foreground">
|
|
||||||
<p>
|
|
||||||
Create a server wallet to start using transactions and other
|
|
||||||
project features.
|
|
||||||
</p>
|
|
||||||
<CreateServerWallet
|
|
||||||
managementAccessToken={managementAccessToken}
|
|
||||||
project={project}
|
|
||||||
teamSlug={teamSlug}
|
|
||||||
setAsProjectWallet
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+137
-133
@@ -1,23 +1,23 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
import { Badge } from "@workspace/ui/components/badge";
|
||||||
import {
|
import {
|
||||||
ArrowLeftRightIcon,
|
|
||||||
BookTextIcon,
|
BookTextIcon,
|
||||||
BoxIcon,
|
BoxIcon,
|
||||||
DatabaseIcon,
|
DatabaseIcon,
|
||||||
HomeIcon,
|
HomeIcon,
|
||||||
LockIcon,
|
|
||||||
RssIcon,
|
RssIcon,
|
||||||
Settings2Icon,
|
Settings2Icon,
|
||||||
WebhookIcon,
|
WebhookIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { FullWidthSidebarLayout } from "@/components/blocks/full-width-sidebar-layout";
|
import {
|
||||||
import { Badge } from "@/components/ui/badge";
|
FullWidthSidebarLayout,
|
||||||
|
type ShadcnSidebarLink,
|
||||||
|
} from "@/components/blocks/full-width-sidebar-layout";
|
||||||
import { BridgeIcon } from "@/icons/BridgeIcon";
|
import { BridgeIcon } from "@/icons/BridgeIcon";
|
||||||
import { ContractIcon } from "@/icons/ContractIcon";
|
import { ContractIcon } from "@/icons/ContractIcon";
|
||||||
import { InsightIcon } from "@/icons/InsightIcon";
|
import { InsightIcon } from "@/icons/InsightIcon";
|
||||||
import { NebulaIcon } from "@/icons/NebulaIcon";
|
import { NebulaIcon } from "@/icons/NebulaIcon";
|
||||||
import { PayIcon } from "@/icons/PayIcon";
|
import { PayIcon } from "@/icons/PayIcon";
|
||||||
import { SmartAccountIcon } from "@/icons/SmartAccountIcon";
|
|
||||||
import { TokenIcon } from "@/icons/TokenIcon";
|
import { TokenIcon } from "@/icons/TokenIcon";
|
||||||
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
||||||
|
|
||||||
@@ -25,136 +25,140 @@ export function ProjectSidebarLayout(props: {
|
|||||||
layoutPath: string;
|
layoutPath: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
|
const contentSidebarLinks = [
|
||||||
|
{
|
||||||
|
exactMatch: true,
|
||||||
|
href: props.layoutPath,
|
||||||
|
icon: HomeIcon,
|
||||||
|
label: "Overview",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "Build",
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
subMenu: {
|
||||||
|
icon: WalletProductIcon,
|
||||||
|
label: "Wallets",
|
||||||
|
},
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/wallets/user-wallets`,
|
||||||
|
label: "User Wallets",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/wallets/server-wallets`,
|
||||||
|
label: "Server Wallets",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/wallets/sponsored-gas`,
|
||||||
|
label: "Gas Sponsorship",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/contracts`,
|
||||||
|
icon: ContractIcon,
|
||||||
|
label: "Contracts",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/ai`,
|
||||||
|
icon: NebulaIcon,
|
||||||
|
label: "AI",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "Monetize",
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/x402`,
|
||||||
|
icon: PayIcon,
|
||||||
|
label: (
|
||||||
|
<span className="flex items-center gap-2">
|
||||||
|
x402 <Badge>New</Badge>
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/bridge`,
|
||||||
|
icon: BridgeIcon,
|
||||||
|
label: "Bridge",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/tokens`,
|
||||||
|
icon: TokenIcon,
|
||||||
|
label: "Tokens",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: "Scale",
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/insight`,
|
||||||
|
icon: InsightIcon,
|
||||||
|
label: "Insight",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/rpc`,
|
||||||
|
icon: RssIcon,
|
||||||
|
label: "RPC",
|
||||||
|
},
|
||||||
|
// linkely want to move this to `team` level eventually
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/engine`,
|
||||||
|
icon: DatabaseIcon,
|
||||||
|
label: "Engine",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] satisfies ShadcnSidebarLink[];
|
||||||
|
|
||||||
|
const footerSidebarLinks = [
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/webhooks/contracts`,
|
||||||
|
icon: WebhookIcon,
|
||||||
|
isActive: (pathname) => {
|
||||||
|
return pathname.startsWith(`${props.layoutPath}/webhooks`);
|
||||||
|
},
|
||||||
|
label: "Webhooks",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: `${props.layoutPath}/settings`,
|
||||||
|
icon: Settings2Icon,
|
||||||
|
label: "Project Settings",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
separator: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "https://portal.thirdweb.com",
|
||||||
|
icon: BookTextIcon,
|
||||||
|
label: "Documentation",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
href: "https://playground.thirdweb.com/wallets/sign-in/button",
|
||||||
|
icon: BoxIcon,
|
||||||
|
label: "Playground",
|
||||||
|
},
|
||||||
|
] satisfies ShadcnSidebarLink[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FullWidthSidebarLayout
|
<FullWidthSidebarLayout
|
||||||
contentSidebarLinks={[
|
contentSidebarLinks={contentSidebarLinks}
|
||||||
{
|
footerSidebarLinks={footerSidebarLinks}
|
||||||
exactMatch: true,
|
|
||||||
href: props.layoutPath,
|
|
||||||
icon: HomeIcon,
|
|
||||||
label: "Overview",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
separator: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
group: "Build",
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/wallets`,
|
|
||||||
icon: WalletProductIcon,
|
|
||||||
label: "Wallets",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/transactions`,
|
|
||||||
icon: ArrowLeftRightIcon,
|
|
||||||
label: (
|
|
||||||
<span className="flex items-center gap-2">
|
|
||||||
Transactions <Badge>New</Badge>
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/contracts`,
|
|
||||||
icon: ContractIcon,
|
|
||||||
label: "Contracts",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/ai`,
|
|
||||||
icon: NebulaIcon,
|
|
||||||
label: "AI",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
separator: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
group: "Monetize",
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/payments`,
|
|
||||||
icon: PayIcon,
|
|
||||||
label: "Payments",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/bridge`,
|
|
||||||
icon: BridgeIcon,
|
|
||||||
label: "Bridge",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/tokens`,
|
|
||||||
icon: TokenIcon,
|
|
||||||
label: "Tokens",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
separator: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
group: "Scale",
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/insight`,
|
|
||||||
icon: InsightIcon,
|
|
||||||
label: "Insight",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/account-abstraction`,
|
|
||||||
icon: SmartAccountIcon,
|
|
||||||
label: "Account Abstraction",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/rpc`,
|
|
||||||
icon: RssIcon,
|
|
||||||
label: "RPC",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/vault`,
|
|
||||||
icon: LockIcon,
|
|
||||||
label: "Vault",
|
|
||||||
},
|
|
||||||
// linkely want to move this to `team` level eventually
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/engine`,
|
|
||||||
icon: DatabaseIcon,
|
|
||||||
label: "Engine",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
footerSidebarLinks={[
|
|
||||||
{
|
|
||||||
separator: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/webhooks/contracts`,
|
|
||||||
icon: WebhookIcon,
|
|
||||||
isActive: (pathname) => {
|
|
||||||
return pathname.startsWith(`${props.layoutPath}/webhooks`);
|
|
||||||
},
|
|
||||||
label: "Webhooks",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: `${props.layoutPath}/settings`,
|
|
||||||
icon: Settings2Icon,
|
|
||||||
label: "Project Settings",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
separator: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: "https://portal.thirdweb.com",
|
|
||||||
icon: BookTextIcon,
|
|
||||||
label: "Documentation",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
href: "https://playground.thirdweb.com/connect/sign-in/button",
|
|
||||||
icon: BoxIcon,
|
|
||||||
label: "Playground",
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</FullWidthSidebarLayout>
|
</FullWidthSidebarLayout>
|
||||||
|
|||||||
+736
@@ -0,0 +1,736 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import {
|
||||||
|
ArrowLeftRightIcon,
|
||||||
|
EllipsisVerticalIcon,
|
||||||
|
RefreshCcwIcon,
|
||||||
|
SendIcon,
|
||||||
|
ShuffleIcon,
|
||||||
|
WalletIcon,
|
||||||
|
} from "lucide-react";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import { type ThirdwebClient, toWei } from "thirdweb";
|
||||||
|
import { useWalletBalance } from "thirdweb/react";
|
||||||
|
import { isAddress } from "thirdweb/utils";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { sendProjectWalletTokens } from "@/actions/project-wallet/send-tokens";
|
||||||
|
import type { Project } from "@/api/project/projects";
|
||||||
|
import { FundWalletModal } from "@/components/blocks/fund-wallets-modal";
|
||||||
|
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
|
||||||
|
import { WalletAddress } from "@/components/blocks/wallet-address";
|
||||||
|
import { Badge } from "@/components/ui/badge";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { CopyTextButton } from "@/components/ui/CopyTextButton";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Spinner } from "@/components/ui/Spinner";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import type { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
|
||||||
|
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
||||||
|
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { updateDefaultProjectWallet } from "../../transactions/lib/vault.client";
|
||||||
|
|
||||||
|
type GetProjectServerWallets = (params: {
|
||||||
|
managementAccessToken: string;
|
||||||
|
projectId: string;
|
||||||
|
}) => Promise<ProjectWalletSummary[]>;
|
||||||
|
|
||||||
|
type ProjectWalletControlsProps = {
|
||||||
|
projectWallet: ProjectWalletSummary;
|
||||||
|
project: Project;
|
||||||
|
defaultChainId?: number;
|
||||||
|
teamSlug: string;
|
||||||
|
getProjectServerWallets: GetProjectServerWallets;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function ProjectWalletDetailsSection(props: ProjectWalletControlsProps) {
|
||||||
|
const { projectWallet, project, defaultChainId } = props;
|
||||||
|
const [isSendOpen, setIsSendOpen] = useState(false);
|
||||||
|
const [isReceiveOpen, setIsReceiveOpen] = useState(false);
|
||||||
|
const [selectedChainId, setSelectedChainId] = useState(defaultChainId ?? 1);
|
||||||
|
const [isChangeWalletOpen, setIsChangeWalletOpen] = useState(false);
|
||||||
|
|
||||||
|
const chain = useV5DashboardChain(selectedChainId);
|
||||||
|
|
||||||
|
const engineCloudService = useMemo(
|
||||||
|
() => project.services?.find((service) => service.name === "engineCloud"),
|
||||||
|
[project.services],
|
||||||
|
);
|
||||||
|
|
||||||
|
const managementAccessToken =
|
||||||
|
engineCloudService?.managementAccessToken ?? undefined;
|
||||||
|
|
||||||
|
const isManagedVault = !!engineCloudService?.encryptedAdminKey;
|
||||||
|
|
||||||
|
const serverWalletsQuery = useQuery({
|
||||||
|
enabled: !!managementAccessToken,
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!managementAccessToken) {
|
||||||
|
return [] as ProjectWalletSummary[];
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.getProjectServerWallets({
|
||||||
|
managementAccessToken,
|
||||||
|
projectId: project.id,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
queryKey: ["project", project.id, "server-wallets", managementAccessToken],
|
||||||
|
staleTime: 60_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const balanceQuery = useWalletBalance({
|
||||||
|
address: projectWallet.address,
|
||||||
|
chain,
|
||||||
|
client: props.client,
|
||||||
|
});
|
||||||
|
|
||||||
|
const canChangeWallet =
|
||||||
|
serverWalletsQuery.data && serverWalletsQuery.data.length > 1;
|
||||||
|
|
||||||
|
const router = useDashboardRouter();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="rounded-xl border border-border bg-card relative">
|
||||||
|
<DropdownMenu>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
aria-label="Open wallet actions"
|
||||||
|
className="p-2 h-auto w-auto absolute right-4 top-4 z-10"
|
||||||
|
variant="ghost"
|
||||||
|
>
|
||||||
|
<EllipsisVerticalIcon className="size-5" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-64 rounded-xl">
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
onSelect={() => setIsSendOpen(true)}
|
||||||
|
>
|
||||||
|
<SendIcon className="size-4 text-muted-foreground" />
|
||||||
|
Send funds
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
onSelect={() => setIsReceiveOpen(true)}
|
||||||
|
>
|
||||||
|
<WalletIcon className="size-4 text-muted-foreground" />
|
||||||
|
Receive funds
|
||||||
|
</DropdownMenuItem>
|
||||||
|
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
onSelect={() =>
|
||||||
|
router.push(
|
||||||
|
`/team/${props.teamSlug}/${props.project.slug}/transactions`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<ArrowLeftRightIcon className="size-4 text-muted-foreground" />
|
||||||
|
View transactions
|
||||||
|
</DropdownMenuItem>
|
||||||
|
|
||||||
|
{canChangeWallet && (
|
||||||
|
<DropdownMenuItem
|
||||||
|
className="flex items-center gap-2"
|
||||||
|
onSelect={() => setIsChangeWalletOpen(true)}
|
||||||
|
>
|
||||||
|
<ShuffleIcon className="size-4 text-muted-foreground" />
|
||||||
|
Change project wallet
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
|
||||||
|
<div className="p-4 relative flex flex-col gap-5">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-foreground mb-1">Wallet Address</p>
|
||||||
|
<CopyTextButton
|
||||||
|
textToShow={projectWallet.address}
|
||||||
|
textToCopy={projectWallet.address}
|
||||||
|
tooltip="Copy wallet address"
|
||||||
|
copyIconPosition="right"
|
||||||
|
variant="ghost"
|
||||||
|
className="text-muted-foreground -translate-x-1.5 py-0 h-auto"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-foreground mb-1">Wallet Label</p>
|
||||||
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<p className="text-sm break-all py-2 sm:py-0 text-muted-foreground">
|
||||||
|
{projectWallet.label || "N/A"}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-4 border-t border-dashed flex justify-between items-center">
|
||||||
|
<div>
|
||||||
|
<p className="text-sm text-foreground mb-1">Balance</p>
|
||||||
|
<div className="flex items-center gap-1">
|
||||||
|
{balanceQuery.isFetching || !balanceQuery.data ? (
|
||||||
|
<Skeleton className="h-5 w-[100px]" />
|
||||||
|
) : (
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{balanceQuery.data.displayValue} {balanceQuery.data.symbol}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
aria-label="Refresh balance"
|
||||||
|
className="p-1 h-auto w-auto"
|
||||||
|
disabled={balanceQuery.isFetching}
|
||||||
|
onClick={() => balanceQuery.refetch()}
|
||||||
|
variant="ghost"
|
||||||
|
>
|
||||||
|
<RefreshCcwIcon
|
||||||
|
className={cn(
|
||||||
|
"size-3 text-muted-foreground",
|
||||||
|
balanceQuery.isFetching && "animate-spin",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SingleNetworkSelector
|
||||||
|
chainId={selectedChainId}
|
||||||
|
className="w-fit rounded-full bg-background hover:bg-accent/50"
|
||||||
|
client={props.client}
|
||||||
|
disableDeprecated
|
||||||
|
disableChainId
|
||||||
|
onChange={setSelectedChainId}
|
||||||
|
placeholder="Select network"
|
||||||
|
popoverContentClassName="!w-[320px] rounded-xl overflow-hidden"
|
||||||
|
align="end"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<SendProjectWalletModal
|
||||||
|
chainId={selectedChainId}
|
||||||
|
client={props.client}
|
||||||
|
isManagedVault={isManagedVault}
|
||||||
|
label={projectWallet.label || ""}
|
||||||
|
onClose={() => setIsSendOpen(false)}
|
||||||
|
onSuccess={() => balanceQuery.refetch()}
|
||||||
|
open={isSendOpen}
|
||||||
|
publishableKey={project.publishableKey}
|
||||||
|
teamId={project.teamId}
|
||||||
|
walletAddress={projectWallet.address}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FundWalletModal
|
||||||
|
checkoutWidgetTitle="Fund Project Wallet"
|
||||||
|
client={props.client}
|
||||||
|
defaultChainId={selectedChainId}
|
||||||
|
description="Use your card or crypto to deposit into this server wallet"
|
||||||
|
onOpenChange={setIsReceiveOpen}
|
||||||
|
open={isReceiveOpen}
|
||||||
|
recipientAddress={projectWallet.address}
|
||||||
|
title="Fund project wallet"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Dialog onOpenChange={setIsChangeWalletOpen} open={isChangeWalletOpen}>
|
||||||
|
<DialogContent className="gap-0 p-0 overflow-hidden">
|
||||||
|
<ChangeProjectWalletDialogContent
|
||||||
|
isOpen={isChangeWalletOpen}
|
||||||
|
setIsOpen={setIsChangeWalletOpen}
|
||||||
|
serverWallets={{
|
||||||
|
data: serverWalletsQuery.data ?? [],
|
||||||
|
isPending: serverWalletsQuery.isLoading,
|
||||||
|
}}
|
||||||
|
projectWallet={projectWallet}
|
||||||
|
client={props.client}
|
||||||
|
project={project}
|
||||||
|
managementAccessToken={managementAccessToken}
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ChangeProjectWalletDialogContent(props: {
|
||||||
|
isOpen: boolean;
|
||||||
|
setIsOpen: (isOpen: boolean) => void;
|
||||||
|
serverWallets: {
|
||||||
|
data: ProjectWalletSummary[];
|
||||||
|
isPending: boolean;
|
||||||
|
};
|
||||||
|
projectWallet: ProjectWalletSummary;
|
||||||
|
managementAccessToken: string | undefined;
|
||||||
|
project: Project;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
}) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const router = useDashboardRouter();
|
||||||
|
|
||||||
|
const [selectedWalletId, setSelectedWalletId] = useState<string | undefined>(
|
||||||
|
props.projectWallet.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
const serverWallets = props.serverWallets.data;
|
||||||
|
|
||||||
|
const currentWalletAddressLower = props.projectWallet.address.toLowerCase();
|
||||||
|
|
||||||
|
const selectedWallet = useMemo(() => {
|
||||||
|
if (!selectedWalletId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverWallets.find((wallet) => wallet.id === selectedWalletId);
|
||||||
|
}, [selectedWalletId, serverWallets]);
|
||||||
|
|
||||||
|
const isSelectionDifferent = Boolean(
|
||||||
|
selectedWallet &&
|
||||||
|
selectedWallet.address.toLowerCase() !== currentWalletAddressLower,
|
||||||
|
);
|
||||||
|
|
||||||
|
const changeWalletMutation = useMutation({
|
||||||
|
mutationFn: async (wallet: ProjectWalletSummary) => {
|
||||||
|
await updateDefaultProjectWallet({
|
||||||
|
project: props.project,
|
||||||
|
projectWalletAddress: wallet.address,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
const message =
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Failed to update project wallet";
|
||||||
|
toast.error(message);
|
||||||
|
},
|
||||||
|
onSuccess: async () => {
|
||||||
|
toast.success("Project wallet updated");
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: [
|
||||||
|
"project",
|
||||||
|
props.project.id,
|
||||||
|
"server-wallets",
|
||||||
|
props.managementAccessToken,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
router.refresh();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<DialogHeader className="p-4 lg:p-6">
|
||||||
|
<DialogTitle>Change Project Wallet</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Choose a server wallet to use as project wallet
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="px-4 pb-8 lg:px-6">
|
||||||
|
{props.serverWallets.isPending ? (
|
||||||
|
<div className="flex justify-center py-6">
|
||||||
|
<Spinner className="size-5" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<Select
|
||||||
|
onValueChange={(value) => {
|
||||||
|
setSelectedWalletId(value);
|
||||||
|
}}
|
||||||
|
value={selectedWalletId ?? ""}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue placeholder="Select server wallet">
|
||||||
|
{selectedWallet ? (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<WalletAddress
|
||||||
|
address={selectedWallet.address}
|
||||||
|
client={props.client}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-sm text-foreground">
|
||||||
|
{selectedWallet.label ?? "Unnamed server wallet"}
|
||||||
|
</span>
|
||||||
|
{selectedWallet.address.toLowerCase() ===
|
||||||
|
currentWalletAddressLower && (
|
||||||
|
<Badge variant="success" className="text-xs">
|
||||||
|
current
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
"Select server wallet"
|
||||||
|
)}
|
||||||
|
</SelectValue>
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{serverWallets.map((wallet) => {
|
||||||
|
const isCurrent =
|
||||||
|
wallet.address.toLowerCase() === currentWalletAddressLower;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SelectItem key={wallet.id} value={wallet.id}>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<WalletAddress
|
||||||
|
address={wallet.address}
|
||||||
|
client={props.client}
|
||||||
|
/>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-sm text-foreground">
|
||||||
|
{wallet.label ?? "Unnamed server wallet"}
|
||||||
|
</span>
|
||||||
|
{isCurrent && (
|
||||||
|
<Badge variant="success" className="text-xs">
|
||||||
|
current
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-3 border-t bg-card p-4 lg:p-6">
|
||||||
|
<Button
|
||||||
|
onClick={() => props.setIsOpen(false)}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={changeWalletMutation.isPending}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={
|
||||||
|
!selectedWallet ||
|
||||||
|
!isSelectionDifferent ||
|
||||||
|
changeWalletMutation.isPending
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
if (selectedWallet) {
|
||||||
|
changeWalletMutation.mutate(selectedWallet);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{changeWalletMutation.isPending && (
|
||||||
|
<Spinner className="mr-2 size-4" />
|
||||||
|
)}
|
||||||
|
Set as project wallet
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const createSendFormSchema = (secretKeyLabel: string) =>
|
||||||
|
z.object({
|
||||||
|
chainId: z.number({
|
||||||
|
required_error: "Select a network",
|
||||||
|
}),
|
||||||
|
toAddress: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1, "Destination address is required")
|
||||||
|
.refine((value) => Boolean(isAddress(value)), {
|
||||||
|
message: "Enter a valid wallet address",
|
||||||
|
}),
|
||||||
|
amount: z.string().trim().min(1, "Amount is required"),
|
||||||
|
secretKey: z.string().trim().min(1, `${secretKeyLabel} is required`),
|
||||||
|
vaultAccessToken: z.string().trim(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const SECRET_KEY_LABEL = "Project secret key";
|
||||||
|
|
||||||
|
type SendFormValues = z.infer<ReturnType<typeof createSendFormSchema>>;
|
||||||
|
|
||||||
|
type SendProjectWalletModalProps = {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
onSuccess: () => void;
|
||||||
|
walletAddress: string;
|
||||||
|
publishableKey: string;
|
||||||
|
teamId: string;
|
||||||
|
chainId: number;
|
||||||
|
label: string;
|
||||||
|
client: ReturnType<typeof getClientThirdwebClient>;
|
||||||
|
isManagedVault: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const secretKeyLabel = SECRET_KEY_LABEL;
|
||||||
|
const secretKeyPlaceholder = "Enter your project secret key";
|
||||||
|
const secretKeyHelper =
|
||||||
|
"Your project secret key was generated when you created your project. If you lost it, regenerate one from Project settings.";
|
||||||
|
const vaultAccessTokenHelper =
|
||||||
|
"Vault access tokens are optional credentials with server wallet permissions. Manage them in Vault settings.";
|
||||||
|
|
||||||
|
function SendProjectWalletModal(props: SendProjectWalletModalProps) {
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
onOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen) {
|
||||||
|
props.onClose();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
open={props.open}
|
||||||
|
>
|
||||||
|
<DialogContent className="gap-0 p-0 overflow-hidden">
|
||||||
|
<SendProjectWalletModalContent {...props} />
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SendProjectWalletModalContent(props: SendProjectWalletModalProps) {
|
||||||
|
const {
|
||||||
|
onClose,
|
||||||
|
onSuccess,
|
||||||
|
walletAddress,
|
||||||
|
publishableKey,
|
||||||
|
teamId,
|
||||||
|
chainId,
|
||||||
|
label,
|
||||||
|
client,
|
||||||
|
isManagedVault,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const formSchema = useMemo(() => createSendFormSchema(SECRET_KEY_LABEL), []);
|
||||||
|
|
||||||
|
const form = useForm<SendFormValues>({
|
||||||
|
defaultValues: {
|
||||||
|
amount: "0",
|
||||||
|
chainId,
|
||||||
|
secretKey: "",
|
||||||
|
vaultAccessToken: "",
|
||||||
|
toAddress: "",
|
||||||
|
},
|
||||||
|
mode: "onChange",
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedChain = useV5DashboardChain(form.watch("chainId"));
|
||||||
|
|
||||||
|
const sendMutation = useMutation({
|
||||||
|
mutationFn: async (values: SendFormValues) => {
|
||||||
|
const quantityWei = toWei(values.amount).toString();
|
||||||
|
const secretKeyValue = values.secretKey.trim();
|
||||||
|
const vaultAccessTokenValue = values.vaultAccessToken.trim();
|
||||||
|
|
||||||
|
const result = await sendProjectWalletTokens({
|
||||||
|
chainId: values.chainId,
|
||||||
|
publishableKey,
|
||||||
|
quantityWei,
|
||||||
|
recipientAddress: values.toAddress,
|
||||||
|
teamId,
|
||||||
|
walletAddress,
|
||||||
|
secretKey: secretKeyValue,
|
||||||
|
...(vaultAccessTokenValue
|
||||||
|
? { vaultAccessToken: vaultAccessTokenValue }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result.ok) {
|
||||||
|
const errorMessage =
|
||||||
|
typeof result.error === "string"
|
||||||
|
? result.error
|
||||||
|
: "Failed to send funds";
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.transactionIds;
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast.error(error.message);
|
||||||
|
},
|
||||||
|
onSuccess: (transactionIds) => {
|
||||||
|
toast.success("Transfer submitted", {
|
||||||
|
description:
|
||||||
|
transactionIds && transactionIds.length > 0
|
||||||
|
? `Transaction ID: ${transactionIds[0]}`
|
||||||
|
: undefined,
|
||||||
|
});
|
||||||
|
onSuccess();
|
||||||
|
onClose();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="gap-0 p-0">
|
||||||
|
<DialogHeader className="p-4 lg:p-6">
|
||||||
|
<DialogTitle>Send from {label}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Execute a one-off transfer using your server wallet.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<Form {...form}>
|
||||||
|
<form
|
||||||
|
onSubmit={form.handleSubmit((values) => {
|
||||||
|
void sendMutation.mutateAsync(values);
|
||||||
|
})}
|
||||||
|
>
|
||||||
|
<div className="space-y-4 px-4 pb-8 lg:px-6">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="chainId"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Network</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SingleNetworkSelector
|
||||||
|
chainId={field.value}
|
||||||
|
className="bg-card"
|
||||||
|
client={client}
|
||||||
|
disableDeprecated
|
||||||
|
onChange={(nextChainId) => {
|
||||||
|
field.onChange(nextChainId);
|
||||||
|
}}
|
||||||
|
placeholder="Select network"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="toAddress"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Send to</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input autoComplete="off" placeholder="0x..." {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="amount"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Amount</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input inputMode="decimal" min="0" step="any" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Sending native token
|
||||||
|
{selectedChain?.nativeCurrency?.symbol
|
||||||
|
? ` (${selectedChain.nativeCurrency.symbol})`
|
||||||
|
: ""}
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="secretKey"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{secretKeyLabel}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
placeholder={secretKeyPlaceholder}
|
||||||
|
spellCheck={false}
|
||||||
|
type="password"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>{secretKeyHelper}</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!isManagedVault && (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="vaultAccessToken"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>
|
||||||
|
Vault access token
|
||||||
|
<span className="text-muted-foreground"> (optional)</span>
|
||||||
|
</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
autoComplete="off"
|
||||||
|
autoCorrect="off"
|
||||||
|
placeholder="Enter a vault access token (optional)"
|
||||||
|
spellCheck={false}
|
||||||
|
type="password"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>{vaultAccessTokenHelper}</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-3 border-t bg-card p-4 lg:p-6">
|
||||||
|
<Button onClick={onClose} type="button" variant="outline">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="gap-2"
|
||||||
|
disabled={!form.formState.isValid || sendMutation.isPending}
|
||||||
|
type="submit"
|
||||||
|
>
|
||||||
|
{sendMutation.isPending && <Spinner className="size-4" />}
|
||||||
|
Submit transfer
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+126
@@ -0,0 +1,126 @@
|
|||||||
|
import type { Meta, StoryObj } from "@storybook/nextjs";
|
||||||
|
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
|
||||||
|
import { projectStub } from "@/storybook/stubs";
|
||||||
|
import { storybookThirdwebClient } from "@/storybook/utils";
|
||||||
|
import { ProjectWalletSectionUI } from "./project-wallet";
|
||||||
|
|
||||||
|
const meta = {
|
||||||
|
component: ProjectWalletSectionUI,
|
||||||
|
title: "Project/ProjectWalletSection",
|
||||||
|
parameters: {
|
||||||
|
nextjs: {
|
||||||
|
appDirectory: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
decorators: [
|
||||||
|
(Story) => (
|
||||||
|
<div className="container py-8 pb-20 max-w-7xl">
|
||||||
|
<Story />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
],
|
||||||
|
} satisfies Meta<typeof ProjectWalletSectionUI>;
|
||||||
|
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof meta>;
|
||||||
|
|
||||||
|
const projectWithManagedAccessToken = projectStub("foo", "bar");
|
||||||
|
projectWithManagedAccessToken.services = [
|
||||||
|
{
|
||||||
|
name: "engineCloud",
|
||||||
|
actions: [],
|
||||||
|
managementAccessToken: "managed-access-token",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const projectWithoutManagedAccessToken = projectStub("foo", "bar");
|
||||||
|
|
||||||
|
const projectWallet1: ProjectWalletSummary = {
|
||||||
|
id: "server-wallet-id",
|
||||||
|
address: "0x1F846F6DAE38E1C88D71EAA191760B15f38B7A37",
|
||||||
|
label: "Project Wallet 1",
|
||||||
|
};
|
||||||
|
|
||||||
|
const projectWallet2: ProjectWalletSummary = {
|
||||||
|
id: "server-wallet-id-2",
|
||||||
|
address: "0x83Dd93fA5D8343094f850f90B3fb90088C1bB425",
|
||||||
|
label: "Project Wallet 2",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NoProjectWalletSetNoManagedAccessToken: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithoutManagedAccessToken,
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
teamSlug: "bar",
|
||||||
|
projectWallet: undefined,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NoProjectWalletSetWithManagedAccessToken: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithManagedAccessToken,
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
teamSlug: "bar",
|
||||||
|
projectWallet: undefined,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
return [];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NoProjectWalletSetWithManagedAccessTokenAndServerWallets: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithManagedAccessToken,
|
||||||
|
teamSlug: "bar",
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
projectWallet: undefined,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
return [projectWallet1, projectWallet2];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const NoProjectWalletSetLoading: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithManagedAccessToken,
|
||||||
|
teamSlug: "bar",
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
projectWallet: undefined,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100000));
|
||||||
|
return [projectWallet1, projectWallet2];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ProjectWalletSetMultipleServerWallets: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithManagedAccessToken,
|
||||||
|
teamSlug: "bar",
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
projectWallet: projectWallet1,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
return [projectWallet1, projectWallet2];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ProjectWalletSetSingleServerWallet: Story = {
|
||||||
|
args: {
|
||||||
|
project: projectWithManagedAccessToken,
|
||||||
|
teamSlug: "bar",
|
||||||
|
projectWallet: projectWallet1,
|
||||||
|
client: storybookThirdwebClient,
|
||||||
|
getProjectServerWallets: async () => {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
return [projectWallet1];
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
+331
@@ -0,0 +1,331 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { UnderlineLink } from "@workspace/ui/components/UnderlineLink";
|
||||||
|
import { ChevronDownIcon, XIcon } from "lucide-react";
|
||||||
|
import { useMemo, useState } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import type { ThirdwebClient } from "thirdweb";
|
||||||
|
import { listProjectServerWallets } from "@/actions/project-wallet/list-server-wallets";
|
||||||
|
import type { Project } from "@/api/project/projects";
|
||||||
|
import { WalletAddress } from "@/components/blocks/wallet-address";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from "@/components/ui/dialog";
|
||||||
|
import { Spinner } from "@/components/ui/Spinner";
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
||||||
|
import type { ProjectWalletSummary } from "@/lib/server/project-wallet";
|
||||||
|
import { updateDefaultProjectWallet } from "../../transactions/lib/vault.client";
|
||||||
|
import { CreateServerWallet } from "../../transactions/server-wallets/components/create-server-wallet.client";
|
||||||
|
import { ProjectWalletDetailsSection } from "./project-wallet-details";
|
||||||
|
|
||||||
|
type GetProjectServerWallets = (params: {
|
||||||
|
managementAccessToken: string;
|
||||||
|
projectId: string;
|
||||||
|
}) => Promise<ProjectWalletSummary[]>;
|
||||||
|
|
||||||
|
function CreateProjectWalletSection(props: {
|
||||||
|
project: Project;
|
||||||
|
teamSlug: string;
|
||||||
|
getProjectServerWallets: GetProjectServerWallets;
|
||||||
|
}) {
|
||||||
|
const { project, teamSlug } = props;
|
||||||
|
const router = useDashboardRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const client = useMemo(() => getClientThirdwebClient(), []);
|
||||||
|
const [selectedWalletId, setSelectedWalletId] = useState<string | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
const [isSelectDialogOpen, setIsSelectDialogOpen] = useState(false);
|
||||||
|
|
||||||
|
const managementAccessToken =
|
||||||
|
props.project.services?.find((service) => service.name === "engineCloud")
|
||||||
|
?.managementAccessToken ?? undefined;
|
||||||
|
|
||||||
|
const serverWalletsQuery = useQuery({
|
||||||
|
enabled: Boolean(managementAccessToken),
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!managementAccessToken) {
|
||||||
|
return [] as ProjectWalletSummary[];
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.getProjectServerWallets({
|
||||||
|
managementAccessToken,
|
||||||
|
projectId: project.id,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
queryKey: ["project", project.id, "server-wallets", managementAccessToken],
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const serverWallets = serverWalletsQuery.data ?? [];
|
||||||
|
|
||||||
|
const effectiveSelectedWalletId = useMemo(() => {
|
||||||
|
if (
|
||||||
|
selectedWalletId &&
|
||||||
|
serverWallets.some((wallet) => wallet.id === selectedWalletId)
|
||||||
|
) {
|
||||||
|
return selectedWalletId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverWallets[0]?.id;
|
||||||
|
}, [selectedWalletId, serverWallets]);
|
||||||
|
|
||||||
|
const selectedWallet = useMemo(() => {
|
||||||
|
if (!effectiveSelectedWalletId) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serverWallets.find(
|
||||||
|
(wallet) => wallet.id === effectiveSelectedWalletId,
|
||||||
|
);
|
||||||
|
}, [effectiveSelectedWalletId, serverWallets]);
|
||||||
|
|
||||||
|
const setDefaultWalletMutation = useMutation({
|
||||||
|
mutationFn: async (wallet: ProjectWalletSummary) => {
|
||||||
|
await updateDefaultProjectWallet({
|
||||||
|
project,
|
||||||
|
projectWalletAddress: wallet.address,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
const message =
|
||||||
|
error instanceof Error
|
||||||
|
? error.message
|
||||||
|
: "Failed to update project wallet";
|
||||||
|
toast.error(message);
|
||||||
|
},
|
||||||
|
onSuccess: async (_, wallet) => {
|
||||||
|
const descriptionLabel = wallet.label ?? wallet.address;
|
||||||
|
toast.success("Project wallet updated", {
|
||||||
|
description: `Now pointing to ${descriptionLabel}`,
|
||||||
|
});
|
||||||
|
await queryClient.invalidateQueries({
|
||||||
|
queryKey: [
|
||||||
|
"project",
|
||||||
|
project.id,
|
||||||
|
"server-wallets",
|
||||||
|
managementAccessToken,
|
||||||
|
],
|
||||||
|
});
|
||||||
|
setIsSelectDialogOpen(false);
|
||||||
|
router.refresh();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const canSelectExisting =
|
||||||
|
Boolean(managementAccessToken) && serverWallets.length > 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-xl border p-4 bg-card">
|
||||||
|
<div className="rounded-full p-2 border bg-background inline-flex mb-4">
|
||||||
|
<XIcon className="size-3.5 text-muted-foreground" />
|
||||||
|
</div>
|
||||||
|
<h2 className="text-sm font-medium text-foreground mb-0.5">
|
||||||
|
No Project Wallet set
|
||||||
|
</h2>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Set a project wallet to set the default sender in thirdweb API.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="mt-4 space-y-5 text-foreground">
|
||||||
|
{serverWalletsQuery.isLoading ? (
|
||||||
|
<Skeleton className="h-[36px] max-w-lg rounded-full" />
|
||||||
|
) : canSelectExisting ? (
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Button
|
||||||
|
className="bg-background rounded-full gap-2"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedWalletId(effectiveSelectedWalletId);
|
||||||
|
setIsSelectDialogOpen(true);
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
<ChevronDownIcon className="size-4 text-muted-foreground" />
|
||||||
|
Select a server wallet
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<CreateServerWallet
|
||||||
|
project={project}
|
||||||
|
teamSlug={teamSlug}
|
||||||
|
setAsProjectWallet
|
||||||
|
button={{ size: "sm", iconClassName: "size-3.5" }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Dialog
|
||||||
|
onOpenChange={(nextOpen) => {
|
||||||
|
if (!nextOpen) {
|
||||||
|
setIsSelectDialogOpen(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
open={isSelectDialogOpen}
|
||||||
|
>
|
||||||
|
<DialogContent className="gap-0 p-0 overflow-hidden">
|
||||||
|
<DialogHeader className="p-4 lg:p-6">
|
||||||
|
<DialogTitle>Select project wallet</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Choose a server wallet to use as the default for this
|
||||||
|
project.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<div className="px-4 pb-8 lg:px-6">
|
||||||
|
{serverWalletsQuery.isLoading ? (
|
||||||
|
<div className="flex justify-center py-6">
|
||||||
|
<Spinner className="size-5" />
|
||||||
|
</div>
|
||||||
|
) : serverWallets.length === 0 ? (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
No server wallets found.
|
||||||
|
</p>
|
||||||
|
) : (
|
||||||
|
<div className="flex flex-col gap-3">
|
||||||
|
<Select
|
||||||
|
onValueChange={(value) => setSelectedWalletId(value)}
|
||||||
|
value={selectedWalletId ?? ""}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-full">
|
||||||
|
<SelectValue placeholder="Select server wallet" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{serverWallets.map((wallet) => (
|
||||||
|
<SelectItem key={wallet.id} value={wallet.id}>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<WalletAddress
|
||||||
|
address={wallet.address}
|
||||||
|
client={client}
|
||||||
|
className="h-auto py-1"
|
||||||
|
/>
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{wallet.label}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex justify-end gap-3 border-t bg-card p-4 lg:p-6">
|
||||||
|
<Button
|
||||||
|
onClick={() => {
|
||||||
|
setIsSelectDialogOpen(false);
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={setDefaultWalletMutation.isPending}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
disabled={
|
||||||
|
!selectedWallet || setDefaultWalletMutation.isPending
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
if (selectedWallet) {
|
||||||
|
setDefaultWalletMutation.mutate(selectedWallet);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{setDefaultWalletMutation.isPending && (
|
||||||
|
<Spinner className="mr-2 size-4" />
|
||||||
|
)}
|
||||||
|
Set as project wallet
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-3 text-sm text-muted-foreground">
|
||||||
|
<CreateServerWallet
|
||||||
|
project={project}
|
||||||
|
teamSlug={teamSlug}
|
||||||
|
setAsProjectWallet
|
||||||
|
button={{ size: "sm", iconClassName: "size-3.5" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProjectWalletSectionUI(props: {
|
||||||
|
project: Project;
|
||||||
|
teamSlug: string;
|
||||||
|
projectWallet: ProjectWalletSummary | undefined;
|
||||||
|
getProjectServerWallets: GetProjectServerWallets;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className="mb-3">
|
||||||
|
<h2 className="mb-1 font-semibold text-xl tracking-tight">
|
||||||
|
Project Wallet
|
||||||
|
</h2>
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
The server wallet to be used as the default sender in{" "}
|
||||||
|
<UnderlineLink
|
||||||
|
href="https://portal.thirdweb.com/reference"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
thirdweb API
|
||||||
|
</UnderlineLink>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{props.projectWallet ? (
|
||||||
|
<ProjectWalletDetailsSection
|
||||||
|
project={props.project}
|
||||||
|
projectWallet={props.projectWallet}
|
||||||
|
client={props.client}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
getProjectServerWallets={props.getProjectServerWallets}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CreateProjectWalletSection
|
||||||
|
project={props.project}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
getProjectServerWallets={props.getProjectServerWallets}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ProjectWalletSection(props: {
|
||||||
|
project: Project;
|
||||||
|
teamSlug: string;
|
||||||
|
projectWallet: ProjectWalletSummary | undefined;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<ProjectWalletSectionUI
|
||||||
|
project={props.project}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
client={props.client}
|
||||||
|
projectWallet={props.projectWallet}
|
||||||
|
getProjectServerWallets={listProjectServerWallets}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
-1
@@ -59,7 +59,6 @@ export function ErrorRate({ datapoints }: { datapoints: ResultItem[] }) {
|
|||||||
key={tag}
|
key={tag}
|
||||||
stackId="a"
|
stackId="a"
|
||||||
stroke={`var(--color-${tag})`}
|
stroke={`var(--color-${tag})`}
|
||||||
type="natural"
|
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+8
@@ -14,6 +14,7 @@ type AggregatedMetrics = {
|
|||||||
|
|
||||||
export function ProjectHighlightsCard(props: {
|
export function ProjectHighlightsCard(props: {
|
||||||
selectedChart: string | undefined;
|
selectedChart: string | undefined;
|
||||||
|
aggregatedUserStats: InAppWalletStats[];
|
||||||
userStats: InAppWalletStats[];
|
userStats: InAppWalletStats[];
|
||||||
volumeStats: UniversalBridgeStats[];
|
volumeStats: UniversalBridgeStats[];
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
@@ -22,6 +23,7 @@ export function ProjectHighlightsCard(props: {
|
|||||||
}) {
|
}) {
|
||||||
const {
|
const {
|
||||||
selectedChart,
|
selectedChart,
|
||||||
|
aggregatedUserStats,
|
||||||
userStats,
|
userStats,
|
||||||
volumeStats,
|
volumeStats,
|
||||||
teamSlug,
|
teamSlug,
|
||||||
@@ -70,6 +72,12 @@ export function ProjectHighlightsCard(props: {
|
|||||||
: "activeUsers"
|
: "activeUsers"
|
||||||
}
|
}
|
||||||
aggregateFn={(_data, key) => {
|
aggregateFn={(_data, key) => {
|
||||||
|
if (key === "activeUsers") {
|
||||||
|
return aggregatedUserStats.reduce(
|
||||||
|
(acc, curr) => acc + curr.uniqueWalletsConnected,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
}
|
||||||
return timeSeriesData.reduce((acc, curr) => acc + curr[key], 0);
|
return timeSeriesData.reduce((acc, curr) => acc + curr[key], 0);
|
||||||
}}
|
}}
|
||||||
chartConfig={chartConfig}
|
chartConfig={chartConfig}
|
||||||
|
|||||||
@@ -39,10 +39,8 @@ import type {
|
|||||||
import { loginRedirect } from "@/utils/redirects";
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
import { PieChartCard } from "../../../components/Analytics/PieChartCard";
|
import { PieChartCard } from "../../../components/Analytics/PieChartCard";
|
||||||
import { EngineCloudChartCardAsync } from "./components/EngineCloudChartCard";
|
import { EngineCloudChartCardAsync } from "./components/EngineCloudChartCard";
|
||||||
import {
|
import { ProjectFTUX } from "./components/ProjectFTUX/ProjectFTUX";
|
||||||
ProjectFTUX,
|
import { ProjectWalletSection } from "./components/project-wallet/project-wallet";
|
||||||
ProjectWalletSection,
|
|
||||||
} from "./components/ProjectFTUX/ProjectFTUX";
|
|
||||||
import { RpcMethodBarChartCardAsync } from "./components/RpcMethodBarChartCard";
|
import { RpcMethodBarChartCardAsync } from "./components/RpcMethodBarChartCard";
|
||||||
import { TransactionsChartCardAsync } from "./components/Transactions";
|
import { TransactionsChartCardAsync } from "./components/Transactions";
|
||||||
import { ProjectHighlightsCard } from "./overview/highlights-card";
|
import { ProjectHighlightsCard } from "./overview/highlights-card";
|
||||||
@@ -112,9 +110,6 @@ export default async function ProjectOverviewPage(props: PageProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const projectWallet = await getProjectWallet(project);
|
const projectWallet = await getProjectWallet(project);
|
||||||
const managementAccessToken =
|
|
||||||
project.services?.find((service) => service.name === "engineCloud")
|
|
||||||
?.managementAccessToken ?? undefined;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ResponsiveSearchParamsProvider value={searchParams}>
|
<ResponsiveSearchParamsProvider value={searchParams}>
|
||||||
@@ -135,14 +130,17 @@ export default async function ProjectOverviewPage(props: PageProps) {
|
|||||||
actions: null,
|
actions: null,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<ProjectWalletSection
|
||||||
|
project={project}
|
||||||
|
teamSlug={params.team_slug}
|
||||||
|
projectWallet={projectWallet}
|
||||||
|
client={client}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="h-10" />
|
||||||
|
|
||||||
{isActive ? (
|
{isActive ? (
|
||||||
<div className="flex flex-col gap-4 md:gap-6">
|
<div className="flex flex-col gap-4 md:gap-6">
|
||||||
<ProjectWalletSection
|
|
||||||
project={project}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
wallet={projectWallet}
|
|
||||||
managementAccessToken={managementAccessToken}
|
|
||||||
/>
|
|
||||||
<ResponsiveTimeFilters defaultRange={defaultRange} />
|
<ResponsiveTimeFilters defaultRange={defaultRange} />
|
||||||
<ProjectAnalytics
|
<ProjectAnalytics
|
||||||
authToken={authToken}
|
authToken={authToken}
|
||||||
@@ -155,12 +153,7 @@ export default async function ProjectOverviewPage(props: PageProps) {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<ProjectFTUX
|
<ProjectFTUX project={project} teamSlug={params.team_slug} />
|
||||||
project={project}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
wallet={projectWallet}
|
|
||||||
managementAccessToken={managementAccessToken}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</ProjectPage>
|
</ProjectPage>
|
||||||
</ResponsiveSearchParamsProvider>
|
</ResponsiveSearchParamsProvider>
|
||||||
@@ -385,8 +378,18 @@ async function AsyncAppHighlightsCard(props: {
|
|||||||
params: PageParams;
|
params: PageParams;
|
||||||
authToken: string;
|
authToken: string;
|
||||||
}) {
|
}) {
|
||||||
const [walletUserStatsTimeSeries, universalBridgeUsage] =
|
const [aggregatedUserStats, walletUserStatsTimeSeries, universalBridgeUsage] =
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
|
getInAppWalletUsage(
|
||||||
|
{
|
||||||
|
from: props.range.from,
|
||||||
|
period: "all",
|
||||||
|
projectId: props.project.id,
|
||||||
|
teamId: props.project.teamId,
|
||||||
|
to: props.range.to,
|
||||||
|
},
|
||||||
|
props.authToken,
|
||||||
|
),
|
||||||
getInAppWalletUsage(
|
getInAppWalletUsage(
|
||||||
{
|
{
|
||||||
from: props.range.from,
|
from: props.range.from,
|
||||||
@@ -415,6 +418,11 @@ async function AsyncAppHighlightsCard(props: {
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<ProjectHighlightsCard
|
<ProjectHighlightsCard
|
||||||
|
aggregatedUserStats={
|
||||||
|
aggregatedUserStats.status === "fulfilled"
|
||||||
|
? aggregatedUserStats.value
|
||||||
|
: []
|
||||||
|
}
|
||||||
selectedChart={props.selectedChart}
|
selectedChart={props.selectedChart}
|
||||||
selectedChartQueryParam={props.selectedChartQueryParam}
|
selectedChartQueryParam={props.selectedChartQueryParam}
|
||||||
teamSlug={props.params.team_slug}
|
teamSlug={props.params.team_slug}
|
||||||
|
|||||||
+9
-9
@@ -81,7 +81,7 @@ export default async function Page(props: {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "playground",
|
type: "playground",
|
||||||
href: "https://playground.thirdweb.com/payments/ui-components",
|
href: "https://playground.thirdweb.com/bridge",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "api",
|
type: "api",
|
||||||
@@ -93,20 +93,20 @@ export default async function Page(props: {
|
|||||||
center: {
|
center: {
|
||||||
links: [
|
links: [
|
||||||
{
|
{
|
||||||
href: "https://playground.thirdweb.com/payments/ui-components",
|
href: "https://playground.thirdweb.com/bridge/buy-widget",
|
||||||
label: "UI Component",
|
label: "Buy Widget",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "https://playground.thirdweb.com/connect/payments/fund-wallet",
|
href: "https://playground.thirdweb.com/bridge/checkout-widget",
|
||||||
label: "Buy Crypto",
|
label: "Checkout Widget",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "https://playground.thirdweb.com/connect/payments/commerce",
|
href: "https://playground.thirdweb.com/bridge/transaction-widget",
|
||||||
label: "Checkout",
|
label: "Transaction Widget",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
href: "https://playground.thirdweb.com/connect/payments/transactions",
|
href: "https://playground.thirdweb.com/bridge/swap-widget",
|
||||||
label: "Transactions",
|
label: "Swap Widget",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
title: "Demos",
|
title: "Demos",
|
||||||
|
|||||||
+43
-22
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { UnderlineLink } from "@workspace/ui/components/UnderlineLink";
|
||||||
import { formatDistanceToNow } from "date-fns";
|
import { formatDistanceToNow } from "date-fns";
|
||||||
import {
|
import {
|
||||||
DotIcon,
|
DotIcon,
|
||||||
|
InfoIcon,
|
||||||
MoreVerticalIcon,
|
MoreVerticalIcon,
|
||||||
PencilIcon,
|
PencilIcon,
|
||||||
PlusIcon,
|
PlusIcon,
|
||||||
@@ -25,6 +27,7 @@ import {
|
|||||||
updateWebhook,
|
updateWebhook,
|
||||||
} from "@/api/universal-bridge/developer";
|
} from "@/api/universal-bridge/developer";
|
||||||
import { GenericLoadingPage } from "@/components/blocks/skeletons/GenericLoadingPage";
|
import { GenericLoadingPage } from "@/components/blocks/skeletons/GenericLoadingPage";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { CopyTextButton } from "@/components/ui/CopyTextButton";
|
import { CopyTextButton } from "@/components/ui/CopyTextButton";
|
||||||
import { Checkbox, CheckboxWithLabel } from "@/components/ui/checkbox";
|
import { Checkbox, CheckboxWithLabel } from "@/components/ui/checkbox";
|
||||||
@@ -435,28 +438,30 @@ function BridgeWebhookModalContent(
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FormField
|
{props.type === "edit" && props.webhook.version === 1 && (
|
||||||
name="version"
|
<FormField
|
||||||
render={({ field }) => (
|
name="version"
|
||||||
<FormItem>
|
render={({ field }) => (
|
||||||
<FormLabel>Version</FormLabel>
|
<FormItem>
|
||||||
<Select {...field} onValueChange={field.onChange}>
|
<FormLabel>Version</FormLabel>
|
||||||
<SelectTrigger className="w-full">
|
<Select {...field} onValueChange={field.onChange}>
|
||||||
<SelectValue placeholder="v2" />
|
<SelectTrigger className="w-full">
|
||||||
</SelectTrigger>
|
<SelectValue placeholder="v2" />
|
||||||
<SelectContent>
|
</SelectTrigger>
|
||||||
<SelectItem value="2">v2</SelectItem>
|
<SelectContent>
|
||||||
<SelectItem value="1">v1</SelectItem>
|
<SelectItem value="2">v2</SelectItem>
|
||||||
</SelectContent>
|
<SelectItem value="1">v1</SelectItem>
|
||||||
</Select>
|
</SelectContent>
|
||||||
<FormDescription>
|
</Select>
|
||||||
Select the data format of the webhook payload (v2 recommended,
|
<FormDescription>
|
||||||
v1 for legacy users).
|
Select the data format of the webhook payload (v2 recommended,
|
||||||
</FormDescription>
|
v1 for legacy users).
|
||||||
<FormMessage />
|
</FormDescription>
|
||||||
</FormItem>
|
<FormMessage />
|
||||||
)}
|
</FormItem>
|
||||||
/>
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{props.type === "create" && (
|
{props.type === "create" && (
|
||||||
<section>
|
<section>
|
||||||
@@ -486,6 +491,22 @@ function BridgeWebhookModalContent(
|
|||||||
</section>
|
</section>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<Alert variant="warning">
|
||||||
|
<InfoIcon className="size-4" />
|
||||||
|
<AlertTitle> Verify payload before processing </AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
Make sure to verify receiver, destination chain, token address and
|
||||||
|
amount to ensure that it represents the expected state of the
|
||||||
|
transaction before processing it in your backend.{" "}
|
||||||
|
<UnderlineLink
|
||||||
|
href="https://portal.thirdweb.com/bridge/webhooks#verify-payload"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Learn more
|
||||||
|
</UnderlineLink>
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
className="gap-2"
|
className="gap-2"
|
||||||
|
|||||||
+2
-2
@@ -220,9 +220,9 @@ export function ProjectGeneralSettingsPageUI(props: {
|
|||||||
const projectLayout = `/team/${props.teamSlug}/${props.project.slug}`;
|
const projectLayout = `/team/${props.teamSlug}/${props.project.slug}`;
|
||||||
|
|
||||||
const paths = {
|
const paths = {
|
||||||
aaConfig: `${projectLayout}/settings/account-abstraction`,
|
aaConfig: `${projectLayout}/wallets/sponsored-gas/configuration`,
|
||||||
afterDeleteRedirectTo: `/team/${props.teamSlug}`,
|
afterDeleteRedirectTo: `/team/${props.teamSlug}`,
|
||||||
inAppConfig: `${projectLayout}/settings/wallets`,
|
inAppConfig: `${projectLayout}/wallets/user-wallets/configuration`,
|
||||||
payConfig: `${projectLayout}/settings/payments`,
|
payConfig: `${projectLayout}/settings/payments`,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
-95
@@ -1,95 +0,0 @@
|
|||||||
import { CircleAlertIcon } from "lucide-react";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import { getAuthToken } from "@/api/auth-token";
|
|
||||||
import { getProject } from "@/api/project/projects";
|
|
||||||
import { getTeamBySlug } from "@/api/team/get-team";
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
||||||
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { getValidTeamPlan } from "@/utils/getValidTeamPlan";
|
|
||||||
import { loginRedirect } from "@/utils/redirects";
|
|
||||||
import { DefaultFactoriesSection } from "../../account-abstraction/factories/AccountFactories";
|
|
||||||
import { YourFactoriesSection } from "../../account-abstraction/factories/AccountFactories/your-factories";
|
|
||||||
import { AccountAbstractionSettingsPage } from "../../account-abstraction/settings/SponsorshipPolicies";
|
|
||||||
import { ProjectSettingsBreadcrumb } from "../_components/project-settings-breadcrumb";
|
|
||||||
|
|
||||||
export default async function Page(props: {
|
|
||||||
params: Promise<{ team_slug: string; project_slug: string }>;
|
|
||||||
}) {
|
|
||||||
const { team_slug, project_slug } = await props.params;
|
|
||||||
|
|
||||||
const [team, project, authToken] = await Promise.all([
|
|
||||||
getTeamBySlug(team_slug),
|
|
||||||
getProject(team_slug, project_slug),
|
|
||||||
|
|
||||||
getAuthToken(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!authToken) {
|
|
||||||
loginRedirect(`/team/${team_slug}/settings/account-abstraction`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!team) {
|
|
||||||
redirect("/team");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!project) {
|
|
||||||
redirect(`/team/${team_slug}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = getClientThirdwebClient({
|
|
||||||
jwt: authToken,
|
|
||||||
teamId: team.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const bundlerService = project.services.find((s) => s.name === "bundler");
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<ProjectSettingsBreadcrumb
|
|
||||||
teamSlug={team_slug}
|
|
||||||
projectSlug={project_slug}
|
|
||||||
page="Account Abstraction"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div className="space-y-8 mt-6">
|
|
||||||
{!bundlerService ? (
|
|
||||||
<Alert variant="warning">
|
|
||||||
<CircleAlertIcon className="size-5" />
|
|
||||||
<AlertTitle>Account Abstraction service is disabled</AlertTitle>
|
|
||||||
<AlertDescription>
|
|
||||||
Enable Account Abstraction service in{" "}
|
|
||||||
<UnderlineLink
|
|
||||||
href={`/team/${team_slug}/${project_slug}/settings`}
|
|
||||||
>
|
|
||||||
project settings
|
|
||||||
</UnderlineLink>{" "}
|
|
||||||
to configure the sponsorship rules
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<AccountAbstractionSettingsPage
|
|
||||||
bundlerService={bundlerService}
|
|
||||||
client={client}
|
|
||||||
project={project}
|
|
||||||
teamId={team.id}
|
|
||||||
teamSlug={team.slug}
|
|
||||||
validTeamPlan={getValidTeamPlan(team)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DefaultFactoriesSection />
|
|
||||||
<YourFactoriesSection
|
|
||||||
authToken={authToken}
|
|
||||||
clientThirdwebClient={client}
|
|
||||||
projectId={project.id}
|
|
||||||
projectSlug={project.slug}
|
|
||||||
teamId={team.id}
|
|
||||||
teamSlug={team.slug}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
-51
@@ -1,6 +1,4 @@
|
|||||||
import "server-only";
|
import "server-only";
|
||||||
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "@/constants/public-envs";
|
|
||||||
import { API_SERVER_SECRET } from "@/constants/server-envs";
|
|
||||||
|
|
||||||
export type SMSCountryTiers = {
|
export type SMSCountryTiers = {
|
||||||
tier1: string[];
|
tier1: string[];
|
||||||
@@ -10,52 +8,3 @@ export type SMSCountryTiers = {
|
|||||||
tier5: string[];
|
tier5: string[];
|
||||||
tier6: string[];
|
tier6: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getSMSCountryTiers() {
|
|
||||||
if (!API_SERVER_SECRET) {
|
|
||||||
throw new Error("API_SERVER_SECRET is not set");
|
|
||||||
}
|
|
||||||
const res = await fetch(
|
|
||||||
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/sms/list-country-tiers`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-service-api-key": API_SERVER_SECRET,
|
|
||||||
},
|
|
||||||
next: {
|
|
||||||
revalidate: 15 * 60, //15 minutes
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!res.ok) {
|
|
||||||
console.error(
|
|
||||||
"Failed to fetch sms country tiers",
|
|
||||||
res.status,
|
|
||||||
res.statusText,
|
|
||||||
);
|
|
||||||
res.body?.cancel();
|
|
||||||
return {
|
|
||||||
tier1: [],
|
|
||||||
tier2: [],
|
|
||||||
tier3: [],
|
|
||||||
tier4: [],
|
|
||||||
tier5: [],
|
|
||||||
tier6: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return (await res.json()).data as SMSCountryTiers;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to parse sms country tiers", e);
|
|
||||||
return {
|
|
||||||
tier1: [],
|
|
||||||
tier2: [],
|
|
||||||
tier3: [],
|
|
||||||
tier4: [],
|
|
||||||
tier5: [],
|
|
||||||
tier6: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+3
-81
@@ -2,7 +2,7 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { useMutation } from "@tanstack/react-query";
|
import { useMutation } from "@tanstack/react-query";
|
||||||
import type { ProjectEmbeddedWalletsService } from "@thirdweb-dev/service-utils";
|
import type { ProjectEmbeddedWalletsService } from "@thirdweb-dev/service-utils";
|
||||||
import { CircleAlertIcon, PlusIcon, Trash2Icon } from "lucide-react";
|
import { PlusIcon, Trash2Icon } from "lucide-react";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { type UseFormReturn, useFieldArray, useForm } from "react-hook-form";
|
import { type UseFormReturn, useFieldArray, useForm } from "react-hook-form";
|
||||||
@@ -13,7 +13,6 @@ import type { Project } from "@/api/project/projects";
|
|||||||
import type { Team } from "@/api/team/get-team";
|
import type { Team } from "@/api/team/get-team";
|
||||||
import { FileInput } from "@/components/blocks/FileInput";
|
import { FileInput } from "@/components/blocks/FileInput";
|
||||||
import { GatedSwitch } from "@/components/blocks/GatedSwitch";
|
import { GatedSwitch } from "@/components/blocks/GatedSwitch";
|
||||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { DynamicHeight } from "@/components/ui/DynamicHeight";
|
import { DynamicHeight } from "@/components/ui/DynamicHeight";
|
||||||
import {
|
import {
|
||||||
@@ -31,7 +30,6 @@ import { Spinner } from "@/components/ui/Spinner";
|
|||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
||||||
import { planToTierRecordForGating } from "@/constants/planToTierRecord";
|
import { planToTierRecordForGating } from "@/constants/planToTierRecord";
|
||||||
import { updateProjectClient } from "@/hooks/useApi";
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import {
|
import {
|
||||||
type ApiKeyEmbeddedWalletsValidationSchema,
|
type ApiKeyEmbeddedWalletsValidationSchema,
|
||||||
@@ -57,82 +55,6 @@ type UpdateAPIKeyTrackingData = {
|
|||||||
hasCustomAuthEndpoint: boolean;
|
hasCustomAuthEndpoint: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function InAppWalletSettingsPage(props: InAppWalletSettingsPageProps) {
|
|
||||||
const updateProject = useMutation({
|
|
||||||
mutationFn: async (projectValues: Partial<Project>) => {
|
|
||||||
await updateProjectClient(
|
|
||||||
{
|
|
||||||
projectId: props.project.id,
|
|
||||||
teamId: props.teamId,
|
|
||||||
},
|
|
||||||
projectValues,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function handleUpdateProject(projectValues: Partial<Project>) {
|
|
||||||
updateProject.mutate(projectValues, {
|
|
||||||
onError: (err) => {
|
|
||||||
toast.error("Failed to update an API Key");
|
|
||||||
console.error(err);
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
toast.success("In-App Wallet API Key configuration updated");
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<InAppWalletSettingsPageUI
|
|
||||||
{...props}
|
|
||||||
isUpdating={updateProject.isPending}
|
|
||||||
smsCountryTiers={props.smsCountryTiers}
|
|
||||||
updateApiKey={handleUpdateProject}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const InAppWalletSettingsPageUI: React.FC<
|
|
||||||
InAppWalletSettingsPageProps & {
|
|
||||||
updateApiKey: (
|
|
||||||
projectValues: Partial<Project>,
|
|
||||||
trackingData: UpdateAPIKeyTrackingData,
|
|
||||||
) => void;
|
|
||||||
isUpdating: boolean;
|
|
||||||
smsCountryTiers: SMSCountryTiers;
|
|
||||||
}
|
|
||||||
> = (props) => {
|
|
||||||
const embeddedWalletService = props.project.services.find(
|
|
||||||
(service) => service.name === "embeddedWallets",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!embeddedWalletService) {
|
|
||||||
return (
|
|
||||||
<Alert variant="warning">
|
|
||||||
<CircleAlertIcon className="size-5" />
|
|
||||||
<AlertTitle>In-App wallets service is disabled</AlertTitle>
|
|
||||||
<AlertDescription>
|
|
||||||
Enable In-App wallets service in the{" "}
|
|
||||||
<UnderlineLink
|
|
||||||
href={`/team/${props.teamSlug}/${props.project.slug}/settings`}
|
|
||||||
>
|
|
||||||
project settings
|
|
||||||
</UnderlineLink>{" "}
|
|
||||||
to configure settings
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<InAppWalletSettingsUI
|
|
||||||
{...props}
|
|
||||||
client={props.client}
|
|
||||||
embeddedWalletService={embeddedWalletService}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const InAppWalletSettingsUI: React.FC<
|
export const InAppWalletSettingsUI: React.FC<
|
||||||
InAppWalletSettingsPageProps & {
|
InAppWalletSettingsPageProps & {
|
||||||
updateApiKey: (
|
updateApiKey: (
|
||||||
@@ -191,7 +113,7 @@ export const InAppWalletSettingsUI: React.FC<
|
|||||||
) {
|
) {
|
||||||
return toast.error("Custom JSON Web Token configuration is invalid", {
|
return toast.error("Custom JSON Web Token configuration is invalid", {
|
||||||
description:
|
description:
|
||||||
"To use In-App Wallets with Custom JSON Web Token, provide JWKS URI and AUD.",
|
"To use User Wallets with Custom JSON Web Token, provide JWKS URI and AUD.",
|
||||||
dismissible: true,
|
dismissible: true,
|
||||||
duration: 9000,
|
duration: 9000,
|
||||||
});
|
});
|
||||||
@@ -202,7 +124,7 @@ export const InAppWalletSettingsUI: React.FC<
|
|||||||
"Custom Authentication Endpoint configuration is invalid",
|
"Custom Authentication Endpoint configuration is invalid",
|
||||||
{
|
{
|
||||||
description:
|
description:
|
||||||
"To use In-App Wallets with Custom Authentication Endpoint, provide a valid URL.",
|
"To use User Wallets with Custom Authentication Endpoint, provide a valid URL.",
|
||||||
dismissible: true,
|
dismissible: true,
|
||||||
duration: 9000,
|
duration: 9000,
|
||||||
},
|
},
|
||||||
|
|||||||
+88
-31
@@ -1,45 +1,102 @@
|
|||||||
import { ResponsiveSearchParamsProvider } from "responsive-rsc";
|
"use client";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { Spinner } from "@workspace/ui/components/spinner";
|
||||||
|
import { useMemo } from "react";
|
||||||
import type { ThirdwebClient } from "thirdweb";
|
import type { ThirdwebClient } from "thirdweb";
|
||||||
import type { Project } from "@/api/project/projects";
|
import type { Project } from "@/api/project/projects";
|
||||||
|
import { getLastNDaysRange } from "@/components/analytics/date-range-selector";
|
||||||
|
import { normalizeTimeISOString } from "@/lib/time";
|
||||||
import { UnifiedTransactionsTable } from "../components/transactions-table.client";
|
import { UnifiedTransactionsTable } from "../components/transactions-table.client";
|
||||||
|
import { getTransactionAnalyticsSummary } from "../lib/analytics-summary.client";
|
||||||
import type { Wallet } from "../server-wallets/wallet-table/types";
|
import type { Wallet } from "../server-wallets/wallet-table/types";
|
||||||
import { TransactionAnalyticsFilter } from "./filter";
|
import type { SolanaWallet } from "../solana-wallets/wallet-table/types";
|
||||||
import { TransactionsChartCard } from "./tx-chart/tx-chart";
|
import { EngineChecklist } from "./ftux.client";
|
||||||
|
import { TransactionsAnalytics } from "./tx-chart/tx-chart";
|
||||||
|
|
||||||
export function TransactionsAnalyticsPageContent(props: {
|
export function TransactionsAnalyticsPageContent(props: {
|
||||||
searchParams: {
|
|
||||||
from?: string | undefined | string[];
|
|
||||||
to?: string | undefined | string[];
|
|
||||||
interval?: string | undefined | string[];
|
|
||||||
};
|
|
||||||
project: Project;
|
project: Project;
|
||||||
showAnalytics: boolean;
|
showAnalytics: boolean;
|
||||||
wallets?: Wallet[];
|
wallets: Wallet[];
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
client: ThirdwebClient;
|
client: ThirdwebClient;
|
||||||
|
authToken: string;
|
||||||
|
teamId: string;
|
||||||
|
isManagedVault: boolean;
|
||||||
|
testTxWithWallet: string | undefined;
|
||||||
|
testSolanaTxWithWallet: string | undefined;
|
||||||
|
solanaWallets: SolanaWallet[];
|
||||||
}) {
|
}) {
|
||||||
return (
|
const defaultRange = useMemo(() => {
|
||||||
<ResponsiveSearchParamsProvider value={props.searchParams}>
|
const range = getLastNDaysRange("last-30");
|
||||||
<div className="flex grow flex-col gap-6">
|
return {
|
||||||
{props.showAnalytics && (
|
from: normalizeTimeISOString(range.from),
|
||||||
<>
|
to: normalizeTimeISOString(range.to),
|
||||||
<div className="flex justify-end">
|
};
|
||||||
<TransactionAnalyticsFilter />
|
}, []);
|
||||||
</div>
|
|
||||||
<TransactionsChartCard
|
const engineTxSummaryQuery = useQuery({
|
||||||
project={props.project}
|
queryKey: [
|
||||||
searchParams={props.searchParams}
|
"engine-tx-analytics-summary",
|
||||||
teamSlug={props.teamSlug}
|
props.teamId,
|
||||||
wallets={props.wallets ?? []}
|
props.project.publishableKey,
|
||||||
/>
|
props.authToken,
|
||||||
</>
|
defaultRange.from,
|
||||||
)}
|
defaultRange.to,
|
||||||
<UnifiedTransactionsTable
|
],
|
||||||
client={props.client}
|
queryFn: async () => {
|
||||||
project={props.project}
|
const data = await getTransactionAnalyticsSummary({
|
||||||
teamSlug={props.teamSlug}
|
clientId: props.project.publishableKey,
|
||||||
/>
|
teamId: props.teamId,
|
||||||
|
authToken: props.authToken,
|
||||||
|
startDate: defaultRange.from,
|
||||||
|
endDate: defaultRange.to,
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (engineTxSummaryQuery.isPending) {
|
||||||
|
return (
|
||||||
|
<div className="flex h-[642px] grow items-center justify-center bg-card rounded-xl border">
|
||||||
|
<Spinner className="size-10" />
|
||||||
</div>
|
</div>
|
||||||
</ResponsiveSearchParamsProvider>
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasTransactions = engineTxSummaryQuery.data
|
||||||
|
? engineTxSummaryQuery.data.totalCount > 0
|
||||||
|
: false;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex grow flex-col gap-10">
|
||||||
|
<EngineChecklist
|
||||||
|
isManagedVault={props.isManagedVault}
|
||||||
|
client={props.client}
|
||||||
|
hasTransactions={hasTransactions}
|
||||||
|
project={props.project}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
testTxWithWallet={props.testTxWithWallet}
|
||||||
|
testSolanaTxWithWallet={props.testSolanaTxWithWallet}
|
||||||
|
wallets={props.wallets}
|
||||||
|
solanaWallets={props.solanaWallets}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{props.showAnalytics && hasTransactions && (
|
||||||
|
<TransactionsAnalytics
|
||||||
|
project={props.project}
|
||||||
|
authToken={props.authToken}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
wallets={props.wallets ?? []}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<UnifiedTransactionsTable
|
||||||
|
client={props.client}
|
||||||
|
project={props.project}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
"use client";
|
|
||||||
|
|
||||||
import {
|
|
||||||
useResponsiveSearchParams,
|
|
||||||
useSetResponsiveSearchParams,
|
|
||||||
} from "responsive-rsc";
|
|
||||||
import { DateRangeSelector } from "@/components/analytics/date-range-selector";
|
|
||||||
import { IntervalSelector } from "@/components/analytics/interval-selector";
|
|
||||||
import { normalizeTimeISOString } from "@/lib/time";
|
|
||||||
import { getTxAnalyticsFiltersFromSearchParams } from "../lib/utils";
|
|
||||||
|
|
||||||
export function TransactionAnalyticsFilter() {
|
|
||||||
const responsiveSearchParams = useResponsiveSearchParams();
|
|
||||||
const setResponsiveSearchParams = useSetResponsiveSearchParams();
|
|
||||||
|
|
||||||
const { range, interval } = getTxAnalyticsFiltersFromSearchParams({
|
|
||||||
from: responsiveSearchParams.from,
|
|
||||||
interval: responsiveSearchParams.interval,
|
|
||||||
to: responsiveSearchParams.to,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="no-scrollbar flex items-center gap-3 max-sm:overflow-auto">
|
|
||||||
<DateRangeSelector
|
|
||||||
popoverAlign="end"
|
|
||||||
range={range}
|
|
||||||
setRange={(newRange) => {
|
|
||||||
setResponsiveSearchParams((v) => {
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
from: normalizeTimeISOString(newRange.from),
|
|
||||||
to: normalizeTimeISOString(newRange.to),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<IntervalSelector
|
|
||||||
intervalType={interval}
|
|
||||||
setIntervalType={(newInterval) => {
|
|
||||||
setResponsiveSearchParams((v) => {
|
|
||||||
return {
|
|
||||||
...v,
|
|
||||||
interval: newInterval,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+7
-24
@@ -3,14 +3,13 @@ import { useMemo } from "react";
|
|||||||
import type { ThirdwebClient } from "thirdweb";
|
import type { ThirdwebClient } from "thirdweb";
|
||||||
import type { Project } from "@/api/project/projects";
|
import type { Project } from "@/api/project/projects";
|
||||||
import { type Step, StepsCard } from "@/components/blocks/StepsCard";
|
import { type Step, StepsCard } from "@/components/blocks/StepsCard";
|
||||||
import CreateServerWallet from "../server-wallets/components/create-server-wallet.client";
|
import { CreateServerWallet } from "../server-wallets/components/create-server-wallet.client";
|
||||||
import type { Wallet } from "../server-wallets/wallet-table/types";
|
import type { Wallet } from "../server-wallets/wallet-table/types";
|
||||||
import type { SolanaWallet } from "../solana-wallets/wallet-table/types";
|
import type { SolanaWallet } from "../solana-wallets/wallet-table/types";
|
||||||
import { SendTestSolanaTransaction } from "./send-test-solana-tx.client";
|
import { SendTestSolanaTransaction } from "./send-test-solana-tx.client";
|
||||||
import { SendTestTransaction } from "./send-test-tx.client";
|
import { SendTestTransaction } from "./send-test-tx.client";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
project: Project;
|
project: Project;
|
||||||
wallets: Wallet[];
|
wallets: Wallet[];
|
||||||
solanaWallets: SolanaWallet[];
|
solanaWallets: SolanaWallet[];
|
||||||
@@ -29,11 +28,12 @@ export const EngineChecklist: React.FC<Props> = (props) => {
|
|||||||
const steps: Step[] = [];
|
const steps: Step[] = [];
|
||||||
steps.push({
|
steps.push({
|
||||||
children: (
|
children: (
|
||||||
<CreateServerWalletStep
|
<div className="mt-4 flex flex-row gap-4">
|
||||||
managementAccessToken={props.managementAccessToken}
|
<CreateServerWallet
|
||||||
project={props.project}
|
project={props.project}
|
||||||
teamSlug={props.teamSlug}
|
teamSlug={props.teamSlug}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
),
|
),
|
||||||
completed: props.wallets.length > 0 || props.hasTransactions,
|
completed: props.wallets.length > 0 || props.hasTransactions,
|
||||||
description:
|
description:
|
||||||
@@ -61,7 +61,6 @@ export const EngineChecklist: React.FC<Props> = (props) => {
|
|||||||
});
|
});
|
||||||
return steps;
|
return steps;
|
||||||
}, [
|
}, [
|
||||||
props.managementAccessToken,
|
|
||||||
props.project,
|
props.project,
|
||||||
props.wallets,
|
props.wallets,
|
||||||
props.hasTransactions,
|
props.hasTransactions,
|
||||||
@@ -113,19 +112,3 @@ export const EngineChecklist: React.FC<Props> = (props) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function CreateServerWalletStep(props: {
|
|
||||||
project: Project;
|
|
||||||
teamSlug: string;
|
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="mt-4 flex flex-row gap-4">
|
|
||||||
<CreateServerWallet
|
|
||||||
managementAccessToken={props.managementAccessToken}
|
|
||||||
project={props.project}
|
|
||||||
teamSlug={props.teamSlug}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|||||||
+36
-3
@@ -1,7 +1,12 @@
|
|||||||
|
"use client";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { ActivityIcon, CoinsIcon } from "lucide-react";
|
import { ActivityIcon, CoinsIcon } from "lucide-react";
|
||||||
import { toEther } from "thirdweb/utils";
|
import { toEther } from "thirdweb/utils";
|
||||||
import { StatCard } from "@/components/analytics/stat"; // Assuming correct path
|
import { StatCard } from "@/components/analytics/stat"; // Assuming correct path
|
||||||
import type { TransactionSummaryData } from "../lib/analytics";
|
import {
|
||||||
|
getTransactionAnalyticsSummary,
|
||||||
|
type TransactionSummaryData,
|
||||||
|
} from "../lib/analytics-summary.client";
|
||||||
|
|
||||||
// Renders the UI based on fetched data or pending state
|
// Renders the UI based on fetched data or pending state
|
||||||
function TransactionAnalyticsSummaryUI(props: {
|
function TransactionAnalyticsSummaryUI(props: {
|
||||||
@@ -88,9 +93,37 @@ function TransactionAnalyticsSummaryUI(props: {
|
|||||||
export function TransactionAnalyticsSummary(props: {
|
export function TransactionAnalyticsSummary(props: {
|
||||||
teamId: string;
|
teamId: string;
|
||||||
clientId: string;
|
clientId: string;
|
||||||
initialData: TransactionSummaryData | undefined;
|
authToken: string;
|
||||||
|
startDate?: string;
|
||||||
|
endDate?: string;
|
||||||
}) {
|
}) {
|
||||||
|
const engineTxSummaryQuery = useQuery({
|
||||||
|
queryKey: [
|
||||||
|
"engine-tx-analytics-summary",
|
||||||
|
props.teamId,
|
||||||
|
props.clientId,
|
||||||
|
props.authToken,
|
||||||
|
props.startDate,
|
||||||
|
props.endDate,
|
||||||
|
],
|
||||||
|
queryFn: async () => {
|
||||||
|
const data = await getTransactionAnalyticsSummary({
|
||||||
|
clientId: props.clientId,
|
||||||
|
teamId: props.teamId,
|
||||||
|
authToken: props.authToken,
|
||||||
|
startDate: props.startDate,
|
||||||
|
endDate: props.endDate,
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TransactionAnalyticsSummaryUI data={props.initialData} isPending={false} />
|
<TransactionAnalyticsSummaryUI
|
||||||
|
data={engineTxSummaryQuery.data}
|
||||||
|
isPending={engineTxSummaryQuery.isPending}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+75
@@ -0,0 +1,75 @@
|
|||||||
|
"use client";
|
||||||
|
import { NEXT_PUBLIC_ENGINE_CLOUD_URL } from "@/constants/public-envs";
|
||||||
|
import type { TransactionStats } from "@/types/analytics";
|
||||||
|
|
||||||
|
export async function getTransactionsChartData({
|
||||||
|
teamId,
|
||||||
|
clientId,
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
interval,
|
||||||
|
authToken,
|
||||||
|
}: {
|
||||||
|
teamId: string;
|
||||||
|
clientId: string;
|
||||||
|
from: string;
|
||||||
|
to: string;
|
||||||
|
interval: "day" | "week";
|
||||||
|
authToken: string;
|
||||||
|
}): Promise<TransactionStats[]> {
|
||||||
|
const filters = {
|
||||||
|
endDate: to,
|
||||||
|
resolution: interval,
|
||||||
|
startDate: from,
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
`${NEXT_PUBLIC_ENGINE_CLOUD_URL}/v1/transactions/analytics`,
|
||||||
|
{
|
||||||
|
body: JSON.stringify(filters),
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client-id": clientId,
|
||||||
|
"x-team-id": teamId,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
if (response.status === 401 || response.status === 400) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO - need to handle this error state, like we do with the connect charts
|
||||||
|
throw new Error(
|
||||||
|
`Error fetching transactions chart data: ${response.status} ${
|
||||||
|
response.statusText
|
||||||
|
} - ${await response.text().catch(() => "Unknown error")}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type TransactionsChartResponse = {
|
||||||
|
result: {
|
||||||
|
analytics: Array<{
|
||||||
|
timeBucket: string;
|
||||||
|
chainId: string;
|
||||||
|
count: number;
|
||||||
|
}>;
|
||||||
|
metadata: {
|
||||||
|
resolution: string;
|
||||||
|
startDate: string;
|
||||||
|
endDate: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const data = (await response.json()) as TransactionsChartResponse;
|
||||||
|
|
||||||
|
return data.result.analytics.map((stat) => ({
|
||||||
|
chainId: Number(stat.chainId),
|
||||||
|
count: stat.count,
|
||||||
|
date: stat.timeBucket,
|
||||||
|
}));
|
||||||
|
}
|
||||||
+4
-10
@@ -108,10 +108,10 @@ export function TransactionsChartCardUI(props: {
|
|||||||
customHeader={
|
customHeader={
|
||||||
<div className="relative px-6 pt-6">
|
<div className="relative px-6 pt-6">
|
||||||
<h3 className="mb-0.5 font-semibold text-xl tracking-tight">
|
<h3 className="mb-0.5 font-semibold text-xl tracking-tight">
|
||||||
Daily Transactions
|
Transactions
|
||||||
</h3>
|
</h3>
|
||||||
<p className="text-muted-foreground text-sm">
|
<p className="text-muted-foreground text-sm">
|
||||||
Amount of daily transactions by chain.
|
transactions broken down by chain
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="top-6 right-6 mb-8 grid grid-cols-2 items-center gap-2 md:absolute md:mb-0 md:flex">
|
<div className="top-6 right-6 mb-8 grid grid-cols-2 items-center gap-2 md:absolute md:mb-0 md:flex">
|
||||||
@@ -184,7 +184,7 @@ function EmptyChartContent(props: {
|
|||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.push(
|
router.push(
|
||||||
`/team/${props.teamSlug}/${props.project.slug}/vault`,
|
`/team/${props.teamSlug}/${props.project.slug}/wallets/server-wallets/configuration`,
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
variant="primary"
|
variant="primary"
|
||||||
@@ -194,13 +194,7 @@ function EmptyChartContent(props: {
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<p className="flex items-center gap-2 rounded-full border bg-background px-3.5 py-1.5 text-sm">
|
<p className="text-sm text-muted-foreground">No transactions found</p>
|
||||||
<span className="!pointer-events-auto relative flex size-2">
|
|
||||||
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-sky-400 opacity-75" />
|
|
||||||
<span className="relative inline-flex size-2 rounded-full bg-primary" />
|
|
||||||
</span>
|
|
||||||
Waiting for transactions...
|
|
||||||
</p>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+59
-53
@@ -1,73 +1,79 @@
|
|||||||
import { ResponsiveSuspense } from "responsive-rsc";
|
"use client";
|
||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import { useState } from "react";
|
||||||
import type { Project } from "@/api/project/projects";
|
import type { Project } from "@/api/project/projects";
|
||||||
import { getTransactionsChart } from "../../lib/analytics";
|
import {
|
||||||
import { getTxAnalyticsFiltersFromSearchParams } from "../../lib/utils";
|
DateRangeSelector,
|
||||||
|
getLastNDaysRange,
|
||||||
|
} from "@/components/analytics/date-range-selector";
|
||||||
|
import { IntervalSelector } from "@/components/analytics/interval-selector";
|
||||||
|
import { normalizeTimeISOString } from "@/lib/time";
|
||||||
import type { Wallet } from "../../server-wallets/wallet-table/types";
|
import type { Wallet } from "../../server-wallets/wallet-table/types";
|
||||||
|
import { TransactionAnalyticsSummary } from "../summary";
|
||||||
|
import { getTransactionsChartData } from "./data";
|
||||||
import { TransactionsChartCardUI } from "./tx-chart-ui";
|
import { TransactionsChartCardUI } from "./tx-chart-ui";
|
||||||
|
|
||||||
async function AsyncTransactionsChartCard(props: {
|
export function TransactionsAnalytics(props: {
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
interval: "day" | "week";
|
|
||||||
project: Project;
|
project: Project;
|
||||||
wallets: Wallet[];
|
wallets: Wallet[];
|
||||||
|
authToken: string;
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
}) {
|
}) {
|
||||||
const data = await getTransactionsChart({
|
const [range, setRange] = useState(() => getLastNDaysRange("last-30"));
|
||||||
|
const [interval, setInterval] = useState<"day" | "week">("day");
|
||||||
|
|
||||||
|
const normalizedFrom = normalizeTimeISOString(range.from);
|
||||||
|
const normalizedTo = normalizeTimeISOString(range.to);
|
||||||
|
|
||||||
|
const params = {
|
||||||
clientId: props.project.publishableKey,
|
clientId: props.project.publishableKey,
|
||||||
from: props.from,
|
from: normalizedFrom,
|
||||||
interval: props.interval,
|
interval: interval,
|
||||||
teamId: props.project.teamId,
|
teamId: props.project.teamId,
|
||||||
to: props.to,
|
to: normalizedTo,
|
||||||
|
authToken: props.authToken,
|
||||||
|
};
|
||||||
|
|
||||||
|
const engineTxAnalytics = useQuery({
|
||||||
|
queryKey: ["engine-tx-analytics", params],
|
||||||
|
queryFn: async () => {
|
||||||
|
const data = await getTransactionsChartData(params);
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
refetchOnMount: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TransactionsChartCardUI
|
<div className="flex flex-col gap-6">
|
||||||
isPending={false}
|
<div className="flex justify-start">
|
||||||
project={props.project}
|
<div className="no-scrollbar flex items-center gap-3 max-sm:overflow-auto">
|
||||||
teamSlug={props.teamSlug}
|
<DateRangeSelector
|
||||||
userOpStats={data}
|
popoverAlign="end"
|
||||||
wallets={props.wallets}
|
range={range}
|
||||||
/>
|
setRange={setRange}
|
||||||
);
|
/>
|
||||||
}
|
|
||||||
|
|
||||||
export function TransactionsChartCard(props: {
|
<IntervalSelector
|
||||||
searchParams: {
|
intervalType={interval}
|
||||||
from?: string | undefined | string[];
|
setIntervalType={setInterval}
|
||||||
to?: string | undefined | string[];
|
/>
|
||||||
interval?: string | undefined | string[];
|
</div>
|
||||||
};
|
</div>
|
||||||
project: Project;
|
<TransactionAnalyticsSummary
|
||||||
wallets: Wallet[];
|
authToken={props.authToken}
|
||||||
teamSlug: string;
|
clientId={props.project.publishableKey}
|
||||||
}) {
|
teamId={props.project.teamId}
|
||||||
const { range, interval } = getTxAnalyticsFiltersFromSearchParams(
|
startDate={normalizedFrom}
|
||||||
props.searchParams,
|
endDate={normalizedTo}
|
||||||
);
|
/>
|
||||||
|
<TransactionsChartCardUI
|
||||||
return (
|
isPending={engineTxAnalytics.isPending}
|
||||||
<ResponsiveSuspense
|
|
||||||
// TODO - change this if this component does not end up using these params
|
|
||||||
fallback={
|
|
||||||
<TransactionsChartCardUI
|
|
||||||
isPending={true}
|
|
||||||
project={props.project}
|
|
||||||
teamSlug={props.teamSlug}
|
|
||||||
userOpStats={[]}
|
|
||||||
wallets={[]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
searchParamsUsed={["from", "to", "interval"]}
|
|
||||||
>
|
|
||||||
<AsyncTransactionsChartCard
|
|
||||||
from={range.from.toISOString()}
|
|
||||||
interval={interval}
|
|
||||||
project={props.project}
|
project={props.project}
|
||||||
teamSlug={props.teamSlug}
|
teamSlug={props.teamSlug}
|
||||||
to={range.to.toISOString()}
|
userOpStats={engineTxAnalytics.data ?? []}
|
||||||
wallets={props.wallets}
|
wallets={props.wallets}
|
||||||
/>
|
/>
|
||||||
</ResponsiveSuspense>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+127
-90
@@ -10,6 +10,7 @@ import {
|
|||||||
XIcon,
|
XIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import type { ThirdwebClient } from "thirdweb";
|
import type { ThirdwebClient } from "thirdweb";
|
||||||
@@ -21,6 +22,7 @@ import {
|
|||||||
import type { Project } from "@/api/project/projects";
|
import type { Project } from "@/api/project/projects";
|
||||||
import { FundWalletModal } from "@/components/blocks/fund-wallets-modal";
|
import { FundWalletModal } from "@/components/blocks/fund-wallets-modal";
|
||||||
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
|
import { SingleNetworkSelector } from "@/components/blocks/NetworkSelectors";
|
||||||
|
import { PaginationButtons } from "@/components/blocks/pagination-buttons";
|
||||||
import { SolanaAddress } from "@/components/blocks/solana-address";
|
import { SolanaAddress } from "@/components/blocks/solana-address";
|
||||||
import { WalletAddress } from "@/components/blocks/wallet-address";
|
import { WalletAddress } from "@/components/blocks/wallet-address";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
@@ -33,13 +35,12 @@ import {
|
|||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import {
|
import {
|
||||||
Pagination,
|
Select,
|
||||||
PaginationContent,
|
SelectContent,
|
||||||
PaginationItem,
|
SelectItem,
|
||||||
PaginationLink,
|
SelectTrigger,
|
||||||
PaginationNext,
|
SelectValue,
|
||||||
PaginationPrevious,
|
} from "@/components/ui/select";
|
||||||
} from "@/components/ui/pagination";
|
|
||||||
import { Skeleton } from "@/components/ui/skeleton";
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import {
|
import {
|
||||||
@@ -57,8 +58,9 @@ import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
|
|||||||
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
||||||
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { fetchSolanaBalance } from "../lib/getSolanaBalance";
|
||||||
import { updateDefaultProjectWallet } from "../lib/vault.client";
|
import { updateDefaultProjectWallet } from "../lib/vault.client";
|
||||||
import CreateServerWallet from "../server-wallets/components/create-server-wallet.client";
|
import { CreateServerWallet } from "../server-wallets/components/create-server-wallet.client";
|
||||||
import type { Wallet as EVMWallet } from "../server-wallets/wallet-table/types";
|
import type { Wallet as EVMWallet } from "../server-wallets/wallet-table/types";
|
||||||
import { CreateSolanaWallet } from "../solana-wallets/components/create-solana-wallet.client";
|
import { CreateSolanaWallet } from "../solana-wallets/components/create-solana-wallet.client";
|
||||||
import { UpgradeSolanaPermissions } from "../solana-wallets/components/upgrade-solana-permissions.client";
|
import { UpgradeSolanaPermissions } from "../solana-wallets/components/upgrade-solana-permissions.client";
|
||||||
@@ -77,9 +79,10 @@ interface ServerWalletsTableProps {
|
|||||||
solanaTotalPages: number;
|
solanaTotalPages: number;
|
||||||
project: Project;
|
project: Project;
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
client: ThirdwebClient;
|
client: ThirdwebClient;
|
||||||
solanaPermissionError?: boolean;
|
solanaPermissionError?: boolean;
|
||||||
|
authToken: string;
|
||||||
|
pageSize: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
||||||
@@ -88,7 +91,6 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
solanaWallets,
|
solanaWallets,
|
||||||
project,
|
project,
|
||||||
teamSlug,
|
teamSlug,
|
||||||
managementAccessToken,
|
|
||||||
evmTotalRecords,
|
evmTotalRecords,
|
||||||
evmCurrentPage,
|
evmCurrentPage,
|
||||||
evmTotalPages,
|
evmTotalPages,
|
||||||
@@ -97,10 +99,15 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
solanaTotalPages,
|
solanaTotalPages,
|
||||||
client,
|
client,
|
||||||
solanaPermissionError,
|
solanaPermissionError,
|
||||||
|
authToken,
|
||||||
|
pageSize,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [activeChain, setActiveChain] = useState<WalletChain>("evm");
|
const [activeChain, setActiveChain] = useState<WalletChain>("evm");
|
||||||
const [selectedChainId, setSelectedChainId] = useState<number>(1);
|
const [selectedChainId, setSelectedChainId] = useState<number>(1);
|
||||||
|
const [selectedSolanaChain, setSelectedSolanaChain] = useState<
|
||||||
|
"solana:mainnet" | "solana:devnet"
|
||||||
|
>("solana:mainnet");
|
||||||
const [showSmartAccount, setShowSmartAccount] = useState(false);
|
const [showSmartAccount, setShowSmartAccount] = useState(false);
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -134,11 +141,7 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
<div className="flex flex-row gap-2.5">
|
<div className="flex flex-row gap-2.5">
|
||||||
{activeChain === "evm" && (
|
{activeChain === "evm" && (
|
||||||
<>
|
<>
|
||||||
<CreateServerWallet
|
<CreateServerWallet project={project} teamSlug={teamSlug} />
|
||||||
managementAccessToken={managementAccessToken}
|
|
||||||
project={project}
|
|
||||||
teamSlug={teamSlug}
|
|
||||||
/>
|
|
||||||
<SingleNetworkSelector
|
<SingleNetworkSelector
|
||||||
chainId={selectedChainId}
|
chainId={selectedChainId}
|
||||||
onChange={setSelectedChainId}
|
onChange={setSelectedChainId}
|
||||||
@@ -151,12 +154,33 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{activeChain === "solana" && (
|
{activeChain === "solana" && (
|
||||||
<CreateSolanaWallet
|
<>
|
||||||
managementAccessToken={managementAccessToken}
|
<CreateSolanaWallet
|
||||||
project={project}
|
project={project}
|
||||||
teamSlug={teamSlug}
|
teamSlug={teamSlug}
|
||||||
disabled={solanaPermissionError}
|
disabled={solanaPermissionError}
|
||||||
/>
|
/>
|
||||||
|
<Select
|
||||||
|
value={selectedSolanaChain}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setSelectedSolanaChain(
|
||||||
|
value as "solana:mainnet" | "solana:devnet",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="w-fit min-w-[180px] rounded-full bg-background hover:bg-accent/50">
|
||||||
|
<SelectValue placeholder="Select network" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent className="rounded-xl">
|
||||||
|
<SelectItem value="solana:mainnet" className="rounded-lg">
|
||||||
|
Solana Mainnet
|
||||||
|
</SelectItem>
|
||||||
|
<SelectItem value="solana:devnet" className="rounded-lg">
|
||||||
|
Solana Devnet
|
||||||
|
</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -285,6 +309,8 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
project={project}
|
project={project}
|
||||||
teamSlug={teamSlug}
|
teamSlug={teamSlug}
|
||||||
client={client}
|
client={client}
|
||||||
|
authToken={authToken}
|
||||||
|
chainId={selectedSolanaChain}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</TableBody>
|
</TableBody>
|
||||||
@@ -303,13 +329,13 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
</TableContainer>
|
</TableContainer>
|
||||||
|
|
||||||
{totalPages > 1 && (
|
{totalPages > 1 && (
|
||||||
<WalletsPagination
|
<ServerWalletsPagination
|
||||||
activeChain={activeChain}
|
activeChain={activeChain}
|
||||||
currentPage={currentPage}
|
currentPage={currentPage}
|
||||||
|
currentCount={wallets.length}
|
||||||
|
pageSize={pageSize}
|
||||||
totalPages={totalPages}
|
totalPages={totalPages}
|
||||||
totalRecords={totalRecords}
|
totalRecords={totalRecords}
|
||||||
teamSlug={teamSlug}
|
|
||||||
projectSlug={project.slug}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -319,78 +345,69 @@ export function ServerWalletsTable(props: ServerWalletsTableProps) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wallets Pagination Component
|
function ServerWalletsPagination({
|
||||||
function WalletsPagination({
|
|
||||||
activeChain,
|
activeChain,
|
||||||
currentPage,
|
currentPage,
|
||||||
|
currentCount,
|
||||||
|
pageSize,
|
||||||
totalPages,
|
totalPages,
|
||||||
totalRecords,
|
totalRecords,
|
||||||
teamSlug,
|
|
||||||
projectSlug,
|
|
||||||
}: {
|
}: {
|
||||||
activeChain: WalletChain;
|
activeChain: WalletChain;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
|
currentCount: number;
|
||||||
|
pageSize: number;
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
totalRecords: number;
|
totalRecords: number;
|
||||||
teamSlug: string;
|
|
||||||
projectSlug: string;
|
|
||||||
}) {
|
}) {
|
||||||
|
const router = useDashboardRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const pageParam = activeChain === "evm" ? "page" : "solana_page";
|
const pageParam = activeChain === "evm" ? "page" : "solana_page";
|
||||||
|
|
||||||
|
const effectivePageSize = pageSize > 0 ? pageSize : currentCount;
|
||||||
|
const rangeStart =
|
||||||
|
totalRecords && effectivePageSize
|
||||||
|
? Math.min((currentPage - 1) * effectivePageSize + 1, totalRecords)
|
||||||
|
: 0;
|
||||||
|
const computedCount = currentCount
|
||||||
|
? currentCount
|
||||||
|
: totalRecords && effectivePageSize
|
||||||
|
? Math.min(effectivePageSize, totalRecords - rangeStart + 1)
|
||||||
|
: 0;
|
||||||
|
const rangeEnd = totalRecords
|
||||||
|
? Math.min(rangeStart + Math.max(computedCount - 1, 0), totalRecords)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
const handlePageChange = (page: number) => {
|
||||||
|
const params = new URLSearchParams(searchParams?.toString() ?? "");
|
||||||
|
if (page <= 1) {
|
||||||
|
params.delete(pageParam);
|
||||||
|
} else {
|
||||||
|
params.set(pageParam, page.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
const queryString = params.toString();
|
||||||
|
router.push(queryString ? `${pathname}?${queryString}` : pathname);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center border-t p-6">
|
<div className="border-t px-6 py-6">
|
||||||
<div className="mb-4 text-muted-foreground text-sm">
|
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||||
Found {totalRecords} {activeChain === "evm" ? "EVM" : "Solana"} wallets
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{totalRecords
|
||||||
|
? `Showing ${rangeStart.toLocaleString()}-${rangeEnd.toLocaleString()} of ${totalRecords.toLocaleString()} ` +
|
||||||
|
(activeChain === "evm" ? "EVM" : "Solana") +
|
||||||
|
" wallets"
|
||||||
|
: `No ${activeChain === "evm" ? "EVM" : "Solana"} wallets found`}
|
||||||
|
</span>
|
||||||
|
<PaginationButtons
|
||||||
|
activePage={currentPage}
|
||||||
|
className="justify-start lg:justify-end"
|
||||||
|
onPageClick={handlePageChange}
|
||||||
|
totalPages={totalPages}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Pagination>
|
|
||||||
<PaginationContent>
|
|
||||||
<PaginationItem>
|
|
||||||
<Link
|
|
||||||
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${
|
|
||||||
currentPage > 1 ? currentPage - 1 : 1
|
|
||||||
}`}
|
|
||||||
legacyBehavior
|
|
||||||
passHref
|
|
||||||
>
|
|
||||||
<PaginationPrevious
|
|
||||||
className={
|
|
||||||
currentPage <= 1 ? "pointer-events-none opacity-50" : ""
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Link>
|
|
||||||
</PaginationItem>
|
|
||||||
{Array.from({ length: totalPages }, (_, i) => i + 1).map(
|
|
||||||
(pageNumber) => (
|
|
||||||
<PaginationItem key={`page-${pageNumber}`}>
|
|
||||||
<Link
|
|
||||||
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${pageNumber}`}
|
|
||||||
passHref
|
|
||||||
>
|
|
||||||
<PaginationLink isActive={currentPage === pageNumber}>
|
|
||||||
{pageNumber}
|
|
||||||
</PaginationLink>
|
|
||||||
</Link>
|
|
||||||
</PaginationItem>
|
|
||||||
),
|
|
||||||
)}
|
|
||||||
<PaginationItem>
|
|
||||||
<Link
|
|
||||||
href={`/team/${teamSlug}/${projectSlug}/transactions?${pageParam}=${
|
|
||||||
currentPage < totalPages ? currentPage + 1 : totalPages
|
|
||||||
}`}
|
|
||||||
passHref
|
|
||||||
>
|
|
||||||
<PaginationNext
|
|
||||||
className={
|
|
||||||
currentPage >= totalPages
|
|
||||||
? "pointer-events-none opacity-50"
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Link>
|
|
||||||
</PaginationItem>
|
|
||||||
</PaginationContent>
|
|
||||||
</Pagination>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -514,11 +531,15 @@ function SolanaWalletRow({
|
|||||||
project,
|
project,
|
||||||
teamSlug,
|
teamSlug,
|
||||||
client,
|
client,
|
||||||
|
authToken,
|
||||||
|
chainId,
|
||||||
}: {
|
}: {
|
||||||
wallet: SolanaWallet;
|
wallet: SolanaWallet;
|
||||||
project: Project;
|
project: Project;
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
client: ThirdwebClient;
|
client: ThirdwebClient;
|
||||||
|
authToken: string;
|
||||||
|
chainId: "solana:mainnet" | "solana:devnet";
|
||||||
}) {
|
}) {
|
||||||
const engineService = project.services.find(
|
const engineService = project.services.find(
|
||||||
(s) => s.name === "engineCloud",
|
(s) => s.name === "engineCloud",
|
||||||
@@ -554,7 +575,12 @@ function SolanaWalletRow({
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<SolanaWalletBalance publicKey={wallet.publicKey} />
|
<SolanaWalletBalance
|
||||||
|
publicKey={wallet.publicKey}
|
||||||
|
authToken={authToken}
|
||||||
|
clientId={project.publishableKey}
|
||||||
|
chainId={chainId}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
|
||||||
<TableCell>
|
<TableCell>
|
||||||
@@ -746,16 +772,27 @@ function WalletBalance({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SolanaWalletBalance({ publicKey }: { publicKey: string }) {
|
function SolanaWalletBalance({
|
||||||
|
publicKey,
|
||||||
|
authToken,
|
||||||
|
clientId,
|
||||||
|
chainId,
|
||||||
|
}: {
|
||||||
|
publicKey: string;
|
||||||
|
authToken: string;
|
||||||
|
clientId: string;
|
||||||
|
chainId: "solana:mainnet" | "solana:devnet";
|
||||||
|
}) {
|
||||||
const balance = useQuery({
|
const balance = useQuery({
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
// TODO: Implement actual Solana balance fetching
|
return await fetchSolanaBalance({
|
||||||
return {
|
publicKey,
|
||||||
displayValue: "0",
|
authToken,
|
||||||
symbol: "SOL",
|
clientId,
|
||||||
};
|
chainId,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
queryKey: ["solanaWalletBalance", publicKey],
|
queryKey: ["solanaWalletBalance", publicKey, chainId],
|
||||||
});
|
});
|
||||||
|
|
||||||
if (balance.isFetching) {
|
if (balance.isFetching) {
|
||||||
|
|||||||
+88
@@ -0,0 +1,88 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { NEXT_PUBLIC_ENGINE_CLOUD_URL } from "@/constants/public-envs";
|
||||||
|
|
||||||
|
export type TransactionSummaryData = {
|
||||||
|
totalCount: number;
|
||||||
|
totalGasCostWei: string;
|
||||||
|
totalGasUnitsUsed: string; // Keep fetched data structure
|
||||||
|
};
|
||||||
|
|
||||||
|
type AnalyticsSummaryApiResponse = {
|
||||||
|
result: {
|
||||||
|
summary: {
|
||||||
|
totalCount: number;
|
||||||
|
totalGasCostWei: string;
|
||||||
|
totalGasUnitsUsed: string;
|
||||||
|
};
|
||||||
|
metadata: {
|
||||||
|
startDate?: string;
|
||||||
|
endDate?: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetches data from the /analytics-summary endpoint
|
||||||
|
export async function getTransactionAnalyticsSummary(props: {
|
||||||
|
teamId: string;
|
||||||
|
clientId: string;
|
||||||
|
authToken: string;
|
||||||
|
startDate?: string;
|
||||||
|
endDate?: string;
|
||||||
|
}): Promise<TransactionSummaryData> {
|
||||||
|
const body: {
|
||||||
|
startDate?: string;
|
||||||
|
endDate?: string;
|
||||||
|
} = {};
|
||||||
|
|
||||||
|
if (props.startDate) {
|
||||||
|
body.startDate = props.startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.endDate) {
|
||||||
|
body.endDate = props.endDate;
|
||||||
|
}
|
||||||
|
const defaultData: TransactionSummaryData = {
|
||||||
|
totalCount: 0,
|
||||||
|
totalGasCostWei: "0",
|
||||||
|
totalGasUnitsUsed: "0",
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(
|
||||||
|
`${NEXT_PUBLIC_ENGINE_CLOUD_URL}/v1/transactions/analytics-summary`,
|
||||||
|
{
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${props.authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client-id": props.clientId,
|
||||||
|
"x-team-id": props.teamId,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
if (response.status === 401 || response.status === 400) {
|
||||||
|
console.error("Unauthorized fetching transaction summary");
|
||||||
|
return defaultData;
|
||||||
|
}
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(
|
||||||
|
`Error fetching transaction summary: ${response.status} ${response.statusText} - ${errorText}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = (await response.json()) as AnalyticsSummaryApiResponse;
|
||||||
|
|
||||||
|
return {
|
||||||
|
totalCount: data.result.summary.totalCount ?? 0,
|
||||||
|
totalGasCostWei: data.result.summary.totalGasCostWei ?? "0",
|
||||||
|
totalGasUnitsUsed: data.result.summary.totalGasUnitsUsed ?? "0",
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch transaction summary:", error);
|
||||||
|
return defaultData;
|
||||||
|
}
|
||||||
|
}
|
||||||
-147
@@ -1,157 +1,10 @@
|
|||||||
import { getAuthToken } from "@/api/auth-token";
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
import { NEXT_PUBLIC_ENGINE_CLOUD_URL } from "@/constants/public-envs";
|
import { NEXT_PUBLIC_ENGINE_CLOUD_URL } from "@/constants/public-envs";
|
||||||
import type { TransactionStats } from "@/types/analytics";
|
|
||||||
import type {
|
import type {
|
||||||
Transaction,
|
Transaction,
|
||||||
TransactionsResponse,
|
TransactionsResponse,
|
||||||
} from "../analytics/tx-table/types";
|
} from "../analytics/tx-table/types";
|
||||||
|
|
||||||
// Define the structure of the data we expect back from our fetch function
|
|
||||||
export type TransactionSummaryData = {
|
|
||||||
totalCount: number;
|
|
||||||
totalGasCostWei: string;
|
|
||||||
totalGasUnitsUsed: string; // Keep fetched data structure
|
|
||||||
};
|
|
||||||
|
|
||||||
// Define the structure of the API response
|
|
||||||
type AnalyticsSummaryApiResponse = {
|
|
||||||
result: {
|
|
||||||
summary: {
|
|
||||||
totalCount: number;
|
|
||||||
totalGasCostWei: string;
|
|
||||||
totalGasUnitsUsed: string;
|
|
||||||
};
|
|
||||||
metadata: {
|
|
||||||
startDate?: string;
|
|
||||||
endDate?: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Fetches data from the /analytics-summary endpoint
|
|
||||||
export async function getTransactionAnalyticsSummary(props: {
|
|
||||||
teamId: string;
|
|
||||||
clientId: string;
|
|
||||||
}): Promise<TransactionSummaryData> {
|
|
||||||
const authToken = await getAuthToken();
|
|
||||||
const body = {};
|
|
||||||
const defaultData: TransactionSummaryData = {
|
|
||||||
totalCount: 0,
|
|
||||||
totalGasCostWei: "0",
|
|
||||||
totalGasUnitsUsed: "0",
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await fetch(
|
|
||||||
`${NEXT_PUBLIC_ENGINE_CLOUD_URL}/v1/transactions/analytics-summary`,
|
|
||||||
{
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-client-id": props.clientId,
|
|
||||||
"x-team-id": props.teamId,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
if (response.status === 401 || response.status === 400) {
|
|
||||||
console.error("Unauthorized fetching transaction summary");
|
|
||||||
return defaultData;
|
|
||||||
}
|
|
||||||
const errorText = await response.text();
|
|
||||||
throw new Error(
|
|
||||||
`Error fetching transaction summary: ${response.status} ${response.statusText} - ${errorText}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = (await response.json()) as AnalyticsSummaryApiResponse;
|
|
||||||
|
|
||||||
return {
|
|
||||||
totalCount: data.result.summary.totalCount ?? 0,
|
|
||||||
totalGasCostWei: data.result.summary.totalGasCostWei ?? "0",
|
|
||||||
totalGasUnitsUsed: data.result.summary.totalGasUnitsUsed ?? "0",
|
|
||||||
};
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Failed to fetch transaction summary:", error);
|
|
||||||
return defaultData;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getTransactionsChart({
|
|
||||||
teamId,
|
|
||||||
clientId,
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
interval,
|
|
||||||
}: {
|
|
||||||
teamId: string;
|
|
||||||
clientId: string;
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
interval: "day" | "week";
|
|
||||||
}): Promise<TransactionStats[]> {
|
|
||||||
const authToken = await getAuthToken();
|
|
||||||
|
|
||||||
const filters = {
|
|
||||||
endDate: to,
|
|
||||||
resolution: interval,
|
|
||||||
startDate: from,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await fetch(
|
|
||||||
`${NEXT_PUBLIC_ENGINE_CLOUD_URL}/v1/transactions/analytics`,
|
|
||||||
{
|
|
||||||
body: JSON.stringify(filters),
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${authToken}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-client-id": clientId,
|
|
||||||
"x-team-id": teamId,
|
|
||||||
},
|
|
||||||
method: "POST",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
if (response.status === 401 || response.status === 400) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO - need to handle this error state, like we do with the connect charts
|
|
||||||
throw new Error(
|
|
||||||
`Error fetching transactions chart data: ${response.status} ${
|
|
||||||
response.statusText
|
|
||||||
} - ${await response.text().catch(() => "Unknown error")}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
type TransactionsChartResponse = {
|
|
||||||
result: {
|
|
||||||
analytics: Array<{
|
|
||||||
timeBucket: string;
|
|
||||||
chainId: string;
|
|
||||||
count: number;
|
|
||||||
}>;
|
|
||||||
metadata: {
|
|
||||||
resolution: string;
|
|
||||||
startDate: string;
|
|
||||||
endDate: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const data = (await response.json()) as TransactionsChartResponse;
|
|
||||||
|
|
||||||
return data.result.analytics.map((stat) => ({
|
|
||||||
chainId: Number(stat.chainId),
|
|
||||||
count: stat.count,
|
|
||||||
date: stat.timeBucket,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getSingleTransaction({
|
export async function getSingleTransaction({
|
||||||
teamId,
|
teamId,
|
||||||
clientId,
|
clientId,
|
||||||
|
|||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
import { configure, getSolanaWalletBalance } from "@thirdweb-dev/api";
|
||||||
|
import { THIRDWEB_API_HOST } from "@/constants/urls";
|
||||||
|
|
||||||
|
// Configure the API client to use the correct base URL
|
||||||
|
configure({
|
||||||
|
override: {
|
||||||
|
baseUrl: THIRDWEB_API_HOST,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function fetchSolanaBalance({
|
||||||
|
publicKey,
|
||||||
|
authToken,
|
||||||
|
clientId,
|
||||||
|
chainId = "solana:mainnet",
|
||||||
|
}: {
|
||||||
|
publicKey: string;
|
||||||
|
authToken: string;
|
||||||
|
clientId: string;
|
||||||
|
chainId?: "solana:mainnet" | "solana:devnet";
|
||||||
|
}): Promise<{
|
||||||
|
displayValue: string;
|
||||||
|
symbol: string;
|
||||||
|
value: string;
|
||||||
|
decimals: number;
|
||||||
|
} | null> {
|
||||||
|
try {
|
||||||
|
const response = await getSolanaWalletBalance({
|
||||||
|
path: {
|
||||||
|
address: publicKey,
|
||||||
|
},
|
||||||
|
query: {
|
||||||
|
chainId,
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-client-id": clientId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.error || !response.data) {
|
||||||
|
console.error(
|
||||||
|
"Error fetching Solana balance:",
|
||||||
|
response.error || "No data returned",
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
displayValue: response.data.result.displayValue,
|
||||||
|
symbol: "SOL",
|
||||||
|
value: response.data.result.value,
|
||||||
|
decimals: response.data.result.decimals,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching Solana balance:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
import { getFiltersFromSearchParams } from "@/lib/time";
|
|
||||||
|
|
||||||
export function getTxAnalyticsFiltersFromSearchParams(params: {
|
|
||||||
from?: string | undefined | string[];
|
|
||||||
to?: string | undefined | string[];
|
|
||||||
interval?: string | undefined | string[];
|
|
||||||
}) {
|
|
||||||
return getFiltersFromSearchParams({
|
|
||||||
defaultRange: "last-30",
|
|
||||||
from: params.from,
|
|
||||||
interval: params.interval,
|
|
||||||
to: params.to,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
+6
-220
@@ -1,225 +1,11 @@
|
|||||||
import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk";
|
import { redirect } from "next/navigation";
|
||||||
import { ArrowLeftRightIcon } from "lucide-react";
|
|
||||||
import { notFound, redirect } from "next/navigation";
|
|
||||||
import { getAuthToken } from "@/api/auth-token";
|
|
||||||
import { getProject } from "@/api/project/projects";
|
|
||||||
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
|
||||||
import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { TransactionsAnalyticsPageContent } from "./analytics/analytics-page";
|
|
||||||
import { EngineChecklist } from "./analytics/ftux.client";
|
|
||||||
import { TransactionAnalyticsSummary } from "./analytics/summary";
|
|
||||||
import { ServerWalletsTable } from "./components/server-wallets-table.client";
|
|
||||||
import { getTransactionAnalyticsSummary } from "./lib/analytics";
|
|
||||||
import type { Wallet } from "./server-wallets/wallet-table/types";
|
|
||||||
import { listSolanaAccounts } from "./solana-wallets/lib/vault.client";
|
|
||||||
import type { SolanaWallet } from "./solana-wallets/wallet-table/types";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
// Redirect old Transactions page to new Server Wallets Overview
|
||||||
|
export default async function Page(props: {
|
||||||
export default async function TransactionsAnalyticsPage(props: {
|
|
||||||
params: Promise<{ team_slug: string; project_slug: string }>;
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
searchParams: Promise<{
|
|
||||||
from?: string | string[] | undefined;
|
|
||||||
to?: string | string[] | undefined;
|
|
||||||
interval?: string | string[] | undefined;
|
|
||||||
testTxWithWallet?: string | string[] | undefined;
|
|
||||||
testSolanaTxWithWallet?: string | string[] | undefined;
|
|
||||||
page?: string;
|
|
||||||
solana_page?: string;
|
|
||||||
}>;
|
|
||||||
}) {
|
}) {
|
||||||
const [params, searchParams, authToken] = await Promise.all([
|
const params = await props.params;
|
||||||
props.params,
|
redirect(
|
||||||
props.searchParams,
|
`/team/${params.team_slug}/${params.project_slug}/wallets/server-wallets`,
|
||||||
getAuthToken(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!authToken) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const [vaultClient, project] = await Promise.all([
|
|
||||||
createVaultClient({
|
|
||||||
baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL,
|
|
||||||
}).catch(() => undefined),
|
|
||||||
getProject(params.team_slug, params.project_slug),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!project) {
|
|
||||||
redirect(`/team/${params.team_slug}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!vaultClient) {
|
|
||||||
return <div>Error: Failed to connect to Vault</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const projectEngineCloudService = project.services.find(
|
|
||||||
(service) => service.name === "engineCloud",
|
|
||||||
);
|
|
||||||
|
|
||||||
const managementAccessToken =
|
|
||||||
projectEngineCloudService?.managementAccessToken;
|
|
||||||
const isManagedVault = !!projectEngineCloudService?.encryptedAdminKey;
|
|
||||||
|
|
||||||
const pageSize = 10;
|
|
||||||
const currentPage = Number.parseInt(searchParams.page ?? "1");
|
|
||||||
const solanCurrentPage = Number.parseInt(searchParams.solana_page ?? "1");
|
|
||||||
|
|
||||||
const eoas = managementAccessToken
|
|
||||||
? await listEoas({
|
|
||||||
client: vaultClient,
|
|
||||||
request: {
|
|
||||||
auth: {
|
|
||||||
accessToken: managementAccessToken,
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
page: currentPage - 1,
|
|
||||||
// @ts-expect-error - TODO: fix this
|
|
||||||
page_size: pageSize,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
: { data: { items: [], totalRecords: 0 }, error: null, success: true };
|
|
||||||
|
|
||||||
const wallets = eoas.data?.items as Wallet[] | undefined;
|
|
||||||
|
|
||||||
// Fetch Solana accounts - gracefully handle permission errors
|
|
||||||
let solanaAccounts: {
|
|
||||||
data: { items: SolanaWallet[]; totalRecords: number };
|
|
||||||
error: Error | null;
|
|
||||||
success: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (managementAccessToken) {
|
|
||||||
solanaAccounts = await listSolanaAccounts({
|
|
||||||
managementAccessToken,
|
|
||||||
page: solanCurrentPage,
|
|
||||||
limit: pageSize,
|
|
||||||
projectId: project.id,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
solanaAccounts = {
|
|
||||||
data: { items: [], totalRecords: 0 },
|
|
||||||
error: null,
|
|
||||||
success: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if error is a permission error
|
|
||||||
const isSolanaPermissionError =
|
|
||||||
solanaAccounts.error?.message.includes("AUTH_INSUFFICIENT_SCOPE") ?? false;
|
|
||||||
|
|
||||||
const initialData = await getTransactionAnalyticsSummary({
|
|
||||||
clientId: project.publishableKey,
|
|
||||||
teamId: project.teamId,
|
|
||||||
}).catch(() => undefined);
|
|
||||||
const hasTransactions = initialData ? initialData.totalCount > 0 : false;
|
|
||||||
|
|
||||||
const client = getClientThirdwebClient({
|
|
||||||
jwt: authToken,
|
|
||||||
teamId: project.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProjectPage
|
|
||||||
header={{
|
|
||||||
client,
|
|
||||||
icon: ArrowLeftRightIcon,
|
|
||||||
title: "Transactions",
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Send, monitor, and manage transactions.{" "}
|
|
||||||
<br className="max-sm:hidden" /> Send transactions from user or
|
|
||||||
server wallets, sponsor gas, monitor transaction status, and more
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
actions: null,
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
type: "docs",
|
|
||||||
href: "https://portal.thirdweb.com/transactions",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "playground",
|
|
||||||
href: "https://playground.thirdweb.com/transactions/airdrop-tokens",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "api",
|
|
||||||
href: "https://api.thirdweb.com/reference#tag/transactions",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="flex flex-col gap-10">
|
|
||||||
<EngineChecklist
|
|
||||||
isManagedVault={isManagedVault}
|
|
||||||
client={client}
|
|
||||||
hasTransactions={hasTransactions}
|
|
||||||
managementAccessToken={managementAccessToken ?? undefined}
|
|
||||||
project={project}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
testTxWithWallet={searchParams.testTxWithWallet as string | undefined}
|
|
||||||
testSolanaTxWithWallet={
|
|
||||||
searchParams.testSolanaTxWithWallet as string | undefined
|
|
||||||
}
|
|
||||||
wallets={wallets ?? []}
|
|
||||||
solanaWallets={solanaAccounts.data.items}
|
|
||||||
/>
|
|
||||||
{hasTransactions &&
|
|
||||||
!searchParams.testTxWithWallet &&
|
|
||||||
!searchParams.testSolanaTxWithWallet && (
|
|
||||||
<TransactionAnalyticsSummary
|
|
||||||
clientId={project.publishableKey}
|
|
||||||
initialData={initialData}
|
|
||||||
teamId={project.teamId}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* transactions */}
|
|
||||||
<TransactionsAnalyticsPageContent
|
|
||||||
client={client}
|
|
||||||
project={project}
|
|
||||||
searchParams={searchParams}
|
|
||||||
showAnalytics={
|
|
||||||
hasTransactions &&
|
|
||||||
!searchParams.testTxWithWallet &&
|
|
||||||
!searchParams.testSolanaTxWithWallet
|
|
||||||
}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
wallets={wallets}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Server Wallets (EVM + Solana) */}
|
|
||||||
{eoas.error ? (
|
|
||||||
<div className="rounded-xl border border-destructive/50 bg-destructive/10 p-4">
|
|
||||||
<p className="text-destructive font-semibold mb-2">
|
|
||||||
EVM Wallet Error
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{eoas.error.message}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<ServerWalletsTable
|
|
||||||
client={client}
|
|
||||||
evmCurrentPage={currentPage}
|
|
||||||
evmTotalPages={Math.ceil(eoas.data.totalRecords / pageSize)}
|
|
||||||
evmTotalRecords={eoas.data.totalRecords}
|
|
||||||
evmWallets={eoas.data.items as Wallet[]}
|
|
||||||
managementAccessToken={managementAccessToken ?? undefined}
|
|
||||||
project={project}
|
|
||||||
solanaCurrentPage={solanCurrentPage}
|
|
||||||
solanaTotalPages={Math.ceil(
|
|
||||||
solanaAccounts.data.totalRecords / pageSize,
|
|
||||||
)}
|
|
||||||
solanaTotalRecords={solanaAccounts.data.totalRecords}
|
|
||||||
solanaWallets={solanaAccounts.data.items}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
solanaPermissionError={isSolanaPermissionError}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</ProjectPage>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-9
@@ -15,18 +15,26 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import { Spinner } from "@/components/ui/Spinner";
|
import { Spinner } from "@/components/ui/Spinner";
|
||||||
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
import { createProjectServerWallet } from "../../lib/vault.client";
|
import { createProjectServerWallet } from "../../lib/vault.client";
|
||||||
|
|
||||||
export default function CreateServerWallet(props: {
|
export function CreateServerWallet(props: {
|
||||||
project: Project;
|
project: Project;
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
setAsProjectWallet?: boolean;
|
setAsProjectWallet?: boolean;
|
||||||
|
button?: {
|
||||||
|
size?: "default" | "sm" | "lg";
|
||||||
|
iconClassName?: string;
|
||||||
|
};
|
||||||
}) {
|
}) {
|
||||||
const router = useDashboardRouter();
|
const router = useDashboardRouter();
|
||||||
const [label, setLabel] = useState("");
|
const [label, setLabel] = useState("");
|
||||||
const [modalOpen, setModalOpen] = useState(false);
|
const [modalOpen, setModalOpen] = useState(false);
|
||||||
|
|
||||||
|
const managementAccessToken =
|
||||||
|
props.project.services?.find((service) => service.name === "engineCloud")
|
||||||
|
?.managementAccessToken ?? undefined;
|
||||||
|
|
||||||
const createEoaMutation = useMutation({
|
const createEoaMutation = useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
managementAccessToken,
|
managementAccessToken,
|
||||||
@@ -53,12 +61,12 @@ export default function CreateServerWallet(props: {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleCreateServerWallet = async () => {
|
const handleCreateServerWallet = async () => {
|
||||||
if (!props.managementAccessToken) {
|
if (!managementAccessToken) {
|
||||||
router.push(`/team/${props.teamSlug}/${props.project.slug}/vault`);
|
router.push(`/team/${props.teamSlug}/${props.project.slug}/vault`);
|
||||||
} else {
|
} else {
|
||||||
await createEoaMutation.mutateAsync({
|
await createEoaMutation.mutateAsync({
|
||||||
label,
|
label,
|
||||||
managementAccessToken: props.managementAccessToken,
|
managementAccessToken: managementAccessToken,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -68,21 +76,32 @@ export default function CreateServerWallet(props: {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
<Button
|
||||||
className="gap-1.5 rounded-full bg-background"
|
className="gap-1.5 rounded-full bg-background text-foreground"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
size={props.button?.size}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
props.managementAccessToken
|
managementAccessToken
|
||||||
? setModalOpen(true)
|
? setModalOpen(true)
|
||||||
: router.push(`/team/${props.teamSlug}/${props.project.slug}/vault`)
|
: router.push(`/team/${props.teamSlug}/${props.project.slug}/vault`)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Spinner className="size-4" />
|
<Spinner
|
||||||
|
className={cn(
|
||||||
|
"size-4 text-muted-foreground",
|
||||||
|
props.button?.iconClassName,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
) : (
|
) : (
|
||||||
<PlusIcon className="size-4 text-muted-foreground" />
|
<PlusIcon
|
||||||
|
className={cn(
|
||||||
|
"size-4 text-muted-foreground",
|
||||||
|
props.button?.iconClassName,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{props.managementAccessToken
|
{managementAccessToken
|
||||||
? isLoading
|
? isLoading
|
||||||
? "Creating..."
|
? "Creating..."
|
||||||
: "Create Server Wallet"
|
: "Create Server Wallet"
|
||||||
|
|||||||
+8
-5
@@ -20,7 +20,6 @@ import { useDashboardRouter } from "@/lib/DashboardRouter";
|
|||||||
import { createSolanaAccount } from "../lib/vault.client";
|
import { createSolanaAccount } from "../lib/vault.client";
|
||||||
|
|
||||||
export function CreateSolanaWallet(props: {
|
export function CreateSolanaWallet(props: {
|
||||||
managementAccessToken: string | undefined;
|
|
||||||
project: Project;
|
project: Project;
|
||||||
teamSlug: string;
|
teamSlug: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
@@ -29,14 +28,18 @@ export function CreateSolanaWallet(props: {
|
|||||||
const [label, setLabel] = useState("");
|
const [label, setLabel] = useState("");
|
||||||
const router = useDashboardRouter();
|
const router = useDashboardRouter();
|
||||||
|
|
||||||
|
const managementAccessToken =
|
||||||
|
props.project.services?.find((service) => service.name === "engineCloud")
|
||||||
|
?.managementAccessToken ?? undefined;
|
||||||
|
|
||||||
const createMutation = useMutation({
|
const createMutation = useMutation({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (!props.managementAccessToken) {
|
if (!managementAccessToken) {
|
||||||
throw new Error("No management access token");
|
throw new Error("No management access token");
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await createSolanaAccount({
|
const result = await createSolanaAccount({
|
||||||
managementAccessToken: props.managementAccessToken,
|
managementAccessToken: managementAccessToken,
|
||||||
label: label.trim(),
|
label: label.trim(),
|
||||||
projectId: props.project.id,
|
projectId: props.project.id,
|
||||||
teamId: props.project.teamId,
|
teamId: props.project.teamId,
|
||||||
@@ -67,8 +70,8 @@ export function CreateSolanaWallet(props: {
|
|||||||
<Dialog open={open} onOpenChange={setOpen}>
|
<Dialog open={open} onOpenChange={setOpen}>
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="default"
|
variant="outline"
|
||||||
className="gap-2 rounded-full bg-foreground hover:bg-foreground/90"
|
className="gap-1.5 rounded-full bg-background text-foreground"
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
>
|
>
|
||||||
<PlusIcon className="size-4" />
|
<PlusIcon className="size-4" />
|
||||||
|
|||||||
+13
-7
@@ -1,3 +1,4 @@
|
|||||||
|
import { UnderlineLink } from "@workspace/ui/components/UnderlineLink";
|
||||||
import { InfoIcon } from "lucide-react";
|
import { InfoIcon } from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import type { Project } from "@/api/project/projects";
|
import type { Project } from "@/api/project/projects";
|
||||||
@@ -53,15 +54,20 @@ export function KeyManagement({
|
|||||||
{isManagedVault && (
|
{isManagedVault && (
|
||||||
<div className="flex flex-col gap-6 overflow-hidden rounded-lg border border-border bg-card">
|
<div className="flex flex-col gap-6 overflow-hidden rounded-lg border border-border bg-card">
|
||||||
<div className="flex flex-col p-6">
|
<div className="flex flex-col p-6">
|
||||||
<h2 className="font-semibold text-xl tracking-tight">
|
<h2 className="font-semibold text-xl tracking-tight mb-1">
|
||||||
Managed Vault
|
Managed Vault
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-muted-foreground text-sm">
|
<p className="text-muted-foreground text-sm max-w-3xl">
|
||||||
Your vault is currently managed by Thirdweb so you can access it
|
If you choose to eject and manage your own vault keys, you'll need
|
||||||
via you project secret key. You can eject and manage your own
|
to provide your vault access token alongside your project secret
|
||||||
vault keys at any time. Doing so means you'll need to pass your
|
key when using the Transactions API.{" "}
|
||||||
own vault access token to the transactions API additionally to
|
<UnderlineLink
|
||||||
your project secret key.
|
href="https://portal.thirdweb.com/vault"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
Learn more about Vault
|
||||||
|
</UnderlineLink>
|
||||||
</p>
|
</p>
|
||||||
<div className="h-4" />
|
<div className="h-4" />
|
||||||
<div className="flex flex-col gap-3 lg:flex-row lg:items-center">
|
<div className="flex flex-col gap-3 lg:flex-row lg:items-center">
|
||||||
|
|||||||
+6
-53
@@ -1,58 +1,11 @@
|
|||||||
import { LockIcon } from "lucide-react";
|
import { redirect } from "next/navigation";
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
import { getAuthToken } from "@/api/auth-token";
|
|
||||||
import { getProject } from "@/api/project/projects";
|
|
||||||
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { KeyManagement } from "./components/key-management";
|
|
||||||
|
|
||||||
export default async function VaultPage(props: {
|
// Redirect old Vault page to new Server Wallets Configuration
|
||||||
|
export default async function Page(props: {
|
||||||
params: Promise<{ team_slug: string; project_slug: string }>;
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
}) {
|
}) {
|
||||||
const { team_slug, project_slug } = await props.params;
|
const params = await props.params;
|
||||||
const [authToken, project] = await Promise.all([
|
redirect(
|
||||||
getAuthToken(),
|
`/team/${params.team_slug}/${params.project_slug}/wallets/server-wallets/configuration`,
|
||||||
getProject(team_slug, project_slug),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!project || !authToken) {
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
const projectEngineCloudService = project.services.find(
|
|
||||||
(service) => service.name === "engineCloud",
|
|
||||||
);
|
|
||||||
|
|
||||||
const maskedAdminKey = projectEngineCloudService?.maskedAdminKey;
|
|
||||||
const isManagedVault = !!projectEngineCloudService?.encryptedAdminKey;
|
|
||||||
|
|
||||||
const client = getClientThirdwebClient({
|
|
||||||
jwt: authToken,
|
|
||||||
teamId: project.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ProjectPage
|
|
||||||
header={{
|
|
||||||
client,
|
|
||||||
title: "Vault",
|
|
||||||
icon: LockIcon,
|
|
||||||
description:
|
|
||||||
"Secure, non-custodial key management system for your server wallets.",
|
|
||||||
actions: null,
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
type: "docs",
|
|
||||||
href: "https://portal.thirdweb.com/vault",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<KeyManagement
|
|
||||||
maskedAdminKey={maskedAdminKey ?? undefined}
|
|
||||||
isManagedVault={isManagedVault}
|
|
||||||
project={project}
|
|
||||||
/>
|
|
||||||
</ProjectPage>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -19,7 +19,7 @@ export const Variants: Story = {
|
|||||||
function Component() {
|
function Component() {
|
||||||
const title = "This is Title";
|
const title = "This is Title";
|
||||||
const description =
|
const description =
|
||||||
"This is an example of a description about in-app wallet usage chart";
|
"This is an example of a description about user wallet usage chart";
|
||||||
return (
|
return (
|
||||||
<div className="container flex max-w-6xl flex-col gap-10 py-10">
|
<div className="container flex max-w-6xl flex-col gap-10 py-10">
|
||||||
<BadgeContainer label="30 days">
|
<BadgeContainer label="30 days">
|
||||||
@@ -87,6 +87,7 @@ const authMethodsToPickFrom: InAppWalletAuth[] = [
|
|||||||
"line",
|
"line",
|
||||||
"x",
|
"x",
|
||||||
"tiktok",
|
"tiktok",
|
||||||
|
"epic",
|
||||||
"coinbase",
|
"coinbase",
|
||||||
"farcaster",
|
"farcaster",
|
||||||
"telegram",
|
"telegram",
|
||||||
|
|||||||
+1
-1
@@ -21,7 +21,7 @@ function InAppWalletAnalyticsUI({
|
|||||||
return (
|
return (
|
||||||
<InAppWalletUsersChartCardUI
|
<InAppWalletUsersChartCardUI
|
||||||
title="Unique Users"
|
title="Unique Users"
|
||||||
description="The total number of active in-app wallet users on your project."
|
description="The total number of active user wallet users on your project."
|
||||||
inAppWalletStats={stats || []}
|
inAppWalletStats={stats || []}
|
||||||
isPending={isPending}
|
isPending={isPending}
|
||||||
/>
|
/>
|
||||||
|
|||||||
-226
@@ -1,226 +0,0 @@
|
|||||||
import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk";
|
|
||||||
import { redirect } from "next/navigation";
|
|
||||||
import { ResponsiveSearchParamsProvider } from "responsive-rsc";
|
|
||||||
import { getAuthToken } from "@/api/auth-token";
|
|
||||||
import { getProject } from "@/api/project/projects";
|
|
||||||
import type { DurationId } from "@/components/analytics/date-range-selector";
|
|
||||||
import { ResponsiveTimeFilters } from "@/components/analytics/responsive-time-filters";
|
|
||||||
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
|
||||||
import { InAppWalletUsersPageContent } from "@/components/in-app-wallet-users-content/in-app-wallet-users-content";
|
|
||||||
import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs";
|
|
||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
|
||||||
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
|
||||||
import { getFiltersFromSearchParams } from "@/lib/time";
|
|
||||||
import { loginRedirect } from "@/utils/redirects";
|
|
||||||
import { ServerWalletsTable } from "../transactions/components/server-wallets-table.client";
|
|
||||||
import type { Wallet } from "../transactions/server-wallets/wallet-table/types";
|
|
||||||
import { listSolanaAccounts } from "../transactions/solana-wallets/lib/vault.client";
|
|
||||||
import type { SolanaWallet } from "../transactions/solana-wallets/wallet-table/types";
|
|
||||||
import { InAppWalletAnalytics } from "./analytics/chart";
|
|
||||||
import { InAppWalletsSummary } from "./analytics/chart/Summary";
|
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
|
||||||
|
|
||||||
export default async function Page(props: {
|
|
||||||
params: Promise<{ team_slug: string; project_slug: string }>;
|
|
||||||
searchParams: Promise<{
|
|
||||||
from?: string;
|
|
||||||
to?: string;
|
|
||||||
type?: string;
|
|
||||||
interval?: string;
|
|
||||||
page?: string;
|
|
||||||
solana_page?: string;
|
|
||||||
}>;
|
|
||||||
}) {
|
|
||||||
const [searchParams, params] = await Promise.all([
|
|
||||||
props.searchParams,
|
|
||||||
props.params,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const authToken = await getAuthToken();
|
|
||||||
if (!authToken) {
|
|
||||||
loginRedirect(`/team/${params.team_slug}/${params.project_slug}/wallets`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const defaultRange: DurationId = "last-30";
|
|
||||||
const { range, interval } = getFiltersFromSearchParams({
|
|
||||||
defaultRange,
|
|
||||||
from: searchParams.from,
|
|
||||||
interval: searchParams.interval,
|
|
||||||
to: searchParams.to,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [vaultClient, project] = await Promise.all([
|
|
||||||
createVaultClient({
|
|
||||||
baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL,
|
|
||||||
}).catch(() => undefined),
|
|
||||||
getProject(params.team_slug, params.project_slug),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!project) {
|
|
||||||
redirect(`/team/${params.team_slug}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const projectEngineCloudService = project.services.find(
|
|
||||||
(service) => service.name === "engineCloud",
|
|
||||||
);
|
|
||||||
|
|
||||||
const managementAccessToken =
|
|
||||||
projectEngineCloudService?.managementAccessToken;
|
|
||||||
|
|
||||||
// Fetch server wallets with pagination (5 per page)
|
|
||||||
const pageSize = 5;
|
|
||||||
const currentPage = Number.parseInt(searchParams.page ?? "1");
|
|
||||||
const solanCurrentPage = Number.parseInt(searchParams.solana_page ?? "1");
|
|
||||||
|
|
||||||
// Fetch EVM wallets
|
|
||||||
const eoas =
|
|
||||||
vaultClient && managementAccessToken
|
|
||||||
? await listEoas({
|
|
||||||
client: vaultClient,
|
|
||||||
request: {
|
|
||||||
auth: {
|
|
||||||
accessToken: managementAccessToken,
|
|
||||||
},
|
|
||||||
options: {
|
|
||||||
page: currentPage - 1,
|
|
||||||
// @ts-expect-error - TODO: fix this
|
|
||||||
page_size: pageSize,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
: { data: { items: [], totalRecords: 0 }, error: null, success: true };
|
|
||||||
|
|
||||||
// Fetch Solana wallets
|
|
||||||
let solanaAccounts: {
|
|
||||||
data: { items: SolanaWallet[]; totalRecords: number };
|
|
||||||
error: Error | null;
|
|
||||||
success: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (managementAccessToken) {
|
|
||||||
solanaAccounts = await listSolanaAccounts({
|
|
||||||
managementAccessToken,
|
|
||||||
page: solanCurrentPage,
|
|
||||||
limit: pageSize,
|
|
||||||
projectId: project.id,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
solanaAccounts = {
|
|
||||||
data: { items: [], totalRecords: 0 },
|
|
||||||
error: null,
|
|
||||||
success: true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for Solana permission errors
|
|
||||||
const isSolanaPermissionError = solanaAccounts.error?.message?.includes(
|
|
||||||
"AUTH_INSUFFICIENT_SCOPE",
|
|
||||||
);
|
|
||||||
|
|
||||||
const client = getClientThirdwebClient({
|
|
||||||
jwt: authToken,
|
|
||||||
teamId: project.teamId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ResponsiveSearchParamsProvider value={searchParams}>
|
|
||||||
<ProjectPage
|
|
||||||
header={{
|
|
||||||
icon: WalletProductIcon,
|
|
||||||
client,
|
|
||||||
title: "Wallets",
|
|
||||||
description: (
|
|
||||||
<>
|
|
||||||
Create wallets for your users with flexible authentication
|
|
||||||
options.
|
|
||||||
<br className="max-sm:hidden" /> Choose from email/phone
|
|
||||||
verification, OAuth, passkeys, or external wallet connections
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
actions: null,
|
|
||||||
settings: {
|
|
||||||
href: `/team/${params.team_slug}/${params.project_slug}/settings/wallets`,
|
|
||||||
},
|
|
||||||
links: [
|
|
||||||
{
|
|
||||||
type: "docs",
|
|
||||||
href: "https://portal.thirdweb.com/wallets",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "playground",
|
|
||||||
href: "https://playground.thirdweb.com/wallets/in-app-wallet",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: "api",
|
|
||||||
href: "https://api.thirdweb.com/reference#tag/wallets",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className="flex flex-col gap-4 md:gap-6">
|
|
||||||
<ResponsiveTimeFilters defaultRange={defaultRange} />
|
|
||||||
<InAppWalletsSummary
|
|
||||||
projectId={project.id}
|
|
||||||
teamId={project.teamId}
|
|
||||||
authToken={authToken}
|
|
||||||
range={range}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<InAppWalletAnalytics
|
|
||||||
interval={interval}
|
|
||||||
projectId={project.id}
|
|
||||||
range={range}
|
|
||||||
teamId={project.teamId}
|
|
||||||
authToken={authToken}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{/* Server Wallets Section (EVM + Solana) */}
|
|
||||||
<div className="flex flex-col gap-4">
|
|
||||||
{eoas.error ? (
|
|
||||||
<div className="rounded-xl border border-destructive/50 bg-destructive/10 p-4">
|
|
||||||
<p className="text-destructive font-semibold mb-2">
|
|
||||||
EVM Wallet Error
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
{eoas.error.message || "Failed to load EVM wallets"}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<ServerWalletsTable
|
|
||||||
client={client}
|
|
||||||
evmCurrentPage={currentPage}
|
|
||||||
evmTotalPages={Math.ceil(eoas.data.totalRecords / pageSize)}
|
|
||||||
evmTotalRecords={eoas.data.totalRecords}
|
|
||||||
evmWallets={eoas.data.items as Wallet[]}
|
|
||||||
managementAccessToken={managementAccessToken ?? undefined}
|
|
||||||
project={project}
|
|
||||||
solanaCurrentPage={solanCurrentPage}
|
|
||||||
solanaTotalPages={Math.ceil(
|
|
||||||
solanaAccounts.data.totalRecords / pageSize,
|
|
||||||
)}
|
|
||||||
solanaTotalRecords={solanaAccounts.data.totalRecords}
|
|
||||||
solanaWallets={solanaAccounts.data.items}
|
|
||||||
teamSlug={params.team_slug}
|
|
||||||
solanaPermissionError={isSolanaPermissionError || false}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* User Wallets Section */}
|
|
||||||
<div className="flex flex-col gap-4">
|
|
||||||
<h2 className="font-semibold text-2xl tracking-tight">
|
|
||||||
User wallets
|
|
||||||
</h2>
|
|
||||||
<InAppWalletUsersPageContent
|
|
||||||
authToken={authToken}
|
|
||||||
client={client}
|
|
||||||
projectClientId={project.publishableKey}
|
|
||||||
teamId={project.teamId}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ProjectPage>
|
|
||||||
</ResponsiveSearchParamsProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import { KeyManagement } from "../../../vault/components/key-management";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const { team_slug, project_slug } = await props.params;
|
||||||
|
const [authToken, project] = await Promise.all([
|
||||||
|
getAuthToken(),
|
||||||
|
getProject(team_slug, project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${team_slug}/${project_slug}/wallets/server-wallets/configuration`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectEngineCloudService = project.services.find(
|
||||||
|
(service) => service.name === "engineCloud",
|
||||||
|
);
|
||||||
|
|
||||||
|
const maskedAdminKey = projectEngineCloudService?.maskedAdminKey;
|
||||||
|
const isManagedVault = !!projectEngineCloudService?.encryptedAdminKey;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<KeyManagement
|
||||||
|
maskedAdminKey={maskedAdminKey ?? undefined}
|
||||||
|
isManagedVault={isManagedVault}
|
||||||
|
project={project}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
|
||||||
|
export default async function Layout(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await props.params;
|
||||||
|
const basePath = `/team/${params.team_slug}/${params.project_slug}/wallets/server-wallets`;
|
||||||
|
|
||||||
|
const [authToken, project] = await Promise.all([
|
||||||
|
getAuthToken(),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProjectPage
|
||||||
|
header={{
|
||||||
|
icon: WalletProductIcon,
|
||||||
|
title: "Server Wallets",
|
||||||
|
description:
|
||||||
|
"Wallet used to relay transactions from your backend at scale",
|
||||||
|
actions: null,
|
||||||
|
client,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
type: "docs",
|
||||||
|
href: "https://portal.thirdweb.com/wallets/server",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
name: "Overview",
|
||||||
|
path: `${basePath}`,
|
||||||
|
exactMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Configuration",
|
||||||
|
path: `${basePath}/configuration`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</ProjectPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
import { createVaultClient, listEoas } from "@thirdweb-dev/vault-sdk";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { NEXT_PUBLIC_THIRDWEB_VAULT_URL } from "@/constants/public-envs";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import { TransactionsAnalyticsPageContent } from "../../transactions/analytics/analytics-page";
|
||||||
|
import { ServerWalletsTable } from "../../transactions/components/server-wallets-table.client";
|
||||||
|
import type { Wallet } from "../../transactions/server-wallets/wallet-table/types";
|
||||||
|
import { listSolanaAccounts } from "../../transactions/solana-wallets/lib/vault.client";
|
||||||
|
import type { SolanaWallet } from "../../transactions/solana-wallets/wallet-table/types";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
searchParams: Promise<{
|
||||||
|
from?: string | string[];
|
||||||
|
to?: string | string[];
|
||||||
|
interval?: string | string[];
|
||||||
|
testTxWithWallet?: string | string[];
|
||||||
|
testSolanaTxWithWallet?: string | string[];
|
||||||
|
page?: string;
|
||||||
|
solana_page?: string;
|
||||||
|
}>;
|
||||||
|
}) {
|
||||||
|
const [params, searchParams, authToken] = await Promise.all([
|
||||||
|
props.params,
|
||||||
|
props.searchParams,
|
||||||
|
getAuthToken(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${params.team_slug}/${params.project_slug}/wallets/server-wallets`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [vaultClient, project] = await Promise.all([
|
||||||
|
createVaultClient({
|
||||||
|
baseUrl: NEXT_PUBLIC_THIRDWEB_VAULT_URL,
|
||||||
|
}).catch(() => undefined),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!vaultClient) {
|
||||||
|
return <div>Error: Failed to connect to Vault</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const projectEngineCloudService = project.services.find(
|
||||||
|
(service) => service.name === "engineCloud",
|
||||||
|
);
|
||||||
|
|
||||||
|
const managementAccessToken =
|
||||||
|
projectEngineCloudService?.managementAccessToken;
|
||||||
|
const isManagedVault = !!projectEngineCloudService?.encryptedAdminKey;
|
||||||
|
|
||||||
|
const pageSize = 10;
|
||||||
|
const currentPage = Number.parseInt(searchParams.page ?? "1");
|
||||||
|
const solanaCurrentPage = Number.parseInt(searchParams.solana_page ?? "1");
|
||||||
|
|
||||||
|
const eoas = managementAccessToken
|
||||||
|
? await listEoas({
|
||||||
|
client: vaultClient,
|
||||||
|
request: {
|
||||||
|
auth: {
|
||||||
|
accessToken: managementAccessToken,
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
page: currentPage - 1,
|
||||||
|
// @ts-expect-error - TODO: fix this
|
||||||
|
page_size: pageSize,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
: { data: { items: [], totalRecords: 0 }, error: null, success: true };
|
||||||
|
|
||||||
|
const wallets = (eoas.data?.items as Wallet[] | undefined) ?? [];
|
||||||
|
|
||||||
|
let solanaAccounts: {
|
||||||
|
data: { items: SolanaWallet[]; totalRecords: number };
|
||||||
|
error: Error | null;
|
||||||
|
success: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (managementAccessToken) {
|
||||||
|
solanaAccounts = await listSolanaAccounts({
|
||||||
|
managementAccessToken,
|
||||||
|
page: solanaCurrentPage,
|
||||||
|
limit: pageSize,
|
||||||
|
projectId: project.id,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
solanaAccounts = {
|
||||||
|
data: { items: [], totalRecords: 0 },
|
||||||
|
error: null,
|
||||||
|
success: true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const isSolanaPermissionError =
|
||||||
|
solanaAccounts.error?.message.includes("AUTH_INSUFFICIENT_SCOPE") ?? false;
|
||||||
|
|
||||||
|
const testTxWithWallet =
|
||||||
|
typeof searchParams.testTxWithWallet === "string"
|
||||||
|
? searchParams.testTxWithWallet
|
||||||
|
: undefined;
|
||||||
|
const testSolanaTxWithWallet =
|
||||||
|
typeof searchParams.testSolanaTxWithWallet === "string"
|
||||||
|
? searchParams.testSolanaTxWithWallet
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const hasTransactions = wallets.length > 0;
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-10">
|
||||||
|
<TransactionsAnalyticsPageContent
|
||||||
|
authToken={authToken}
|
||||||
|
client={client}
|
||||||
|
isManagedVault={isManagedVault}
|
||||||
|
project={project}
|
||||||
|
showAnalytics={
|
||||||
|
hasTransactions && !testTxWithWallet && !testSolanaTxWithWallet
|
||||||
|
}
|
||||||
|
solanaWallets={solanaAccounts.data.items}
|
||||||
|
teamId={project.teamId}
|
||||||
|
teamSlug={params.team_slug}
|
||||||
|
testSolanaTxWithWallet={testSolanaTxWithWallet}
|
||||||
|
testTxWithWallet={testTxWithWallet}
|
||||||
|
wallets={wallets}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{eoas.error ? (
|
||||||
|
<div className="rounded-xl border border-destructive/50 bg-destructive/10 p-4">
|
||||||
|
<p className="text-destructive font-semibold mb-2">
|
||||||
|
EVM Wallet Error
|
||||||
|
</p>
|
||||||
|
<p className="text-sm text-muted-foreground">{eoas.error.message}</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ServerWalletsTable
|
||||||
|
client={client}
|
||||||
|
evmCurrentPage={currentPage}
|
||||||
|
evmTotalPages={Math.ceil(eoas.data.totalRecords / pageSize)}
|
||||||
|
evmTotalRecords={eoas.data.totalRecords}
|
||||||
|
evmWallets={wallets}
|
||||||
|
pageSize={pageSize}
|
||||||
|
project={project}
|
||||||
|
solanaCurrentPage={solanaCurrentPage}
|
||||||
|
solanaTotalPages={Math.ceil(
|
||||||
|
solanaAccounts.data.totalRecords / pageSize,
|
||||||
|
)}
|
||||||
|
solanaTotalRecords={solanaAccounts.data.totalRecords}
|
||||||
|
solanaWallets={solanaAccounts.data.items}
|
||||||
|
teamSlug={params.team_slug}
|
||||||
|
solanaPermissionError={isSolanaPermissionError}
|
||||||
|
authToken={authToken}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
import { CircleAlertIcon } from "lucide-react";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { getTeamBySlug } from "@/api/team/get-team";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
|
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { getValidTeamPlan } from "@/utils/getValidTeamPlan";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import { DefaultFactoriesSection } from "../../../account-abstraction/factories/AccountFactories";
|
||||||
|
import { YourFactoriesSection } from "../../../account-abstraction/factories/AccountFactories/your-factories";
|
||||||
|
import { AccountAbstractionSettingsPage } from "../../../account-abstraction/settings/SponsorshipPolicies";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const { team_slug, project_slug } = await props.params;
|
||||||
|
|
||||||
|
const [team, project, authToken] = await Promise.all([
|
||||||
|
getTeamBySlug(team_slug),
|
||||||
|
getProject(team_slug, project_slug),
|
||||||
|
getAuthToken(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${team_slug}/${project_slug}/wallets/sponsored-gas/configuration`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!team) {
|
||||||
|
redirect("/team");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: team.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
const bundlerService = project.services.find((s) => s.name === "bundler");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
{!bundlerService ? (
|
||||||
|
<Alert variant="warning">
|
||||||
|
<CircleAlertIcon className="size-5" />
|
||||||
|
<AlertTitle>Account Abstraction service is disabled</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
Enable Account Abstraction service in{" "}
|
||||||
|
<UnderlineLink href={`/team/${team_slug}/${project_slug}/settings`}>
|
||||||
|
project settings
|
||||||
|
</UnderlineLink>{" "}
|
||||||
|
to configure the sponsorship rules
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<AccountAbstractionSettingsPage
|
||||||
|
bundlerService={bundlerService}
|
||||||
|
client={client}
|
||||||
|
project={project}
|
||||||
|
teamId={team.id}
|
||||||
|
teamSlug={team.slug}
|
||||||
|
validTeamPlan={getValidTeamPlan(team)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DefaultFactoriesSection />
|
||||||
|
<YourFactoriesSection
|
||||||
|
authToken={authToken}
|
||||||
|
clientThirdwebClient={client}
|
||||||
|
projectId={project.id}
|
||||||
|
projectSlug={project.slug}
|
||||||
|
teamId={team.id}
|
||||||
|
teamSlug={team.slug}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
|
||||||
|
export default async function Layout(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await props.params;
|
||||||
|
const basePath = `/team/${params.team_slug}/${params.project_slug}/wallets/sponsored-gas`;
|
||||||
|
|
||||||
|
const [authToken, project] = await Promise.all([
|
||||||
|
getAuthToken(),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProjectPage
|
||||||
|
header={{
|
||||||
|
icon: WalletProductIcon,
|
||||||
|
title: "Gas Sponsorship",
|
||||||
|
description:
|
||||||
|
"Cover gas fees on behalf of your users for a seamless onboarding experience",
|
||||||
|
actions: null,
|
||||||
|
client,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
type: "docs",
|
||||||
|
href: "https://portal.thirdweb.com/transactions/sponsor",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
name: "Overview",
|
||||||
|
path: `${basePath}`,
|
||||||
|
exactMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Configuration",
|
||||||
|
path: `${basePath}/configuration`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</ProjectPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import type { SearchParams } from "nuqs/server";
|
||||||
|
import { getUserOpUsage } from "@/api/analytics";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { getTeamBySlug } from "@/api/team/get-team";
|
||||||
|
import {
|
||||||
|
getLastNDaysRange,
|
||||||
|
type Range,
|
||||||
|
} from "@/components/analytics/date-range-selector";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import { AccountAbstractionSummary } from "../../account-abstraction/AccountAbstractionAnalytics/AccountAbstractionSummary";
|
||||||
|
import { SmartWalletsBillingAlert } from "../../account-abstraction/Alerts";
|
||||||
|
import { AccountAbstractionAnalytics } from "../../account-abstraction/aa-analytics";
|
||||||
|
import { searchParamLoader } from "../../account-abstraction/search-params";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
searchParams: Promise<SearchParams>;
|
||||||
|
}) {
|
||||||
|
const [params, searchParams, authToken] = await Promise.all([
|
||||||
|
props.params,
|
||||||
|
searchParamLoader(props.searchParams),
|
||||||
|
getAuthToken(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${params.team_slug}/${params.project_slug}/wallets/sponsored-gas`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [team, project] = await Promise.all([
|
||||||
|
getTeamBySlug(params.team_slug),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!team) {
|
||||||
|
redirect("/team");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const interval = searchParams.interval ?? "week";
|
||||||
|
const rangeType = searchParams.range || "last-120";
|
||||||
|
|
||||||
|
const range: Range = {
|
||||||
|
from:
|
||||||
|
rangeType === "custom"
|
||||||
|
? searchParams.from
|
||||||
|
: getLastNDaysRange(rangeType).from,
|
||||||
|
to:
|
||||||
|
rangeType === "custom"
|
||||||
|
? searchParams.to
|
||||||
|
: getLastNDaysRange(rangeType).to,
|
||||||
|
type: rangeType,
|
||||||
|
};
|
||||||
|
|
||||||
|
const userOpStats = await getUserOpUsage(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: interval,
|
||||||
|
projectId: project.id,
|
||||||
|
teamId: project.teamId,
|
||||||
|
to: range.to,
|
||||||
|
},
|
||||||
|
authToken,
|
||||||
|
);
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
const isBundlerServiceEnabled = !!project.services.find(
|
||||||
|
(s) => s.name === "bundler",
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasSmartWalletsWithoutBilling =
|
||||||
|
isBundlerServiceEnabled &&
|
||||||
|
team.billingStatus !== "validPayment" &&
|
||||||
|
team.billingStatus !== "pastDue";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{hasSmartWalletsWithoutBilling && (
|
||||||
|
<>
|
||||||
|
<SmartWalletsBillingAlert teamSlug={params.team_slug} />
|
||||||
|
<div className="h-10" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<div className="flex grow flex-col gap-10">
|
||||||
|
<AccountAbstractionSummary
|
||||||
|
projectId={project.id}
|
||||||
|
teamId={project.teamId}
|
||||||
|
authToken={authToken}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<AccountAbstractionAnalytics
|
||||||
|
client={client}
|
||||||
|
projectId={project.id}
|
||||||
|
teamId={project.teamId}
|
||||||
|
teamSlug={params.team_slug}
|
||||||
|
userOpStats={userOpStats}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
import "server-only";
|
||||||
|
import { NEXT_PUBLIC_THIRDWEB_API_HOST } from "@/constants/public-envs";
|
||||||
|
import { API_SERVER_SECRET } from "@/constants/server-envs";
|
||||||
|
|
||||||
|
export type SMSCountryTiers = {
|
||||||
|
tier1: string[];
|
||||||
|
tier2: string[];
|
||||||
|
tier3: string[];
|
||||||
|
tier4: string[];
|
||||||
|
tier5: string[];
|
||||||
|
tier6: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function getSMSCountryTiers() {
|
||||||
|
if (!API_SERVER_SECRET) {
|
||||||
|
throw new Error("API_SERVER_SECRET is not set");
|
||||||
|
}
|
||||||
|
const res = await fetch(
|
||||||
|
`${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/sms/list-country-tiers`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"x-service-api-key": API_SERVER_SECRET,
|
||||||
|
},
|
||||||
|
next: {
|
||||||
|
revalidate: 15 * 60, //15 minutes
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
console.error(
|
||||||
|
"Failed to fetch sms country tiers",
|
||||||
|
res.status,
|
||||||
|
res.statusText,
|
||||||
|
);
|
||||||
|
res.body?.cancel();
|
||||||
|
return {
|
||||||
|
tier1: [],
|
||||||
|
tier2: [],
|
||||||
|
tier3: [],
|
||||||
|
tier4: [],
|
||||||
|
tier5: [],
|
||||||
|
tier6: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return (await res.json()).data as SMSCountryTiers;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to parse sms country tiers", e);
|
||||||
|
return {
|
||||||
|
tier1: [],
|
||||||
|
tier2: [],
|
||||||
|
tier3: [],
|
||||||
|
tier4: [],
|
||||||
|
tier5: [],
|
||||||
|
tier6: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
+891
@@ -0,0 +1,891 @@
|
|||||||
|
"use client";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { useMutation } from "@tanstack/react-query";
|
||||||
|
import type { ProjectEmbeddedWalletsService } from "@thirdweb-dev/service-utils";
|
||||||
|
import { CircleAlertIcon, PlusIcon, Trash2Icon } from "lucide-react";
|
||||||
|
import type React from "react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { type UseFormReturn, useFieldArray, useForm } from "react-hook-form";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
import type { ThirdwebClient } from "thirdweb";
|
||||||
|
import { upload } from "thirdweb/storage";
|
||||||
|
import type { Project } from "@/api/project/projects";
|
||||||
|
import type { Team } from "@/api/team/get-team";
|
||||||
|
import { FileInput } from "@/components/blocks/FileInput";
|
||||||
|
import { GatedSwitch } from "@/components/blocks/GatedSwitch";
|
||||||
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { DynamicHeight } from "@/components/ui/DynamicHeight";
|
||||||
|
import {
|
||||||
|
Form,
|
||||||
|
FormControl,
|
||||||
|
FormDescription,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from "@/components/ui/form";
|
||||||
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label";
|
||||||
|
import { Spinner } from "@/components/ui/Spinner";
|
||||||
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
import { UnderlineLink } from "@/components/ui/UnderlineLink";
|
||||||
|
import { planToTierRecordForGating } from "@/constants/planToTierRecord";
|
||||||
|
import { updateProjectClient } from "@/hooks/useApi";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import {
|
||||||
|
type ApiKeyEmbeddedWalletsValidationSchema,
|
||||||
|
apiKeyEmbeddedWalletsValidationSchema,
|
||||||
|
} from "@/schema/validations";
|
||||||
|
import { resolveSchemeWithErrorHandler } from "@/utils/resolveSchemeWithErrorHandler";
|
||||||
|
import { toArrFromList } from "@/utils/string";
|
||||||
|
import type { SMSCountryTiers } from "../api/sms";
|
||||||
|
import { CountrySelector } from "./sms-country-select";
|
||||||
|
|
||||||
|
type InAppWalletSettingsPageProps = {
|
||||||
|
project: Project;
|
||||||
|
teamId: string;
|
||||||
|
teamSlug: string;
|
||||||
|
teamPlan: Team["billingPlan"];
|
||||||
|
smsCountryTiers: SMSCountryTiers;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
type UpdateAPIKeyTrackingData = {
|
||||||
|
hasCustomBranding: boolean;
|
||||||
|
hasCustomJwt: boolean;
|
||||||
|
hasCustomAuthEndpoint: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function InAppWalletSettingsPage(props: InAppWalletSettingsPageProps) {
|
||||||
|
const updateProject = useMutation({
|
||||||
|
mutationFn: async (projectValues: Partial<Project>) => {
|
||||||
|
await updateProjectClient(
|
||||||
|
{
|
||||||
|
projectId: props.project.id,
|
||||||
|
teamId: props.teamId,
|
||||||
|
},
|
||||||
|
projectValues,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleUpdateProject(projectValues: Partial<Project>) {
|
||||||
|
updateProject.mutate(projectValues, {
|
||||||
|
onError: (err) => {
|
||||||
|
toast.error("Failed to update an API Key");
|
||||||
|
console.error(err);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success("Configuration updated successfully");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InAppWalletSettingsPageUI
|
||||||
|
{...props}
|
||||||
|
isUpdating={updateProject.isPending}
|
||||||
|
smsCountryTiers={props.smsCountryTiers}
|
||||||
|
updateApiKey={handleUpdateProject}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const InAppWalletSettingsPageUI: React.FC<
|
||||||
|
InAppWalletSettingsPageProps & {
|
||||||
|
updateApiKey: (
|
||||||
|
projectValues: Partial<Project>,
|
||||||
|
trackingData: UpdateAPIKeyTrackingData,
|
||||||
|
) => void;
|
||||||
|
isUpdating: boolean;
|
||||||
|
smsCountryTiers: SMSCountryTiers;
|
||||||
|
}
|
||||||
|
> = (props) => {
|
||||||
|
const embeddedWalletService = props.project.services.find(
|
||||||
|
(service) => service.name === "embeddedWallets",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!embeddedWalletService) {
|
||||||
|
return (
|
||||||
|
<Alert variant="warning">
|
||||||
|
<CircleAlertIcon className="size-5" />
|
||||||
|
<AlertTitle>Wallets service is disabled</AlertTitle>
|
||||||
|
<AlertDescription>
|
||||||
|
Enable Wallets service in the{" "}
|
||||||
|
<UnderlineLink
|
||||||
|
href={`/team/${props.teamSlug}/${props.project.slug}/settings`}
|
||||||
|
>
|
||||||
|
project settings
|
||||||
|
</UnderlineLink>{" "}
|
||||||
|
to configure settings
|
||||||
|
</AlertDescription>
|
||||||
|
</Alert>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<InAppWalletSettingsUI
|
||||||
|
{...props}
|
||||||
|
client={props.client}
|
||||||
|
embeddedWalletService={embeddedWalletService}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const InAppWalletSettingsUI: React.FC<
|
||||||
|
InAppWalletSettingsPageProps & {
|
||||||
|
updateApiKey: (
|
||||||
|
projectValues: Partial<Project>,
|
||||||
|
trackingData: UpdateAPIKeyTrackingData,
|
||||||
|
) => void;
|
||||||
|
isUpdating: boolean;
|
||||||
|
embeddedWalletService: ProjectEmbeddedWalletsService;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
}
|
||||||
|
> = (props) => {
|
||||||
|
const services = props.project.services;
|
||||||
|
|
||||||
|
const config = props.embeddedWalletService;
|
||||||
|
|
||||||
|
const hasCustomBranding =
|
||||||
|
!!config.applicationImageUrl?.length || !!config.applicationName?.length;
|
||||||
|
|
||||||
|
const authRequiredPlan = "growth";
|
||||||
|
const brandingRequiredPlan = "starter";
|
||||||
|
|
||||||
|
// growth or higher plan required
|
||||||
|
const canEditSmsCountries =
|
||||||
|
planToTierRecordForGating[props.teamPlan] >=
|
||||||
|
planToTierRecordForGating[authRequiredPlan];
|
||||||
|
|
||||||
|
const form = useForm<ApiKeyEmbeddedWalletsValidationSchema>({
|
||||||
|
resolver: zodResolver(apiKeyEmbeddedWalletsValidationSchema),
|
||||||
|
values: {
|
||||||
|
customAuthEndpoint: config.customAuthEndpoint || undefined,
|
||||||
|
customAuthentication: config.customAuthentication || undefined,
|
||||||
|
...(hasCustomBranding
|
||||||
|
? {
|
||||||
|
branding: {
|
||||||
|
applicationImageUrl: config.applicationImageUrl || undefined,
|
||||||
|
applicationName: config.applicationName || undefined,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined),
|
||||||
|
redirectUrls: (config.redirectUrls || []).join("\n"),
|
||||||
|
smsEnabledCountryISOs: config.smsEnabledCountryISOs
|
||||||
|
? config.smsEnabledCountryISOs
|
||||||
|
: canEditSmsCountries
|
||||||
|
? ["US", "CA"]
|
||||||
|
: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleSubmit = form.handleSubmit((values) => {
|
||||||
|
const { customAuthentication, customAuthEndpoint, branding, redirectUrls } =
|
||||||
|
values;
|
||||||
|
|
||||||
|
if (
|
||||||
|
customAuthentication &&
|
||||||
|
(!customAuthentication.aud.length || !customAuthentication.jwksUri.length)
|
||||||
|
) {
|
||||||
|
return toast.error("Custom JSON Web Token configuration is invalid", {
|
||||||
|
description:
|
||||||
|
"To use user wallets with Custom JSON Web Token, provide JWKS URI and AUD.",
|
||||||
|
dismissible: true,
|
||||||
|
duration: 9000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customAuthEndpoint && !customAuthEndpoint.authEndpoint.length) {
|
||||||
|
return toast.error(
|
||||||
|
"Custom Authentication Endpoint configuration is invalid",
|
||||||
|
{
|
||||||
|
description:
|
||||||
|
"To use user wallets with Custom Authentication Endpoint, provide a valid URL.",
|
||||||
|
dismissible: true,
|
||||||
|
duration: 9000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const newServices = services.map((service) => {
|
||||||
|
if (service.name !== "embeddedWallets") {
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...service,
|
||||||
|
applicationImageUrl: branding?.applicationImageUrl,
|
||||||
|
applicationName: branding?.applicationName || props.project.name,
|
||||||
|
customAuthEndpoint,
|
||||||
|
customAuthentication,
|
||||||
|
redirectUrls: toArrFromList(redirectUrls || "", true),
|
||||||
|
smsEnabledCountryISOs: values.smsEnabledCountryISOs,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
props.updateApiKey(
|
||||||
|
{
|
||||||
|
services: newServices,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
hasCustomAuthEndpoint: !!customAuthEndpoint,
|
||||||
|
hasCustomBranding: !!branding,
|
||||||
|
hasCustomJwt: !!customAuthentication,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Form {...form}>
|
||||||
|
<form autoComplete="off" className="space-y-6" onSubmit={handleSubmit}>
|
||||||
|
{/* Branding */}
|
||||||
|
<BrandingFieldset
|
||||||
|
client={props.client}
|
||||||
|
form={form}
|
||||||
|
requiredPlan={brandingRequiredPlan}
|
||||||
|
teamPlan={props.teamPlan}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
isUpdating={props.isUpdating}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<NativeAppsFieldset form={form} isUpdating={props.isUpdating} />
|
||||||
|
|
||||||
|
{/* Authentication */}
|
||||||
|
<Fieldset
|
||||||
|
legend="Authentication"
|
||||||
|
footer={
|
||||||
|
<div className="flex justify-end p-4 md:px-6 border-t border-dashed">
|
||||||
|
<Button
|
||||||
|
className="gap-2"
|
||||||
|
type="submit"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{props.isUpdating && <Spinner className="size-4" />}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<JSONWebTokenFields
|
||||||
|
form={form}
|
||||||
|
requiredPlan={authRequiredPlan}
|
||||||
|
teamPlan={props.teamPlan}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="my-5 border-t border-dashed" />
|
||||||
|
|
||||||
|
<AuthEndpointFields
|
||||||
|
form={form}
|
||||||
|
requiredPlan={authRequiredPlan}
|
||||||
|
teamPlan={props.teamPlan}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="my-5 border-t border-dashed" />
|
||||||
|
|
||||||
|
<SMSCountryFields
|
||||||
|
form={form}
|
||||||
|
requiredPlan={authRequiredPlan}
|
||||||
|
smsCountryTiers={props.smsCountryTiers}
|
||||||
|
teamPlan={props.teamPlan}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
/>
|
||||||
|
</Fieldset>
|
||||||
|
</form>
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function BrandingFieldset(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
teamPlan: Team["billingPlan"];
|
||||||
|
teamSlug: string;
|
||||||
|
requiredPlan: Team["billingPlan"];
|
||||||
|
client: ThirdwebClient;
|
||||||
|
isUpdating: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<FieldsetWithDescription
|
||||||
|
legend="Branding"
|
||||||
|
description="Set an app name and logo to be used in the emails sent to users"
|
||||||
|
footer={
|
||||||
|
<div className="flex justify-end p-4 md:px-6 border-t border-dashed">
|
||||||
|
<Button className="gap-2" type="submit" size="sm" variant="outline">
|
||||||
|
{props.isUpdating && <Spinner className="size-4" />}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className="absolute top-8 right-6">
|
||||||
|
<GatedSwitch
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
switchProps={{
|
||||||
|
checked: !!props.form.watch("branding"),
|
||||||
|
id: "branding-switch",
|
||||||
|
onCheckedChange: (checked) =>
|
||||||
|
props.form.setValue(
|
||||||
|
"branding",
|
||||||
|
checked
|
||||||
|
? {
|
||||||
|
applicationImageUrl: "",
|
||||||
|
applicationName: "",
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
trackingLabel="customEmailLogoAndName"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<GatedCollapsibleContainer
|
||||||
|
className="border-t border-dashed pt-5"
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
isExpanded={!!props.form.watch("branding")}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
>
|
||||||
|
<div className="flex flex-col gap-6 lg:flex-row">
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="branding.applicationImageUrl"
|
||||||
|
render={() => (
|
||||||
|
<FormItem className="lg:border-r lg:border-dashed lg:pr-6">
|
||||||
|
<div className="space-y-1">
|
||||||
|
<FormLabel>Application Image URL</FormLabel>
|
||||||
|
<FormDescription className="!mb-4">
|
||||||
|
Logo that will display in the emails sent to users.{" "}
|
||||||
|
<br className="max-sm:hidden" /> The image must be squared
|
||||||
|
with recommended size of 72x72 px.
|
||||||
|
</FormDescription>
|
||||||
|
|
||||||
|
<FormMessage />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<FormControl>
|
||||||
|
<AppImageFormControl
|
||||||
|
client={props.client}
|
||||||
|
setUri={(uri) => {
|
||||||
|
props.form.setValue("branding.applicationImageUrl", uri, {
|
||||||
|
shouldDirty: true,
|
||||||
|
shouldTouch: true,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
uri={props.form.watch("branding.applicationImageUrl")}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Application Name */}
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="branding.applicationName"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Application Name</FormLabel>
|
||||||
|
<FormDescription>
|
||||||
|
Name that will be displayed in the emails sent to users.{" "}
|
||||||
|
<br className="max-sm:hidden" /> Defaults to your API Key's
|
||||||
|
name.
|
||||||
|
</FormDescription>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} className="max-w-md" />
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</GatedCollapsibleContainer>
|
||||||
|
</FieldsetWithDescription>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AppImageFormControl(props: {
|
||||||
|
uri: string | undefined;
|
||||||
|
setUri: (uri: string) => void;
|
||||||
|
client: ThirdwebClient;
|
||||||
|
}) {
|
||||||
|
const [image, setImage] = useState<File | undefined>();
|
||||||
|
const resolveUrl = resolveSchemeWithErrorHandler({
|
||||||
|
client: props.client,
|
||||||
|
uri: props.uri || undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
const uploadImage = useMutation({
|
||||||
|
mutationFn: async (file: File) => {
|
||||||
|
const uri = await upload({
|
||||||
|
client: props.client,
|
||||||
|
files: [file],
|
||||||
|
});
|
||||||
|
|
||||||
|
return uri;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex">
|
||||||
|
<div className="relative">
|
||||||
|
<FileInput
|
||||||
|
accept={{ "image/*": [] }}
|
||||||
|
className="w-24 rounded-full bg-background"
|
||||||
|
client={props.client}
|
||||||
|
disableHelperText
|
||||||
|
setValue={async (v) => {
|
||||||
|
try {
|
||||||
|
setImage(v);
|
||||||
|
const uri = await uploadImage.mutateAsync(v);
|
||||||
|
props.setUri(uri);
|
||||||
|
} catch (error) {
|
||||||
|
setImage(undefined);
|
||||||
|
toast.error("Failed to upload image", {
|
||||||
|
description: error instanceof Error ? error.message : undefined,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
value={image || resolveUrl}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{uploadImage.isPending && (
|
||||||
|
<div className="absolute inset-0 flex items-center justify-center rounded-full border bg-background/50">
|
||||||
|
<Spinner className="size-7" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SMSCountryFields(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
smsCountryTiers: SMSCountryTiers;
|
||||||
|
teamPlan: Team["billingPlan"];
|
||||||
|
requiredPlan: Team["billingPlan"];
|
||||||
|
teamSlug: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SwitchContainer
|
||||||
|
description="Optionally allow users in selected countries to login via SMS OTP."
|
||||||
|
switchId="sms-switch"
|
||||||
|
title="SMS"
|
||||||
|
>
|
||||||
|
<GatedSwitch
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
switchProps={{
|
||||||
|
checked: !!props.form.watch("smsEnabledCountryISOs").length,
|
||||||
|
id: "sms-switch",
|
||||||
|
onCheckedChange: (checked) =>
|
||||||
|
props.form.setValue(
|
||||||
|
"smsEnabledCountryISOs",
|
||||||
|
checked ? ["US", "CA"] : [],
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
trackingLabel="sms"
|
||||||
|
/>
|
||||||
|
</SwitchContainer>
|
||||||
|
|
||||||
|
<GatedCollapsibleContainer
|
||||||
|
className="grid grid-cols-1"
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
isExpanded={!!props.form.watch("smsEnabledCountryISOs").length}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="smsEnabledCountryISOs"
|
||||||
|
render={({ field }) => (
|
||||||
|
<CountrySelector
|
||||||
|
countryTiers={props.smsCountryTiers}
|
||||||
|
onChange={field.onChange}
|
||||||
|
selected={field.value}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</GatedCollapsibleContainer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function JSONWebTokenFields(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
teamPlan: Team["billingPlan"];
|
||||||
|
teamSlug: string;
|
||||||
|
requiredPlan: Team["billingPlan"];
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SwitchContainer
|
||||||
|
description={
|
||||||
|
<>
|
||||||
|
Optionally allow users to authenticate with a custom JWT.{" "}
|
||||||
|
<UnderlineLink
|
||||||
|
href="https://portal.thirdweb.com/wallets/custom-auth"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Learn more
|
||||||
|
</UnderlineLink>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
switchId="authentication-switch"
|
||||||
|
title="Custom JSON Web Token"
|
||||||
|
>
|
||||||
|
<GatedSwitch
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
switchProps={{
|
||||||
|
checked: !!props.form.watch("customAuthentication"),
|
||||||
|
id: "authentication-switch",
|
||||||
|
onCheckedChange: (checked) => {
|
||||||
|
props.form.setValue(
|
||||||
|
"customAuthentication",
|
||||||
|
checked ? { aud: "", jwksUri: "" } : undefined,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
trackingLabel="customAuthJWT"
|
||||||
|
/>
|
||||||
|
</SwitchContainer>
|
||||||
|
|
||||||
|
<GatedCollapsibleContainer
|
||||||
|
className="grid grid-cols-1 gap-6 lg:grid-cols-2"
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
isExpanded={!!props.form.watch("customAuthentication")}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="customAuthentication.jwksUri"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>JWKS URI</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="https://example.com/.well-known/jwks.json"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>Enter the URI of the JWKS</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="customAuthentication.aud"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>AUD Value</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input {...field} placeholder="AUD" />
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Enter the audience claim for the JWT
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</GatedCollapsibleContainer>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AuthEndpointFields(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
teamPlan: Team["billingPlan"];
|
||||||
|
teamSlug: string;
|
||||||
|
requiredPlan: Team["billingPlan"];
|
||||||
|
}) {
|
||||||
|
const expandCustomAuthEndpointField =
|
||||||
|
props.form.watch("customAuthEndpoint") !== undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<SwitchContainer
|
||||||
|
description={
|
||||||
|
<>
|
||||||
|
Optionally allow users to authenticate with any arbitrary payload
|
||||||
|
that you provide.{" "}
|
||||||
|
<UnderlineLink
|
||||||
|
href="https://portal.thirdweb.com/wallets/custom-auth"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
target="_blank"
|
||||||
|
>
|
||||||
|
Learn more
|
||||||
|
</UnderlineLink>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
switchId="auth-endpoint-switch"
|
||||||
|
title="Custom Authentication Endpoint"
|
||||||
|
>
|
||||||
|
<GatedSwitch
|
||||||
|
currentPlan={props.teamPlan}
|
||||||
|
requiredPlan={props.requiredPlan}
|
||||||
|
switchProps={{
|
||||||
|
checked: expandCustomAuthEndpointField,
|
||||||
|
id: "auth-endpoint-switch",
|
||||||
|
onCheckedChange: (checked) => {
|
||||||
|
props.form.setValue(
|
||||||
|
"customAuthEndpoint",
|
||||||
|
checked
|
||||||
|
? {
|
||||||
|
authEndpoint: "",
|
||||||
|
customHeaders: [],
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
teamSlug={props.teamSlug}
|
||||||
|
trackingLabel="customAuthEndpoint"
|
||||||
|
/>
|
||||||
|
</SwitchContainer>
|
||||||
|
|
||||||
|
{/* useFieldArray used on this component - it creates empty customAuthEndpoint.customHeaders array on mount */}
|
||||||
|
{/* So only mount if expandCustomAuthEndpointField is true */}
|
||||||
|
{expandCustomAuthEndpointField && (
|
||||||
|
<AuthEndpointFieldsContent form={props.form} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function AuthEndpointFieldsContent(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
}) {
|
||||||
|
const customHeaderFields = useFieldArray({
|
||||||
|
control: props.form.control,
|
||||||
|
name: "customAuthEndpoint.customHeaders",
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="mt-6 grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||||
|
<FormField
|
||||||
|
control={props.form.control}
|
||||||
|
name="customAuthEndpoint.authEndpoint"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Authentication Endpoint</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder="https://example.com/your-auth-verifier"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Enter the URL of your server where we will send the user payload
|
||||||
|
for verification
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<Label className="mb-3 inline-block">Custom Headers</Label>
|
||||||
|
<div className="flex flex-col gap-4">
|
||||||
|
{customHeaderFields.fields.map((field, customHeaderIdx) => {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-4" key={field.id}>
|
||||||
|
<Input
|
||||||
|
placeholder="Name"
|
||||||
|
type="text"
|
||||||
|
{...props.form.register(
|
||||||
|
`customAuthEndpoint.customHeaders.${customHeaderIdx}.key`,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
placeholder="Value"
|
||||||
|
type="text"
|
||||||
|
{...props.form.register(
|
||||||
|
`customAuthEndpoint.customHeaders.${customHeaderIdx}.value`,
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
aria-label="Remove header"
|
||||||
|
className="!w-auto px-3"
|
||||||
|
onClick={() => {
|
||||||
|
customHeaderFields.remove(customHeaderIdx);
|
||||||
|
}}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<Trash2Icon className="size-4 shrink-0 text-destructive-text" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
className="w-full gap-2 bg-background"
|
||||||
|
onClick={() => {
|
||||||
|
customHeaderFields.append({
|
||||||
|
key: "",
|
||||||
|
value: "",
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
<PlusIcon className="size-4" />
|
||||||
|
Add header
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="mt-3 text-muted-foreground text-sm">
|
||||||
|
Set custom headers to be sent along the request with the payload to
|
||||||
|
the authentication endpoint above. This can be used to verify the
|
||||||
|
incoming requests
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function NativeAppsFieldset(props: {
|
||||||
|
form: UseFormReturn<ApiKeyEmbeddedWalletsValidationSchema>;
|
||||||
|
isUpdating: boolean;
|
||||||
|
}) {
|
||||||
|
const { form } = props;
|
||||||
|
return (
|
||||||
|
<Fieldset
|
||||||
|
legend="Native Apps"
|
||||||
|
footer={
|
||||||
|
<div className="flex justify-end p-4 md:px-6 border-t border-dashed">
|
||||||
|
<Button className="gap-2" type="submit" size="sm" variant="outline">
|
||||||
|
{props.isUpdating && <Spinner className="size-4" />}
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="redirectUrls"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Allowed redirect URIs</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
{...field}
|
||||||
|
placeholder="appName://, localhost:3000, https://example.com"
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormDescription>
|
||||||
|
Enter redirect URIs separated by commas or new lines. This is
|
||||||
|
often your application's deep link.
|
||||||
|
<br className="max-sm:hidden" />
|
||||||
|
Currently only used in Unity, Unreal Engine and React Native
|
||||||
|
platform when users authenticate through social logins.
|
||||||
|
</FormDescription>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Fieldset>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function GatedCollapsibleContainer(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
isExpanded: boolean;
|
||||||
|
className?: string;
|
||||||
|
requiredPlan: Team["billingPlan"];
|
||||||
|
currentPlan: Team["billingPlan"];
|
||||||
|
}) {
|
||||||
|
const upgradeRequired =
|
||||||
|
planToTierRecordForGating[props.currentPlan] <
|
||||||
|
planToTierRecordForGating[props.requiredPlan];
|
||||||
|
|
||||||
|
if (!props.isExpanded || upgradeRequired) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={cn("mt-5 fade-in-0 duration-300 animate-in", props.className)}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Fieldset(props: {
|
||||||
|
legend: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
footer?: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border bg-card relative">
|
||||||
|
<DynamicHeight>
|
||||||
|
<fieldset className="p-4 md:px-6 md:py-5">
|
||||||
|
{/* put inside div to remove default styles on legend */}
|
||||||
|
<div className="border-b pb-4 mb-5 border-dashed font-semibold text-xl tracking-tight">
|
||||||
|
<legend> {props.legend}</legend>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{props.children}
|
||||||
|
</fieldset>
|
||||||
|
</DynamicHeight>
|
||||||
|
{props.footer}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FieldsetWithDescription(props: {
|
||||||
|
legend: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
footer?: React.ReactNode;
|
||||||
|
description: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border bg-card relative">
|
||||||
|
<DynamicHeight>
|
||||||
|
<fieldset className="p-4 md:p-6">
|
||||||
|
{/* put inside div to remove default styles on legend */}
|
||||||
|
<div className="pr-20">
|
||||||
|
<legend className="font-semibold text-xl tracking-tight">
|
||||||
|
{props.legend}
|
||||||
|
</legend>
|
||||||
|
<p className="text-muted-foreground text-sm">{props.description}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{props.children}
|
||||||
|
</fieldset>
|
||||||
|
</DynamicHeight>
|
||||||
|
{props.footer}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SwitchContainer(props: {
|
||||||
|
switchId: string;
|
||||||
|
title: string;
|
||||||
|
description: React.ReactNode;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-between gap-6">
|
||||||
|
<div>
|
||||||
|
<Label className="text-base" htmlFor={props.switchId}>
|
||||||
|
{props.title}
|
||||||
|
</Label>
|
||||||
|
<p className="mt-0.5 text-muted-foreground text-sm ">
|
||||||
|
{props.description}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+210
@@ -0,0 +1,210 @@
|
|||||||
|
/** biome-ignore-all lint/a11y/useSemanticElements: EXPECTED */
|
||||||
|
|
||||||
|
import { CheckIcon, ChevronDownIcon } from "lucide-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Checkbox } from "@/components/ui/checkbox";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import type { SMSCountryTiers } from "../../api/sms";
|
||||||
|
import { countryNames, countryPrefixes, getCountryFlag, tierPricing } from ".";
|
||||||
|
|
||||||
|
interface CountrySelectorProps {
|
||||||
|
countryTiers: SMSCountryTiers;
|
||||||
|
selected: string[];
|
||||||
|
onChange: (selectedCountries: string[]) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CountrySelector({
|
||||||
|
countryTiers,
|
||||||
|
selected,
|
||||||
|
onChange,
|
||||||
|
}: CountrySelectorProps) {
|
||||||
|
// Helper function to check if a country is selected
|
||||||
|
const isCountrySelected = (country: string) => selected.includes(country);
|
||||||
|
|
||||||
|
// Check if all countries in a tier are selected
|
||||||
|
const isTierSelected = (tier: string) => {
|
||||||
|
const tierCountries = countryTiers[tier as keyof typeof countryTiers];
|
||||||
|
return tierCountries.every((country) => isCountrySelected(country));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Toggle a tier selection
|
||||||
|
const toggleTier = (tier: string) => {
|
||||||
|
const tierCountries = countryTiers[tier as keyof typeof countryTiers];
|
||||||
|
let newSelected: string[];
|
||||||
|
|
||||||
|
if (isTierSelected(tier)) {
|
||||||
|
// Deselect all countries in this tier
|
||||||
|
newSelected = selected.filter(
|
||||||
|
(country) => !tierCountries.includes(country),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Select all countries in this tier
|
||||||
|
const currentSelected = new Set(selected);
|
||||||
|
for (const country of tierCountries) {
|
||||||
|
currentSelected.add(country);
|
||||||
|
}
|
||||||
|
newSelected = Array.from(currentSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call onChange with the updated selection
|
||||||
|
onChange(newSelected);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Toggle a single country selection
|
||||||
|
const toggleCountry = (country: string) => {
|
||||||
|
let newSelected: string[];
|
||||||
|
|
||||||
|
if (isCountrySelected(country)) {
|
||||||
|
// Remove country from selection
|
||||||
|
newSelected = selected.filter((c) => c !== country);
|
||||||
|
} else {
|
||||||
|
// Add country to selection
|
||||||
|
newSelected = [...selected, country];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call onChange with the updated selection
|
||||||
|
onChange(newSelected);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-5">
|
||||||
|
{Object.entries(countryTiers).map(([tier, tierCountries], index) => {
|
||||||
|
const selectedTierCountries = tierCountries.filter((country) =>
|
||||||
|
isCountrySelected(country),
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TierCard
|
||||||
|
key={tier}
|
||||||
|
tierIndex={index}
|
||||||
|
tier={tier}
|
||||||
|
onToggleTier={() => toggleTier(tier)}
|
||||||
|
tierCountries={tierCountries}
|
||||||
|
selectedTierCountries={selectedTierCountries}
|
||||||
|
onToggleCountry={toggleCountry}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TierCard(props: {
|
||||||
|
tier: string;
|
||||||
|
tierIndex: number;
|
||||||
|
onToggleTier: () => void;
|
||||||
|
tierCountries: string[];
|
||||||
|
selectedTierCountries: string[];
|
||||||
|
onToggleCountry: (country: string) => void;
|
||||||
|
}) {
|
||||||
|
const {
|
||||||
|
tier,
|
||||||
|
tierIndex,
|
||||||
|
onToggleTier,
|
||||||
|
tierCountries: countries,
|
||||||
|
selectedTierCountries: selectedCountries,
|
||||||
|
onToggleCountry,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const [isExpanded, setIsExpanded] = useState(true);
|
||||||
|
const isPartiallySelected =
|
||||||
|
selectedCountries.length > 0 && selectedCountries.length < countries.length;
|
||||||
|
const isTierFullySelected = selectedCountries.length === countries.length;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="overflow-hidden rounded-xl border bg-background">
|
||||||
|
{/* header */}
|
||||||
|
<div className="flex items-center px-4 py-3 gap-3 justify-between">
|
||||||
|
{/* left */}
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Checkbox
|
||||||
|
checked={
|
||||||
|
isPartiallySelected ? "indeterminate" : isTierFullySelected
|
||||||
|
}
|
||||||
|
id={`tier-${tier}`}
|
||||||
|
onCheckedChange={onToggleTier}
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
className="flex-1 cursor-pointer font-medium text-sm"
|
||||||
|
htmlFor={`tier-${tier}`}
|
||||||
|
>
|
||||||
|
Tier {tierIndex + 1}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
{isPartiallySelected && (
|
||||||
|
<span className="text-muted-foreground text-sm">
|
||||||
|
({selectedCountries.length}/{countries.length})
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* right */}
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"text-sm",
|
||||||
|
tier === "tier1"
|
||||||
|
? "text-green-600 dark:text-green-500"
|
||||||
|
: "text-muted-foreground",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{tierPricing[tier as keyof typeof tierPricing]}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
className="p-0 size-7"
|
||||||
|
onClick={() => setIsExpanded(!isExpanded)}
|
||||||
|
>
|
||||||
|
<ChevronDownIcon
|
||||||
|
className={cn(
|
||||||
|
"size-4 transition-transform",
|
||||||
|
isExpanded && "rotate-180",
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* body */}
|
||||||
|
{isExpanded && (
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 translate-y-[1px] translate-x-[1px] -ml-[1px] border-t",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{countries.map((country) => {
|
||||||
|
const isSelected = selectedCountries.includes(country);
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
className={cn(
|
||||||
|
"justify-between gap-3 text-start h-auto rounded-none border-l-0 border-t-0 border-border py-2.5 bg-background",
|
||||||
|
)}
|
||||||
|
key={country}
|
||||||
|
onClick={() => onToggleCountry(country)}
|
||||||
|
title={countryNames[country] || country}
|
||||||
|
>
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="text-3xl">{getCountryFlag(country)}</div>
|
||||||
|
<div className="space-y-0.5">
|
||||||
|
<div className="font-medium text-sm">
|
||||||
|
{countryNames[country] || country}
|
||||||
|
</div>
|
||||||
|
<div className="text-muted-foreground text-xs tabular-nums">
|
||||||
|
{countryPrefixes[country]
|
||||||
|
? `${countryPrefixes[country]}`
|
||||||
|
: ""}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{isSelected && <CheckIcon className="size-5 text-foreground" />}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
export { default as CountrySelector } from "./country-selector";
|
||||||
|
export {
|
||||||
|
countryNames,
|
||||||
|
countryPrefixes,
|
||||||
|
getCountryFlag,
|
||||||
|
tierPricing,
|
||||||
|
} from "./utils";
|
||||||
+482
@@ -0,0 +1,482 @@
|
|||||||
|
// Pricing for each tier
|
||||||
|
export const tierPricing = {
|
||||||
|
tier1: "Included",
|
||||||
|
tier2: "$0.05 per SMS",
|
||||||
|
tier3: "$0.10 per SMS",
|
||||||
|
tier4: "$0.20 per SMS",
|
||||||
|
tier5: "$0.40 per SMS",
|
||||||
|
tier6: "$1.00 per SMS",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// Country names mapped to ISO codes
|
||||||
|
export const countryNames: Record<string, string> = {
|
||||||
|
// Tier 4
|
||||||
|
AD: "Andorra",
|
||||||
|
AE: "United Arab Emirates",
|
||||||
|
|
||||||
|
// Tier 5
|
||||||
|
AF: "Afghanistan",
|
||||||
|
AG: "Antigua and Barbuda",
|
||||||
|
AI: "Anguilla",
|
||||||
|
AL: "Albania",
|
||||||
|
AM: "Armenia",
|
||||||
|
AO: "Angola",
|
||||||
|
|
||||||
|
// Tier 6
|
||||||
|
RU: "Russia/Kazakhstan",
|
||||||
|
PG: "Papua New Guinea",
|
||||||
|
UZ: "Uzbekistan",
|
||||||
|
TZ: "Tanzania",
|
||||||
|
KM: "Comoros",
|
||||||
|
BT: "Bhutan",
|
||||||
|
|
||||||
|
// Tier 3
|
||||||
|
AR: "Argentina",
|
||||||
|
AS: "American Samoa",
|
||||||
|
AT: "Austria",
|
||||||
|
AU: "Australia",
|
||||||
|
AW: "Aruba",
|
||||||
|
AZ: "Azerbaijan",
|
||||||
|
BA: "Bosnia and Herzegovina",
|
||||||
|
BB: "Barbados",
|
||||||
|
BD: "Bangladesh",
|
||||||
|
BE: "Belgium",
|
||||||
|
BF: "Burkina Faso",
|
||||||
|
BG: "Bulgaria",
|
||||||
|
|
||||||
|
// Tier 2
|
||||||
|
BH: "Bahrain",
|
||||||
|
BI: "Burundi",
|
||||||
|
BJ: "Benin",
|
||||||
|
BM: "Bermuda",
|
||||||
|
BN: "Brunei",
|
||||||
|
BO: "Bolivia",
|
||||||
|
BR: "Brazil",
|
||||||
|
BS: "Bahamas",
|
||||||
|
BW: "Botswana",
|
||||||
|
BY: "Belarus",
|
||||||
|
BZ: "Belize",
|
||||||
|
// Tier 1
|
||||||
|
CA: "Canada",
|
||||||
|
CD: "DR Congo",
|
||||||
|
CG: "Congo",
|
||||||
|
CH: "Switzerland",
|
||||||
|
CI: "Ivory Coast",
|
||||||
|
CK: "Cook Islands",
|
||||||
|
CL: "Chile",
|
||||||
|
CM: "Cameroon",
|
||||||
|
CN: "China",
|
||||||
|
CO: "Colombia",
|
||||||
|
CR: "Costa Rica",
|
||||||
|
CU: "Cuba",
|
||||||
|
CV: "Cape Verde",
|
||||||
|
CY: "Cyprus",
|
||||||
|
CZ: "Czech Republic",
|
||||||
|
DE: "Germany",
|
||||||
|
DJ: "Djibouti",
|
||||||
|
DK: "Denmark",
|
||||||
|
DM: "Dominica",
|
||||||
|
DO: "Dominican Republic",
|
||||||
|
DZ: "Algeria",
|
||||||
|
EC: "Ecuador",
|
||||||
|
EE: "Estonia",
|
||||||
|
EG: "Egypt",
|
||||||
|
ER: "Eritrea",
|
||||||
|
ES: "Spain",
|
||||||
|
ET: "Ethiopia",
|
||||||
|
FI: "Finland",
|
||||||
|
FJ: "Fiji",
|
||||||
|
FK: "Falkland Islands",
|
||||||
|
FM: "Micronesia",
|
||||||
|
FO: "Faroe Islands",
|
||||||
|
FR: "France",
|
||||||
|
GA: "Gabon",
|
||||||
|
GB: "United Kingdom",
|
||||||
|
GD: "Grenada",
|
||||||
|
GE: "Georgia",
|
||||||
|
GF: "French Guiana",
|
||||||
|
GH: "Ghana",
|
||||||
|
GI: "Gibraltar",
|
||||||
|
GL: "Greenland",
|
||||||
|
GM: "Gambia",
|
||||||
|
GN: "Guinea",
|
||||||
|
GP: "Guadeloupe",
|
||||||
|
GQ: "Equatorial Guinea",
|
||||||
|
GR: "Greece",
|
||||||
|
GT: "Guatemala",
|
||||||
|
GU: "Guam",
|
||||||
|
GW: "Guinea-Bissau",
|
||||||
|
GY: "Guyana",
|
||||||
|
HK: "Hong Kong",
|
||||||
|
HN: "Honduras",
|
||||||
|
HR: "Croatia",
|
||||||
|
HT: "Haiti",
|
||||||
|
HU: "Hungary",
|
||||||
|
ID: "Indonesia",
|
||||||
|
IE: "Ireland",
|
||||||
|
IL: "Israel",
|
||||||
|
IN: "India",
|
||||||
|
IQ: "Iraq",
|
||||||
|
IS: "Iceland",
|
||||||
|
IT: "Italy",
|
||||||
|
JM: "Jamaica",
|
||||||
|
JO: "Jordan",
|
||||||
|
JP: "Japan",
|
||||||
|
KE: "Kenya",
|
||||||
|
KG: "Kyrgyzstan",
|
||||||
|
KH: "Cambodia",
|
||||||
|
KI: "Kiribati",
|
||||||
|
KN: "Saint Kitts and Nevis",
|
||||||
|
KR: "South Korea",
|
||||||
|
KW: "Kuwait",
|
||||||
|
KY: "Cayman Islands",
|
||||||
|
KZ: "Kazakhstan",
|
||||||
|
LA: "Laos PDR",
|
||||||
|
LB: "Lebanon",
|
||||||
|
LC: "Saint Lucia",
|
||||||
|
LI: "Liechtenstein",
|
||||||
|
LK: "Sri Lanka",
|
||||||
|
LR: "Liberia",
|
||||||
|
LS: "Lesotho",
|
||||||
|
LT: "Lithuania",
|
||||||
|
LU: "Luxembourg",
|
||||||
|
LV: "Latvia",
|
||||||
|
LY: "Libya",
|
||||||
|
MA: "Morocco",
|
||||||
|
MC: "Monaco",
|
||||||
|
MD: "Moldova",
|
||||||
|
ME: "Montenegro",
|
||||||
|
MG: "Madagascar",
|
||||||
|
MH: "Marshall Islands",
|
||||||
|
MK: "North Macedonia",
|
||||||
|
ML: "Mali",
|
||||||
|
MM: "Myanmar",
|
||||||
|
MN: "Mongolia",
|
||||||
|
MO: "Macao",
|
||||||
|
MQ: "Martinique",
|
||||||
|
MR: "Mauritania",
|
||||||
|
MS: "Montserrat",
|
||||||
|
MT: "Malta",
|
||||||
|
MU: "Mauritius",
|
||||||
|
MV: "Maldives",
|
||||||
|
MW: "Malawi",
|
||||||
|
MX: "Mexico",
|
||||||
|
MY: "Malaysia",
|
||||||
|
MZ: "Mozambique",
|
||||||
|
NA: "Namibia",
|
||||||
|
NC: "New Caledonia",
|
||||||
|
NE: "Niger",
|
||||||
|
NF: "Norfolk Island",
|
||||||
|
NG: "Nigeria",
|
||||||
|
NI: "Nicaragua",
|
||||||
|
NL: "Netherlands",
|
||||||
|
NO: "Norway",
|
||||||
|
NP: "Nepal",
|
||||||
|
NU: "Niue",
|
||||||
|
NZ: "New Zealand",
|
||||||
|
OM: "Oman",
|
||||||
|
PA: "Panama",
|
||||||
|
PE: "Peru",
|
||||||
|
PF: "French Polynesia",
|
||||||
|
PH: "Philippines",
|
||||||
|
PK: "Pakistan",
|
||||||
|
PL: "Poland",
|
||||||
|
PM: "Saint Pierre and Miquelon",
|
||||||
|
PR: "Puerto Rico",
|
||||||
|
PS: "Palestinian Territory",
|
||||||
|
PT: "Portugal",
|
||||||
|
PW: "Palau",
|
||||||
|
PY: "Paraguay",
|
||||||
|
QA: "Qatar",
|
||||||
|
RE: "Réunion",
|
||||||
|
RO: "Romania",
|
||||||
|
RS: "Serbia",
|
||||||
|
RW: "Rwanda",
|
||||||
|
SA: "Saudi Arabia",
|
||||||
|
SB: "Solomon Islands",
|
||||||
|
SC: "Seychelles",
|
||||||
|
SD: "Sudan",
|
||||||
|
SE: "Sweden",
|
||||||
|
SG: "Singapore",
|
||||||
|
SI: "Slovenia",
|
||||||
|
SK: "Slovakia",
|
||||||
|
SL: "Sierra Leone",
|
||||||
|
SM: "San Marino",
|
||||||
|
SN: "Senegal",
|
||||||
|
SO: "Somalia",
|
||||||
|
SR: "Suriname",
|
||||||
|
SS: "South Sudan",
|
||||||
|
ST: "Sao Tome and Principe",
|
||||||
|
SV: "El Salvador",
|
||||||
|
SY: "Syria",
|
||||||
|
SZ: "Eswatini",
|
||||||
|
TC: "Turks and Caicos Islands",
|
||||||
|
TD: "Chad",
|
||||||
|
TG: "Togo",
|
||||||
|
TH: "Thailand",
|
||||||
|
TL: "East Timor",
|
||||||
|
TM: "Turkmenistan",
|
||||||
|
TN: "Tunisia",
|
||||||
|
TO: "Tonga",
|
||||||
|
TR: "Turkey",
|
||||||
|
TT: "Trinidad and Tobago",
|
||||||
|
TV: "Tuvalu",
|
||||||
|
TW: "Taiwan",
|
||||||
|
UA: "Ukraine",
|
||||||
|
UG: "Uganda",
|
||||||
|
US: "United States",
|
||||||
|
UY: "Uruguay",
|
||||||
|
VC: "Saint Vincent and the Grenadines",
|
||||||
|
VE: "Venezuela",
|
||||||
|
VG: "Virgin Islands, British",
|
||||||
|
VI: "Virgin Islands, U.S.",
|
||||||
|
VN: "Vietnam",
|
||||||
|
VU: "Vanuatu",
|
||||||
|
WF: "Wallis and Futuna",
|
||||||
|
WS: "Samoa",
|
||||||
|
YE: "Yemen",
|
||||||
|
ZA: "South Africa",
|
||||||
|
ZM: "Zambia",
|
||||||
|
ZW: "Zimbabwe",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export const countryPrefixes: Record<string, string> = {
|
||||||
|
// Tier 4
|
||||||
|
AD: "+376",
|
||||||
|
AE: "+971",
|
||||||
|
|
||||||
|
// Tier 5
|
||||||
|
AF: "+93",
|
||||||
|
AG: "+1",
|
||||||
|
AI: "+1",
|
||||||
|
AL: "+355",
|
||||||
|
AM: "+374",
|
||||||
|
AO: "+244",
|
||||||
|
|
||||||
|
// Tier 6
|
||||||
|
RU: "+7",
|
||||||
|
PG: "+675",
|
||||||
|
UZ: "+998",
|
||||||
|
TZ: "+255",
|
||||||
|
KM: "+269",
|
||||||
|
BT: "+975",
|
||||||
|
|
||||||
|
// Tier 3
|
||||||
|
AR: "+54",
|
||||||
|
AS: "+1",
|
||||||
|
AT: "+43",
|
||||||
|
AU: "+61",
|
||||||
|
AW: "+297",
|
||||||
|
AZ: "+994",
|
||||||
|
BA: "+387",
|
||||||
|
BB: "+1",
|
||||||
|
BD: "+880",
|
||||||
|
BE: "+32",
|
||||||
|
BF: "+226",
|
||||||
|
BG: "+359",
|
||||||
|
|
||||||
|
// Tier 2
|
||||||
|
BH: "+973",
|
||||||
|
BI: "+257",
|
||||||
|
BJ: "+229",
|
||||||
|
BM: "+1",
|
||||||
|
BN: "+673",
|
||||||
|
BO: "+591",
|
||||||
|
BR: "+55",
|
||||||
|
BS: "+1",
|
||||||
|
BW: "+267",
|
||||||
|
BY: "+375",
|
||||||
|
BZ: "+501",
|
||||||
|
// Tier 1
|
||||||
|
CA: "+1",
|
||||||
|
CD: "+243",
|
||||||
|
CG: "+242",
|
||||||
|
CH: "+41",
|
||||||
|
CI: "+225",
|
||||||
|
CK: "+682",
|
||||||
|
CL: "+56",
|
||||||
|
CM: "+237",
|
||||||
|
CN: "+86",
|
||||||
|
CO: "+57",
|
||||||
|
CR: "+506",
|
||||||
|
CU: "+53",
|
||||||
|
CV: "+238",
|
||||||
|
CY: "+357",
|
||||||
|
CZ: "+420",
|
||||||
|
DE: "+49",
|
||||||
|
DJ: "+253",
|
||||||
|
DK: "+45",
|
||||||
|
DM: "+1",
|
||||||
|
DO: "+1",
|
||||||
|
DZ: "+213",
|
||||||
|
EC: "+593",
|
||||||
|
EE: "+372",
|
||||||
|
EG: "+20",
|
||||||
|
ER: "+291",
|
||||||
|
ES: "+34",
|
||||||
|
ET: "+251",
|
||||||
|
FI: "+358",
|
||||||
|
FJ: "+679",
|
||||||
|
FK: "+500",
|
||||||
|
FM: "+691",
|
||||||
|
FO: "+298",
|
||||||
|
FR: "+33",
|
||||||
|
GA: "+241",
|
||||||
|
GB: "+44",
|
||||||
|
GD: "+1",
|
||||||
|
GE: "+995",
|
||||||
|
GF: "+594",
|
||||||
|
GH: "+233",
|
||||||
|
GI: "+350",
|
||||||
|
GL: "+299",
|
||||||
|
GM: "+220",
|
||||||
|
GN: "+224",
|
||||||
|
GP: "+590",
|
||||||
|
GQ: "+240",
|
||||||
|
GR: "+30",
|
||||||
|
GT: "+502",
|
||||||
|
GU: "+1",
|
||||||
|
GW: "+245",
|
||||||
|
GY: "+592",
|
||||||
|
HK: "+852",
|
||||||
|
HN: "+504",
|
||||||
|
HR: "+385",
|
||||||
|
HT: "+509",
|
||||||
|
HU: "+36",
|
||||||
|
ID: "+62",
|
||||||
|
IE: "+353",
|
||||||
|
IL: "+972",
|
||||||
|
IN: "+91",
|
||||||
|
IQ: "+964",
|
||||||
|
IS: "+354",
|
||||||
|
IT: "+39",
|
||||||
|
JM: "+1",
|
||||||
|
JO: "+962",
|
||||||
|
JP: "+81",
|
||||||
|
KE: "+254",
|
||||||
|
KG: "+996",
|
||||||
|
KH: "+855",
|
||||||
|
KI: "+686",
|
||||||
|
KN: "+1",
|
||||||
|
KR: "+82",
|
||||||
|
KW: "+965",
|
||||||
|
KY: "+1",
|
||||||
|
KZ: "+7",
|
||||||
|
LA: "+856",
|
||||||
|
LB: "+961",
|
||||||
|
LC: "+1",
|
||||||
|
LI: "+423",
|
||||||
|
LK: "+94",
|
||||||
|
LR: "+231",
|
||||||
|
LS: "+266",
|
||||||
|
LT: "+370",
|
||||||
|
LU: "+352",
|
||||||
|
LV: "+371",
|
||||||
|
LY: "+218",
|
||||||
|
MA: "+212",
|
||||||
|
MC: "+377",
|
||||||
|
MD: "+373",
|
||||||
|
ME: "+382",
|
||||||
|
MG: "+261",
|
||||||
|
MH: "+692",
|
||||||
|
MK: "+389",
|
||||||
|
ML: "+223",
|
||||||
|
MM: "+95",
|
||||||
|
MN: "+976",
|
||||||
|
MO: "+853",
|
||||||
|
MQ: "+596",
|
||||||
|
MR: "+222",
|
||||||
|
MS: "+1",
|
||||||
|
MT: "+356",
|
||||||
|
MU: "+230",
|
||||||
|
MV: "+960",
|
||||||
|
MW: "+265",
|
||||||
|
MX: "+52",
|
||||||
|
MY: "+60",
|
||||||
|
MZ: "+258",
|
||||||
|
NA: "+264",
|
||||||
|
NC: "+687",
|
||||||
|
NE: "+227",
|
||||||
|
NF: "+672",
|
||||||
|
NG: "+234",
|
||||||
|
NI: "+505",
|
||||||
|
NL: "+31",
|
||||||
|
NO: "+47",
|
||||||
|
NP: "+977",
|
||||||
|
NU: "+683",
|
||||||
|
NZ: "+64",
|
||||||
|
OM: "+968",
|
||||||
|
PA: "+507",
|
||||||
|
PE: "+51",
|
||||||
|
PF: "+689",
|
||||||
|
PH: "+63",
|
||||||
|
PK: "+92",
|
||||||
|
PL: "+48",
|
||||||
|
PM: "+508",
|
||||||
|
PR: "+1",
|
||||||
|
PS: "+970",
|
||||||
|
PT: "+351",
|
||||||
|
PW: "+680",
|
||||||
|
PY: "+595",
|
||||||
|
QA: "+974",
|
||||||
|
RE: "+262",
|
||||||
|
RO: "+40",
|
||||||
|
RS: "+381",
|
||||||
|
RW: "+250",
|
||||||
|
SA: "+966",
|
||||||
|
SB: "+677",
|
||||||
|
SC: "+248",
|
||||||
|
SD: "+249",
|
||||||
|
SE: "+46",
|
||||||
|
SG: "+65",
|
||||||
|
SI: "+386",
|
||||||
|
SK: "+421",
|
||||||
|
SL: "+232",
|
||||||
|
SM: "+378",
|
||||||
|
SN: "+221",
|
||||||
|
SO: "+252",
|
||||||
|
SR: "+597",
|
||||||
|
SS: "+211",
|
||||||
|
ST: "+239",
|
||||||
|
SV: "+503",
|
||||||
|
SY: "+963",
|
||||||
|
SZ: "+268",
|
||||||
|
TC: "+1",
|
||||||
|
TD: "+235",
|
||||||
|
TG: "+228",
|
||||||
|
TH: "+66",
|
||||||
|
TL: "+670",
|
||||||
|
TM: "+993",
|
||||||
|
TN: "+216",
|
||||||
|
TO: "+676",
|
||||||
|
TR: "+90",
|
||||||
|
TT: "+1",
|
||||||
|
TV: "+688",
|
||||||
|
TW: "+886",
|
||||||
|
UA: "+380",
|
||||||
|
UG: "+256",
|
||||||
|
US: "+1",
|
||||||
|
UY: "+598",
|
||||||
|
VC: "+1",
|
||||||
|
VE: "+58",
|
||||||
|
VG: "+1",
|
||||||
|
VI: "+1",
|
||||||
|
VN: "+84",
|
||||||
|
VU: "+678",
|
||||||
|
WF: "+681",
|
||||||
|
WS: "+685",
|
||||||
|
YE: "+967",
|
||||||
|
ZA: "+27",
|
||||||
|
ZM: "+260",
|
||||||
|
ZW: "+263",
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// Helper function to convert country code to flag emoji
|
||||||
|
export const getCountryFlag = (countryCode: string) => {
|
||||||
|
const codePoints = countryCode
|
||||||
|
.toUpperCase()
|
||||||
|
.split("")
|
||||||
|
.map((char) => 127397 + char.charCodeAt(0));
|
||||||
|
|
||||||
|
return String.fromCodePoint(...codePoints);
|
||||||
|
};
|
||||||
+3
-8
@@ -5,7 +5,6 @@ import { getTeamBySlug } from "@/api/team/get-team";
|
|||||||
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
import { getValidTeamPlan } from "@/utils/getValidTeamPlan";
|
import { getValidTeamPlan } from "@/utils/getValidTeamPlan";
|
||||||
import { loginRedirect } from "@/utils/redirects";
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
import { ProjectSettingsBreadcrumb } from "../_components/project-settings-breadcrumb";
|
|
||||||
import { getSMSCountryTiers } from "./api/sms";
|
import { getSMSCountryTiers } from "./api/sms";
|
||||||
import { InAppWalletSettingsPage } from "./components";
|
import { InAppWalletSettingsPage } from "./components";
|
||||||
|
|
||||||
@@ -22,7 +21,9 @@ export default async function Page(props: {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (!authToken) {
|
if (!authToken) {
|
||||||
loginRedirect(`/team/${team_slug}/settings/wallets`);
|
loginRedirect(
|
||||||
|
`/team/${team_slug}/${project_slug}/wallets/user-wallets/configuration`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!team) {
|
if (!team) {
|
||||||
@@ -40,12 +41,6 @@ export default async function Page(props: {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
<ProjectSettingsBreadcrumb
|
|
||||||
teamSlug={team_slug}
|
|
||||||
projectSlug={project_slug}
|
|
||||||
page="Wallets"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<InAppWalletSettingsPage
|
<InAppWalletSettingsPage
|
||||||
client={client}
|
client={client}
|
||||||
project={project}
|
project={project}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { WalletProductIcon } from "@/icons/WalletProductIcon";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
|
||||||
|
export default async function Layout(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await props.params;
|
||||||
|
const basePath = `/team/${params.team_slug}/${params.project_slug}/wallets/user-wallets`;
|
||||||
|
|
||||||
|
const [authToken, project] = await Promise.all([
|
||||||
|
getAuthToken(),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProjectPage
|
||||||
|
header={{
|
||||||
|
icon: WalletProductIcon,
|
||||||
|
title: "User Wallets",
|
||||||
|
description:
|
||||||
|
"Secure, auto-generated wallets created for authenticated users using email, socials, or passkeys",
|
||||||
|
actions: null,
|
||||||
|
client,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
type: "docs",
|
||||||
|
href: "https://portal.thirdweb.com/wallets/users",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
name: "Overview",
|
||||||
|
path: `${basePath}`,
|
||||||
|
exactMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Configuration",
|
||||||
|
path: `${basePath}/configuration`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</ProjectPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
+81
@@ -0,0 +1,81 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { ResponsiveSearchParamsProvider } from "responsive-rsc";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import type { DurationId } from "@/components/analytics/date-range-selector";
|
||||||
|
import { ResponsiveTimeFilters } from "@/components/analytics/responsive-time-filters";
|
||||||
|
import { InAppWalletUsersPageContent } from "@/components/in-app-wallet-users-content/in-app-wallet-users-content";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { getFiltersFromSearchParams } from "@/lib/time";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import { InAppWalletAnalytics } from "../analytics/chart";
|
||||||
|
import { InAppWalletsSummary } from "../analytics/chart/Summary";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
searchParams: Promise<{
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
type?: string;
|
||||||
|
interval?: string;
|
||||||
|
}>;
|
||||||
|
}) {
|
||||||
|
const [searchParams, params] = await Promise.all([
|
||||||
|
props.searchParams,
|
||||||
|
props.params,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const authToken = await getAuthToken();
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${params.team_slug}/${params.project_slug}/wallets/user-wallets`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultRange: DurationId = "last-30";
|
||||||
|
const { range, interval } = getFiltersFromSearchParams({
|
||||||
|
defaultRange,
|
||||||
|
from: searchParams.from,
|
||||||
|
interval: searchParams.interval,
|
||||||
|
to: searchParams.to,
|
||||||
|
});
|
||||||
|
|
||||||
|
const project = await getProject(params.team_slug, params.project_slug);
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResponsiveSearchParamsProvider value={searchParams}>
|
||||||
|
<div className="flex flex-col gap-4 md:gap-6">
|
||||||
|
<ResponsiveTimeFilters defaultRange={defaultRange} />
|
||||||
|
<InAppWalletsSummary
|
||||||
|
authToken={authToken}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
<InAppWalletAnalytics
|
||||||
|
authToken={authToken}
|
||||||
|
interval={interval}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
<InAppWalletUsersPageContent
|
||||||
|
authToken={authToken}
|
||||||
|
client={client}
|
||||||
|
projectClientId={project.publishableKey}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ResponsiveSearchParamsProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
+69
@@ -0,0 +1,69 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { BotIcon, ServerIcon, WalletIcon } from "lucide-react";
|
||||||
|
import { FeatureCard } from "../payments/components/FeatureCard.client";
|
||||||
|
|
||||||
|
export function QuickStartSection() {
|
||||||
|
return (
|
||||||
|
<section>
|
||||||
|
<div className="mb-4">
|
||||||
|
<h2 className="font-semibold text-xl tracking-tight">Quick Start</h2>
|
||||||
|
<p className="text-muted-foreground text-sm">
|
||||||
|
Choose how to integrate x402 payments into your project.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
|
<FeatureCard
|
||||||
|
title="Payment gate your API"
|
||||||
|
description="Make your endpoints payable with a single line of code"
|
||||||
|
icon={ServerIcon}
|
||||||
|
id="x402_server"
|
||||||
|
setupTime={2}
|
||||||
|
features={[
|
||||||
|
"Supports 170+ chains",
|
||||||
|
"Supports 6.7k+ tokens",
|
||||||
|
"Dynamic pricing logic",
|
||||||
|
]}
|
||||||
|
link={{
|
||||||
|
href: "https://portal.thirdweb.com/x402/server",
|
||||||
|
label: "Get Started",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FeatureCard
|
||||||
|
title="Let your users pay for x402 resources"
|
||||||
|
description="Handle x402 payments from any user wallet in your apps"
|
||||||
|
icon={WalletIcon}
|
||||||
|
id="x402_client"
|
||||||
|
setupTime={2}
|
||||||
|
features={[
|
||||||
|
"Works with any wallet",
|
||||||
|
"No gas required",
|
||||||
|
"One line of code",
|
||||||
|
]}
|
||||||
|
link={{
|
||||||
|
href: "https://portal.thirdweb.com/x402/client",
|
||||||
|
label: "Get Started",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FeatureCard
|
||||||
|
title="Equip your agents with x402 tools"
|
||||||
|
description="Give your AI agents a wallet and the ability to pay for any x402 resource"
|
||||||
|
icon={BotIcon}
|
||||||
|
id="x402_agents"
|
||||||
|
setupTime={2}
|
||||||
|
features={[
|
||||||
|
"Remote MCP server",
|
||||||
|
"Low level APIs",
|
||||||
|
"Works with any AI framework",
|
||||||
|
]}
|
||||||
|
link={{
|
||||||
|
href: "https://portal.thirdweb.com/x402/agents",
|
||||||
|
label: "Get Started",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { usePathname, useSearchParams } from "next/navigation";
|
||||||
|
import { useCallback } from "react";
|
||||||
|
import { useDashboardRouter } from "@/lib/DashboardRouter";
|
||||||
|
import type { Metric } from "./MetricSwitcher";
|
||||||
|
import { MetricSwitcher } from "./MetricSwitcher";
|
||||||
|
|
||||||
|
export function ChartMetricSwitcher() {
|
||||||
|
const router = useDashboardRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const metric = (searchParams.get("metric") as Metric) || "payments";
|
||||||
|
|
||||||
|
const handleMetricChange = useCallback(
|
||||||
|
(newMetric: Metric) => {
|
||||||
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
|
params.set("metric", newMetric);
|
||||||
|
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||||
|
},
|
||||||
|
[pathname, router, searchParams],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<MetricSwitcher value={metric} onChange={handleMetricChange} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from "@/components/ui/select";
|
||||||
|
|
||||||
|
export type Metric = "payments" | "volume";
|
||||||
|
|
||||||
|
export function MetricSwitcher(props: {
|
||||||
|
value: Metric;
|
||||||
|
onChange: (value: Metric) => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-muted-foreground text-sm font-medium">Show:</span>
|
||||||
|
<Select value={props.value} onValueChange={props.onChange}>
|
||||||
|
<SelectTrigger className="w-[180px] rounded-full">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="payments">Payments</SelectItem>
|
||||||
|
<SelectItem value="volume">Volume (USD)</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+133
@@ -0,0 +1,133 @@
|
|||||||
|
import { CreditCardIcon, DollarSignIcon, UsersIcon } from "lucide-react";
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import { getX402Settlements } from "@/api/analytics";
|
||||||
|
import type { Range } from "@/components/analytics/date-range-selector";
|
||||||
|
import { StatCard } from "@/components/analytics/stat";
|
||||||
|
import type {
|
||||||
|
X402SettlementsByPayer,
|
||||||
|
X402SettlementsOverall,
|
||||||
|
} from "@/types/analytics";
|
||||||
|
|
||||||
|
function X402SummaryInner(props: {
|
||||||
|
totalPayments: number | undefined;
|
||||||
|
totalBuyers: number | undefined;
|
||||||
|
totalVolume: number | undefined;
|
||||||
|
isPending: boolean;
|
||||||
|
}) {
|
||||||
|
const formatUSD = (value: number) => {
|
||||||
|
return `$${value.toLocaleString("en-US", {
|
||||||
|
minimumFractionDigits: 2,
|
||||||
|
maximumFractionDigits: 6,
|
||||||
|
})}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-3 gap-4">
|
||||||
|
<StatCard
|
||||||
|
icon={CreditCardIcon}
|
||||||
|
isPending={props.isPending}
|
||||||
|
label="Total Payments"
|
||||||
|
value={props.totalPayments || 0}
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
icon={UsersIcon}
|
||||||
|
isPending={props.isPending}
|
||||||
|
label="Total Buyers"
|
||||||
|
value={props.totalBuyers || 0}
|
||||||
|
/>
|
||||||
|
<StatCard
|
||||||
|
formatter={formatUSD}
|
||||||
|
icon={DollarSignIcon}
|
||||||
|
isPending={props.isPending}
|
||||||
|
label="Total Volume"
|
||||||
|
value={props.totalVolume || 0}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function AsyncX402Summary(props: {
|
||||||
|
teamId: string;
|
||||||
|
projectId: string;
|
||||||
|
authToken: string;
|
||||||
|
range: Range;
|
||||||
|
}) {
|
||||||
|
const { teamId, projectId, authToken, range } = props;
|
||||||
|
|
||||||
|
const [overallStats, payerStats] = await Promise.all([
|
||||||
|
getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: "all",
|
||||||
|
projectId,
|
||||||
|
teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "overall",
|
||||||
|
},
|
||||||
|
authToken,
|
||||||
|
).catch(() => []),
|
||||||
|
getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: "all",
|
||||||
|
projectId,
|
||||||
|
teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "payer",
|
||||||
|
},
|
||||||
|
authToken,
|
||||||
|
).catch(() => []),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const totalPayments = (overallStats as X402SettlementsOverall[]).reduce(
|
||||||
|
(acc, curr) => acc + curr.totalRequests,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
const totalVolume = (overallStats as X402SettlementsOverall[]).reduce(
|
||||||
|
(acc, curr) => acc + curr.totalValueUSD,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Count unique payers
|
||||||
|
const uniquePayers = new Set(
|
||||||
|
(payerStats as X402SettlementsByPayer[]).map((stat) => stat.payer),
|
||||||
|
);
|
||||||
|
const totalBuyers = uniquePayers.size;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<X402SummaryInner
|
||||||
|
totalBuyers={totalBuyers}
|
||||||
|
totalPayments={totalPayments}
|
||||||
|
totalVolume={totalVolume}
|
||||||
|
isPending={false}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function X402Summary(props: {
|
||||||
|
teamId: string;
|
||||||
|
projectId: string;
|
||||||
|
authToken: string;
|
||||||
|
range: Range;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Suspense
|
||||||
|
fallback={
|
||||||
|
<X402SummaryInner
|
||||||
|
totalBuyers={undefined}
|
||||||
|
totalPayments={undefined}
|
||||||
|
totalVolume={undefined}
|
||||||
|
isPending={true}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<AsyncX402Summary
|
||||||
|
authToken={props.authToken}
|
||||||
|
projectId={props.projectId}
|
||||||
|
range={props.range}
|
||||||
|
teamId={props.teamId}
|
||||||
|
/>
|
||||||
|
</Suspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
+160
@@ -0,0 +1,160 @@
|
|||||||
|
"use client";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { type ReactNode, useMemo } from "react";
|
||||||
|
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
|
||||||
|
import type { ChartConfig } from "@/components/ui/chart";
|
||||||
|
import { useAllChainsData } from "@/hooks/chains/allChains";
|
||||||
|
import type { X402SettlementsByChainId } from "@/types/analytics";
|
||||||
|
import { toUSD } from "@/utils/number";
|
||||||
|
|
||||||
|
type ChartData = Record<string, number> & {
|
||||||
|
time: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function X402SettlementsByChainChartCard({
|
||||||
|
rawData,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: {
|
||||||
|
rawData: X402SettlementsByChainId[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
}) {
|
||||||
|
const maxChainsToDisplay = 10;
|
||||||
|
const isVolumeMetric = metric === "volume";
|
||||||
|
const chainsStore = useAllChainsData();
|
||||||
|
|
||||||
|
const { data, chainsToDisplay, chartConfig, isAllEmpty } = useMemo(() => {
|
||||||
|
const dateToValueMap: Map<string, ChartData> = new Map();
|
||||||
|
const chainToCountMap: Map<string, number> = new Map();
|
||||||
|
|
||||||
|
for (const dataItem of rawData) {
|
||||||
|
const { date, chainId, totalRequests, totalValueUSD } = dataItem;
|
||||||
|
const value = isVolumeMetric ? totalValueUSD : totalRequests;
|
||||||
|
let dateRecord = dateToValueMap.get(date);
|
||||||
|
|
||||||
|
if (!dateRecord) {
|
||||||
|
dateRecord = { time: date } as ChartData;
|
||||||
|
dateToValueMap.set(date, dateRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert chainId to chain name
|
||||||
|
const chain = chainsStore.idToChain.get(Number(chainId));
|
||||||
|
const chainName = chain?.name || chainId.toString();
|
||||||
|
|
||||||
|
dateRecord[chainName] = (dateRecord[chainName] || 0) + value;
|
||||||
|
chainToCountMap.set(
|
||||||
|
chainName,
|
||||||
|
(chainToCountMap.get(chainName) || 0) + value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort chains by count (highest count first) - remove the ones with 0 count
|
||||||
|
const sortedChainsByCount = Array.from(chainToCountMap.entries())
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.filter((x) => x[1] > 0);
|
||||||
|
|
||||||
|
const chainsToDisplayArray = sortedChainsByCount
|
||||||
|
.slice(0, maxChainsToDisplay)
|
||||||
|
.map(([chain]) => chain);
|
||||||
|
const chainsToDisplaySet = new Set(chainsToDisplayArray);
|
||||||
|
|
||||||
|
// Loop over each entry in dateToValueMap
|
||||||
|
// Replace the chain that is not in chainsToDisplay with "Other"
|
||||||
|
// Add total key that is the sum of all chains
|
||||||
|
for (const dateRecord of dateToValueMap.values()) {
|
||||||
|
// Calculate total
|
||||||
|
let totalCountOfDay = 0;
|
||||||
|
for (const key of Object.keys(dateRecord)) {
|
||||||
|
if (key !== "time") {
|
||||||
|
totalCountOfDay += (dateRecord[key] as number) || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysToMove = Object.keys(dateRecord).filter(
|
||||||
|
(key) => key !== "time" && !chainsToDisplaySet.has(key),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const chain of keysToMove) {
|
||||||
|
dateRecord.Other = (dateRecord.Other || 0) + (dateRecord[chain] || 0);
|
||||||
|
delete dateRecord[chain];
|
||||||
|
}
|
||||||
|
|
||||||
|
dateRecord.total = totalCountOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnValue: ChartData[] = Array.from(dateToValueMap.values()).sort(
|
||||||
|
(a, b) => new Date(a.time).getTime() - new Date(b.time).getTime(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const chartConfig: ChartConfig = {};
|
||||||
|
for (let i = 0; i < chainsToDisplayArray.length; i++) {
|
||||||
|
const chain = chainsToDisplayArray[i];
|
||||||
|
if (chain) {
|
||||||
|
chartConfig[chain] = {
|
||||||
|
label: chain,
|
||||||
|
color: `hsl(var(--chart-${(i % 10) + 1}))`,
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need to display "Other" chains
|
||||||
|
if (sortedChainsByCount.length > maxChainsToDisplay) {
|
||||||
|
chartConfig.Other = {
|
||||||
|
label: "Other",
|
||||||
|
color: "hsl(var(--muted-foreground))",
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
chainsToDisplayArray.push("Other");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
chartConfig,
|
||||||
|
data: returnValue,
|
||||||
|
isAllEmpty: returnValue.every((d) => (d.total || 0) === 0),
|
||||||
|
chainsToDisplay: chainsToDisplayArray,
|
||||||
|
};
|
||||||
|
}, [rawData, isVolumeMetric, chainsStore]);
|
||||||
|
|
||||||
|
const emptyChartState = (
|
||||||
|
<div className="flex h-[250px] items-center justify-center">
|
||||||
|
<p className="text-muted-foreground text-sm">No data available</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = isVolumeMetric ? "Volume by Chain" : "Payments by Chain";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThirdwebBarChart
|
||||||
|
chartClassName="aspect-auto h-[250px]"
|
||||||
|
config={chartConfig}
|
||||||
|
customHeader={
|
||||||
|
<div className="px-6 pt-6">
|
||||||
|
<h3 className="mb-0.5 font-semibold text-xl tracking-tight">
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
data={data}
|
||||||
|
emptyChartState={emptyChartState}
|
||||||
|
hideLabel={false}
|
||||||
|
isPending={isPending}
|
||||||
|
showLegend
|
||||||
|
toolTipValueFormatter={(value: unknown) => {
|
||||||
|
if (isVolumeMetric) {
|
||||||
|
return `${toUSD(Number(value))}`;
|
||||||
|
}
|
||||||
|
return value as ReactNode;
|
||||||
|
}}
|
||||||
|
toolTipLabelFormatter={(_v, item) => {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
const time = item[0].payload.time as string;
|
||||||
|
return format(new Date(time), "MMM d, yyyy");
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}}
|
||||||
|
variant="stacked"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
+158
@@ -0,0 +1,158 @@
|
|||||||
|
"use client";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { type ReactNode, useMemo } from "react";
|
||||||
|
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
|
||||||
|
import type { ChartConfig } from "@/components/ui/chart";
|
||||||
|
import type { X402SettlementsByPayer } from "@/types/analytics";
|
||||||
|
import { toUSD } from "@/utils/number";
|
||||||
|
|
||||||
|
type ChartData = Record<string, number> & {
|
||||||
|
time: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function X402SettlementsByPayerChartCard({
|
||||||
|
rawData,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: {
|
||||||
|
rawData: X402SettlementsByPayer[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
}) {
|
||||||
|
const maxPayersToDisplay = 10;
|
||||||
|
const isVolumeMetric = metric === "volume";
|
||||||
|
|
||||||
|
const { data, payersToDisplay, chartConfig, isAllEmpty } = useMemo(() => {
|
||||||
|
const dateToValueMap: Map<string, ChartData> = new Map();
|
||||||
|
const payerToCountMap: Map<string, number> = new Map();
|
||||||
|
|
||||||
|
for (const dataItem of rawData) {
|
||||||
|
const { date, payer, totalRequests, totalValueUSD } = dataItem;
|
||||||
|
const value = isVolumeMetric ? totalValueUSD : totalRequests;
|
||||||
|
let dateRecord = dateToValueMap.get(date);
|
||||||
|
|
||||||
|
if (!dateRecord) {
|
||||||
|
dateRecord = { time: date } as ChartData;
|
||||||
|
dateToValueMap.set(date, dateRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Truncate payer address for display
|
||||||
|
const displayPayer =
|
||||||
|
payer.length > 10 ? `${payer.slice(0, 6)}...${payer.slice(-4)}` : payer;
|
||||||
|
|
||||||
|
dateRecord[displayPayer] = (dateRecord[displayPayer] || 0) + value;
|
||||||
|
payerToCountMap.set(
|
||||||
|
displayPayer,
|
||||||
|
(payerToCountMap.get(displayPayer) || 0) + value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort payers by count (highest count first) - remove the ones with 0 count
|
||||||
|
const sortedPayersByCount = Array.from(payerToCountMap.entries())
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.filter((x) => x[1] > 0);
|
||||||
|
|
||||||
|
const payersToDisplayArray = sortedPayersByCount
|
||||||
|
.slice(0, maxPayersToDisplay)
|
||||||
|
.map(([payer]) => payer);
|
||||||
|
const payersToDisplay = new Set(payersToDisplayArray);
|
||||||
|
|
||||||
|
// Loop over each entry in dateToValueMap
|
||||||
|
// Replace the payer that is not in payersToDisplay with "Other"
|
||||||
|
// Add total key that is the sum of all payers
|
||||||
|
for (const dateRecord of dateToValueMap.values()) {
|
||||||
|
// Calculate total
|
||||||
|
let totalCountOfDay = 0;
|
||||||
|
for (const key of Object.keys(dateRecord)) {
|
||||||
|
if (key !== "time") {
|
||||||
|
totalCountOfDay += (dateRecord[key] as number) || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysToMove = Object.keys(dateRecord).filter(
|
||||||
|
(key) => key !== "time" && !payersToDisplay.has(key),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const payer of keysToMove) {
|
||||||
|
dateRecord.Other = (dateRecord.Other || 0) + (dateRecord[payer] || 0);
|
||||||
|
delete dateRecord[payer];
|
||||||
|
}
|
||||||
|
|
||||||
|
dateRecord.total = totalCountOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnValue: ChartData[] = Array.from(dateToValueMap.values()).sort(
|
||||||
|
(a, b) => new Date(a.time).getTime() - new Date(b.time).getTime(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const chartConfig: ChartConfig = {};
|
||||||
|
for (let i = 0; i < payersToDisplayArray.length; i++) {
|
||||||
|
const payer = payersToDisplayArray[i];
|
||||||
|
if (payer) {
|
||||||
|
chartConfig[payer] = {
|
||||||
|
label: payer,
|
||||||
|
color: `hsl(var(--chart-${(i % 10) + 1}))`,
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need to display "Other" payers
|
||||||
|
if (sortedPayersByCount.length > maxPayersToDisplay) {
|
||||||
|
chartConfig.Other = {
|
||||||
|
label: "Other",
|
||||||
|
color: "hsl(var(--muted-foreground))",
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
payersToDisplayArray.push("Other");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
chartConfig,
|
||||||
|
data: returnValue,
|
||||||
|
isAllEmpty: returnValue.every((d) => (d.total || 0) === 0),
|
||||||
|
payersToDisplay: payersToDisplayArray,
|
||||||
|
};
|
||||||
|
}, [rawData, isVolumeMetric]);
|
||||||
|
|
||||||
|
const emptyChartState = (
|
||||||
|
<div className="flex h-[250px] items-center justify-center">
|
||||||
|
<p className="text-muted-foreground text-sm">No data available</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = isVolumeMetric ? "Volume by Buyer" : "Payments by Buyer";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThirdwebBarChart
|
||||||
|
chartClassName="aspect-auto h-[250px]"
|
||||||
|
config={chartConfig}
|
||||||
|
customHeader={
|
||||||
|
<div className="px-6 pt-6">
|
||||||
|
<h3 className="mb-0.5 font-semibold text-xl tracking-tight">
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
data={data}
|
||||||
|
emptyChartState={emptyChartState}
|
||||||
|
hideLabel={false}
|
||||||
|
isPending={isPending}
|
||||||
|
showLegend
|
||||||
|
toolTipValueFormatter={(value: unknown) => {
|
||||||
|
if (isVolumeMetric) {
|
||||||
|
return `${toUSD(Number(value))}`;
|
||||||
|
}
|
||||||
|
return value as ReactNode;
|
||||||
|
}}
|
||||||
|
toolTipLabelFormatter={(_v, item) => {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
const time = item[0].payload.time as string;
|
||||||
|
return format(new Date(time), "MMM d, yyyy");
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}}
|
||||||
|
variant="stacked"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
+155
@@ -0,0 +1,155 @@
|
|||||||
|
"use client";
|
||||||
|
import { format } from "date-fns";
|
||||||
|
import { type ReactNode, useMemo } from "react";
|
||||||
|
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
|
||||||
|
import type { ChartConfig } from "@/components/ui/chart";
|
||||||
|
import type { X402SettlementsByResource } from "@/types/analytics";
|
||||||
|
import { toUSD } from "@/utils/number";
|
||||||
|
|
||||||
|
type ChartData = Record<string, number> & {
|
||||||
|
time: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function X402SettlementsByResourceChartCard({
|
||||||
|
rawData,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: {
|
||||||
|
rawData: X402SettlementsByResource[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
}) {
|
||||||
|
const maxResourcesToDisplay = 10;
|
||||||
|
const isVolumeMetric = metric === "volume";
|
||||||
|
|
||||||
|
const { data, resourcesToDisplay, chartConfig, isAllEmpty } = useMemo(() => {
|
||||||
|
const dateToValueMap: Map<string, ChartData> = new Map();
|
||||||
|
const resourceToCountMap: Map<string, number> = new Map();
|
||||||
|
|
||||||
|
for (const dataItem of rawData) {
|
||||||
|
const { date, resource, totalRequests, totalValueUSD } = dataItem;
|
||||||
|
const value = isVolumeMetric ? totalValueUSD : totalRequests;
|
||||||
|
let dateRecord = dateToValueMap.get(date);
|
||||||
|
|
||||||
|
if (!dateRecord) {
|
||||||
|
dateRecord = { time: date } as ChartData;
|
||||||
|
dateToValueMap.set(date, dateRecord);
|
||||||
|
}
|
||||||
|
|
||||||
|
dateRecord[resource] = (dateRecord[resource] || 0) + value;
|
||||||
|
resourceToCountMap.set(
|
||||||
|
resource,
|
||||||
|
(resourceToCountMap.get(resource) || 0) + value,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort resources by count (highest count first) - remove the ones with 0 count
|
||||||
|
const sortedResourcesByCount = Array.from(resourceToCountMap.entries())
|
||||||
|
.sort((a, b) => b[1] - a[1])
|
||||||
|
.filter((x) => x[1] > 0);
|
||||||
|
|
||||||
|
const resourcesToDisplayArray = sortedResourcesByCount
|
||||||
|
.slice(0, maxResourcesToDisplay)
|
||||||
|
.map(([resource]) => resource);
|
||||||
|
const resourcesToDisplay = new Set(resourcesToDisplayArray);
|
||||||
|
|
||||||
|
// Loop over each entry in dateToValueMap
|
||||||
|
// Replace the resource that is not in resourcesToDisplay with "Other"
|
||||||
|
// Add total key that is the sum of all resources
|
||||||
|
for (const dateRecord of dateToValueMap.values()) {
|
||||||
|
// Calculate total
|
||||||
|
let totalCountOfDay = 0;
|
||||||
|
for (const key of Object.keys(dateRecord)) {
|
||||||
|
if (key !== "time") {
|
||||||
|
totalCountOfDay += (dateRecord[key] as number) || 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const keysToMove = Object.keys(dateRecord).filter(
|
||||||
|
(key) => key !== "time" && !resourcesToDisplay.has(key),
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const resource of keysToMove) {
|
||||||
|
dateRecord.Other =
|
||||||
|
(dateRecord.Other || 0) + (dateRecord[resource] || 0);
|
||||||
|
delete dateRecord[resource];
|
||||||
|
}
|
||||||
|
|
||||||
|
dateRecord.total = totalCountOfDay;
|
||||||
|
}
|
||||||
|
|
||||||
|
const returnValue: ChartData[] = Array.from(dateToValueMap.values()).sort(
|
||||||
|
(a, b) => new Date(a.time).getTime() - new Date(b.time).getTime(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const chartConfig: ChartConfig = {};
|
||||||
|
for (let i = 0; i < resourcesToDisplayArray.length; i++) {
|
||||||
|
const resource = resourcesToDisplayArray[i];
|
||||||
|
if (resource) {
|
||||||
|
chartConfig[resource] = {
|
||||||
|
label: resource,
|
||||||
|
color: `hsl(var(--chart-${(i % 10) + 1}))`,
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we need to display "Other" resources
|
||||||
|
if (sortedResourcesByCount.length > maxResourcesToDisplay) {
|
||||||
|
chartConfig.Other = {
|
||||||
|
label: "Other",
|
||||||
|
color: "hsl(var(--muted-foreground))",
|
||||||
|
isCurrency: isVolumeMetric,
|
||||||
|
};
|
||||||
|
resourcesToDisplayArray.push("Other");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
chartConfig,
|
||||||
|
data: returnValue,
|
||||||
|
isAllEmpty: returnValue.every((d) => (d.total || 0) === 0),
|
||||||
|
resourcesToDisplay: resourcesToDisplayArray,
|
||||||
|
};
|
||||||
|
}, [rawData, isVolumeMetric]);
|
||||||
|
|
||||||
|
const emptyChartState = (
|
||||||
|
<div className="flex h-[250px] items-center justify-center">
|
||||||
|
<p className="text-muted-foreground text-sm">No data available</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const title = isVolumeMetric ? "Volume by Resource" : "Payments by Resource";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ThirdwebBarChart
|
||||||
|
chartClassName="aspect-auto h-[250px]"
|
||||||
|
config={chartConfig}
|
||||||
|
customHeader={
|
||||||
|
<div className="px-6 pt-6">
|
||||||
|
<h3 className="mb-0.5 font-semibold text-xl tracking-tight">
|
||||||
|
{title}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
data={data}
|
||||||
|
emptyChartState={emptyChartState}
|
||||||
|
hideLabel={false}
|
||||||
|
isPending={isPending}
|
||||||
|
showLegend
|
||||||
|
toolTipValueFormatter={(value: unknown) => {
|
||||||
|
if (isVolumeMetric) {
|
||||||
|
return `${toUSD(Number(value))}`;
|
||||||
|
}
|
||||||
|
return value as ReactNode;
|
||||||
|
}}
|
||||||
|
toolTipLabelFormatter={(_v, item) => {
|
||||||
|
if (Array.isArray(item)) {
|
||||||
|
const time = item[0].payload.time as string;
|
||||||
|
return format(new Date(time), "MMM d, yyyy");
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}}
|
||||||
|
variant="stacked"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
+249
@@ -0,0 +1,249 @@
|
|||||||
|
import { ResponsiveSuspense } from "responsive-rsc";
|
||||||
|
import { getX402Settlements } from "@/api/analytics";
|
||||||
|
import {
|
||||||
|
getLastNDaysRange,
|
||||||
|
type Range,
|
||||||
|
} from "@/components/analytics/date-range-selector";
|
||||||
|
import type {
|
||||||
|
X402SettlementsByChainId,
|
||||||
|
X402SettlementsByPayer,
|
||||||
|
X402SettlementsByResource,
|
||||||
|
} from "@/types/analytics";
|
||||||
|
import { X402SettlementsByChainChartCard } from "./X402SettlementsByChainChartCard";
|
||||||
|
import { X402SettlementsByPayerChartCard } from "./X402SettlementsByPayerChartCard";
|
||||||
|
import { X402SettlementsByResourceChartCard } from "./X402SettlementsByResourceChartCard";
|
||||||
|
|
||||||
|
// Payments by Resource Chart
|
||||||
|
type X402SettlementsByResourceChartProps = {
|
||||||
|
interval: "day" | "week";
|
||||||
|
range: Range;
|
||||||
|
stats: X402SettlementsByResource[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
};
|
||||||
|
|
||||||
|
function X402SettlementsByResourceChartUI({
|
||||||
|
stats,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: X402SettlementsByResourceChartProps) {
|
||||||
|
return (
|
||||||
|
<X402SettlementsByResourceChartCard
|
||||||
|
rawData={stats}
|
||||||
|
isPending={isPending}
|
||||||
|
metric={metric}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type AsyncX402SettlementsByResourceChartProps = Omit<
|
||||||
|
X402SettlementsByResourceChartProps,
|
||||||
|
"stats" | "isPending"
|
||||||
|
> & {
|
||||||
|
teamId: string;
|
||||||
|
projectId: string;
|
||||||
|
authToken: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function AsyncX402SettlementsByResourceChart(
|
||||||
|
props: AsyncX402SettlementsByResourceChartProps,
|
||||||
|
) {
|
||||||
|
const range = props.range ?? getLastNDaysRange("last-30");
|
||||||
|
|
||||||
|
const stats = await getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: props.interval,
|
||||||
|
projectId: props.projectId,
|
||||||
|
teamId: props.teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "resource",
|
||||||
|
},
|
||||||
|
props.authToken,
|
||||||
|
).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<X402SettlementsByResourceChartUI
|
||||||
|
{...props}
|
||||||
|
isPending={false}
|
||||||
|
range={range}
|
||||||
|
stats={stats as X402SettlementsByResource[]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function X402SettlementsByResourceChart(
|
||||||
|
props: AsyncX402SettlementsByResourceChartProps,
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<ResponsiveSuspense
|
||||||
|
fallback={
|
||||||
|
<X402SettlementsByResourceChartUI
|
||||||
|
{...props}
|
||||||
|
isPending={true}
|
||||||
|
stats={[]}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
searchParamsUsed={["from", "to", "interval", "metric"]}
|
||||||
|
>
|
||||||
|
<AsyncX402SettlementsByResourceChart {...props} />
|
||||||
|
</ResponsiveSuspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payments by Payer Chart
|
||||||
|
type X402SettlementsByPayerChartProps = {
|
||||||
|
interval: "day" | "week";
|
||||||
|
range: Range;
|
||||||
|
stats: X402SettlementsByPayer[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
};
|
||||||
|
|
||||||
|
function X402SettlementsByPayerChartUI({
|
||||||
|
stats,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: X402SettlementsByPayerChartProps) {
|
||||||
|
return (
|
||||||
|
<X402SettlementsByPayerChartCard
|
||||||
|
rawData={stats}
|
||||||
|
isPending={isPending}
|
||||||
|
metric={metric}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type AsyncX402SettlementsByPayerChartProps = Omit<
|
||||||
|
X402SettlementsByPayerChartProps,
|
||||||
|
"stats" | "isPending"
|
||||||
|
> & {
|
||||||
|
teamId: string;
|
||||||
|
projectId: string;
|
||||||
|
authToken: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function AsyncX402SettlementsByPayerChart(
|
||||||
|
props: AsyncX402SettlementsByPayerChartProps,
|
||||||
|
) {
|
||||||
|
const range = props.range ?? getLastNDaysRange("last-30");
|
||||||
|
|
||||||
|
const stats = await getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: props.interval,
|
||||||
|
projectId: props.projectId,
|
||||||
|
teamId: props.teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "payer",
|
||||||
|
},
|
||||||
|
props.authToken,
|
||||||
|
).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<X402SettlementsByPayerChartUI
|
||||||
|
{...props}
|
||||||
|
isPending={false}
|
||||||
|
range={range}
|
||||||
|
stats={stats as X402SettlementsByPayer[]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function X402SettlementsByPayerChart(
|
||||||
|
props: AsyncX402SettlementsByPayerChartProps,
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<ResponsiveSuspense
|
||||||
|
fallback={
|
||||||
|
<X402SettlementsByPayerChartUI {...props} isPending={true} stats={[]} />
|
||||||
|
}
|
||||||
|
searchParamsUsed={["from", "to", "interval", "metric"]}
|
||||||
|
>
|
||||||
|
<AsyncX402SettlementsByPayerChart {...props} />
|
||||||
|
</ResponsiveSuspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payments by Chain Chart
|
||||||
|
type X402SettlementsByChainChartProps = {
|
||||||
|
interval: "day" | "week";
|
||||||
|
range: Range;
|
||||||
|
stats: X402SettlementsByChainId[];
|
||||||
|
isPending: boolean;
|
||||||
|
metric?: "payments" | "volume";
|
||||||
|
};
|
||||||
|
|
||||||
|
function X402SettlementsByChainChartUI({
|
||||||
|
stats,
|
||||||
|
isPending,
|
||||||
|
metric = "payments",
|
||||||
|
}: X402SettlementsByChainChartProps) {
|
||||||
|
return (
|
||||||
|
<X402SettlementsByChainChartCard
|
||||||
|
rawData={stats}
|
||||||
|
isPending={isPending}
|
||||||
|
metric={metric}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
type AsyncX402SettlementsByChainChartProps = Omit<
|
||||||
|
X402SettlementsByChainChartProps,
|
||||||
|
"stats" | "isPending"
|
||||||
|
> & {
|
||||||
|
teamId: string;
|
||||||
|
projectId: string;
|
||||||
|
authToken: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
async function AsyncX402SettlementsByChainChart(
|
||||||
|
props: AsyncX402SettlementsByChainChartProps,
|
||||||
|
) {
|
||||||
|
const range = props.range ?? getLastNDaysRange("last-30");
|
||||||
|
|
||||||
|
const stats = await getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: props.interval,
|
||||||
|
projectId: props.projectId,
|
||||||
|
teamId: props.teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "chainId",
|
||||||
|
},
|
||||||
|
props.authToken,
|
||||||
|
).catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<X402SettlementsByChainChartUI
|
||||||
|
{...props}
|
||||||
|
isPending={false}
|
||||||
|
range={range}
|
||||||
|
stats={stats as X402SettlementsByChainId[]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function X402SettlementsByChainChart(
|
||||||
|
props: AsyncX402SettlementsByChainChartProps,
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
<ResponsiveSuspense
|
||||||
|
fallback={
|
||||||
|
<X402SettlementsByChainChartUI {...props} isPending={true} stats={[]} />
|
||||||
|
}
|
||||||
|
searchParamsUsed={["from", "to", "interval", "metric"]}
|
||||||
|
>
|
||||||
|
<AsyncX402SettlementsByChainChart {...props} />
|
||||||
|
</ResponsiveSuspense>
|
||||||
|
);
|
||||||
|
}
|
||||||
+63
@@ -0,0 +1,63 @@
|
|||||||
|
import { CodeServer } from "@/components/ui/code/code.server";
|
||||||
|
import { WaitingForIntegrationCard } from "../../components/WaitingForIntegrationCard/WaitingForIntegrationCard";
|
||||||
|
|
||||||
|
export function X402EmptyState(props: { walletAddress?: string }) {
|
||||||
|
return (
|
||||||
|
<WaitingForIntegrationCard
|
||||||
|
codeTabs={[
|
||||||
|
{
|
||||||
|
code: (
|
||||||
|
<CodeServer
|
||||||
|
className="bg-background"
|
||||||
|
code={jsCode(props.walletAddress)}
|
||||||
|
lang="ts"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
label: "JavaScript",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
ctas={[
|
||||||
|
{
|
||||||
|
href: "https://portal.thirdweb.com/x402",
|
||||||
|
label: "View Docs",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
title="Start Monetizing your API"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const jsCode = (walletAddress?: string) => `\
|
||||||
|
import { createThirdwebClient } from "thirdweb";
|
||||||
|
import { facilitator, settlePayment } from "thirdweb/x402";
|
||||||
|
import { arbitrumSepolia } from "thirdweb/chains";
|
||||||
|
|
||||||
|
const client = createThirdwebClient({ secretKey: "your-secret-key" });
|
||||||
|
|
||||||
|
const thirdwebX402Facilitator = facilitator({
|
||||||
|
client,
|
||||||
|
serverWalletAddress: "${walletAddress || "0xYourWalletAddress"}",
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
// process the payment
|
||||||
|
const result = await settlePayment({
|
||||||
|
resourceUrl: "https://api.example.com/premium-content",
|
||||||
|
method: "GET",
|
||||||
|
paymentData: request.headers.get("x-payment"),
|
||||||
|
network: arbitrumSepolia,
|
||||||
|
price: "$0.01",
|
||||||
|
facilitator: thirdwebX402Facilitator,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.status === 200) {
|
||||||
|
// Payment successful, continue to app logic
|
||||||
|
return Response.json({ data: "premium content" });
|
||||||
|
} else {
|
||||||
|
return Response.json(result.responseBody, {
|
||||||
|
status: result.status,
|
||||||
|
headers: result.responseHeaders,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await props.params;
|
||||||
|
|
||||||
|
const authToken = await getAuthToken();
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(
|
||||||
|
`/team/${params.team_slug}/${params.project_slug}/x402/configuration`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const project = await getProject(params.team_slug, params.project_slug);
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-6">
|
||||||
|
<div className="rounded-lg border border-border bg-card p-8 text-center">
|
||||||
|
<h2 className="text-2xl font-semibold">Coming Soon</h2>
|
||||||
|
<p className="mt-2 text-muted-foreground">
|
||||||
|
x402 payments configuration will be available soon.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
+64
@@ -0,0 +1,64 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import { ProjectPage } from "@/components/blocks/project-page/project-page";
|
||||||
|
import { getClientThirdwebClient } from "@/constants/thirdweb-client.client";
|
||||||
|
import { PayIcon } from "@/icons/PayIcon";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
|
||||||
|
export default async function Layout(props: {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
}) {
|
||||||
|
const params = await props.params;
|
||||||
|
const basePath = `/team/${params.team_slug}/${params.project_slug}/x402`;
|
||||||
|
|
||||||
|
const [authToken, project] = await Promise.all([
|
||||||
|
getAuthToken(),
|
||||||
|
getProject(params.team_slug, params.project_slug),
|
||||||
|
]);
|
||||||
|
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = getClientThirdwebClient({
|
||||||
|
jwt: authToken,
|
||||||
|
teamId: project.teamId,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ProjectPage
|
||||||
|
header={{
|
||||||
|
icon: PayIcon,
|
||||||
|
title: "x402 Payments",
|
||||||
|
description: "Instant payments for your APIs, apps and agents",
|
||||||
|
actions: null,
|
||||||
|
client,
|
||||||
|
links: [
|
||||||
|
{
|
||||||
|
type: "docs",
|
||||||
|
href: "https://portal.thirdweb.com/x402",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
name: "Overview",
|
||||||
|
path: `${basePath}`,
|
||||||
|
exactMatch: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Configuration",
|
||||||
|
path: `${basePath}/configuration`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{props.children}
|
||||||
|
</ProjectPage>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
import { redirect } from "next/navigation";
|
||||||
|
import { ResponsiveSearchParamsProvider } from "responsive-rsc";
|
||||||
|
import { getX402Settlements } from "@/api/analytics";
|
||||||
|
import { getAuthToken } from "@/api/auth-token";
|
||||||
|
import { getProject } from "@/api/project/projects";
|
||||||
|
import type { DurationId } from "@/components/analytics/date-range-selector";
|
||||||
|
import { ResponsiveTimeFilters } from "@/components/analytics/responsive-time-filters";
|
||||||
|
import { getProjectWallet } from "@/lib/server/project-wallet";
|
||||||
|
import { getFiltersFromSearchParams } from "@/lib/time";
|
||||||
|
import type { X402SettlementsOverall } from "@/types/analytics";
|
||||||
|
import { loginRedirect } from "@/utils/redirects";
|
||||||
|
import {
|
||||||
|
X402SettlementsByChainChart,
|
||||||
|
X402SettlementsByPayerChart,
|
||||||
|
X402SettlementsByResourceChart,
|
||||||
|
} from "./analytics";
|
||||||
|
import { ChartMetricSwitcher } from "./analytics/ChartsSection";
|
||||||
|
import { X402Summary } from "./analytics/Summary";
|
||||||
|
import { X402EmptyState } from "./components/X402EmptyState";
|
||||||
|
import { QuickStartSection } from "./QuickstartSection.client";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
|
export default async function Page(props: {
|
||||||
|
params: Promise<{ team_slug: string; project_slug: string }>;
|
||||||
|
searchParams: Promise<{
|
||||||
|
from?: string;
|
||||||
|
to?: string;
|
||||||
|
type?: string;
|
||||||
|
interval?: string;
|
||||||
|
metric?: string;
|
||||||
|
}>;
|
||||||
|
}) {
|
||||||
|
const [searchParams, params] = await Promise.all([
|
||||||
|
props.searchParams,
|
||||||
|
props.params,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const authToken = await getAuthToken();
|
||||||
|
if (!authToken) {
|
||||||
|
loginRedirect(`/team/${params.team_slug}/${params.project_slug}/x402`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultRange: DurationId = "last-30";
|
||||||
|
const { range, interval } = getFiltersFromSearchParams({
|
||||||
|
defaultRange,
|
||||||
|
from: searchParams.from,
|
||||||
|
interval: searchParams.interval,
|
||||||
|
to: searchParams.to,
|
||||||
|
});
|
||||||
|
|
||||||
|
const project = await getProject(params.team_slug, params.project_slug);
|
||||||
|
if (!project) {
|
||||||
|
redirect(`/team/${params.team_slug}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there are any payments to determine if we should show empty state
|
||||||
|
const overallStats = await getX402Settlements(
|
||||||
|
{
|
||||||
|
from: range.from,
|
||||||
|
period: "all",
|
||||||
|
projectId: project.id,
|
||||||
|
teamId: project.teamId,
|
||||||
|
to: range.to,
|
||||||
|
groupBy: "overall",
|
||||||
|
},
|
||||||
|
authToken,
|
||||||
|
).catch(() => []);
|
||||||
|
|
||||||
|
const totalPayments = (overallStats as X402SettlementsOverall[]).reduce(
|
||||||
|
(acc, curr) => acc + curr.totalRequests,
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get project wallet for prefilling the code snippet
|
||||||
|
const projectWallet = await getProjectWallet(project);
|
||||||
|
|
||||||
|
const metric = (searchParams.metric as "payments" | "volume") || "payments";
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ResponsiveSearchParamsProvider value={searchParams}>
|
||||||
|
<div className="flex flex-col gap-4 md:gap-6">
|
||||||
|
<ResponsiveTimeFilters defaultRange={defaultRange} />
|
||||||
|
{totalPayments === 0 ? (
|
||||||
|
<X402EmptyState walletAddress={projectWallet?.address} />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<X402Summary
|
||||||
|
authToken={authToken}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
<ChartMetricSwitcher />
|
||||||
|
<X402SettlementsByResourceChart
|
||||||
|
authToken={authToken}
|
||||||
|
interval={interval}
|
||||||
|
metric={metric}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
<X402SettlementsByChainChart
|
||||||
|
authToken={authToken}
|
||||||
|
interval={interval}
|
||||||
|
metric={metric}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
<X402SettlementsByPayerChart
|
||||||
|
authToken={authToken}
|
||||||
|
interval={interval}
|
||||||
|
metric={metric}
|
||||||
|
projectId={project.id}
|
||||||
|
range={range}
|
||||||
|
teamId={project.teamId}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<div className="pt-4">
|
||||||
|
<QuickStartSection />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ResponsiveSearchParamsProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 64 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user