@0xsequence/provider 0.36.5 → 0.36.8

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.
@@ -796,6 +796,27 @@ class WalletRequestHandler {
796
796
  response.result = gasPrice.toHexString();
797
797
  break;
798
798
  }
799
+
800
+ case 'wallet_switchEthereumChain':
801
+ {
802
+ const [switchParams] = request.params;
803
+
804
+ if (!switchParams.chainId || switchParams.chainId.length === 0) {
805
+ throw new Error('invalid chainId');
806
+ }
807
+
808
+ const _chainId = ethers.ethers.BigNumber.from(switchParams.chainId);
809
+
810
+ const ok = await _this.setDefaultNetwork(_chainId.toString(), true);
811
+
812
+ if (!ok) {
813
+ throw new Error(`unable to set chainId ${_chainId}`);
814
+ }
815
+
816
+ response.result = null; // success
817
+
818
+ break;
819
+ }
799
820
  // smart wallet method
800
821
 
801
822
  case 'sequence_getWalletContext':
@@ -807,16 +828,16 @@ class WalletRequestHandler {
807
828
 
808
829
  case 'sequence_getWalletConfig':
809
830
  {
810
- const [_chainId] = request.params;
811
- response.result = await signer.getWalletConfig(_chainId);
831
+ const [_chainId2] = request.params;
832
+ response.result = await signer.getWalletConfig(_chainId2);
812
833
  break;
813
834
  }
814
835
  // smart wallet method
815
836
 
816
837
  case 'sequence_getWalletState':
817
838
  {
818
- const [_chainId2] = request.params;
819
- response.result = await signer.getWalletState(_chainId2);
839
+ const [_chainId3] = request.params;
840
+ response.result = await signer.getWalletState(_chainId3);
820
841
  break;
821
842
  }
822
843
  // smart wallet method
@@ -2431,7 +2452,11 @@ class MuxMessageProvider {
2431
2452
  this.provider = this.messageProviders[0];
2432
2453
  this.provider.register();
2433
2454
  return;
2434
- }
2455
+ } // REVIEW/NOTE: ........ this method does not work for the chrome-extension. The issue becomes
2456
+ // when the browser quits or restarts, the "open" event is never triggered. Perhaps the code here is fine,
2457
+ // or maybe its not. What should happen is when a dapp makes a request, it will call openWallet
2458
+ // below, in which case one of the events will register. So perhaps this is fine.
2459
+
2435
2460
 
2436
2461
  this.messageProviders.forEach(m => {
2437
2462
  m.register();
@@ -2667,7 +2692,7 @@ class WindowMessageProvider extends BaseProviderTransport {
2667
2692
  if (!isBrowserExtension()) {
2668
2693
  intent.options.origin = window.location.origin;
2669
2694
  }
2670
- } // encode intent as base6 url-encoded param
2695
+ } // encode intent as base64 url-encoded param
2671
2696
 
2672
2697
 
2673
2698
  windowSessionParams.set('intent', utils.base64EncodeObject(intent));
@@ -3195,8 +3220,15 @@ class Wallet {
3195
3220
  }
3196
3221
 
3197
3222
  if ((_this$config$transpor5 = this.config.transports) != null && (_this$config$transpor6 = _this$config$transpor5.extensionTransport) != null && _this$config$transpor6.enabled) {
3198
- this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime);
3199
- this.transport.messageProvider.add(this.transport.extensionMessageProvider);
3223
+ this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime); // this.transport.extensionMessageProvider.register()
3224
+
3225
+ this.transport.messageProvider.add(this.transport.extensionMessageProvider); // NOTE/REVIEW: see note in mux-message-provider
3226
+ //
3227
+ // We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
3228
+ // send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
3229
+ // the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
3230
+ //
3231
+ // this.transport.messageProvider.add(this.transport.extensionMessageProvider)
3200
3232
  }
3201
3233
 
3202
3234
  this.transport.messageProvider.register(); // .....
@@ -796,6 +796,27 @@ class WalletRequestHandler {
796
796
  response.result = gasPrice.toHexString();
797
797
  break;
798
798
  }
799
+
800
+ case 'wallet_switchEthereumChain':
801
+ {
802
+ const [switchParams] = request.params;
803
+
804
+ if (!switchParams.chainId || switchParams.chainId.length === 0) {
805
+ throw new Error('invalid chainId');
806
+ }
807
+
808
+ const _chainId = ethers.ethers.BigNumber.from(switchParams.chainId);
809
+
810
+ const ok = await _this.setDefaultNetwork(_chainId.toString(), true);
811
+
812
+ if (!ok) {
813
+ throw new Error(`unable to set chainId ${_chainId}`);
814
+ }
815
+
816
+ response.result = null; // success
817
+
818
+ break;
819
+ }
799
820
  // smart wallet method
800
821
 
801
822
  case 'sequence_getWalletContext':
@@ -807,16 +828,16 @@ class WalletRequestHandler {
807
828
 
808
829
  case 'sequence_getWalletConfig':
809
830
  {
810
- const [_chainId] = request.params;
811
- response.result = await signer.getWalletConfig(_chainId);
831
+ const [_chainId2] = request.params;
832
+ response.result = await signer.getWalletConfig(_chainId2);
812
833
  break;
813
834
  }
814
835
  // smart wallet method
815
836
 
816
837
  case 'sequence_getWalletState':
817
838
  {
818
- const [_chainId2] = request.params;
819
- response.result = await signer.getWalletState(_chainId2);
839
+ const [_chainId3] = request.params;
840
+ response.result = await signer.getWalletState(_chainId3);
820
841
  break;
821
842
  }
822
843
  // smart wallet method
@@ -2431,7 +2452,11 @@ class MuxMessageProvider {
2431
2452
  this.provider = this.messageProviders[0];
2432
2453
  this.provider.register();
2433
2454
  return;
2434
- }
2455
+ } // REVIEW/NOTE: ........ this method does not work for the chrome-extension. The issue becomes
2456
+ // when the browser quits or restarts, the "open" event is never triggered. Perhaps the code here is fine,
2457
+ // or maybe its not. What should happen is when a dapp makes a request, it will call openWallet
2458
+ // below, in which case one of the events will register. So perhaps this is fine.
2459
+
2435
2460
 
2436
2461
  this.messageProviders.forEach(m => {
2437
2462
  m.register();
@@ -2667,7 +2692,7 @@ class WindowMessageProvider extends BaseProviderTransport {
2667
2692
  if (!isBrowserExtension()) {
2668
2693
  intent.options.origin = window.location.origin;
2669
2694
  }
2670
- } // encode intent as base6 url-encoded param
2695
+ } // encode intent as base64 url-encoded param
2671
2696
 
2672
2697
 
2673
2698
  windowSessionParams.set('intent', utils.base64EncodeObject(intent));
@@ -3195,8 +3220,15 @@ class Wallet {
3195
3220
  }
3196
3221
 
3197
3222
  if ((_this$config$transpor5 = this.config.transports) != null && (_this$config$transpor6 = _this$config$transpor5.extensionTransport) != null && _this$config$transpor6.enabled) {
3198
- this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime);
3199
- this.transport.messageProvider.add(this.transport.extensionMessageProvider);
3223
+ this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime); // this.transport.extensionMessageProvider.register()
3224
+
3225
+ this.transport.messageProvider.add(this.transport.extensionMessageProvider); // NOTE/REVIEW: see note in mux-message-provider
3226
+ //
3227
+ // We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
3228
+ // send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
3229
+ // the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
3230
+ //
3231
+ // this.transport.messageProvider.add(this.transport.extensionMessageProvider)
3200
3232
  }
3201
3233
 
3202
3234
  this.transport.messageProvider.register(); // .....
@@ -792,6 +792,27 @@ class WalletRequestHandler {
792
792
  response.result = gasPrice.toHexString();
793
793
  break;
794
794
  }
795
+
796
+ case 'wallet_switchEthereumChain':
797
+ {
798
+ const [switchParams] = request.params;
799
+
800
+ if (!switchParams.chainId || switchParams.chainId.length === 0) {
801
+ throw new Error('invalid chainId');
802
+ }
803
+
804
+ const _chainId = ethers.BigNumber.from(switchParams.chainId);
805
+
806
+ const ok = await _this.setDefaultNetwork(_chainId.toString(), true);
807
+
808
+ if (!ok) {
809
+ throw new Error(`unable to set chainId ${_chainId}`);
810
+ }
811
+
812
+ response.result = null; // success
813
+
814
+ break;
815
+ }
795
816
  // smart wallet method
796
817
 
797
818
  case 'sequence_getWalletContext':
@@ -803,16 +824,16 @@ class WalletRequestHandler {
803
824
 
804
825
  case 'sequence_getWalletConfig':
805
826
  {
806
- const [_chainId] = request.params;
807
- response.result = await signer.getWalletConfig(_chainId);
827
+ const [_chainId2] = request.params;
828
+ response.result = await signer.getWalletConfig(_chainId2);
808
829
  break;
809
830
  }
810
831
  // smart wallet method
811
832
 
812
833
  case 'sequence_getWalletState':
813
834
  {
814
- const [_chainId2] = request.params;
815
- response.result = await signer.getWalletState(_chainId2);
835
+ const [_chainId3] = request.params;
836
+ response.result = await signer.getWalletState(_chainId3);
816
837
  break;
817
838
  }
818
839
  // smart wallet method
@@ -2427,7 +2448,11 @@ class MuxMessageProvider {
2427
2448
  this.provider = this.messageProviders[0];
2428
2449
  this.provider.register();
2429
2450
  return;
2430
- }
2451
+ } // REVIEW/NOTE: ........ this method does not work for the chrome-extension. The issue becomes
2452
+ // when the browser quits or restarts, the "open" event is never triggered. Perhaps the code here is fine,
2453
+ // or maybe its not. What should happen is when a dapp makes a request, it will call openWallet
2454
+ // below, in which case one of the events will register. So perhaps this is fine.
2455
+
2431
2456
 
2432
2457
  this.messageProviders.forEach(m => {
2433
2458
  m.register();
@@ -2663,7 +2688,7 @@ class WindowMessageProvider extends BaseProviderTransport {
2663
2688
  if (!isBrowserExtension()) {
2664
2689
  intent.options.origin = window.location.origin;
2665
2690
  }
2666
- } // encode intent as base6 url-encoded param
2691
+ } // encode intent as base64 url-encoded param
2667
2692
 
2668
2693
 
2669
2694
  windowSessionParams.set('intent', base64EncodeObject(intent));
@@ -3191,8 +3216,15 @@ class Wallet {
3191
3216
  }
3192
3217
 
3193
3218
  if ((_this$config$transpor5 = this.config.transports) != null && (_this$config$transpor6 = _this$config$transpor5.extensionTransport) != null && _this$config$transpor6.enabled) {
3194
- this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime);
3195
- this.transport.messageProvider.add(this.transport.extensionMessageProvider);
3219
+ this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime); // this.transport.extensionMessageProvider.register()
3220
+
3221
+ this.transport.messageProvider.add(this.transport.extensionMessageProvider); // NOTE/REVIEW: see note in mux-message-provider
3222
+ //
3223
+ // We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
3224
+ // send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
3225
+ // the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
3226
+ //
3227
+ // this.transport.messageProvider.add(this.transport.extensionMessageProvider)
3196
3228
  }
3197
3229
 
3198
3230
  this.transport.messageProvider.register(); // .....
@@ -78,22 +78,22 @@ export declare enum EventType {
78
78
  DEBUG = "_debug"
79
79
  }
80
80
  export interface WalletEventTypes {
81
- 'open': (openInfo: {
81
+ open: (openInfo: {
82
82
  chainId?: string;
83
83
  sessionId?: string;
84
84
  session?: WalletSession;
85
85
  error?: string;
86
86
  }) => void;
87
- 'close': (error?: ProviderRpcError) => void;
88
- 'connect': (connectDetails: ConnectDetails) => void;
89
- 'disconnect': (error?: ProviderRpcError) => void;
90
- 'accountsChanged': (accounts: string[]) => void;
91
- 'chainChanged': (chainIdHex: string) => void;
92
- 'networks': (networks: NetworkConfig[]) => void;
93
- 'walletContext': (walletContext: WalletContext) => void;
87
+ close: (error?: ProviderRpcError) => void;
88
+ connect: (connectDetails: ConnectDetails) => void;
89
+ disconnect: (error?: ProviderRpcError) => void;
90
+ accountsChanged: (accounts: string[]) => void;
91
+ chainChanged: (chainIdHex: string) => void;
92
+ networks: (networks: NetworkConfig[]) => void;
93
+ walletContext: (walletContext: WalletContext) => void;
94
94
  }
95
95
  export interface ProviderEventTypes extends WalletEventTypes {
96
- 'message': (message: ProviderMessageResponse) => void;
96
+ message: (message: ProviderMessageResponse) => void;
97
97
  }
98
98
  export declare enum OpenState {
99
99
  CLOSED = 0,
@@ -106,15 +106,60 @@ export declare enum InitState {
106
106
  OK = 2
107
107
  }
108
108
  export interface ConnectOptions {
109
+ /** Specifies the default network a dapp would like to connect to. This field
110
+ * is optional as it can be provided a number of different ways. */
109
111
  networkId?: string | number;
112
+ /** app name of the dapp which will be announced to user on connect screen */
110
113
  app?: string;
114
+ /** origin hint of the dapp's host opening the wallet. This value will automatically
115
+ * be determined and verified for integrity, and can be omitted. */
111
116
  origin?: string;
117
+ /** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
112
118
  expiry?: number;
119
+ /** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
113
120
  authorize?: boolean;
121
+ /** *Currently not used* askForEmail will prompt to give permission to the dapp to access email address */
114
122
  askForEmail?: boolean;
123
+ /** refresh flag will force a full re-connect (ie. disconnect then connect again) */
115
124
  refresh?: boolean;
125
+ /** keepWalletOpened will keep the wallet window opened after connecting. The default
126
+ * is to automatically close the wallet after connecting. */
116
127
  keepWalletOpened?: boolean;
117
- }
128
+ /** Options to further customize the wallet experience. */
129
+ settings?: Settings;
130
+ }
131
+ /** Options to further customize the wallet experience. */
132
+ export interface Settings {
133
+ /** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
134
+ * themes, you can use the camel case version of the theme names in the wallet settings.
135
+ * For example: "Blue Dark" on wallet UI can be passed as "blueDark".
136
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
137
+ * to set when you open the wallet for user. */
138
+ theme?: ThemeOption;
139
+ /** Specify payment providers to use. If not specified,
140
+ * all available payment providers will be enabled.
141
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
142
+ * to set when you open the wallet for user. */
143
+ includedPaymentProviders?: PaymentProviderOption[];
144
+ /** Specify a default currency to use with payment providers.
145
+ * If not specified, the default is USDC.
146
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
147
+ * to set when you open the wallet for user. */
148
+ defaultFundingCurrency?: CurrencyOption;
149
+ /** If true, lockFundingCurrencyToDefault disables picking any currency provided by payment
150
+ * providers other than the defaultFundingCurrency.
151
+ * If false, it allows picking any currency provided by payment providers.
152
+ * The default is true.
153
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
154
+ * to set when you open the wallet for user. */
155
+ lockFundingCurrencyToDefault?: boolean;
156
+ }
157
+ /** light and dark are the main themes, to use other themes in wallet settings,
158
+ * you can use the camel case version of the name in the wallet settings.
159
+ * For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
160
+ export declare type ThemeOption = 'light' | 'dark' | string;
161
+ export declare type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp';
162
+ export declare type CurrencyOption = 'usdc' | 'eth' | 'matic';
118
163
  export interface ConnectDetails {
119
164
  chainId?: string;
120
165
  error?: string;
@@ -127,6 +172,9 @@ export declare type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'err
127
172
  export declare type OpenWalletIntent = {
128
173
  type: 'connect';
129
174
  options?: ConnectOptions;
175
+ } | {
176
+ type: 'openWithOptions';
177
+ options?: ConnectOptions;
130
178
  } | {
131
179
  type: 'jsonRpcRequest';
132
180
  method: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/provider",
3
- "version": "0.36.5",
3
+ "version": "0.36.8",
4
4
  "description": "provider sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/provider",
6
6
  "source": "src/index.ts",
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@0xsequence/abi": "^0.36.5",
17
- "@0xsequence/auth": "^0.36.5",
18
- "@0xsequence/config": "^0.36.5",
19
- "@0xsequence/network": "^0.36.5",
20
- "@0xsequence/transactions": "^0.36.5",
21
- "@0xsequence/utils": "^0.36.5",
22
- "@0xsequence/wallet": "^0.36.5",
16
+ "@0xsequence/abi": "^0.36.8",
17
+ "@0xsequence/auth": "^0.36.8",
18
+ "@0xsequence/config": "^0.36.8",
19
+ "@0xsequence/network": "^0.36.8",
20
+ "@0xsequence/transactions": "^0.36.8",
21
+ "@0xsequence/utils": "^0.36.8",
22
+ "@0xsequence/wallet": "^0.36.8",
23
23
  "@ethersproject/abstract-signer": "^5.5.0",
24
24
  "@ethersproject/hash": "^5.5.0",
25
25
  "@ethersproject/providers": "^5.5.1",
@@ -26,6 +26,10 @@ export class MuxMessageProvider implements ProviderTransport {
26
26
  return
27
27
  }
28
28
 
29
+ // REVIEW/NOTE: ........ this method does not work for the chrome-extension. The issue becomes
30
+ // when the browser quits or restarts, the "open" event is never triggered. Perhaps the code here is fine,
31
+ // or maybe its not. What should happen is when a dapp makes a request, it will call openWallet
32
+ // below, in which case one of the events will register. So perhaps this is fine.
29
33
  this.messageProviders.forEach(m => {
30
34
  m.register()
31
35
 
@@ -488,6 +488,23 @@ export class WalletRequestHandler implements ExternalProvider, JsonRpcHandler, P
488
488
  break
489
489
  }
490
490
 
491
+ case 'wallet_switchEthereumChain': {
492
+ const [switchParams] = request.params!
493
+ if (!switchParams.chainId || switchParams.chainId.length === 0) {
494
+ throw new Error('invalid chainId')
495
+ }
496
+
497
+ const chainId = ethers.BigNumber.from(switchParams.chainId)
498
+
499
+ const ok = await this.setDefaultNetwork(chainId.toString(), true)
500
+ if (!ok) {
501
+ throw new Error(`unable to set chainId ${chainId}`)
502
+ }
503
+
504
+ response.result = null // success
505
+ break
506
+ }
507
+
491
508
  // smart wallet method
492
509
  case 'sequence_getWalletContext': {
493
510
  response.result = await signer.getWalletContext()
@@ -82,7 +82,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
82
82
  this._init = InitState.NIL
83
83
  this._sessionId = `${performance.now()}`
84
84
  windowSessionParams.set('sid', this._sessionId)
85
-
85
+
86
86
  if (intent) {
87
87
  // for the window-transport, we eagerly/optimistically set the origin host
88
88
  // when connecting to the wallet, however, this will be verified and enforced
@@ -96,7 +96,7 @@ export class WindowMessageProvider extends BaseProviderTransport {
96
96
  intent.options.origin = window.location.origin
97
97
  }
98
98
  }
99
- // encode intent as base6 url-encoded param
99
+ // encode intent as base64 url-encoded param
100
100
  windowSessionParams.set('intent', base64EncodeObject(intent))
101
101
  }
102
102
  if (networkId) {
@@ -109,16 +109,13 @@ export class WindowMessageProvider extends BaseProviderTransport {
109
109
 
110
110
  if (isBrowserExtension()) {
111
111
  windowSize = [450, 750]
112
- windowPos = [
113
- Math.abs(window.screen.width / 2 - windowSize[0] / 2),
114
- Math.abs(window.screen.height / 2 - windowSize[1] / 2)
115
- ]
112
+ windowPos = [Math.abs(window.screen.width / 2 - windowSize[0] / 2), Math.abs(window.screen.height / 2 - windowSize[1] / 2)]
116
113
  } else {
117
114
  windowSize = [450, 750]
118
115
  windowPos = [
119
116
  Math.abs(window.screenX + window.innerWidth / 2 - windowSize[0] / 2),
120
117
  Math.abs(window.screenY + window.innerHeight / 2 - windowSize[1] / 2)
121
- ]
118
+ ]
122
119
  }
123
120
 
124
121
  const windowFeatures =
package/src/types.ts CHANGED
@@ -23,7 +23,7 @@ export interface WalletTransport extends JsonRpcHandler, ProviderMessageTranspor
23
23
  register(): void
24
24
  unregister(): void
25
25
 
26
- notifyOpen(openInfo: { chainId?: string, sessionId?: string, session?: WalletSession, error?: string }): void
26
+ notifyOpen(openInfo: { chainId?: string; sessionId?: string; session?: WalletSession; error?: string }): void
27
27
  notifyClose(error?: ProviderRpcError): void
28
28
 
29
29
  notifyConnect(connectDetails: ConnectDetails): void
@@ -33,10 +33,10 @@ export interface WalletTransport extends JsonRpcHandler, ProviderMessageTranspor
33
33
  }
34
34
 
35
35
  export interface ProviderMessage<T> {
36
- idx: number // message id number
37
- type: string // message type
38
- data: T // the ethereum json-rpc payload
39
- chainId?: number // chain id which the message is intended
36
+ idx: number // message id number
37
+ type: string // message type
38
+ data: T // the ethereum json-rpc payload
39
+ chainId?: number // chain id which the message is intended
40
40
  }
41
41
 
42
42
  export type ProviderMessageRequest = ProviderMessage<JsonRpcRequest>
@@ -83,8 +83,8 @@ export class WindowSessionParams extends URLSearchParams {
83
83
 
84
84
  export interface TransportSession {
85
85
  sessionId?: string | null
86
- networkId?: string | number | null,
87
- intent?: OpenWalletIntent,
86
+ networkId?: string | number | null
87
+ intent?: OpenWalletIntent
88
88
  }
89
89
 
90
90
  export enum EventType {
@@ -105,21 +105,21 @@ export enum EventType {
105
105
  }
106
106
 
107
107
  export interface WalletEventTypes {
108
- 'open': (openInfo: { chainId?: string, sessionId?: string, session?: WalletSession, error?: string }) => void
109
- 'close': (error?: ProviderRpcError) => void
108
+ open: (openInfo: { chainId?: string; sessionId?: string; session?: WalletSession; error?: string }) => void
109
+ close: (error?: ProviderRpcError) => void
110
110
 
111
- 'connect': (connectDetails: ConnectDetails) => void
112
- 'disconnect': (error?: ProviderRpcError) => void
111
+ connect: (connectDetails: ConnectDetails) => void
112
+ disconnect: (error?: ProviderRpcError) => void
113
113
 
114
- 'accountsChanged': (accounts: string[]) => void
115
- 'chainChanged': (chainIdHex: string) => void
114
+ accountsChanged: (accounts: string[]) => void
115
+ chainChanged: (chainIdHex: string) => void
116
116
 
117
- 'networks': (networks: NetworkConfig[]) => void
118
- 'walletContext': (walletContext: WalletContext) => void
117
+ networks: (networks: NetworkConfig[]) => void
118
+ walletContext: (walletContext: WalletContext) => void
119
119
  }
120
120
 
121
121
  export interface ProviderEventTypes extends WalletEventTypes {
122
- 'message': (message: ProviderMessageResponse) => void
122
+ message: (message: ProviderMessageResponse) => void
123
123
  }
124
124
 
125
125
  export enum OpenState {
@@ -135,35 +135,75 @@ export enum InitState {
135
135
  }
136
136
 
137
137
  export interface ConnectOptions {
138
- // networkId specifics the default network a dapp would like to connect to. This field
139
- // is optional as it can be provided a number of different ways.
138
+ /** Specifies the default network a dapp would like to connect to. This field
139
+ * is optional as it can be provided a number of different ways. */
140
140
  networkId?: string | number
141
141
 
142
- // app name of the dapp which will be announced to user on connect screen
142
+ /** app name of the dapp which will be announced to user on connect screen */
143
143
  app?: string
144
144
 
145
- // origin hint of the dapp's host opening the wallet. This value will automatically
146
- // be determined and verified for integrity, and can be omitted.
145
+ /** origin hint of the dapp's host opening the wallet. This value will automatically
146
+ * be determined and verified for integrity, and can be omitted. */
147
147
  origin?: string
148
148
 
149
- // expiry number (in seconds) to expire connect session. default is 1 week of seconds.
149
+ /** expiry number (in seconds) to expire connect session. default is 1 week of seconds. */
150
150
  expiry?: number
151
151
 
152
- // authorize will perform an ETHAuth eip712 signing and return the proof to the dapp.
152
+ /** authorize will perform an ETHAuth eip712 signing and return the proof to the dapp. */
153
153
  authorize?: boolean
154
154
 
155
- // askForEmail will prompt to give permission to the dapp to access email address
155
+ /** *Currently not used* askForEmail will prompt to give permission to the dapp to access email address */
156
156
  // TODO: this feature is currently not used as the wallet does not report emails yet
157
157
  askForEmail?: boolean
158
158
 
159
- // refresh flag will force a full re-connect (ie. disconnect then connect again)
159
+ /** refresh flag will force a full re-connect (ie. disconnect then connect again) */
160
160
  refresh?: boolean
161
161
 
162
- // keepWalletOpened will keep the wallet window opened after connecting. The default
163
- // is to automatically close the wallet after connecting.
162
+ /** keepWalletOpened will keep the wallet window opened after connecting. The default
163
+ * is to automatically close the wallet after connecting. */
164
164
  keepWalletOpened?: boolean
165
+
166
+ /** Options to further customize the wallet experience. */
167
+ settings?: Settings
168
+ }
169
+
170
+ /** Options to further customize the wallet experience. */
171
+ export interface Settings {
172
+ /** Specify a wallet theme. `light` and `dark` are the main themes, to use other available
173
+ * themes, you can use the camel case version of the theme names in the wallet settings.
174
+ * For example: "Blue Dark" on wallet UI can be passed as "blueDark".
175
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
176
+ * to set when you open the wallet for user. */
177
+ theme?: ThemeOption
178
+
179
+ /** Specify payment providers to use. If not specified,
180
+ * all available payment providers will be enabled.
181
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
182
+ * to set when you open the wallet for user. */
183
+ includedPaymentProviders?: PaymentProviderOption[]
184
+
185
+ /** Specify a default currency to use with payment providers.
186
+ * If not specified, the default is USDC.
187
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
188
+ * to set when you open the wallet for user. */
189
+ defaultFundingCurrency?: CurrencyOption
190
+
191
+ /** If true, lockFundingCurrencyToDefault disables picking any currency provided by payment
192
+ * providers other than the defaultFundingCurrency.
193
+ * If false, it allows picking any currency provided by payment providers.
194
+ * The default is true.
195
+ * Note that this setting will not be persisted, use wallet.open with 'openWithOptions' intent
196
+ * to set when you open the wallet for user. */
197
+ lockFundingCurrencyToDefault?: boolean
165
198
  }
166
199
 
200
+ /** light and dark are the main themes, to use other themes in wallet settings,
201
+ * you can use the camel case version of the name in the wallet settings.
202
+ * For example: "Blue Dark" on wallet UI can be passed as "blueDark" */
203
+ export type ThemeOption = 'light' | 'dark' | string
204
+ export type PaymentProviderOption = 'moonpay' | 'wyre' | 'ramp'
205
+ export type CurrencyOption = 'usdc' | 'eth' | 'matic'
206
+
167
207
  export interface ConnectDetails {
168
208
  // chainId (in hex) and error are defined by EIP-1193 expected fields
169
209
  chainId?: string
@@ -187,8 +227,9 @@ export interface ConnectDetails {
187
227
  export type PromptConnectDetails = Pick<ConnectDetails, 'chainId' | 'error' | 'connected' | 'proof' | 'email'>
188
228
 
189
229
  export type OpenWalletIntent =
190
- { type: 'connect'; options?: ConnectOptions } |
191
- { type: 'jsonRpcRequest'; method: string }
230
+ | { type: 'connect'; options?: ConnectOptions }
231
+ | { type: 'openWithOptions'; options?: ConnectOptions }
232
+ | { type: 'jsonRpcRequest'; method: string }
192
233
 
193
234
  export interface MessageToSign {
194
235
  message?: string
@@ -230,23 +271,21 @@ export const ErrSignedInRequired = new ProviderError('Wallet is not signed in. C
230
271
 
231
272
  // TODO: lets build some nice error handling tools, prob in /utils ...
232
273
 
233
- export interface TypedEventEmitter<Events>{
234
- addListener<E extends keyof Events> (event: E, listener: Events[E]): this
235
- on<E extends keyof Events> (event: E, listener: Events[E]): this
236
- once<E extends keyof Events> (event: E, listener: Events[E]): this
237
- prependListener<E extends keyof Events> (event: E, listener: Events[E]): this
238
- prependOnceListener<E extends keyof Events> (event: E, listener: Events[E]): this
274
+ export interface TypedEventEmitter<Events> {
275
+ addListener<E extends keyof Events>(event: E, listener: Events[E]): this
276
+ on<E extends keyof Events>(event: E, listener: Events[E]): this
277
+ once<E extends keyof Events>(event: E, listener: Events[E]): this
278
+ prependListener<E extends keyof Events>(event: E, listener: Events[E]): this
279
+ prependOnceListener<E extends keyof Events>(event: E, listener: Events[E]): this
239
280
 
240
281
  off<E extends keyof Events>(event: E, listener: Events[E]): this
241
- removeAllListeners<E extends keyof Events> (event?: E): this
242
- removeListener<E extends keyof Events> (event: E, listener: Events[E]): this
282
+ removeAllListeners<E extends keyof Events>(event?: E): this
283
+ removeListener<E extends keyof Events>(event: E, listener: Events[E]): this
243
284
 
244
- emit<E extends keyof Events> (event: E, ...args: Arguments<Events[E]>): boolean
245
- eventNames (): (keyof Events | string | symbol)[]
246
- listeners<E extends keyof Events> (event: E): Function[]
247
- listenerCount<E extends keyof Events> (event: E): number
285
+ emit<E extends keyof Events>(event: E, ...args: Arguments<Events[E]>): boolean
286
+ eventNames(): (keyof Events | string | symbol)[]
287
+ listeners<E extends keyof Events>(event: E): Function[]
288
+ listenerCount<E extends keyof Events>(event: E): number
248
289
  }
249
290
 
250
- type Arguments<T> = [T] extends [(...args: infer U) => any]
251
- ? U
252
- : [T] extends [void] ? [] : [T]
291
+ type Arguments<T> = [T] extends [(...args: infer U) => any] ? U : [T] extends [void] ? [] : [T]
package/src/wallet.ts CHANGED
@@ -141,7 +141,16 @@ export class Wallet implements WalletProvider {
141
141
  }
142
142
  if (this.config.transports?.extensionTransport?.enabled) {
143
143
  this.transport.extensionMessageProvider = new ExtensionMessageProvider(this.config.transports.extensionTransport.runtime)
144
+ // this.transport.extensionMessageProvider.register()
144
145
  this.transport.messageProvider.add(this.transport.extensionMessageProvider)
146
+
147
+ // NOTE/REVIEW: see note in mux-message-provider
148
+ //
149
+ // We don't add the extensionMessageProvider here because we don't send requests to it anyways, we seem to
150
+ // send all requests to the WindowMessageProvider anyways. By allowing it, if browser restarts, it will break
151
+ // the entire extension because messageProvider.provider will be undefined. So this is a hack to fix it.
152
+ //
153
+ // this.transport.messageProvider.add(this.transport.extensionMessageProvider)
145
154
  }
146
155
  this.transport.messageProvider.register()
147
156