@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/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AddFrame, ComposeCast, Context, FrameNotificationDetails, Ready, SetPrimaryButtonOptions, SignIn, Swap, ViewProfile, ViewToken } from '@farcaster/frame-core';
1
+ import type { AddFrame, ComposeCast, Context, FrameNotificationDetails, Ready, SendToken, SetPrimaryButtonOptions, SignIn, SwapToken, ViewProfile, ViewToken } from '@farcaster/frame-core';
2
2
  import type { EventEmitter } from 'eventemitter3';
3
3
  import type * as Provider from 'ox/Provider';
4
4
  declare global {
@@ -29,6 +29,7 @@ export type EventMap = {
29
29
  export type Emitter = Compute<EventEmitter<EventMap>>;
30
30
  type SetPrimaryButton = (options: SetPrimaryButtonOptions) => Promise<void>;
31
31
  export type FrameSDK = {
32
+ isInMiniApp: () => Promise<boolean>;
32
33
  context: Promise<Context.FrameContext>;
33
34
  actions: {
34
35
  ready: (options?: Partial<Ready.ReadyOptions>) => Promise<void>;
@@ -38,10 +39,13 @@ export type FrameSDK = {
38
39
  addFrame: AddFrame.AddFrame;
39
40
  signIn: SignIn.SignIn;
40
41
  viewProfile: ViewProfile.ViewProfile;
41
- viewToken: ViewToken.ViewToken;
42
- swap: Swap.Swap;
43
42
  composeCast: <close extends boolean | undefined = undefined>(options?: ComposeCast.Options<close>) => Promise<ComposeCast.Result<close>>;
44
43
  };
44
+ experimental: {
45
+ viewToken: ViewToken.ViewToken;
46
+ sendToken: SendToken.SendToken;
47
+ swapToken: SwapToken.SwapToken;
48
+ };
45
49
  wallet: {
46
50
  ethProvider: Provider.Provider;
47
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/frame-sdk",
3
- "version": "0.0.36",
3
+ "version": "0.0.38",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "comlink": "^4.4.2",
23
23
  "eventemitter3": "^5.0.1",
24
24
  "ox": "^0.4.4",
25
- "@farcaster/frame-core": "0.0.33"
25
+ "@farcaster/frame-core": "0.0.34"
26
26
  },
27
27
  "scripts": {
28
28
  "clean": "rm -rf dist",
package/src/sdk.ts CHANGED
@@ -28,17 +28,58 @@ export function createEmitter(): Emitter {
28
28
  }
29
29
 
30
30
  const emitter = createEmitter()
31
+ let cachedIsInMiniAppResult: boolean | null = null
32
+
33
+ /**
34
+ * Determines if the current environment is a MiniApp context.
35
+ *
36
+ * @param timeoutMs - Optional timeout in milliseconds (default: 50)
37
+ * @returns Promise resolving to boolean indicating if in MiniApp context
38
+ */
39
+ async function isInMiniApp(timeoutMs = 50): Promise<boolean> {
40
+ // Return cached result if we've already determined we are in a MiniApp
41
+ if (cachedIsInMiniAppResult === true) {
42
+ return true
43
+ }
44
+
45
+ // Check for SSR environment - definitely not a MiniApp
46
+ if (typeof window === 'undefined') {
47
+ return false
48
+ }
49
+
50
+ // Short-circuit: definitely NOT a MiniApp
51
+ if (!window.ReactNativeWebView && window === window.parent) {
52
+ return false
53
+ }
54
+
55
+ // At this point, we MIGHT be in a MiniApp (iframe or RN WebView)
56
+ // but need to verify by checking for context communication.
57
+ const isInMiniApp = await Promise.race([
58
+ frameHost.context.then((context) => !!context), // Check if context resolves to truthy
59
+ new Promise<boolean>((resolve) => {
60
+ setTimeout(() => resolve(false), timeoutMs) // Timeout resolves to false
61
+ }),
62
+ ]).catch(() => {
63
+ return false
64
+ })
65
+
66
+ // Cache the result ONLY if true (we are confirmed to be in a MiniApp)
67
+ if (isInMiniApp) {
68
+ cachedIsInMiniAppResult = true
69
+ }
70
+
71
+ return isInMiniApp
72
+ }
31
73
 
32
74
  export const sdk: FrameSDK = {
33
75
  ...emitter,
76
+ isInMiniApp,
34
77
  context: frameHost.context,
35
78
  actions: {
36
79
  setPrimaryButton: frameHost.setPrimaryButton.bind(frameHost),
37
80
  ready: frameHost.ready.bind(frameHost),
38
81
  close: frameHost.close.bind(frameHost),
39
82
  viewProfile: frameHost.viewProfile.bind(frameHost),
40
- viewToken: frameHost.viewToken.bind(frameHost),
41
- swap: frameHost.swap.bind(frameHost),
42
83
  signIn: async (options) => {
43
84
  const response = await frameHost.signIn(options)
44
85
  if (response.result) {
@@ -75,6 +116,11 @@ export const sdk: FrameSDK = {
75
116
  return frameHost.composeCast(options) as never
76
117
  },
77
118
  },
119
+ experimental: {
120
+ viewToken: frameHost.viewToken.bind(frameHost),
121
+ sendToken: frameHost.sendToken.bind(frameHost),
122
+ swapToken: frameHost.swapToken.bind(frameHost),
123
+ },
78
124
  wallet: {
79
125
  ethProvider: provider,
80
126
  },
package/src/types.ts CHANGED
@@ -4,9 +4,10 @@ import type {
4
4
  Context,
5
5
  FrameNotificationDetails,
6
6
  Ready,
7
+ SendToken,
7
8
  SetPrimaryButtonOptions,
8
9
  SignIn,
9
- Swap,
10
+ SwapToken,
10
11
  ViewProfile,
11
12
  ViewToken,
12
13
  } from '@farcaster/frame-core'
@@ -50,6 +51,7 @@ export type Emitter = Compute<EventEmitter<EventMap>>
50
51
  type SetPrimaryButton = (options: SetPrimaryButtonOptions) => Promise<void>
51
52
 
52
53
  export type FrameSDK = {
54
+ isInMiniApp: () => Promise<boolean>
53
55
  context: Promise<Context.FrameContext>
54
56
  actions: {
55
57
  ready: (options?: Partial<Ready.ReadyOptions>) => Promise<void>
@@ -59,12 +61,15 @@ export type FrameSDK = {
59
61
  addFrame: AddFrame.AddFrame
60
62
  signIn: SignIn.SignIn
61
63
  viewProfile: ViewProfile.ViewProfile
62
- viewToken: ViewToken.ViewToken
63
- swap: Swap.Swap
64
64
  composeCast: <close extends boolean | undefined = undefined>(
65
65
  options?: ComposeCast.Options<close>,
66
66
  ) => Promise<ComposeCast.Result<close>>
67
67
  }
68
+ experimental: {
69
+ viewToken: ViewToken.ViewToken
70
+ sendToken: SendToken.SendToken
71
+ swapToken: SwapToken.SwapToken
72
+ }
68
73
  wallet: {
69
74
  ethProvider: Provider.Provider
70
75
  }