Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/connect-evm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix duplicate `onNotification` listener ([#81](https://github.com/MetaMask/connect-monorepo/pull/81))
- Fixed `addEthereumChain` not being prompted on mobile native browsers after a switch chain failure ([#79](https://github.com/MetaMask/connect-monorepo/pull/79))

## [0.1.1]
Expand Down
5 changes: 5 additions & 0 deletions packages/connect-evm/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,11 @@ export class MetamaskConnectEVM {

this.#core.off('wallet_sessionChanged', this.#sessionChangedHandler);

if (this.#removeNotificationHandler) {
this.#removeNotificationHandler();
this.#removeNotificationHandler = undefined;
}

logger('fulfilled-request: disconnect');
}

Expand Down
1 change: 1 addition & 0 deletions packages/connect-multichain/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fix potential listener leak on `MultichainCore.deeplinkConnect` and duplicate `dappClient.on('message')` on `MWPTransport` ([#81](https://github.com/MetaMask/connect-monorepo/pull/81))
- Reverted: Fix mobile deeplink bug that occurred when `MultichainSDK.connect()` was called and the transport was already connected ([#74](https://github.com/MetaMask/connect-monorepo/pull/74))
- Fix rejections of the initial permission approval for deeplink connections not correctly updating the connection status to disconnected ([#75](https://github.com/MetaMask/connect-monorepo/pull/75))

Expand Down
1 change: 1 addition & 0 deletions packages/connect-multichain/src/multichain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export class MultichainSDK extends MultichainCore {
.then(resolve)
.catch(async (error) => {
await this.storage.removeTransport();
this.dappClient.off('message', dappClientMessageHandler);
reject(error instanceof Error ? error : new Error(String(error)));
})
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ export class MWPTransport implements ExtendedTransport {
}

let timeout: NodeJS.Timeout;
let initialConnectionMessageHandler:
| ((message: unknown) => Promise<void>)
| undefined;
const connectionPromise = new Promise<void>((resolve, reject) => {
let connection: Promise<void>;
if (session) {
Expand Down Expand Up @@ -358,7 +361,9 @@ export class MWPTransport implements ExtendedTransport {
};

// just used for initial connection
this.dappClient.on('message', async (message: unknown) => {
initialConnectionMessageHandler = async (
message: unknown,
): Promise<void> => {
if (typeof message === 'object' && message !== null) {
if ('data' in message) {
const messagePayload = message.data as Record<
Expand All @@ -370,6 +375,12 @@ export class MWPTransport implements ExtendedTransport {
messagePayload.method === 'wallet_sessionChanged'
) {
if (messagePayload.error) {
if (initialConnectionMessageHandler) {
this.dappClient.off(
'message',
initialConnectionMessageHandler,
);
}
return rejectConnection(messagePayload.error);
}
await this.storeWalletSession(
Expand All @@ -381,7 +392,9 @@ export class MWPTransport implements ExtendedTransport {
}
}
}
});
};

this.dappClient.on('message', initialConnectionMessageHandler);

dappClient
.connect({
Expand All @@ -391,23 +404,42 @@ export class MWPTransport implements ExtendedTransport {
data: request,
},
})
.catch(rejectConnection);
.catch((error) => {
if (initialConnectionMessageHandler) {
this.dappClient.off(
'message',
initialConnectionMessageHandler,
);
}
rejectConnection(error);
});
},
);
}

timeout = setTimeout(() => {
if (initialConnectionMessageHandler) {
this.dappClient.off('message', initialConnectionMessageHandler);
}
reject(new TransportTimeoutError());
}, this.options.connectionTimeout);

connection.then(resolve).catch(reject);
});

return connectionPromise.finally(() => {
if (timeout) {
clearTimeout(timeout);
}
});
return connectionPromise
.catch((error) => {
if (initialConnectionMessageHandler) {
this.dappClient.off('message', initialConnectionMessageHandler);
initialConnectionMessageHandler = undefined;
}
throw error;
})
.finally(() => {
if (timeout) {
clearTimeout(timeout);
}
});
}

/**
Expand Down Expand Up @@ -515,7 +547,7 @@ export class MWPTransport implements ExtendedTransport {
request: TransportRequest,
response: TransportResponse,
): Promise<void> {
if(response.error) {
if (response.error) {
return;
}
if (CACHED_METHOD_LIST.includes(request.method)) {
Expand Down
Loading