From a6bb3bbda000bf6c8184e29583aa35669cb7b808 Mon Sep 17 00:00:00 2001 From: Yury Demin Date: Wed, 16 Oct 2024 04:32:40 +0300 Subject: [PATCH 1/3] fix qr scanner capture logic --- packages/sdk/src/scopes/components/qr-scanner/qr-scanner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.ts b/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.ts index 8168365df..4bfbd5f63 100644 --- a/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.ts +++ b/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.ts @@ -103,7 +103,7 @@ export function open(options?: OpenSharedOptions & { on(SCANNED_EVENT, (event) => { if (onCaptured) { onCaptured(event.data); - } else if (capture && capture(event.data)) { + } else if (!capture || capture(event.data)) { promise.resolve(event.data); close(); } From 68344bc0ec30bbdc54b7cfd80964b4a2e1e75e57 Mon Sep 17 00:00:00 2001 From: Yury Demin Date: Wed, 16 Oct 2024 17:26:50 +0300 Subject: [PATCH 2/3] add test --- .../scopes/components/qr-scanner/qr-scanner.test.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.test.ts b/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.test.ts index 203f51d41..501bd737f 100644 --- a/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.test.ts +++ b/packages/sdk/src/scopes/components/qr-scanner/qr-scanner.test.ts @@ -75,6 +75,19 @@ describe('open', () => { expect(spy).toHaveBeenCalledWith('web_app_close_scan_qr_popup', undefined); }); + it('should call "web_app_close_scan_qr_popup" if QR was scanned', async () => { + const spy = mockPostEvent(); + const promise = open(); + spy.mockClear(); + dispatchMiniAppsEvent("qr_text_received", { data: "QR1" }); + await promise; + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith( + "web_app_close_scan_qr_popup", + undefined + ); + }); + it('should return promise with undefined if "scan_qr_popup_closed" event was received', async () => { const promise = open({ capture() { From 521a23ed0d978a24ebd4eef8901ddb48108e0dc5 Mon Sep 17 00:00:00 2001 From: Vladislav Kibenko <34907325+heyqbnk@users.noreply.github.com> Date: Thu, 17 Oct 2024 01:19:33 +0500 Subject: [PATCH 3/3] Create small-gifts-know.md --- .changeset/small-gifts-know.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/small-gifts-know.md diff --git a/.changeset/small-gifts-know.md b/.changeset/small-gifts-know.md new file mode 100644 index 000000000..696226243 --- /dev/null +++ b/.changeset/small-gifts-know.md @@ -0,0 +1,5 @@ +--- +"@telegram-apps/sdk": patch +--- + +Fix qr scanner capture logic