Skip to content

Commit

Permalink
Merge pull request #502 from iuriiiurevich/fix/qrscanner-capture
Browse files Browse the repository at this point in the history
fix qr scanner capture logic
  • Loading branch information
heyqbnk authored Oct 16, 2024
2 parents bf29b38 + 521a23e commit 9d10de8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/small-gifts-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@telegram-apps/sdk": patch
---

Fix qr scanner capture logic
13 changes: 13 additions & 0 deletions packages/sdk/src/scopes/components/qr-scanner/qr-scanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 9d10de8

Please sign in to comment.