@phantom/browser-injected-sdk 1.0.0-beta.3 → 1.0.0-beta.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.
@@ -381,7 +381,25 @@ var ethereum = {
381
381
  function createEthereumPlugin() {
382
382
  return {
383
383
  name: "ethereum",
384
- create: () => ethereum
384
+ create: () => {
385
+ try {
386
+ const provider = window?.phantom?.ethereum;
387
+ if (provider) {
388
+ provider.on("connect", () => {
389
+ provider.request({ method: "eth_accounts" }).then((accounts) => {
390
+ if (accounts?.length > 0)
391
+ triggerEvent("connect", accounts);
392
+ }).catch(() => {
393
+ });
394
+ });
395
+ provider.on("disconnect", () => triggerEvent("disconnect", []));
396
+ provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
397
+ provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
398
+ }
399
+ } catch (error) {
400
+ }
401
+ return ethereum;
402
+ }
385
403
  };
386
404
  }
387
405
 
@@ -415,7 +415,25 @@ var ethereum = {
415
415
  function createEthereumPlugin() {
416
416
  return {
417
417
  name: "ethereum",
418
- create: () => ethereum
418
+ create: () => {
419
+ try {
420
+ const provider = window?.phantom?.ethereum;
421
+ if (provider) {
422
+ provider.on("connect", () => {
423
+ provider.request({ method: "eth_accounts" }).then((accounts) => {
424
+ if (accounts?.length > 0)
425
+ triggerEvent("connect", accounts);
426
+ }).catch(() => {
427
+ });
428
+ });
429
+ provider.on("disconnect", () => triggerEvent("disconnect", []));
430
+ provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
431
+ provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
432
+ }
433
+ } catch (error) {
434
+ }
435
+ return ethereum;
436
+ }
419
437
  };
420
438
  }
421
439
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "../chunk-IHSV7HFD.mjs";
3
+ } from "../chunk-CGMYPQYU.mjs";
4
4
  import "../chunk-WUKYLWAZ.mjs";
5
5
  import "../chunk-GV6AIHPN.mjs";
6
6
  export {
package/dist/index.js CHANGED
@@ -439,7 +439,25 @@ var ethereum = {
439
439
  function createEthereumPlugin() {
440
440
  return {
441
441
  name: "ethereum",
442
- create: () => ethereum
442
+ create: () => {
443
+ try {
444
+ const provider = window?.phantom?.ethereum;
445
+ if (provider) {
446
+ provider.on("connect", () => {
447
+ provider.request({ method: "eth_accounts" }).then((accounts) => {
448
+ if (accounts?.length > 0)
449
+ triggerEvent("connect", accounts);
450
+ }).catch(() => {
451
+ });
452
+ });
453
+ provider.on("disconnect", () => triggerEvent("disconnect", []));
454
+ provider.on("accountsChanged", (accounts) => triggerEvent("accountsChanged", accounts));
455
+ provider.on("chainChanged", (chainId) => triggerEvent("chainChanged", chainId));
456
+ }
457
+ } catch (error) {
458
+ }
459
+ return ethereum;
460
+ }
443
461
  };
444
462
  }
445
463
 
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createEthereumPlugin
3
- } from "./chunk-IHSV7HFD.mjs";
3
+ } from "./chunk-CGMYPQYU.mjs";
4
4
  import "./chunk-WUKYLWAZ.mjs";
5
5
  import "./chunk-GV6AIHPN.mjs";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import { P as Plugin } from '../index-04827df9.js';
2
- import { VersionedTransaction, Transaction } from '@solana/web3.js';
2
+ import { VersionedTransaction, Transaction } from '@phantom/sdk-types';
3
3
 
4
4
  declare function connect(): Promise<string | undefined>;
5
5
 
@@ -367,7 +367,24 @@ var solana = {
367
367
  function createSolanaPlugin() {
368
368
  return {
369
369
  name: "solana",
370
- create: () => solana
370
+ create: () => {
371
+ try {
372
+ const provider = window?.phantom?.solana;
373
+ if (provider) {
374
+ provider.on("connect", (publicKey) => {
375
+ if (publicKey)
376
+ triggerEvent("connect", publicKey.toString());
377
+ });
378
+ provider.on("disconnect", () => triggerEvent("disconnect"));
379
+ provider.on("accountChanged", (publicKey) => {
380
+ if (publicKey)
381
+ triggerEvent("accountChanged", publicKey.toString());
382
+ });
383
+ }
384
+ } catch (error) {
385
+ }
386
+ return solana;
387
+ }
371
388
  };
372
389
  }
373
390
  // Annotate the CommonJS export names for ESM import in node:
@@ -334,7 +334,24 @@ var solana = {
334
334
  function createSolanaPlugin() {
335
335
  return {
336
336
  name: "solana",
337
- create: () => solana
337
+ create: () => {
338
+ try {
339
+ const provider = window?.phantom?.solana;
340
+ if (provider) {
341
+ provider.on("connect", (publicKey) => {
342
+ if (publicKey)
343
+ triggerEvent("connect", publicKey.toString());
344
+ });
345
+ provider.on("disconnect", () => triggerEvent("disconnect"));
346
+ provider.on("accountChanged", (publicKey) => {
347
+ if (publicKey)
348
+ triggerEvent("accountChanged", publicKey.toString());
349
+ });
350
+ }
351
+ } catch (error) {
352
+ }
353
+ return solana;
354
+ }
338
355
  };
339
356
  }
340
357
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/browser-injected-sdk",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -42,8 +42,8 @@
42
42
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
43
43
  },
44
44
  "dependencies": {
45
- "@phantom/constants": "^1.0.0-beta.3",
46
- "@solana/web3.js": "^1.98.2"
45
+ "@phantom/constants": "^1.0.0-beta.6",
46
+ "@phantom/sdk-types": "^1.0.0-beta.6"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^29.5.14",