Skip to content
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- ## [[3.2.7](https://github.com/multiversx/mx-sdk-js-webview-provider/pull/46)] - 2026-02-06
- [Fix webview handshake issue](https://github.com/multiversx/mx-sdk-js-webview-provider/pull/46)

- ## [[3.2.6](https://github.com/multiversx/mx-sdk-js-webview-provider/pull/45)] - 2025-11-24
- [Update sdk-core imports](https://github.com/multiversx/mx-sdk-js-webview-provider/pull/44)

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-webview-provider",
"version": "3.2.6",
"version": "3.2.7",
"description": "SDK Webview Provider",
"main": "out/index.js",
"types": "out/index.d.js",
Expand All @@ -10,7 +10,8 @@
"scripts": {
"compile": "tsc -p tsconfig.json",
"pretest": "npm run compile",
"prepare": "npm run compile"
"prepare": "npm run compile",
"publish-verdaccio": "npm run compile && npm publish --registry http://localhost:4873/"
},
"author": "MultiversX",
"license": "MIT",
Expand Down
19 changes: 10 additions & 9 deletions src/WebviewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export class WebviewProvider {
private account: IProviderAccount = { address: '' };
private handshakeResponseTimeout: number = HANDSHAKE_RESPONSE_TIMEOUT;
private allowedOrigin = '*';
private resetStateCallback?: () => void;

static getInstance(options?: IWebviewProviderOptions) {
if (!WebviewProvider._instance) {
Expand All @@ -45,23 +46,19 @@ export class WebviewProvider {
}

constructor(options?: IWebviewProviderOptions) {
if (options?.resetStateCallback) {
this.resetState(options.resetStateCallback);
}
this.resetStateCallback = options?.resetStateCallback;
}

private resetState = (resetStateCallback?: () => void) => {
private setupResetStateListener = () => {
getSafeWindow().addEventListener?.(
'message',
webviewProviderEventHandler(
WindowProviderResponseEnums.resetStateResponse,
(data) => {
if (data.type === WindowProviderResponseEnums.resetStateResponse) {
resetStateCallback?.();

setTimeout(() => {
this.finalizeResetState();
}, 500);
this.finalizeResetState();
this.resetStateCallback?.();
this.initialized = false;
}
},
this.allowedOrigin
Expand Down Expand Up @@ -146,6 +143,10 @@ export class WebviewProvider {

if (type === WindowProviderResponseEnums.finalizeHandshakeResponse) {
this.initialized = true;

if (this.resetStateCallback) {
this.setupResetStateListener();
}
}
} catch {
// No handshake response received
Expand Down