@farcaster/frame-sdk 0.0.36 → 0.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sdk.js CHANGED
@@ -24,16 +24,51 @@ export function createEmitter() {
24
24
  };
25
25
  }
26
26
  const emitter = createEmitter();
27
+ let cachedIsInMiniAppResult = null;
28
+ /**
29
+ * Determines if the current environment is a MiniApp context.
30
+ *
31
+ * @param timeoutMs - Optional timeout in milliseconds (default: 50)
32
+ * @returns Promise resolving to boolean indicating if in MiniApp context
33
+ */
34
+ async function isInMiniApp(timeoutMs = 50) {
35
+ // Return cached result if we've already determined we are in a MiniApp
36
+ if (cachedIsInMiniAppResult === true) {
37
+ return true;
38
+ }
39
+ // Check for SSR environment - definitely not a MiniApp
40
+ if (typeof window === 'undefined') {
41
+ return false;
42
+ }
43
+ // Short-circuit: definitely NOT a MiniApp
44
+ if (!window.ReactNativeWebView && window === window.parent) {
45
+ return false;
46
+ }
47
+ // At this point, we MIGHT be in a MiniApp (iframe or RN WebView)
48
+ // but need to verify by checking for context communication.
49
+ const isInMiniApp = await Promise.race([
50
+ frameHost.context.then((context) => !!context), // Check if context resolves to truthy
51
+ new Promise((resolve) => {
52
+ setTimeout(() => resolve(false), timeoutMs); // Timeout resolves to false
53
+ }),
54
+ ]).catch(() => {
55
+ return false;
56
+ });
57
+ // Cache the result ONLY if true (we are confirmed to be in a MiniApp)
58
+ if (isInMiniApp) {
59
+ cachedIsInMiniAppResult = true;
60
+ }
61
+ return isInMiniApp;
62
+ }
27
63
  export const sdk = {
28
64
  ...emitter,
65
+ isInMiniApp,
29
66
  context: frameHost.context,
30
67
  actions: {
31
68
  setPrimaryButton: frameHost.setPrimaryButton.bind(frameHost),
32
69
  ready: frameHost.ready.bind(frameHost),
33
70
  close: frameHost.close.bind(frameHost),
34
71
  viewProfile: frameHost.viewProfile.bind(frameHost),
35
- viewToken: frameHost.viewToken.bind(frameHost),
36
- swap: frameHost.swap.bind(frameHost),
37
72
  signIn: async (options) => {
38
73
  const response = await frameHost.signIn(options);
39
74
  if (response.result) {
@@ -65,6 +100,11 @@ export const sdk = {
65
100
  return frameHost.composeCast(options);
66
101
  },
67
102
  },
103
+ experimental: {
104
+ viewToken: frameHost.viewToken.bind(frameHost),
105
+ sendToken: frameHost.sendToken.bind(frameHost),
106
+ swapToken: frameHost.swapToken.bind(frameHost),
107
+ },
68
108
  wallet: {
69
109
  ethProvider: provider,
70
110
  },