Skip to content
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

Add Privy Provider #313

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cee39e9
feat: add dapp-kit-react-privy package
fabiorigam Nov 21, 2024
f2e74cb
fix: continue the privy provider
fabiorigam Nov 21, 2024
c0f9ad9
fix: fix build issue
fabiorigam Nov 21, 2024
a89d4e8
fix: add sample privy next app
fabiorigam Nov 22, 2024
f60cdc9
fix: fix issue
fabiorigam Nov 22, 2024
e75f5ec
feat: add ConnectModal
fabiorigam Nov 22, 2024
c233309
fix: fix linter issue
fabiorigam Nov 22, 2024
a852dbe
Merge branch 'main' into add-privy-provider
fabiorigam Nov 25, 2024
436f098
fix: fix merge conflicts
fabiorigam Nov 25, 2024
06c49d8
fix: improve modal
fabiorigam Nov 25, 2024
7f8a302
fix: refactor
fabiorigam Nov 25, 2024
8c1234b
fix: refactor
fabiorigam Nov 25, 2024
8b4bd58
fix: improve example UI
fabiorigam Nov 25, 2024
cd8d0e2
Merge branch 'main' into add-privy-provider
fabiorigam Nov 25, 2024
64c3711
fix: improve modal
fabiorigam Nov 26, 2024
4145d48
feat: add new hooks
fabiorigam Nov 26, 2024
6e5cfc4
fix: add readme files and a small explanation
fabiorigam Nov 28, 2024
e3158b2
fix: update package
fabiorigam Nov 28, 2024
de72ec5
fi: update readme
fabiorigam Nov 28, 2024
8dc3ce2
feat: move config in separate object + solve compilation issues
Agilulfo1820 Dec 6, 2024
20c6328
fix: typos
Agilulfo1820 Dec 6, 2024
fdf8df9
feat: refactor return types
Agilulfo1820 Dec 9, 2024
45d5d9c
feat: fixed issues
Agilulfo1820 Dec 10, 2024
5375d3c
Merge branch 'feat/dan' into add-privy-provider
Agilulfo1820 Dec 10, 2024
3e42858
feat: update twitter logo
Agilulfo1820 Dec 11, 2024
c11a323
feat: handle cross accounts
Agilulfo1820 Dec 11, 2024
a9e11da
feat: use chakra
Agilulfo1820 Dec 11, 2024
4d9e31a
feat: cross app login
Agilulfo1820 Dec 13, 2024
2392826
Merge branch 'feat/cross-accounts' into add-privy-provider
Agilulfo1820 Dec 13, 2024
5539028
fix: transactions
Agilulfo1820 Dec 17, 2024
9788ef0
feat: connect button
Agilulfo1820 Dec 17, 2024
3f947ff
fix: dependency
Agilulfo1820 Dec 17, 2024
246c618
feat: display connected account
Agilulfo1820 Dec 17, 2024
009bfb8
feat: fetch app info
Agilulfo1820 Dec 17, 2024
12caab0
feat: go back to main modal
Agilulfo1820 Dec 17, 2024
27d6e9f
fix: apps info loop
Agilulfo1820 Dec 17, 2024
61d1dba
feat: update params structure
Agilulfo1820 Dec 17, 2024
ae24e1d
feat: copy address
Agilulfo1820 Dec 17, 2024
31e3c49
feat: transaction modal
Agilulfo1820 Dec 17, 2024
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
6 changes: 6 additions & 0 deletions examples/sample-privy-next-app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: ['next'],
rules: {
'@typescript-eslint/unbound-method': 'off',
},
};
37 changes: 37 additions & 0 deletions examples/sample-privy-next-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
55 changes: 55 additions & 0 deletions examples/sample-privy-next-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# `sample-privy-next-app`

This example demonstrates how to integrate the `@vechain/dapp-kit-react-privy` package into a Next.js application. It showcases how to leverage the library for seamless social login and VeChain ecosystem integration, providing a foundation for building robust and user-friendly decentralized applications (dApps).

## How it works

### Step 1: Dynamically Import the SocialLoginWrapper

To ensure compatibility with server-side rendering, dynamically import the SocialLoginWrapper component in layout.tsx:

```typescript
const SocialLoginWrapper = dynamic(
async () =>
(await import('./components/SocialLoginWrapper')).SocialLoginWrapper,
{
ssr: false,
},
);

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<head>
<title>Privy Next JS</title>
</head>
<body>
<SocialLoginWrapper>{children}</SocialLoginWrapper>
</body>
</html>
);
}
```

### Step 2: Use Hooks and Components

Import the necessary hooks and components from @vechain/dapp-kit-react-privy and use them to interact with the VeChain ecosystem in your application:

```typescript
import { useVOT3Balance, useB3TRBalance } from '@vechain/dapp-kit-react-privy';

const b3trBalanceQuery = isConnected
? useB3TRBalance({ address: connectedAccount ?? '' })
: useB3TRBalance({
address: abstractedAccount.embeddedWallet?.address ?? '',
});
const vot3BalanceQuery = isConnected
? useVOT3Balance({ address: connectedAccount ?? '' })
: useVOT3Balance({
address: abstractedAccount.embeddedWallet?.address ?? '',
});
```
18 changes: 18 additions & 0 deletions examples/sample-privy-next-app/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const basePath = process.env.BASE_PATH ?? '';

/** @type {import('next').NextConfig} */
const nextConfig = {
basePath,
output: 'export',
distDir: 'dist',
env: {
basePath,
},
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
};

module.exports = nextConfig;
30 changes: 30 additions & 0 deletions examples/sample-privy-next-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "sample-privy-next-app",
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"clean": "rm -rf .next dist .turbo",
"dev": "next dev"
},
"dependencies": {
"@chakra-ui/react": "2.8.2",
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@vechain/dapp-kit": "*",
"@vechain/dapp-kit-react": "*",
"@vechain/dapp-kit-react-privy": "*",
"next": "14.2.10",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@next/eslint-plugin-next": "^14.1.4",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^9.12.0",
"eslint-config-next": "14.1.4",
"typescript": "5.3.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use client';

import dynamic from 'next/dynamic';

const DAppKitPrivyProvider = dynamic(
async () =>
(await import('@vechain/dapp-kit-react-privy')).DAppKitPrivyProvider,
{
ssr: false,
},
);

interface Props {
children: React.ReactNode;
}

export function SocialLoginWrapper({ children }: Props) {
return (
<DAppKitPrivyProvider
privyConfig={{
appId: process.env.NEXT_PUBLIC_PRIVY_APP_ID!,
clientId: process.env.NEXT_PUBLIC_PRIVY_CLIENT_ID!,
loginMethods: ['google', 'twitter'],
appearance: {
theme: 'light',
accentColor: '#696FFD',
loginMessage: 'Select a social media profile',
logo: 'https://i.ibb.co/ZHGmq3y/image-21.png',
},
embeddedWallets: {
createOnLogin: 'all-users',
},
ecosystemAppsID: [
'clxdoatq601h35inz6qykgmai',
'clz41gcg00e4ay75dmq3uzzgr',
],
}}
feeDelegationConfig={{
delegatorUrl: 'https://sponsor.vechain.energy/by/749',
delegateAllTransactions: true,
}}
dappKitConfig={{
nodeUrl: 'https://node.vechain.energy',
genesis: {
number: 0,
id: '0x00000000851caf3cfdb6e899cf5958bfb1ac3413d346d43539627e6be7ec1b4a',
size: 170,
parentID:
'0xffffffff53616c757465202620526573706563742c20457468657265756d2100',
timestamp: 1530316800,
gasLimit: 10000000,
beneficiary: '0x0000000000000000000000000000000000000000',
gasUsed: 0,
totalScore: 0,
txsRoot:
'0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0',
txsFeatures: 0,
stateRoot:
'0x09bfdf9e24dd5cd5b63f3c1b5d58b97ff02ca0490214a021ed7d99b93867839c',
receiptsRoot:
'0x45b0cfc220ceec5b7c1c62c4d4193d38e4eba48e8815729ce75f9c0ab0e4c1c0',
signer: '0x0000000000000000000000000000000000000000',
isTrunk: true,
transactions: [],
},
themeMode: 'LIGHT',
walletConnectOptions: {
projectId:
process.env.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID!,
metadata: {
name: 'Your App',
description: 'Your app description',
url:
typeof window !== 'undefined'
? window.location.origin
: '',
icons: [
typeof window !== 'undefined'
? `${window.location.origin}/images/logo/my-dapp.png`
: '',
],
},
},
}}
>
{children}
</DAppKitPrivyProvider>
);
}
28 changes: 28 additions & 0 deletions examples/sample-privy-next-app/src/app/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Interface } from 'ethers';

export const b3trMainnetAddress = '0x5ef79995FE8a89e0812330E4378eB2660ceDe699';
export const b3trTestnetAddress = '0xbf64cf86894Ee0877C4e7d03936e35Ee8D8b864F';
export const b3trAbi = new Interface([
// Replace this with your actual transfer function ABI
{
inputs: [
{
name: 'recipient',
type: 'address',
},
{
name: 'amount',
type: 'uint256',
},
],
name: 'transfer',
outputs: [
{
name: '',
type: 'bool',
},
],
stateMutability: 'nonpayable',
type: 'function',
},
]);
Binary file not shown.
Binary file not shown.
23 changes: 23 additions & 0 deletions examples/sample-privy-next-app/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
body {
margin: 0;
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
}
h2 {
margin: 0;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border: 1px solid #000;
border-radius: 20px;
padding: 20px;
}
.label {
margin-top: 20px;
margin-bottom: 10px;
}
29 changes: 29 additions & 0 deletions examples/sample-privy-next-app/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import './globals.css';
import dynamic from 'next/dynamic';

const SocialLoginWrapper = dynamic(
async () =>
(await import('./components/SocialLoginWrapper')).SocialLoginWrapper,
{
ssr: false,
},
);

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en" suppressHydrationWarning={true}>
<head>
<title>Privy Next JS</title>
</head>
<body>
<SocialLoginWrapper>{children}</SocialLoginWrapper>
</body>
</html>
);
}
14 changes: 14 additions & 0 deletions examples/sample-privy-next-app/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";

import dynamic from "next/dynamic";
import React from "react";

const Homepage = dynamic(() => import('./pages/homepage'), {
ssr: false,
});

export default function Page() {
return (
<Homepage />
);
}
Loading
Loading