@dynamic-labs/ethereum 5.0.0-rc.0 → 5.0.0-rc.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.
@@ -1,6 +1,7 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../_virtual/_tslib.js';
3
3
  import { EthereumWalletConnector } from '@dynamic-labs/ethereum-core';
4
+ import { isMobile, WalletRequiresInAppBrowserError } from '@dynamic-labs/utils';
4
5
  import { EthProviderHelper } from '../ethProviderHelper.js';
5
6
  import { logger } from '../utils/logger.js';
6
7
  import { WalletConnectConnector } from '../walletConnect/WalletConnectConnector/WalletConnectConnector.js';
@@ -68,9 +69,40 @@ class InjectedWalletBase extends EthereumWalletConnector {
68
69
  yield this.getAddress();
69
70
  });
70
71
  }
72
+ getSigner() {
73
+ const _super = Object.create(null, {
74
+ getSigner: { get: () => super.getSigner }
75
+ });
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ const signer = yield _super.getSigner.call(this);
78
+ if (signer) {
79
+ return signer;
80
+ }
81
+ // On mobile web (outside the wallet's in-app browser) there is no injected
82
+ // provider for these wallets, so signing silently returns nothing. Redirect
83
+ // into the wallet's in-app browser so signing can continue there, or throw a
84
+ // clear error when neither a provider nor a redirect is possible.
85
+ if (isMobile() && !this.isInstalledOnBrowser()) {
86
+ const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
87
+ if (!didOpenInAppBrowser) {
88
+ throw new WalletRequiresInAppBrowserError(this.name);
89
+ }
90
+ }
91
+ return undefined;
92
+ });
93
+ }
71
94
  signMessage(messageToSign) {
72
95
  return __awaiter(this, void 0, void 0, function* () {
73
96
  var _a;
97
+ // Trigger the in-app-browser redirect up front (mirroring getAddress) so
98
+ // that on mobile web an in-app-browser wallet redirects into its in-app
99
+ // browser instead of silently signing nothing. Delegating to the helper
100
+ // afterwards keeps signing to a single address request (no duplicate wallet
101
+ // prompt), since the helper resolves the address itself.
102
+ const didOpenInAppBrowser = this.openInAppBrowserIfRequired();
103
+ if (didOpenInAppBrowser) {
104
+ return undefined;
105
+ }
74
106
  return (_a = this.ethProviderHelper) === null || _a === void 0 ? void 0 : _a.signMessage(messageToSign);
75
107
  });
76
108
  }
@@ -3,7 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var _tslib = require('../../_virtual/_tslib.cjs');
7
6
  var utils = require('@dynamic-labs/utils');
8
7
  var InjectedWalletBase = require('./InjectedWalletBase.cjs');
9
8
 
@@ -13,22 +12,15 @@ class PhantomEvm extends InjectedWalletBase.InjectedWalletBase {
13
12
  this.name = 'Phantom';
14
13
  this.overrideKey = 'phantomevm';
15
14
  }
16
- getAddress() {
17
- const _super = Object.create(null, {
18
- getAddress: { get: () => super.getAddress }
19
- });
20
- return _tslib.__awaiter(this, void 0, void 0, function* () {
21
- if (this.isInstalledOnBrowser()) {
22
- return _super.getAddress.call(this);
23
- }
24
- if (utils.isMobile()) {
25
- utils.handleMobileWalletRedirect({
26
- nativeLink: 'phantom://browse',
27
- universalLink: 'https://phantom.app/ul/browse',
28
- });
29
- }
30
- return undefined;
31
- });
15
+ openInAppBrowserIfRequired() {
16
+ if (utils.isMobile() && !this.isInstalledOnBrowser()) {
17
+ utils.handleMobileWalletRedirect({
18
+ nativeLink: 'phantom://browse',
19
+ universalLink: 'https://phantom.app/ul/browse',
20
+ });
21
+ return true;
22
+ }
23
+ return false;
32
24
  }
33
25
  canGetChainAddress() {
34
26
  var _a, _b;
@@ -2,6 +2,6 @@ import { InjectedWalletBase } from './InjectedWalletBase';
2
2
  export declare class PhantomEvm extends InjectedWalletBase {
3
3
  name: string;
4
4
  overrideKey: string;
5
- getAddress(): Promise<string | undefined>;
5
+ openInAppBrowserIfRequired(): boolean;
6
6
  canGetChainAddress(): boolean;
7
7
  }
@@ -1,5 +1,4 @@
1
1
  'use client'
2
- import { __awaiter } from '../../_virtual/_tslib.js';
3
2
  import { isMobile, handleMobileWalletRedirect } from '@dynamic-labs/utils';
4
3
  import { InjectedWalletBase } from './InjectedWalletBase.js';
5
4
 
@@ -9,22 +8,15 @@ class PhantomEvm extends InjectedWalletBase {
9
8
  this.name = 'Phantom';
10
9
  this.overrideKey = 'phantomevm';
11
10
  }
12
- getAddress() {
13
- const _super = Object.create(null, {
14
- getAddress: { get: () => super.getAddress }
15
- });
16
- return __awaiter(this, void 0, void 0, function* () {
17
- if (this.isInstalledOnBrowser()) {
18
- return _super.getAddress.call(this);
19
- }
20
- if (isMobile()) {
21
- handleMobileWalletRedirect({
22
- nativeLink: 'phantom://browse',
23
- universalLink: 'https://phantom.app/ul/browse',
24
- });
25
- }
26
- return undefined;
27
- });
11
+ openInAppBrowserIfRequired() {
12
+ if (isMobile() && !this.isInstalledOnBrowser()) {
13
+ handleMobileWalletRedirect({
14
+ nativeLink: 'phantom://browse',
15
+ universalLink: 'https://phantom.app/ul/browse',
16
+ });
17
+ return true;
18
+ }
19
+ return false;
28
20
  }
29
21
  canGetChainAddress() {
30
22
  var _a, _b;
package/src/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type EventEmitter } from 'eventemitter3';
2
- import { PublicClient } from 'viem';
2
+ import { EIP1193Provider, PublicClient } from 'viem';
3
3
  import type { BaseAccountSDKOpts } from '@dynamic-labs-connectors/base-account-evm';
4
4
  import { ProviderCondition } from '@dynamic-labs/wallet-connector-core';
5
5
  import { RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
@@ -8,7 +8,7 @@ declare global {
8
8
  ethereum: IEthereum;
9
9
  }
10
10
  interface Window {
11
- ethereum?: IEthereum;
11
+ ethereum?: EIP1193Provider;
12
12
  phantom?: IWindowPhantom;
13
13
  zerionWallet?: IEthereum;
14
14
  coinbaseWalletExtension?: IEthereum;