Skip to content

feat: {Safe} support #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/example-next/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
NEXT_PUBLIC_PWN_API_URL=https://api.pwn.xyz
NEXT_PUBLIC_PWN_API_URL=https://api.pwn.xyz
NEXT_PUBLIC_PROJECT_ID=
112 changes: 53 additions & 59 deletions apps/example-next/next.config.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,71 @@
//@ts-check

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { composePlugins, withNx } = require('@nx/next');
const { composePlugins, withNx } = require("@nx/next");

/**
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
nx: {
// Set this to true if you would like to use SVGR
// See: https://github.com/gregberge/svgr
svgr: false,
},
nx: {
// Set this to true if you would like to use SVGR
// See: https://github.com/gregberge/svgr
svgr: false,
},

eslint: {
ignoreDuringBuilds: true
},
eslint: {
ignoreDuringBuilds: true,
},

// Add transpilePackages to ensure proper handling of monorepo packages
transpilePackages: [
'@pwndao/sdk-core',
'@pwndao/v1-core',
'@pwndao/sdk-v1-react',
'@pwndao/api-sdk',
],
// Add transpilePackages to ensure proper handling of monorepo packages
transpilePackages: [
"@pwndao/sdk-core",
"@pwndao/v1-core",
"@pwndao/sdk-v1-react",
"@pwndao/api-sdk",
"@reown/appkit",
"@reown/appkit-adapter-wagmi",
],

// Configure webpack to handle React Query properly
webpack: (config, { isServer }) => {
// Fix for pino-pretty
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
net: false,
tls: false,
'pino-pretty': false,
};
}
// Configure webpack to handle React Query and AppKit properly
webpack: (config) => {
config.externals.push("pino-pretty", "lokijs", "encoding");
return config;
},

return config;
},
// backend expects trailing slashes
trailingSlash: true,
// showing kids how to bypass the cors
async rewrites() {
return [
// Handle URLs without trailing slash
{
source: '/api/v1/:path*',
destination: 'http://dev-3.pwn.xyz/api/v1/:path*',
},
// Handle URLs that already have a trailing slash
{
source: '/api/v1/:path*/',
destination: 'https://dev-3.pwn.xyz/api/v1/:path*/',
},
// Handle URLs that already have a trailing slash
{
source: '/api/v2/:path*/',
destination: 'https://dev-3.pwn.xyz/api/v2/:path*/',
},
// Handle URLs without trailing slash
{
source: '/api/v2/:path*',
destination: 'https://dev-3.pwn.xyz/api/v2/:path*',
},
];
},
// backend expects trailing slashes
trailingSlash: true,

// showing kids how to bypass the cors
async rewrites() {
return [
// Handle URLs without trailing slash
{
source: "/api/v1/:path*",
destination: "http://api-staging.pwn.xyz/api/v1/:path*",
},
// Handle URLs that already have a trailing slash
{
source: "/api/v1/:path*/",
destination: "https://api-staging.pwn.xyz/api/v1/:path*/",
},
// Handle URLs that already have a trailing slash
{
source: "/api/v2/:path*/",
destination: "https://api-staging.pwn.xyz/api/v2/:path*/",
},
// Handle URLs without trailing slash
{
source: "/api/v2/:path*",
destination: "https://api-staging.pwn.xyz/api/v2/:path*",
},
];
},
};

const plugins = [
// Add more Next.js plugins to this list if needed.
withNx,
// Add more Next.js plugins to this list if needed.
withNx,
];

module.exports = composePlugins(...plugins)(nextConfig);
3 changes: 3 additions & 0 deletions apps/example-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
"@pwndao/v1-core": "workspace:*",
"@radix-ui/react-label": "^2.1.2",
"@radix-ui/react-slot": "^1.1.2",
"@reown/appkit": "^1.7.2",
"@reown/appkit-adapter-wagmi": "^1.7.2",
"@tailwindcss/postcss": "^4.0.13",
"@tanstack/query-core": "^5.67.3",
"@tanstack/react-query": "^5.67.3",
"@web3modal/wagmi": "^5.1.11",
"ansi-styles": "^6.2.1",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
Expand Down
31 changes: 16 additions & 15 deletions apps/example-next/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import type { Metadata } from "next";
import "./global.css";

import Header from "@/components/Header";
import type { ReactNode } from "react";
import { Providers } from "./providers";
import ContextProvider from "@/context";
import { headers } from "next/headers"; // added

export const metadata = {
title: "PWN SDK Examples",
description: "Example components to interact with the PWN Protocol",
export const metadata: Metadata = {
title: "AppKit Example App",
description: "Powered by Reown",
};

export default function RootLayout({
export default async function RootLayout({
children,
}: {
children: ReactNode;
}) {
}: Readonly<{
children: React.ReactNode;
}>) {
const headersObj = await headers();
const cookies = headersObj.get("cookie");

return (
<html lang="en">
<body>
<Providers>
<div className="min-h-screen flex flex-col">
<Header />
<main className="flex-1">{children}</main>
</div>
</Providers>
<Header />
<ContextProvider cookies={cookies}>{children}</ContextProvider>
</body>
</html>
);
Expand Down
16 changes: 0 additions & 16 deletions apps/example-next/src/app/providers.tsx

This file was deleted.

3 changes: 3 additions & 0 deletions apps/example-next/src/components/ConnectButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function ConnectButton() {
return <appkit-button />;
}
2 changes: 2 additions & 0 deletions apps/example-next/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button } from "@/components/ui/button";
import Link from "next/link";
import ConnectButton from "./ConnectButton";

export default function Header() {
return (
Expand All @@ -24,6 +25,7 @@ export default function Header() {
</nav>
</div>
<div className="flex items-center space-x-4">
<ConnectButton />
<Link
href="https://github.com/pwndao"
target="_blank"
Expand Down
23 changes: 23 additions & 0 deletions apps/example-next/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
import { cookieStorage, createStorage } from "@wagmi/core";
import { mainnet, arbitrum, base, polygon, sepolia } from '@reown/appkit/networks'


export const projectId = process.env.NEXT_PUBLIC_PROJECT_ID;

if (!projectId) {
throw new Error("Project ID is not defined");
}

export const networks = [mainnet, arbitrum, base, polygon, sepolia];

export const wagmiAdapter = new WagmiAdapter({
storage: createStorage({
storage: cookieStorage,
}),
ssr: true,
projectId,
networks,
});

export const config = wagmiAdapter.wagmiConfig;
48 changes: 48 additions & 0 deletions apps/example-next/src/context/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use client'

import { wagmiAdapter, projectId } from '@/config'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { createAppKit } from '@reown/appkit/react'
import { mainnet, arbitrum, base, polygon, sepolia } from '@reown/appkit/networks'
import React, { type ReactNode } from 'react'
import { cookieToInitialState, WagmiProvider, type Config } from 'wagmi'

const queryClient = new QueryClient()

if (!projectId) {
throw new Error('Project ID is not defined')
}

// Set up metadata
const metadata = {
name: 'appkit-example',
description: 'AppKit Example',
url: 'https://appkitexampleapp.com', // origin must match your domain & subdomain
icons: ['https://avatars.githubusercontent.com/u/179229932']
}

// Create the modal
const modal = createAppKit({
adapters: [wagmiAdapter],
projectId,
networks: [mainnet, arbitrum, base, polygon, sepolia],
defaultNetwork: mainnet,
metadata: metadata,
features: {
analytics: true // Optional - defaults to your Cloud configuration
}
})

console.log(modal)

function ContextProvider({ children, cookies }: { children: ReactNode; cookies: string | null }) {
const initialState = cookieToInitialState(wagmiAdapter.wagmiConfig as Config, cookies)

return (
<WagmiProvider config={wagmiAdapter.wagmiConfig as Config} initialState={initialState}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</WagmiProvider>
)
}

export default ContextProvider
Binary file modified bun.lockb
Binary file not shown.
7 changes: 5 additions & 2 deletions packages/v1-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
"!**/*.tsbuildinfo"
],
"dependencies": {
"@moleculexyz/wagmi-safe-wait-for-tx": "^1.0.0",
"@openzeppelin/merkle-tree": "^1.0.8",
"@pwndao/api-sdk": "0.0.1-beta.18",
"@pwndao/sdk-core": "0.0.1-beta.18",
"@safe-global/api-kit": "^3.0.1",
"@safe-global/protocol-kit": "^6.0.3",
"@wagmi/cli": "^2.2.0",
"@wagmi/core": "^2.16.7",
"abitype": "^1.0.8",
"decimal.js": "^10.5.0",
"ts-invariant": "^0.10.3",
"viem": "^2.23.11",
"vitest": "^1.3.1",
"decimal.js": "^10.5.0"
"vitest": "^1.3.1"
},
"devDependencies": {
"@wagmi/cli": "^2.2.0"
Expand Down
Loading
Loading