Skip to content

Commit c45f08f

Browse files
authored
Merge pull request #863 from Telegram-Mini-Apps/bugix/is-tma-problem
Bugix/is tma problem
2 parents 7f5c306 + ca81d1b commit c45f08f

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

.changeset/yellow-adults-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@tma.js/bridge": patch
3+
---
4+
5+
Rework the `hasWebviewProxy` function considering that the passed value is more likely to be window object

packages/bridge/src/env/hasWebviewProxy.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ it('should return true if passed object contains path property "TelegramWebviewP
77
expect(hasWebviewProxy({ TelegramWebviewProxy: {} })).toBe(false);
88
expect(hasWebviewProxy({ TelegramWebviewProxy: { postEvent: [] } })).toBe(false);
99
expect(hasWebviewProxy({
10+
a: 'b',
1011
TelegramWebviewProxy: {
1112
postEvent: () => {
1213
},
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { looseObject, function as fn, is } from 'valibot';
1+
import * as v from 'valibot';
22

33
/**
44
* Returns true in case, passed value contains path `TelegramWebviewProxy.postEvent` property and
@@ -10,8 +10,8 @@ export function hasWebviewProxy<T>(value: T): value is T & {
1010
postEvent: (...args: unknown[]) => unknown;
1111
};
1212
} {
13-
return is(
14-
looseObject({ TelegramWebviewProxy: looseObject({ postEvent: fn() }) }),
15-
value,
13+
return typeof value === 'object' && !!value && !Array.isArray(value) && v.is(
14+
v.looseObject({ TelegramWebviewProxy: v.looseObject({ postEvent: v.function() }) }),
15+
{ TelegramWebviewProxy: (value as Record<string, unknown>).TelegramWebviewProxy },
1616
);
1717
}

0 commit comments

Comments
 (0)