diff --git a/.changeset/proud-dingos-beg.md b/.changeset/proud-dingos-beg.md
new file mode 100644
index 0000000..9e4382a
--- /dev/null
+++ b/.changeset/proud-dingos-beg.md
@@ -0,0 +1,7 @@
+---
+"dappstore": patch
+"@evmos/dappstore-sdk": patch
+"@evmos/dev-wrapper": patch
+---
+
+Creates init command
diff --git a/.changeset/smooth-mails-wonder.md b/.changeset/smooth-mails-wonder.md
new file mode 100644
index 0000000..944bdfb
--- /dev/null
+++ b/.changeset/smooth-mails-wonder.md
@@ -0,0 +1,5 @@
+---
+"dappstore": patch
+---
+
+Rename dappstore cli package
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 3b31177..4e99fa8 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -8,7 +8,7 @@ concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
build:
- name: Release
+ name: CI
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
diff --git a/README.md b/README.md
index 7a4658a..1b61549 100644
--- a/README.md
+++ b/README.md
@@ -1,81 +1,84 @@
-# Turborepo starter
+# DAppStore SDK client
-This is an official starter Turborepo.
+## Standalone usage:
-## Using this example
+```ts
+import { createDAppStoreClient } from "@evmos/dappstore-sdk";
-Run the following command:
+// Waits for the client to establish a connection to the DAppStore
+await dappstore.initialized;
-```sh
-npx create-turbo@latest
+console.log(
+ `DAppStore client initialized.`,
+ `Chain ID: ${dappstore.chainId}, Accounts: ${dappstore.accounts}`
+); // -> DAppStore client initialized. Chain ID: evmos:1, Accounts: ["0x..."]
```
-## What's inside?
-
-This Turborepo includes the following packages/apps:
-
-### Apps and Packages
-
-- `docs`: a [Next.js](https://nextjs.org/) app
-- `web`: another [Next.js](https://nextjs.org/) app
-- `@repo/ui`: a stub React component library shared by both `web` and `docs` applications
-- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
-- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo
-
-Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).
-
-### Utilities
-
-This Turborepo has some additional tools already setup for you:
-
-- [TypeScript](https://www.typescriptlang.org/) for static type checking
-- [ESLint](https://eslint.org/) for code linting
-- [Prettier](https://prettier.io) for code formatting
-
-### Build
-
-To build all apps and packages, run the following command:
-
-```
-cd my-turborepo
-pnpm build
-```
-
-### Develop
-
-To develop all apps and packages, run the following command:
-
+## Subscribe to account and chain id changes:
+
+```ts
+// Shorthand for dappstore.provider.on("accountsChanged", (accounts) => { ... })
+dappstore.onAccountsChange((accounts) => {
+ console.log(`Accounts changed: ${accounts}`); // -> Accounts changed: ["0x..."]
+});
+*
+// Shorthand for dappstore.provider.on("chainChanged", (chainId) => { ... })
+dappstore.onChainChange((chainId) => {
+ console.log(`Chain changed: ${chainId}`); // -> Chain changed: evmos:1
+});
+
+// Or interact directly with the provider
+dappstore.provider.request({ method: "eth_requestAccounts" }).then((accounts) => {
+ console.log(`Accounts: ${accounts}`); // -> Accounts: ["0x..."]
+});
```
-cd my-turborepo
-pnpm dev
-```
-
-### Remote Caching
-Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.
-
-By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:
-
-```
-cd my-turborepo
-npx turbo login
+## Usage with React:
+
+```tsx
+const dappstore = createDAppStoreClient();
+import { useEffect, useState } from "react";
+
+const useAccounts = () => {
+ const [accounts, setAccounts] = useState<`0x${string}`[]>(dappstore.accounts);
+ useEffect(() => {
+ return dappstore.onAccountsChange(setAccounts); // <- returns cleanup function
+ }, []);
+ return acccounts;
+};
+
+const useChainId = () => {
+ const [chainId, setChainId] = useState(dappstore.chainId);
+ useEffect(() => {
+ return dappstore.onChainChange(setChainId);
+ }, []);
+ return chainId;
+};
+
+const App = () => {
+ const accounts = useAccounts();
+ return
Accounts: {accounts.join(", ")}
;
+};
```
-This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).
-
-Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your Turborepo:
-
-```
-npx turbo link
+## Send a transaction:
+
+```ts
+const sendTransaction = async (to: `0x${string}`) => {
+ const [from] = dappstore.accounts;
+ if (!from) {
+ throw new Error("No account connected");
+ }
+
+ return await dappstore.provider.request({
+ method: "eth_sendTransaction",
+ params: [
+ {
+ from,
+ to,
+ value: "0x1", // We recommend using a library like ethers.js or viem to handle amounts
+ },
+ ],
+ });
+};
```
-
-## Useful Links
-
-Learn more about the power of Turborepo:
-
-- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
-- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
-- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
-- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
-- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
-- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
diff --git a/bun.lockb b/bun.lockb
index c14de94..cf05fc8 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/package.json b/package.json
index 18ca2fe..3578624 100644
--- a/package.json
+++ b/package.json
@@ -10,14 +10,16 @@
"release": "bun run build && changeset publish"
},
"devDependencies": {
- "dappstore": "workspace:*",
"@types/bun": "^1.0.4",
+ "@types/node": "^20.11.19",
"autoprefixer": "^10.4.17",
+ "dappstore": "workspace:*",
+ "knip": "^5.0.1",
"postcss": "^8.4.35",
"prettier": "^3.1.1",
"tailwindcss": "^3.4.1",
"turbo": "latest",
- "@evmos/config": "workspace:*"
+ "typescript": "^5.3.3"
},
"engines": {
"node": ">=18"
@@ -29,6 +31,7 @@
"packages/*"
],
"dependencies": {
- "@changesets/cli": "^2.27.1"
+ "@changesets/cli": "^2.27.1",
+ "cross-spawn": "^7.0.3"
}
}
diff --git a/packages/dappstore-cli/build.ts b/packages/dappstore-cli/build.ts
index ec3dcea..1fb7b75 100644
--- a/packages/dappstore-cli/build.ts
+++ b/packages/dappstore-cli/build.ts
@@ -1,26 +1,31 @@
// @ts-nocheck
import Bun from "bun";
import { dependencies, peerDependencies } from "./package.json";
-import { version } from "./package.json";
import { watch } from "node:fs";
-export const build = async () =>
- await Bun.build({
+export const build = async () => {
+ const result = await Bun.build({
entrypoints: ["./src/index.ts"],
target: "node",
format: "esm",
external: [...Object.keys(dependencies), ...Object.keys(peerDependencies)],
outdir: "./dist",
});
-const test = await build();
+
+ if (result.success === false) {
+ result.logs.forEach((log) => console.error(log));
+ return;
+ }
+ console.log("Build successful");
+};
+await build();
if (process.argv.includes("--watch")) {
const srcWatcher = watch(
`${import.meta.dir}/src`,
{ recursive: true },
async (event, filename) => {
- await build();
-
console.log(`Detected ${event} in ${filename} (src)`);
+ await build();
}
);
process.on("SIGINT", () => {
diff --git a/packages/dappstore-cli/package.json b/packages/dappstore-cli/package.json
index 0698c39..798816b 100644
--- a/packages/dappstore-cli/package.json
+++ b/packages/dappstore-cli/package.json
@@ -5,39 +5,27 @@
"type": "module",
"main": "dist/index.js",
"scripts": {
- "build": "bun run ./build.ts"
+ "build": "bun run ./build.ts",
+ "dev": "bun run build -- --watch"
},
"bin": {
"dappstore": "./dist/index.js"
},
"peerDependencies": {},
"devDependencies": {
- "@commander-js/extra-typings": "^11.1.0",
- "@evmos/dappstore-sdk": "workspace:*",
- "@types/eslint": "^8.56.1",
"@types/node": "^20.10.6",
- "@types/react": "^18.2.46",
- "@types/react-dom": "^18.2.18",
- "eslint": "^8.56.0",
- "react": "^18.2.0",
- "typescript": "^5.3.3",
- "viem": "^2.7.9"
+ "typescript": "^5.3.3"
},
"dependencies": {
"@evmos/dev-wrapper": "workspace:*",
- "@types/express": "^4.17.21",
- "@vitejs/plugin-react": "^4.2.1",
+ "@types/cross-spawn": "^6.0.6",
"autoprefixer": "^10.4.17",
"chalk": "^5.3.0",
- "clsx": "^2.1.0",
- "express": "^4.18.2",
- "glob": "^10.3.10",
+ "inquirer": "^9.2.14",
+ "lodash-es": "^4.17.21",
"postcss": "^8.4.33",
- "postcss-scopify": "^0.1.10",
- "react-dom": "^18.2.0",
"tailwindcss": "^3.4.1",
- "ts-dedent": "^2.2.0",
- "vite": "^5.0.12"
+ "@commander-js/extra-typings": "^12.0.0"
},
"publishConfig": {
"access": "public"
diff --git a/packages/dappstore-cli/src/dev.ts b/packages/dappstore-cli/src/dev.ts
index 70afdc7..7c31f8b 100644
--- a/packages/dappstore-cli/src/dev.ts
+++ b/packages/dappstore-cli/src/dev.ts
@@ -1,8 +1,10 @@
import { program } from "@commander-js/extra-typings";
import { serve } from "@evmos/dev-wrapper/serve/serve.js";
+import chalk from "chalk";
program
.command("dev")
+ .description("Start a development server")
.option("-p, --port ", "Development server port", "1337")
.option(
"-t, --target ",
@@ -11,10 +13,20 @@ program
)
.action(async ({ port, target }) => {
+ const targetUrl = target.startsWith("http")
+ ? target
+ : `http://localhost:${target}`;
const app = serve({
- target,
+ target: targetUrl,
});
app.listen(port, () => {
- console.log(`Example app listening on port http://localhost:${port}`);
+ console.log(
+ "\n\n",
+ `${chalk.hex("#FF8C5C")(`☄️ Evmos DAppStore Widget`)} environment running on http://localhost:${port}`,
+ "\n\n",
+ chalk.dim(
+ `Note: Expects your widget server to be running on ${targetUrl}`
+ )
+ );
});
});
diff --git a/packages/dappstore-cli/src/index.d.ts b/packages/dappstore-cli/src/index.d.ts
deleted file mode 100644
index 636e1e3..0000000
--- a/packages/dappstore-cli/src/index.d.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/usr/bin/env node
-import "./dev.js";
-import "./build.js";
-//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/packages/dappstore-cli/src/index.ts b/packages/dappstore-cli/src/index.ts
index a1ca3c7..0571ed1 100644
--- a/packages/dappstore-cli/src/index.ts
+++ b/packages/dappstore-cli/src/index.ts
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import "./dev";
-
+import "./init/init";
import { program } from "@commander-js/extra-typings";
-program.parseAsync(process.argv);
+
+program.parse(process.argv);
diff --git a/packages/dappstore-cli/src/init/detect-port.ts b/packages/dappstore-cli/src/init/detect-port.ts
new file mode 100644
index 0000000..fc4c91a
--- /dev/null
+++ b/packages/dappstore-cli/src/init/detect-port.ts
@@ -0,0 +1,43 @@
+import { readPackageJson } from "./read-package-json.js";
+
+export const detectRunningPort = async (dir: string = ".") => {
+ const pkg = await readPackageJson(dir);
+
+ const startScript = pkg.scripts?.start ?? "";
+ const devScript = pkg.scripts?.dev ?? "";
+ let explicitPort: null | number = parseInt(
+ startScript.match(/(--port|-p) (\d+)/)?.[1] ?? ""
+ );
+
+ if (isNaN(explicitPort)) {
+ explicitPort = null;
+ }
+
+ if (startScript.includes("next") || devScript.includes("next")) {
+ return {
+ framework: "next" as const,
+ port: explicitPort ?? 3000,
+ };
+ }
+ if (startScript.includes("vite") || devScript.includes("vite")) {
+ return {
+ framework: "vite" as const,
+ port: explicitPort ?? 5173,
+ };
+ }
+
+ if (
+ startScript.includes("react-scripts") ||
+ devScript.includes("react-scripts")
+ ) {
+ return {
+ framework: "react-scripts" as const,
+ port: explicitPort ?? 3000,
+ };
+ }
+
+ return {
+ framework: "unknown" as const,
+ port: explicitPort ?? null,
+ };
+};
diff --git a/packages/dappstore-cli/src/init/get-package-manager.ts b/packages/dappstore-cli/src/init/get-package-manager.ts
new file mode 100644
index 0000000..acc099f
--- /dev/null
+++ b/packages/dappstore-cli/src/init/get-package-manager.ts
@@ -0,0 +1,19 @@
+export type PackageManager = "npm" | "pnpm" | "yarn" | "bun";
+
+export function getPkgManager(): PackageManager {
+ const userAgent = process.env.npm_config_user_agent || "";
+
+ if (userAgent.startsWith("yarn")) {
+ return "yarn";
+ }
+
+ if (userAgent.startsWith("pnpm")) {
+ return "pnpm";
+ }
+
+ if (userAgent.startsWith("bun")) {
+ return "bun";
+ }
+
+ return "npm";
+}
diff --git a/packages/dappstore-cli/src/init/get-template.ts b/packages/dappstore-cli/src/init/get-template.ts
new file mode 100644
index 0000000..91bebe3
--- /dev/null
+++ b/packages/dappstore-cli/src/init/get-template.ts
@@ -0,0 +1,26 @@
+const TEMPLATE = `
+import { createDAppStoreClient } from "@evmos/dappstore-sdk";
+
+export const dappstore = createDAppStoreClient();
+
+/**
+ * EIP-1193 provider
+ */
+export const provider = dappstore.provider;
+`;
+// const __dirname = path.dirname(fileURLToPath(import.meta.url));
+export const readTemplate = () => {
+ // try {
+ // return await readFile(
+ // path.join(__dirname, `./templates/dappstore-client.ts`),
+ // "utf-8"
+ // );
+ // } catch (e) {
+ // console.error("Template not found");
+ // process.exit(1);
+ // }
+
+ // TODO: I was actually reading this file with a Bun macro but it's not working on github CI
+ // let's try again in the future
+ return TEMPLATE;
+};
diff --git a/packages/dappstore-cli/src/init/init.ts b/packages/dappstore-cli/src/init/init.ts
new file mode 100644
index 0000000..b276018
--- /dev/null
+++ b/packages/dappstore-cli/src/init/init.ts
@@ -0,0 +1,92 @@
+import { program } from "@commander-js/extra-typings";
+import inquirer from "inquirer";
+import { PackageManager, getPkgManager } from "./get-package-manager.js";
+import { installDependencies } from "./install-dependencies.js";
+import { readPackageJson, writePackageJson } from "./read-package-json.js";
+import chalk from "chalk";
+import { detectRunningPort } from "./detect-port.js";
+import { stat } from "fs/promises";
+import { writeTemplate } from "./write-template.js";
+
+program
+ .command("init")
+ .description("Initialize DAppStore widget in your project")
+
+ .option("--skip-install", "Skip installing dependencies")
+
+ .action(async ({ skipInstall }) => {
+ const detectedPackageManager = getPkgManager();
+ let pkgJson: Awaited>;
+ try {
+ pkgJson = await readPackageJson();
+ } catch (e) {
+ console.log(
+ "\n",
+ chalk.bgRed("package.json not found"),
+ "\n\n",
+ "Make sure you run this command in the root of your project,",
+ "\n",
+ `or you initialize a new project with ${chalk.yellow(
+ `'${detectedPackageManager} init'`
+ )} first.`,
+ "\n"
+ );
+ process.exit(1);
+ }
+
+ const defaultPort = await detectRunningPort();
+ const { packageManager, port } = await inquirer.prompt<{
+ packageManager: PackageManager;
+ port: number;
+ }>([
+ {
+ type: "list",
+ name: "packageManager",
+ message: `Which package manager do you want to use?`,
+
+ choices: ["npm", "pnpm", "bun", "yarn"].map((pm) => ({
+ name: pm === detectedPackageManager ? `${pm} (detected)` : pm,
+ value: pm,
+ })),
+ default: detectedPackageManager,
+ },
+ {
+ type: "number",
+ name: "port",
+
+ message: `What port or url of your development server will run on?`,
+ default: defaultPort.port ?? 3000,
+ },
+ ]);
+ if (!skipInstall) {
+ await installDependencies(packageManager, ["@evmos/dappstore-sdk"]);
+ await installDependencies(packageManager, ["dappstore"], "dev");
+ }
+ const packageJson = await readPackageJson();
+ packageJson.scripts = {
+ ...packageJson.scripts,
+ "dev:dappstore": `dappstore dev --target ${port}`,
+ };
+ await writePackageJson(".", packageJson);
+ let templateDest = "./dappstore-client.ts";
+ try {
+ const srcDir = await stat("src");
+ if (srcDir.isDirectory()) {
+ templateDest = "./src/dappstore-client.ts";
+ }
+ } catch (e) {
+ // noop
+ }
+
+ await writeTemplate(templateDest);
+
+ console.log(
+ "\n",
+ chalk.green(`🚀 DAppStore Widget Setup is completed`),
+ "\n",
+ `To start the development, start your development server, and then run:`,
+ "\n\n",
+
+ chalk.yellow(`\t${packageManager} run dev:dappstore`)
+ );
+ });
diff --git a/packages/dappstore-cli/src/init/install-dependencies.ts b/packages/dappstore-cli/src/init/install-dependencies.ts
new file mode 100644
index 0000000..33e33ad
--- /dev/null
+++ b/packages/dappstore-cli/src/init/install-dependencies.ts
@@ -0,0 +1,49 @@
+import spawn from "cross-spawn";
+import { PackageManager } from "./get-package-manager.js";
+import { readPackageJson } from "./read-package-json.js";
+
+/**
+ * Spawn a package manager installation based on user preference.
+ *
+ * @returns A Promise that resolves once the installation is finished.
+ */
+export async function installDependencies(
+ /** Indicate which package manager to use. */
+ packageManager: PackageManager,
+ dependencies: string[] = [],
+ as: "dev" | "prod" = "dev"
+): Promise {
+ readPackageJson.cache.clear?.();
+ const args: string[] = ["install"];
+ if (as === "dev") {
+ args.push("--save-dev");
+ }
+ args.push(...dependencies);
+
+ /**
+ * Return a Promise that resolves once the installation is finished.
+ */
+ return new Promise((resolve, reject) => {
+ /**
+ * Spawn the installation process.
+ */
+ const child = spawn(packageManager, args, {
+ stdio: "inherit",
+ env: {
+ ...process.env,
+ ADBLOCK: "1",
+ // we set NODE_ENV to development as pnpm skips dev
+ // dependencies when production
+ NODE_ENV: "development",
+ DISABLE_OPENCOLLECTIVE: "1",
+ },
+ });
+ child.on("close", (code) => {
+ if (code !== 0) {
+ reject({ command: `${packageManager} ${args.join(" ")}` });
+ return;
+ }
+ resolve();
+ });
+ });
+}
diff --git a/packages/dappstore-cli/src/init/read-package-json.ts b/packages/dappstore-cli/src/init/read-package-json.ts
new file mode 100644
index 0000000..e8797d6
--- /dev/null
+++ b/packages/dappstore-cli/src/init/read-package-json.ts
@@ -0,0 +1,33 @@
+import { readFile, writeFile } from "fs/promises";
+import { join } from "path";
+import { memoize } from "lodash-es";
+const readJson = async (path: string): Promise => {
+ const content = await readFile(path, "utf-8");
+ return JSON.parse(content);
+};
+
+export const readPackageJson = memoize(async (dir: string = ".") => {
+ const pkgPath = join(process.cwd(), dir, "package.json");
+
+ return await readJson<{
+ name?: string;
+ dependencies?: Record;
+ devDependencies?: Record;
+ scripts?: Record;
+ }>(pkgPath);
+});
+
+export const writePackageJson = async (
+ dir: string = ".",
+ pkg: {
+ name?: string;
+ dependencies?: Record;
+ devDependencies?: Record;
+ scripts?: Record;
+ }
+) => {
+ readPackageJson.cache.clear?.();
+ const pkgPath = join(process.cwd(), dir, "package.json");
+
+ await writeFile(pkgPath, JSON.stringify(pkg, null, 2));
+};
diff --git a/packages/dappstore-cli/src/init/templates/dappstore-client.ts b/packages/dappstore-cli/src/init/templates/dappstore-client.ts
new file mode 100644
index 0000000..3bc2406
--- /dev/null
+++ b/packages/dappstore-cli/src/init/templates/dappstore-client.ts
@@ -0,0 +1,8 @@
+import { createDAppStoreClient } from "@evmos/dappstore-sdk";
+
+export const dappstore = createDAppStoreClient();
+
+/**
+ * EIP-1193 provider
+ */
+export const provider = dappstore.provider;
diff --git a/packages/dappstore-cli/src/init/write-template.ts b/packages/dappstore-cli/src/init/write-template.ts
new file mode 100644
index 0000000..8ebbcf2
--- /dev/null
+++ b/packages/dappstore-cli/src/init/write-template.ts
@@ -0,0 +1,8 @@
+import { writeFile } from "fs/promises";
+import { readTemplate } from "./get-template" with { type: "macro" };
+
+export const writeTemplate = async (destination: string) => {
+ const templatePath = await readTemplate();
+
+ await writeFile(destination, templatePath, "utf-8");
+};
diff --git a/packages/dappstore-cli/tsconfig.json b/packages/dappstore-cli/tsconfig.json
index 0ca48f0..7415bd5 100644
--- a/packages/dappstore-cli/tsconfig.json
+++ b/packages/dappstore-cli/tsconfig.json
@@ -2,11 +2,7 @@
"extends": "@evmos/config/base.json",
"compilerOptions": {
"outDir": "./dist",
- "emitDeclarationOnly": true,
-
- "target": "ESNext",
- "moduleResolution": "NodeNext",
- "module": "NodeNext"
+ "target": "ESNext"
},
"include": ["./src/**/*", "./src/**/*.d.ts"],
"exclude": ["node_modules", "dist"]
diff --git a/packages/dappstore-sdk/package.json b/packages/dappstore-sdk/package.json
index 19e61b7..cef39d7 100644
--- a/packages/dappstore-sdk/package.json
+++ b/packages/dappstore-sdk/package.json
@@ -10,12 +10,12 @@
"dev": "bun run --watch ./build.ts --watch & bun run dev:types",
"build": "bun run ./build.ts & tsc"
},
+ "main": "dist/index.js",
+ "types": "dist/index.d.ts",
"exports": {
".": {
- "import": {
- "types": "./dist/index.d.ts",
- "default": "./dist/index.js"
- }
+ "types": "./dist/index.d.ts",
+ "default": "./dist/index.js"
},
"./internal/host": {
"types": "./dist/host.d.ts",
@@ -27,8 +27,6 @@
"@trpc/server": "next",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.10.6",
- "@types/react": "^18.2.46",
- "@types/react-dom": "^18.2.18",
"@types/uuid": "^9.0.8",
"lodash-es": "^4.17.21",
"typescript": "^5.3.3",
diff --git a/packages/dappstore-sdk/src/client.ts b/packages/dappstore-sdk/src/client.ts
index eff9258..7800f07 100644
--- a/packages/dappstore-sdk/src/client.ts
+++ b/packages/dappstore-sdk/src/client.ts
@@ -68,13 +68,22 @@ class SDKProvider implements StronglyTypedEIP1193Provider {
}
class Client {
- private _host: null | ReturnType = null;
- private _listeners: Record> = {};
- private _provider = new SDKProvider();
- private _ready = false;
- private _chainId: Hex | null = null;
- private _accounts: Hex[] = [];
- private _state: "uninitialized" | "ready" | "error" = "uninitialized";
+ // @internal
+ _host: null | ReturnType = null;
+ // @internal
+ _listeners: Record> = {};
+ // @internal
+ _provider = new SDKProvider();
+ // @internal
+ _ready = false;
+ // @internal
+ _chainId: Hex | null = null;
+ // @internal
+ _accounts: Hex[] = [];
+ // @internal
+ _state: "uninitialized" | "ready" | "error" = "uninitialized";
+
+ initialized: Promise<() => void> = Promise.resolve(() => {});
get ready() {
return this._ready;
}
@@ -88,18 +97,25 @@ class Client {
get provider() {
return this._provider;
}
- private get isInsideIframe() {
+ // @internal
+ get _isInsideIframe() {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
- init() {
- if (this.isInsideIframe === false) {
- throw new Error("Cannot use DAppStore SDK outside of an iframe");
+
+ constructor(autoInit = true) {
+ if (autoInit) this.initialized = this.init();
+ }
+ async init() {
+ if (this._isInsideIframe === false) {
+ throw new Error(
+ "Cannot use DAppStore SDK outside of the DAppStore iframe"
+ );
}
- this.ack();
+ await this.ack();
const unsubAccounts = trpcClient.provider.on.accountsChanged.subscribe(
undefined,
{
@@ -162,7 +178,9 @@ class Client {
}
export const createDAppStoreClient = ({ autoInit = true } = {}) => {
- const client = new Client();
- if (autoInit) client.init();
+ const client = new Client(autoInit);
+
return client;
};
+
+export type DAppStoreClient = Client;
diff --git a/packages/dappstore-sdk/src/index.ts b/packages/dappstore-sdk/src/index.ts
index 9659024..422799b 100644
--- a/packages/dappstore-sdk/src/index.ts
+++ b/packages/dappstore-sdk/src/index.ts
@@ -1,2 +1,2 @@
-export { createDAppStoreClient as createDAppstoreClient } from "./client";
+export { createDAppStoreClient, type DAppStoreClient } from "./client";
export * from "./types/EIP1193Provider";
diff --git a/packages/dev-wrapper/package.json b/packages/dev-wrapper/package.json
index 936f8f8..05a9532 100644
--- a/packages/dev-wrapper/package.json
+++ b/packages/dev-wrapper/package.json
@@ -13,6 +13,8 @@
"preview": "vite preview"
},
"dependencies": {
+ "@tanstack/react-query": "^5.20.5",
+ "@types/express": "^4.17.21",
"clsx": "^2.1.0",
"express": "^4.18.2",
"react": "^18.2.0",
diff --git a/packages/dev-wrapper/serve.ts b/packages/dev-wrapper/serve.ts
index a16bbe8..2444a06 100644
--- a/packages/dev-wrapper/serve.ts
+++ b/packages/dev-wrapper/serve.ts
@@ -5,12 +5,8 @@ import { readFileSync } from "fs";
const __dirname = fileURLToPath(new URL("./", import.meta.url));
export const serve = ({ target }: { target: string }) => {
- const targetUrl = target.startsWith("http")
- ? target
- : `http://localhost:${target}`;
-
const app = express();
- const envScript = ``;
+ const envScript = ``;
const index = readFileSync(
path.join(__dirname, "../app/index.html"),
"utf-8"
diff --git a/packages/dev-wrapper/src/App.tsx b/packages/dev-wrapper/src/App.tsx
index c367163..bf0e591 100644
--- a/packages/dev-wrapper/src/App.tsx
+++ b/packages/dev-wrapper/src/App.tsx
@@ -26,7 +26,7 @@ const Header = () => {
);
};
-export function WalletOptions() {
+function WalletOptions() {
const { connectors, connect, isPending } = useConnect();
const { disconnect } = useDisconnect();
const { isConnected, address } = useAccount();