Skip to content

Commit 507bd39

Browse files
authored
fix: Fix empty sessionProperties causing initial connection request to fail (#138)
* do not call connect with empty object sessionProperties * ensure sessionProperties is not empty * changelog
1 parent 5ec3b0c commit 507bd39

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

packages/connect-evm/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Fix `ConnectEvm.connect()` not being able to establish an initial connection due to empty object `sessionProperties` ([#138](https://github.com/MetaMask/connect-monorepo/pull/138))
13+
1014
## [0.3.0]
1115

1216
### Added

packages/connect-evm/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export class MetamaskConnectEVM {
325325
await this.#core.connect(
326326
caipChainIds as Scope[],
327327
caipAccountIds as CaipAccountId[],
328-
{},
328+
undefined,
329329
forceRequest,
330330
);
331331

packages/connect-multichain/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- `ConnectMultichain.connect()` will send `sessionProperties` as undefined when called with an empty object `{}` in order to ensure that the initial `wallet_createSession` request does not fail immediately ([#138](https://github.com/MetaMask/connect-monorepo/pull/138))
13+
1014
## [0.5.1]
1115

1216
### Fixed

packages/connect-multichain/src/multichain/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,10 +708,13 @@ export class MetaMaskConnectMultichain extends MultichainCore {
708708
logger('Error tracking connection_initiated event', error);
709709
}
710710

711+
// Needed because empty object will cause wallet_createSession to return an error
712+
const nonEmptySessionProperites = Object.keys(sessionProperties ?? {}).length > 0 ? sessionProperties : undefined;
713+
711714
if (this.#transport?.isConnected() && !secure) {
712715
return this.#handleConnection(
713716
this.#transport
714-
.connect({ scopes, caipAccountIds, sessionProperties, forceRequest })
717+
.connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest })
715718
.then(async () => {
716719
if (this.#transport instanceof MWPTransport) {
717720
return this.storage.setTransport(TransportType.MWP);
@@ -727,7 +730,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
727730
if (platformType === PlatformType.MetaMaskMobileWebview) {
728731
const defaultTransport = await this.#setupDefaultTransport();
729732
return this.#handleConnection(
730-
defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }),
733+
defaultTransport.connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest }),
731734
scopes,
732735
transportType,
733736
);
@@ -738,7 +741,7 @@ export class MetaMaskConnectMultichain extends MultichainCore {
738741
const defaultTransport = await this.#setupDefaultTransport();
739742
// Web transport has no initial payload
740743
return this.#handleConnection(
741-
defaultTransport.connect({ scopes, caipAccountIds, sessionProperties, forceRequest }),
744+
defaultTransport.connect({ scopes, caipAccountIds, sessionProperties: nonEmptySessionProperites, forceRequest }),
742745
scopes,
743746
transportType,
744747
);
@@ -755,15 +758,15 @@ export class MetaMaskConnectMultichain extends MultichainCore {
755758
if (secure && !shouldShowInstallModal) {
756759
// Desktop is not preferred option, so we use deeplinks (mobile web)
757760
return this.#handleConnection(
758-
this.#deeplinkConnect(scopes, caipAccountIds, sessionProperties),
761+
this.#deeplinkConnect(scopes, caipAccountIds, nonEmptySessionProperites),
759762
scopes,
760763
transportType,
761764
);
762765
}
763766

764767
// Show install modal for RN, Web + Node
765768
return this.#handleConnection(
766-
this.#showInstallModal(shouldShowInstallModal, scopes, caipAccountIds, sessionProperties),
769+
this.#showInstallModal(shouldShowInstallModal, scopes, caipAccountIds, nonEmptySessionProperites),
767770
scopes,
768771
transportType,
769772
);

0 commit comments

Comments
 (0)