@caatinga/cli 2.0.2 → 2.2.0
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/README.md +12 -6
- package/dist/index.js +226 -17
- package/package.json +3 -3
- package/templates/marketplace-with-token/caatinga.template.json +1 -1
- package/templates/marketplace-with-token/package.json +3 -3
- package/templates/react-vite-counter/caatinga.template.json +1 -1
- package/templates/react-vite-counter/package.json +7 -7
- package/templates/react-vite-counter/pnpm-workspace.yaml +4 -10
- package/templates/react-vite-counter/src/App.tsx +17 -3
- package/templates/react-vite-counter/src/components/ContractNotDeployed.tsx +27 -0
- package/templates/react-vite-counter/src/components/CounterCard.tsx +2 -10
- package/templates/react-vite-counter/src/components/WalletButton.tsx +8 -7
- package/templates/react-vite-counter/src/components/WalletModal.tsx +248 -0
- package/templates/react-vite-counter/src/contracts/generated/counter/src/index.ts +23 -38
- package/templates/react-vite-counter/src/stubs/empty-wallet-dep/index.cjs +3 -0
- package/templates/react-vite-counter/src/stubs/empty-wallet-dep/package.json +6 -0
- package/templates/react-vite-counter/src/stubs/hot-wallet-sdk/index.cjs +7 -0
- package/templates/react-vite-counter/src/stubs/hot-wallet-sdk/package.json +6 -0
- package/templates/react-vite-counter/src/styles.css +261 -0
- package/templates/react-vite-counter/src/wallet-modal-controller.ts +73 -0
- package/templates/react-vite-counter/src/wallet.ts +9 -1
- package/templates/react-vite-counter/vite.config.ts +17 -1
- package/templates/react-vite-counter/src/context/WalletContext.tsx +0 -64
|
@@ -4,12 +4,20 @@ import {
|
|
|
4
4
|
WalletNetwork,
|
|
5
5
|
type StellarWalletsKitMetadata
|
|
6
6
|
} from "@caatinga/client/stellar-wallets-kit";
|
|
7
|
+
import { requestWalletSelection } from "./wallet-modal-controller.js";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const baseWalletAdapter = createStellarWalletsKitAdapter({
|
|
9
10
|
network: WalletNetwork.TESTNET,
|
|
10
11
|
walletConnectMetadata: getWalletConnectMetadata()
|
|
11
12
|
});
|
|
12
13
|
|
|
14
|
+
// Route connect() through the custom <WalletModal> instead of SWK's built-in
|
|
15
|
+
// authModal. Everything else (persistence, restore, signing) is untouched.
|
|
16
|
+
export const stellarWalletAdapter = {
|
|
17
|
+
...baseWalletAdapter,
|
|
18
|
+
openModal: () => requestWalletSelection()
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
export { WalletNetwork };
|
|
14
22
|
|
|
15
23
|
function getWalletConnectMetadata(): StellarWalletsKitMetadata | undefined {
|
|
@@ -2,6 +2,14 @@ import { defineConfig } from "vite";
|
|
|
2
2
|
import react from "@vitejs/plugin-react";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
|
+
// Empty CJS module. Aliasing browser-hostile wallet sub-deps here keeps them out
|
|
6
|
+
// of the bundle on every package manager — no install-time dependency overrides
|
|
7
|
+
// (which differ per pnpm/npm/yarn/bun) required. CJS interop lets any named
|
|
8
|
+
// import resolve to `undefined` without an esbuild "not exported" error.
|
|
9
|
+
const emptyStub = fileURLToPath(
|
|
10
|
+
new URL("./src/stubs/empty-wallet-dep/index.cjs", import.meta.url)
|
|
11
|
+
);
|
|
12
|
+
|
|
5
13
|
export default defineConfig({
|
|
6
14
|
plugins: [react()],
|
|
7
15
|
resolve: {
|
|
@@ -9,7 +17,15 @@ export default defineConfig({
|
|
|
9
17
|
// Stellar Wallets Kit drags NEAR's @hot-wallet/sdk (Node-only crypto) into
|
|
10
18
|
// the browser bundle. The adapter filters HOT Wallet out, so stub the SDK
|
|
11
19
|
// to keep the NEAR chain out of the build. See src/stubs/hot-wallet.ts.
|
|
12
|
-
"@hot-wallet/sdk": fileURLToPath(new URL("./src/stubs/hot-wallet.ts", import.meta.url))
|
|
20
|
+
"@hot-wallet/sdk": fileURLToPath(new URL("./src/stubs/hot-wallet.ts", import.meta.url)),
|
|
21
|
+
// SWK + Reown/WalletConnect pull Trezor Connect (Node-only) and Safe Global
|
|
22
|
+
// SDKs that none of the wallets Caatinga ships actually use. Stub them so the
|
|
23
|
+
// bundle builds without pnpm-only "-" dependency overrides.
|
|
24
|
+
"@trezor/connect-web": emptyStub,
|
|
25
|
+
"@trezor/connect-plugin-stellar": emptyStub,
|
|
26
|
+
"@safe-global/safe-apps-sdk": emptyStub,
|
|
27
|
+
"@safe-global/safe-apps-provider": emptyStub,
|
|
28
|
+
"@safe-global/safe-gateway-typescript-sdk": emptyStub
|
|
13
29
|
}
|
|
14
30
|
}
|
|
15
31
|
});
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
useCallback,
|
|
4
|
-
useContext,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState,
|
|
7
|
-
type ReactNode
|
|
8
|
-
} from "react";
|
|
9
|
-
import { stellarWalletAdapter } from "../wallet.js";
|
|
10
|
-
|
|
11
|
-
interface WalletContextValue {
|
|
12
|
-
publicKey: string | null;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
error: string | null;
|
|
15
|
-
connect: () => Promise<void>;
|
|
16
|
-
disconnect: () => Promise<void>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const WalletContext = createContext<WalletContextValue | null>(null);
|
|
20
|
-
|
|
21
|
-
export function WalletProvider({ children }: { children: ReactNode }) {
|
|
22
|
-
const [publicKey, setPublicKey] = useState<string | null>(null);
|
|
23
|
-
const [loading, setLoading] = useState(false);
|
|
24
|
-
const [error, setError] = useState<string | null>(null);
|
|
25
|
-
|
|
26
|
-
const connect = useCallback(async () => {
|
|
27
|
-
setLoading(true);
|
|
28
|
-
setError(null);
|
|
29
|
-
|
|
30
|
-
try {
|
|
31
|
-
// openModal lists only installed/available wallets and resolves with the
|
|
32
|
-
// chosen account address (rejects if the user dismisses the modal).
|
|
33
|
-
const address = await stellarWalletAdapter.openModal();
|
|
34
|
-
setPublicKey(address);
|
|
35
|
-
} catch (caught) {
|
|
36
|
-
const message = caught instanceof Error ? caught.message : String(caught);
|
|
37
|
-
setError(message);
|
|
38
|
-
} finally {
|
|
39
|
-
setLoading(false);
|
|
40
|
-
}
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
const disconnect = useCallback(async () => {
|
|
44
|
-
await stellarWalletAdapter.disconnect();
|
|
45
|
-
setPublicKey(null);
|
|
46
|
-
setError(null);
|
|
47
|
-
}, []);
|
|
48
|
-
|
|
49
|
-
const value = useMemo<WalletContextValue>(
|
|
50
|
-
() => ({ publicKey, loading, error, connect, disconnect }),
|
|
51
|
-
[publicKey, loading, error, connect, disconnect]
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
return <WalletContext.Provider value={value}>{children}</WalletContext.Provider>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function useWallet(): WalletContextValue {
|
|
58
|
-
const context = useContext(WalletContext);
|
|
59
|
-
if (!context) {
|
|
60
|
-
throw new Error("useWallet must be used within a WalletProvider");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return context;
|
|
64
|
-
}
|