@vue-solana/vue 0.2.0 → 0.2.2

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 CHANGED
@@ -11,6 +11,7 @@ New to Solana? Start with the official docs and the project concepts guide:
11
11
  - [Solana Clusters](https://solana.com/docs/references/clusters)
12
12
  - [Vue Solana Concepts Guide](https://vue-solana-docs.vercel.app/concepts/solana-for-vue-developers)
13
13
  - [`@vue-solana/vue` docs](https://vue-solana-docs.vercel.app/packages/vue)
14
+ - [Live demo](https://vue-solana-docs.vercel.app/demo)
14
15
 
15
16
  ## Install
16
17
 
@@ -157,7 +158,9 @@ This README includes small snippets for quick reference. For a complete runnable
157
158
  pnpm dev:vue
158
159
  ```
159
160
 
160
- Docs: [`examples/vue-vite`](https://vue-solana-docs.vercel.app/examples/vue-vite)
161
+ Docs: <a href="https://vue-solana-docs.vercel.app/examples/vue-vite" target="_blank" rel="noopener noreferrer"><code>examples/vue-vite</code></a>
162
+
163
+ Live demo: [vue-solana-docs.vercel.app/demo](https://vue-solana-docs.vercel.app/demo)
161
164
 
162
165
  ## API
163
166
 
package/dist/index.cjs CHANGED
@@ -180,6 +180,7 @@ function useWallets() {
180
180
  };
181
181
  }
182
182
 
183
+ const RPC_CHECK_TIMEOUT_MS = 1e4;
183
184
  function createSolanaPlugin(options = {}) {
184
185
  return {
185
186
  install(app) {
@@ -191,7 +192,9 @@ function createSolanaPlugin(options = {}) {
191
192
  const error = vue.ref(null);
192
193
  const latestBlockhash = vue.ref(null);
193
194
  let unsubscribeWallets = null;
195
+ let rpcCheckId = 0;
194
196
  async function checkConnection() {
197
+ const checkId = ++rpcCheckId;
195
198
  status.value = "checking";
196
199
  error.value = null;
197
200
  console.info("[Vue Solana] Checking RPC connection", {
@@ -200,7 +203,14 @@ function createSolanaPlugin(options = {}) {
200
203
  wsEndpoint: context.wsEndpoint
201
204
  });
202
205
  try {
203
- const blockhash = await context.connection.getLatestBlockhash();
206
+ const blockhash = await withTimeout(
207
+ context.connection.getLatestBlockhash(),
208
+ RPC_CHECK_TIMEOUT_MS,
209
+ `RPC connection check timed out after ${RPC_CHECK_TIMEOUT_MS / 1e3} seconds.`
210
+ );
211
+ if (checkId !== rpcCheckId) {
212
+ return;
213
+ }
204
214
  latestBlockhash.value = blockhash.blockhash;
205
215
  status.value = "connected";
206
216
  console.info("[Vue Solana] Connected", {
@@ -210,6 +220,9 @@ function createSolanaPlugin(options = {}) {
210
220
  blockhash
211
221
  });
212
222
  } catch (cause) {
223
+ if (checkId !== rpcCheckId) {
224
+ return;
225
+ }
213
226
  status.value = "error";
214
227
  error.value = cause instanceof Error ? cause.message : String(cause);
215
228
  console.error("[Vue Solana] Connection failed", cause);
@@ -249,11 +262,26 @@ function createSolanaPlugin(options = {}) {
249
262
  }
250
263
  };
251
264
  app.provide(solanaInjectionKey, vueContext);
252
- void checkConnection();
265
+ if (typeof window !== "undefined") {
266
+ void checkConnection();
267
+ }
253
268
  }
254
269
  };
255
270
  }
256
271
  const VueSolana = createSolanaPlugin;
272
+ function withTimeout(promise, timeoutMs, message) {
273
+ let timeoutId;
274
+ const timeout = new Promise((_, reject) => {
275
+ timeoutId = setTimeout(() => {
276
+ reject(new Error(message));
277
+ }, timeoutMs);
278
+ });
279
+ return Promise.race([promise, timeout]).finally(() => {
280
+ if (timeoutId) {
281
+ clearTimeout(timeoutId);
282
+ }
283
+ });
284
+ }
257
285
 
258
286
  exports.VueSolana = VueSolana;
259
287
  exports.createSolanaPlugin = createSolanaPlugin;
package/dist/index.mjs CHANGED
@@ -178,6 +178,7 @@ function useWallets() {
178
178
  };
179
179
  }
180
180
 
181
+ const RPC_CHECK_TIMEOUT_MS = 1e4;
181
182
  function createSolanaPlugin(options = {}) {
182
183
  return {
183
184
  install(app) {
@@ -189,7 +190,9 @@ function createSolanaPlugin(options = {}) {
189
190
  const error = ref(null);
190
191
  const latestBlockhash = ref(null);
191
192
  let unsubscribeWallets = null;
193
+ let rpcCheckId = 0;
192
194
  async function checkConnection() {
195
+ const checkId = ++rpcCheckId;
193
196
  status.value = "checking";
194
197
  error.value = null;
195
198
  console.info("[Vue Solana] Checking RPC connection", {
@@ -198,7 +201,14 @@ function createSolanaPlugin(options = {}) {
198
201
  wsEndpoint: context.wsEndpoint
199
202
  });
200
203
  try {
201
- const blockhash = await context.connection.getLatestBlockhash();
204
+ const blockhash = await withTimeout(
205
+ context.connection.getLatestBlockhash(),
206
+ RPC_CHECK_TIMEOUT_MS,
207
+ `RPC connection check timed out after ${RPC_CHECK_TIMEOUT_MS / 1e3} seconds.`
208
+ );
209
+ if (checkId !== rpcCheckId) {
210
+ return;
211
+ }
202
212
  latestBlockhash.value = blockhash.blockhash;
203
213
  status.value = "connected";
204
214
  console.info("[Vue Solana] Connected", {
@@ -208,6 +218,9 @@ function createSolanaPlugin(options = {}) {
208
218
  blockhash
209
219
  });
210
220
  } catch (cause) {
221
+ if (checkId !== rpcCheckId) {
222
+ return;
223
+ }
211
224
  status.value = "error";
212
225
  error.value = cause instanceof Error ? cause.message : String(cause);
213
226
  console.error("[Vue Solana] Connection failed", cause);
@@ -247,10 +260,25 @@ function createSolanaPlugin(options = {}) {
247
260
  }
248
261
  };
249
262
  app.provide(solanaInjectionKey, vueContext);
250
- void checkConnection();
263
+ if (typeof window !== "undefined") {
264
+ void checkConnection();
265
+ }
251
266
  }
252
267
  };
253
268
  }
254
269
  const VueSolana = createSolanaPlugin;
270
+ function withTimeout(promise, timeoutMs, message) {
271
+ let timeoutId;
272
+ const timeout = new Promise((_, reject) => {
273
+ timeoutId = setTimeout(() => {
274
+ reject(new Error(message));
275
+ }, timeoutMs);
276
+ });
277
+ return Promise.race([promise, timeout]).finally(() => {
278
+ if (timeoutId) {
279
+ clearTimeout(timeoutId);
280
+ }
281
+ });
282
+ }
255
283
 
256
284
  export { VueSolana, createSolanaPlugin, solanaInjectionKey, useBalance, useConnection, useRpc, useSignAndSendTransaction, useSolana, useTransaction, useWallet, useWallets };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-solana/vue",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Vue plugin and composables for Solana applications.",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -38,7 +38,7 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@vue-solana/core": "0.2.0"
41
+ "@vue-solana/core": "0.2.1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@solana/web3-compat": "^0.0.21",