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 packages/sdk-multichain/src/multichain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ export class MultichainSDK extends MultichainCore {
this.options.ui.factory.renderInstallModal(
desktopPreferred,
async () => {
if (this.dappClient.state === 'CONNECTED' || this.dappClient.state === 'CONNECTING') {
await this.dappClient.disconnect();
}
return new Promise<ConnectionRequest>((resolveConnectionRequest) => {
this.dappClient.on('session_request', (sessionRequest: SessionRequest) => {
resolveConnectionRequest({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export class MWPTransport implements ExtendedTransport {
private __pendingRequests = new Map<string, PendingRequests>();
private notificationCallbacks = new Set<(data: unknown) => void>();
private currentSessionRequest: SessionRequest | undefined;
private connectionPromise?: Promise<void>;

get pendingRequests() {
return this.__pendingRequests;
Expand Down Expand Up @@ -139,7 +138,7 @@ export class MWPTransport implements ExtendedTransport {
} catch {}

let timeout: NodeJS.Timeout;
this.connectionPromise ??= new Promise<void>((resolve, reject) => {
const connectionPromise = new Promise<void>((resolve, reject) => {
let connection: Promise<void>;
if (session) {
connection = new Promise<void>((resumeResolve, resumeReject) => {
Expand Down Expand Up @@ -175,14 +174,15 @@ export class MWPTransport implements ExtendedTransport {
dappClient.connect({ mode: 'trusted', initialPayload: request }).catch(rejectConnection);
});
}

timeout = setTimeout(() => {
reject(new TransportTimeoutError());
}, this.options.connectionTimeout);

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

return this.connectionPromise.finally(() => {
this.connectionPromise = undefined;
return connectionPromise.finally(() => {
if (timeout) {
clearTimeout(timeout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export abstract class AbstractInstallModal extends Modal<InstallWidgetProps, QRL
}

if (now >= sessionRequest.expiresAt) {
this.stopExpirationCheck();
logger('[UI: InstallModal-nodejs()] ⏰ QR code EXPIRED! Generating new one...');
try {
// Generate new session request
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk-multichain/src/ui/modals/node/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export class InstallModal extends AbstractInstallModal {
console.log(`EXPIRES IN: ${formattedTime}`);
}
}

renderQRCode(link: QRLink, connectionRequest: ConnectionRequest): void {
const { sessionRequest } = connectionRequest;
const expiresIn = sessionRequest.expiresAt - Date.now();
const expiresInSeconds = Math.floor(expiresIn / 1000);
const shouldLog = shouldLogCountdown(expiresInSeconds);
const formattedTime = formatRemainingTime(expiresIn);
this.startExpirationCheck(connectionRequest);
Comment thread
elribonazo marked this conversation as resolved.

this.displayQRWithCountdown(link, expiresIn);

Expand All @@ -41,7 +43,6 @@ export class InstallModal extends AbstractInstallModal {
}
const { link, connectionRequest } = this;
this.renderQRCode(link, connectionRequest);
this.startExpirationCheck(connectionRequest);
}

unmount(): void {
Expand Down
Loading