Skip to content

Commit

Permalink
Merge pull request #57 from multiversx/development
Browse files Browse the repository at this point in the history
v0.4.1
  • Loading branch information
CiprianDraghici authored Aug 12, 2024
2 parents 897c200 + d98d5aa commit 34aea43
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [Update README](https://github.com/multiversx/mx-sdk-js-web-wallet-cross-window-provider/pull/55)


## [[0.4.1](https://github.com/multiversx/mx-sdk-js-web-wallet-cross-window-provider/pull/57)] - 2024-08-12
- [Fix SSR support](https://github.com/multiversx/mx-sdk-js-web-wallet-cross-window-provider/pull/56)

## [[0.4.0](https://github.com/multiversx/mx-sdk-js-web-wallet-cross-window-provider/pull/54)] - 2024-08-07
- [Remove IFrame Provider](https://github.com/multiversx/mx-sdk-js-web-wallet-cross-window-provider/pull/53)

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@multiversx/sdk-web-wallet-cross-window-provider",
"version": "0.4.0",
"version": "0.4.1",
"description": "Signing provider for dApps: Cross Window",
"main": "out/index.js",
"types": "out/index.d.js",
Expand Down
30 changes: 19 additions & 11 deletions src/CrossWindowProvider/CrossWindowProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
ErrTransactionCancelled
} from '../errors';
import { WindowManager } from '../WindowManager';
import { PopupConsent } from './PopupConsent';
import { confirmationDialogTag } from './PopupConsent/constants';
import { PopupConsentModel } from './PopupConsent/PopupConsent.model';

export interface ICrossWindowWalletAccount {
address: string;
Expand Down Expand Up @@ -298,31 +298,39 @@ export class CrossWindowProvider {
}

public async openPopupConsent(): Promise<boolean> {
await import('./PopupConsent/PopupConsent');
const dialog = safeWindow.document?.createElement('div');
const document = safeWindow.document;

if (!this._shouldShowConsentPopup || !document || !dialog) {
if (
!this._shouldShowConsentPopup ||
typeof document === 'undefined' ||
typeof window === 'undefined'
) {
return true;
}

const popup = safeWindow.document?.createElement(
const module = await import('./PopupConsent/PopupConsent');
const PopupConsent = module.PopupConsent;

const customElements = safeWindow.customElements;
if (customElements && !customElements.get(confirmationDialogTag)) {
customElements.define(confirmationDialogTag, PopupConsent);
}

const popup = document.createElement(
confirmationDialogTag
) as PopupConsent;
) as PopupConsentModel & HTMLElement;

popup.walletUrl = this.windowManager.walletUrl;

safeWindow.document?.body.appendChild(popup);
document.body.appendChild(popup);

const popupConsentResponse: boolean = await new Promise<boolean>(
(resolve) => {
popup.onConfirm = () => {
resolve(true);
safeWindow.document?.body.removeChild(popup);
document.body.removeChild(popup);
};
popup.onCancel = () => {
resolve(false);
safeWindow.document?.body.removeChild(popup);
document.body.removeChild(popup);
};
}
);
Expand Down
22 changes: 22 additions & 0 deletions src/CrossWindowProvider/PopupConsent/PopupConsent.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export interface PopupConsentModel {
walletUrl: string;
identifier: string;
events: {
confirm: string;
cancel: string;
mounted: string;
};

onCancel: () => void;
onConfirm: () => void;

attributeChangedCallback(
name: string,
oldValue: string,
newValue: string
): void;
render(): void;
toggleEvents(action: 'removeEventListener' | 'addEventListener'): void;
connectedCallback(): void;
disconnectedCallback(): void;
}
11 changes: 3 additions & 8 deletions src/CrossWindowProvider/PopupConsent/PopupConsent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { safeWindow } from '../../constants';
import { confirmationDialogTag } from './constants';
import { getStyles } from './getStyles';
import { PopupConsentModel } from './PopupConsent.model';

export class PopupConsent extends HTMLElement {
export class PopupConsent extends HTMLElement implements PopupConsentModel {
public walletUrl = '';
public identifier: string = confirmationDialogTag;
public onCancel = () => {
Expand Down Expand Up @@ -97,9 +97,4 @@ export class PopupConsent extends HTMLElement {
disconnectedCallback() {
this.toggleEvents('removeEventListener');
}
}

const customElements = safeWindow.customElements;
if (customElements && !customElements.get(confirmationDialogTag)) {
customElements.define(confirmationDialogTag, PopupConsent);
}
}
2 changes: 1 addition & 1 deletion src/WindowManager/WindowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class WindowManager {
}

async init(): Promise<boolean> {
this.initialized = true;
this.initialized = typeof window !== 'undefined';
return this.initialized;
}

Expand Down

0 comments on commit 34aea43

Please sign in to comment.