@gelatonetwork/smartwallet-react-privy 0.0.2-alpha.1 → 0.0.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +66 -2
- package/_dist/provider.d.ts.map +1 -1
- package/_dist/provider.js +17 -13
- package/_dist/provider.js.map +1 -1
- package/_dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -3
- package/src/provider.tsx +30 -17
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
# @gelatonetwork/smartwallet-react-privy
|
2
2
|
|
3
|
+
## 0.0.2-alpha.4
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [d69774c]
|
8
|
+
- @gelatonetwork/smartwallet@0.0.2-alpha.4
|
9
|
+
- @gelatonetwork/smartwallet-react-types@0.0.2-alpha.4
|
10
|
+
|
11
|
+
## 0.0.2-alpha.3
|
12
|
+
|
13
|
+
### Patch Changes
|
14
|
+
|
15
|
+
- fix: versioning
|
16
|
+
- Updated dependencies
|
17
|
+
- @gelatonetwork/smartwallet-react-types@0.0.2-alpha.3
|
18
|
+
- @gelatonetwork/smartwallet@0.0.2-alpha.3
|
19
|
+
|
20
|
+
## 0.0.2-alpha.2
|
21
|
+
|
22
|
+
### Patch Changes
|
23
|
+
|
24
|
+
- a4745d0: feat: provide gelato smart wallet client from react component
|
25
|
+
- 9d15eea: feat: allow passing gelato apiKey
|
26
|
+
- 5f11604: chore: add readmes
|
27
|
+
- Updated dependencies [a4745d0]
|
28
|
+
- Updated dependencies [9d15eea]
|
29
|
+
- Updated dependencies [5f11604]
|
30
|
+
- Updated dependencies [9d15eea]
|
31
|
+
- @gelatonetwork/smartwallet-react-types@0.0.2-alpha.2
|
32
|
+
- @gelatonetwork/smartwallet@0.0.2-alpha.2
|
33
|
+
|
3
34
|
## 0.0.2-alpha.1
|
4
35
|
|
5
36
|
### Patch Changes
|
package/README.md
CHANGED
@@ -1,3 +1,67 @@
|
|
1
|
-
#
|
1
|
+
# @gelatonetwork/smartwallet-react-privy
|
2
2
|
|
3
|
-
A
|
3
|
+
A React package that provides integration with Privy WaaS (Wallet-as-a-Service) for Gelato Smart Wallet.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- Privy WaaS integration for Gelato smart wallet management
|
8
|
+
- Connect button component for easy wallet connection
|
9
|
+
- Integration with wagmi for Web3 functionality
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
pnpm add @gelatonetwork/smartwallet-react-privy
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Provider Setup
|
20
|
+
|
21
|
+
```tsx
|
22
|
+
import { GelatoSmartWalletPrivyContextProvider } from '@gelatonetwork/smartwallet-react-privy';
|
23
|
+
|
24
|
+
function App() {
|
25
|
+
return (
|
26
|
+
<GelatoSmartWalletPrivyContextProvider
|
27
|
+
settings={{
|
28
|
+
waas: {
|
29
|
+
appId: 'your-privy-app-id'
|
30
|
+
},
|
31
|
+
defaultChain: yourDefaultChain,
|
32
|
+
wagmi: {
|
33
|
+
config: yourWagmiConfig
|
34
|
+
}
|
35
|
+
}}
|
36
|
+
>
|
37
|
+
<YourApp />
|
38
|
+
</GelatoSmartWalletPrivyContextProvider>
|
39
|
+
);
|
40
|
+
}
|
41
|
+
```
|
42
|
+
|
43
|
+
### Using the Connect Button
|
44
|
+
|
45
|
+
```tsx
|
46
|
+
import { GelatoSmartWalletPrivyConnectButton } from '@gelatonetwork/smartwallet-react-privy';
|
47
|
+
|
48
|
+
function ConnectWallet() {
|
49
|
+
return (
|
50
|
+
<GelatoSmartWalletPrivyConnectButton>
|
51
|
+
Connect Wallet
|
52
|
+
</GelatoSmartWalletPrivyConnectButton>
|
53
|
+
);
|
54
|
+
}
|
55
|
+
```
|
56
|
+
|
57
|
+
### Accessing Wallet Context
|
58
|
+
|
59
|
+
```tsx
|
60
|
+
import { useGelatoSmartWalletPrivyContext } from '@gelatonetwork/smartwallet-react-privy';
|
61
|
+
|
62
|
+
function YourComponent() {
|
63
|
+
const { wagmi, logout, switchNetwork } = useGelatoSmartWalletPrivyContext();
|
64
|
+
|
65
|
+
// Use the context values as needed
|
66
|
+
}
|
67
|
+
```
|
package/_dist/provider.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wCAAwC,CAAC;AAMrE,OAAO,KAAK,EAAE,EAAE,EAAa,MAAM,OAAO,CAAC;AAmB3C,eAAO,MAAM,gCAAgC,8BAQ5C,CAAC;AAEF,KAAK,kCAAkC,GAAG,MAAM,CAAC,aAAa,CAAC;AAmH/D,eAAO,MAAM,qCAAqC,EAAE,EAAE,CAAC,kCAAkC,CAyBxF,CAAC"}
|
package/_dist/provider.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { createGelatoSmartWalletClient } from "@gelatonetwork/smartwallet";
|
2
3
|
import { PrivyProvider, usePrivy, useSignAuthorization, useWallets } from "@privy-io/react-auth";
|
3
4
|
import { WagmiProvider, createConfig } from "@privy-io/wagmi";
|
4
5
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
@@ -15,32 +16,32 @@ export const useGelatoSmartWalletPrivyContext = () => {
|
|
15
16
|
}
|
16
17
|
return context;
|
17
18
|
};
|
18
|
-
const GelatoSmartWalletPrivyInternal = ({ children, wagmi }) => {
|
19
|
+
const GelatoSmartWalletPrivyInternal = ({ children, wagmi, apiKey }) => {
|
19
20
|
const { ready, authenticated, logout } = usePrivy();
|
20
21
|
const { wallets, ready: walletsReady } = useWallets();
|
21
22
|
const { signAuthorization } = useSignAuthorization();
|
22
|
-
const [
|
23
|
+
const [smartWalletClient, setSmartWalletClient] = useState(null);
|
23
24
|
const logoutWrapper = async () => {
|
24
|
-
if (!
|
25
|
+
if (!smartWalletClient) {
|
25
26
|
return;
|
26
27
|
}
|
27
|
-
|
28
|
+
setSmartWalletClient(null);
|
28
29
|
await logout();
|
29
30
|
};
|
30
31
|
const switchNetwork = async (chain) => {
|
31
|
-
if (!
|
32
|
+
if (!smartWalletClient) {
|
32
33
|
return;
|
33
34
|
}
|
34
35
|
const primaryWallet = wallets[0];
|
35
36
|
await primaryWallet.switchChain(chain.id);
|
36
|
-
|
37
|
+
smartWalletClient.switchChain({ id: chain.id });
|
37
38
|
};
|
38
39
|
useEffect(() => {
|
39
40
|
if (!ready || !walletsReady) {
|
40
41
|
return;
|
41
42
|
}
|
42
43
|
if (!authenticated || !wallets || wallets.length === 0) {
|
43
|
-
|
44
|
+
setSmartWalletClient(null);
|
44
45
|
return;
|
45
46
|
}
|
46
47
|
const fetchWalletClient = async () => {
|
@@ -54,12 +55,12 @@ const GelatoSmartWalletPrivyInternal = ({ children, wagmi }) => {
|
|
54
55
|
return;
|
55
56
|
}
|
56
57
|
const provider = await primaryWallet.getEthereumProvider();
|
57
|
-
const
|
58
|
+
const client = createWalletClient({
|
58
59
|
account: primaryWallet.address,
|
59
60
|
chain,
|
60
61
|
transport: custom(provider)
|
61
62
|
});
|
62
|
-
|
63
|
+
client.signAuthorization = async (parameters) => {
|
63
64
|
const { chainId, nonce } = parameters;
|
64
65
|
const contractAddress = parameters.contractAddress ?? parameters.address;
|
65
66
|
if (!contractAddress) {
|
@@ -72,18 +73,21 @@ const GelatoSmartWalletPrivyInternal = ({ children, wagmi }) => {
|
|
72
73
|
});
|
73
74
|
return signedAuthorization;
|
74
75
|
};
|
75
|
-
|
76
|
+
const walletClientGelato = createGelatoSmartWalletClient(client, apiKey);
|
77
|
+
setSmartWalletClient(walletClientGelato);
|
76
78
|
}
|
77
79
|
catch (error) {
|
78
80
|
console.error("Failed to get wallet client:", error);
|
79
81
|
}
|
80
82
|
};
|
81
83
|
fetchWalletClient();
|
82
|
-
}, [ready, wallets, walletsReady, authenticated, signAuthorization]);
|
84
|
+
}, [ready, wallets, walletsReady, authenticated, signAuthorization, apiKey]);
|
83
85
|
return (_jsx(GelatoSmartWalletPrivyProviderContext.Provider, { value: {
|
86
|
+
gelato: {
|
87
|
+
client: smartWalletClient
|
88
|
+
},
|
84
89
|
wagmi: {
|
85
|
-
config: wagmi.config
|
86
|
-
client: walletClient
|
90
|
+
config: wagmi.config
|
87
91
|
},
|
88
92
|
logout: logoutWrapper,
|
89
93
|
switchNetwork
|
package/_dist/provider.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAEL,6BAA6B,EAC9B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,uB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