@coinbase/create-cdp-app 0.0.43 → 0.0.45

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.
Files changed (40) hide show
  1. package/dist/index.js +119 -41
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/template-nextjs/src/components/{Header.tsx → evm-eoa/Header.tsx} +0 -4
  5. package/template-nextjs/src/components/evm-eoa/SignedInScreen.tsx +68 -0
  6. package/template-nextjs/src/components/evm-eoa/SignedInScreenWithOnramp.tsx +117 -0
  7. package/template-nextjs/src/components/{UserBalance.tsx → evm-eoa/UserBalance.tsx} +3 -4
  8. package/template-nextjs/src/components/evm-smart/Header.tsx +64 -0
  9. package/template-nextjs/src/components/evm-smart/SignedInScreen.tsx +68 -0
  10. package/template-nextjs/src/components/evm-smart/SignedInScreenWithOnramp.tsx +120 -0
  11. package/template-nextjs/src/components/evm-smart/UserBalance.tsx +43 -0
  12. package/template-nextjs/src/components/solana/Header.tsx +63 -0
  13. package/template-nextjs/src/components/solana/SignedInScreen.tsx +74 -0
  14. package/template-nextjs/src/components/solana/SignedInScreenWithOnramp.tsx +121 -0
  15. package/template-nextjs/src/components/solana/UserBalance.tsx +43 -0
  16. package/template-react/src/evm-eoa/Header.tsx +67 -0
  17. package/template-react/src/evm-eoa/SignedInScreen.tsx +64 -0
  18. package/template-react/src/{UserBalance.tsx → evm-eoa/UserBalance.tsx} +10 -28
  19. package/template-react/src/evm-smart/Header.tsx +68 -0
  20. package/template-react/src/evm-smart/SignedInScreen.tsx +64 -0
  21. package/template-react/src/evm-smart/UserBalance.tsx +44 -0
  22. package/template-react/src/{Header.tsx → solana/Header.tsx} +9 -21
  23. package/template-react/src/solana/SignedInScreen.tsx +70 -0
  24. package/template-react/src/solana/UserBalance.tsx +44 -0
  25. package/template-react-native/{components → evm-eoa}/WalletHeader.tsx +10 -21
  26. package/template-react-native/evm-smart/WalletHeader.tsx +115 -0
  27. package/template-react-native/solana/WalletHeader.tsx +111 -0
  28. package/template-nextjs/src/components/SignedInScreen.tsx +0 -116
  29. package/template-nextjs/src/components/SignedInScreenWithOnramp.tsx +0 -239
  30. package/template-react/src/SignedInScreen.tsx +0 -116
  31. package/template-react-native/Transaction.tsx +0 -101
  32. /package/template-nextjs/src/components/{EOATransaction.tsx → evm-eoa/EOATransaction.tsx} +0 -0
  33. /package/template-nextjs/src/components/{SmartAccountTransaction.tsx → evm-smart/SmartAccountTransaction.tsx} +0 -0
  34. /package/template-nextjs/src/components/{SolanaTransaction.tsx → solana/SolanaTransaction.tsx} +0 -0
  35. /package/template-react/src/{EOATransaction.tsx → evm-eoa/EOATransaction.tsx} +0 -0
  36. /package/template-react/src/{SmartAccountTransaction.tsx → evm-smart/SmartAccountTransaction.tsx} +0 -0
  37. /package/template-react/src/{SolanaTransaction.tsx → solana/SolanaTransaction.tsx} +0 -0
  38. /package/template-react-native/{EOATransaction.tsx → evm-eoa/EOATransaction.tsx} +0 -0
  39. /package/template-react-native/{SmartAccountTransaction.tsx → evm-smart/SmartAccountTransaction.tsx} +0 -0
  40. /package/template-react-native/{SolanaTransaction.tsx → solana/SolanaTransaction.tsx} +0 -0
@@ -1,116 +0,0 @@
1
- import { useEvmAddress, useSolanaAddress, useIsSignedIn } from "@coinbase/cdp-hooks";
2
- import { Connection, clusterApiUrl, LAMPORTS_PER_SOL, PublicKey } from "@solana/web3.js";
3
- import { useCallback, useEffect, useMemo, useState, lazy, Suspense } from "react";
4
- import { createPublicClient, http, formatEther } from "viem";
5
- import { baseSepolia } from "viem/chains";
6
-
7
- import { CDP_CONFIG } from "./config";
8
- import Header from "./Header";
9
- import Loading from "./Loading";
10
- import UserBalance from "./UserBalance";
11
-
12
- const isSolana = !!CDP_CONFIG.solana;
13
- const isSmartAccount = CDP_CONFIG.ethereum?.createOnLogin === "smart";
14
-
15
- // Dynamically determine component path to avoid Vite static analysis
16
- const getComponentPath = () => {
17
- if (isSolana) {
18
- return "./SolanaTransaction";
19
- } else if (isSmartAccount) {
20
- return "./SmartAccountTransaction";
21
- } else {
22
- return "./EOATransaction";
23
- }
24
- };
25
-
26
- const TransactionComponent = lazy(() => import(/* @vite-ignore */ getComponentPath()));
27
-
28
- /**
29
- * Create a viem client to access user's balance on the Base Sepolia network
30
- */
31
- const client = createPublicClient({
32
- chain: baseSepolia,
33
- transport: http(),
34
- });
35
-
36
- /**
37
- * Create a Solana connection to access user's balance on Solana Devnet
38
- */
39
- const solanaConnection = new Connection(clusterApiUrl("devnet"));
40
-
41
- /**
42
- * The Signed In screen
43
- */
44
- function SignedInScreen() {
45
- const { isSignedIn } = useIsSignedIn();
46
- const { evmAddress } = useEvmAddress();
47
- const { solanaAddress } = useSolanaAddress();
48
- const [balance, setBalance] = useState<bigint | undefined>(undefined);
49
-
50
- const address = isSolana ? solanaAddress : evmAddress;
51
-
52
- const formattedBalance = useMemo(() => {
53
- if (balance === undefined) return undefined;
54
- if (isSolana) {
55
- // Convert lamports to SOL
56
- return formatSol(Number(balance));
57
- } else {
58
- // Convert wei to ETH
59
- return formatEther(balance);
60
- }
61
- }, [balance]);
62
-
63
- const getBalance = useCallback(async () => {
64
- if (isSolana && solanaAddress) {
65
- // Get Solana balance in lamports
66
- const lamports = await solanaConnection.getBalance(new PublicKey(solanaAddress));
67
- setBalance(BigInt(lamports));
68
- } else if (!isSolana && evmAddress) {
69
- // Get EVM balance in wei
70
- const weiBalance = await client.getBalance({
71
- address: evmAddress,
72
- });
73
- setBalance(weiBalance);
74
- }
75
- }, [evmAddress, solanaAddress]);
76
-
77
- useEffect(() => {
78
- getBalance();
79
- const interval = setInterval(getBalance, 500);
80
- return () => clearInterval(interval);
81
- }, [getBalance]);
82
-
83
- return (
84
- <>
85
- <Header />
86
- <main className="main flex-col-container flex-grow">
87
- <div className="main-inner flex-col-container">
88
- <div className="card card--user-balance">
89
- <UserBalance balance={formattedBalance} />
90
- </div>
91
- <div className="card card--transaction">
92
- {isSignedIn && address && (
93
- <Suspense fallback={<Loading />}>
94
- <TransactionComponent balance={formattedBalance} onSuccess={getBalance} />
95
- </Suspense>
96
- )}
97
- </div>
98
- </div>
99
- </main>
100
- </>
101
- );
102
- }
103
-
104
- /**
105
- * Format a Solana balance.
106
- *
107
- * @param lamports - The balance in lamports.
108
- * @returns The formatted balance.
109
- */
110
- function formatSol(lamports: number) {
111
- const maxDecimalPlaces = 9;
112
- const roundedStr = (lamports / LAMPORTS_PER_SOL).toFixed(maxDecimalPlaces);
113
- return roundedStr.replace(/0+$/, "").replace(/\.$/, "");
114
- }
115
-
116
- export default SignedInScreen;
@@ -1,101 +0,0 @@
1
- import React, { useState } from "react";
2
- import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
3
- import { useEvmAddress, useSolanaAddress } from "@coinbase/cdp-hooks";
4
- import { useTheme } from "./theme/ThemeContext";
5
- import EOATransaction from "./EOATransaction";
6
- import SolanaTransaction from "./SolanaTransaction";
7
-
8
- interface Props {
9
- onSuccess?: () => void;
10
- }
11
-
12
- function Transaction(props: Props) {
13
- const { onSuccess } = props;
14
- const { colors } = useTheme();
15
- const { evmAddress } = useEvmAddress();
16
- const { solanaAddress } = useSolanaAddress();
17
- const [activeTab, setActiveTab] = useState<"evm" | "solana">("evm");
18
-
19
- // Show tabs only if both EVM and Solana addresses are available
20
- const showTabs = !!evmAddress && !!solanaAddress;
21
-
22
- const createStyles = () =>
23
- StyleSheet.create({
24
- container: {
25
- flex: 1,
26
- width: "100%",
27
- },
28
- tabContainer: {
29
- flexDirection: "row",
30
- marginBottom: 16,
31
- backgroundColor: colors.cardBackground,
32
- borderRadius: 8,
33
- padding: 4,
34
- borderWidth: 1,
35
- borderColor: colors.border,
36
- },
37
- tab: {
38
- flex: 1,
39
- paddingVertical: 12,
40
- alignItems: "center",
41
- borderRadius: 6,
42
- },
43
- activeTab: {
44
- backgroundColor: colors.accent,
45
- },
46
- tabText: {
47
- fontSize: 16,
48
- fontWeight: "600",
49
- color: colors.textSecondary,
50
- },
51
- activeTabText: {
52
- color: "#ffffff",
53
- },
54
- });
55
-
56
- const styles = createStyles();
57
-
58
- // If only one address type is available, show that component directly
59
- if (!showTabs) {
60
- if (evmAddress) {
61
- return <EOATransaction onSuccess={onSuccess} />;
62
- }
63
- if (solanaAddress) {
64
- return <SolanaTransaction onSuccess={onSuccess} />;
65
- }
66
- return null; // Loading state handled by parent
67
- }
68
-
69
- return (
70
- <View style={styles.container}>
71
- {/* Tab selector */}
72
- <View style={styles.tabContainer}>
73
- <TouchableOpacity
74
- style={[styles.tab, activeTab === "evm" && styles.activeTab]}
75
- onPress={() => setActiveTab("evm")}
76
- >
77
- <Text style={[styles.tabText, activeTab === "evm" && styles.activeTabText]}>
78
- Ethereum
79
- </Text>
80
- </TouchableOpacity>
81
- <TouchableOpacity
82
- style={[styles.tab, activeTab === "solana" && styles.activeTab]}
83
- onPress={() => setActiveTab("solana")}
84
- >
85
- <Text style={[styles.tabText, activeTab === "solana" && styles.activeTabText]}>
86
- Solana
87
- </Text>
88
- </TouchableOpacity>
89
- </View>
90
-
91
- {/* Content */}
92
- {activeTab === "evm" ? (
93
- <EOATransaction onSuccess={onSuccess} />
94
- ) : (
95
- <SolanaTransaction onSuccess={onSuccess} />
96
- )}
97
- </View>
98
- );
99
- }
100
-
101
- export default Transaction;