@farcaster/frame-sdk 0.0.64 → 0.1.1
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/index.d.ts +5 -6
- package/dist/index.js +26 -6
- package/dist/index.min.js +8 -8
- package/dist/index.min.js.map +4 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -4
- package/src/index.ts +35 -6
- package/dist/back.d.ts +0 -15
- package/dist/back.js +0 -88
- package/dist/endpoint.d.ts +0 -2
- package/dist/endpoint.js +0 -32
- package/dist/ethereumProvider.d.ts +0 -3
- package/dist/ethereumProvider.js +0 -132
- package/dist/frameHost.d.ts +0 -2
- package/dist/frameHost.js +0 -3
- package/dist/quickAuth.d.ts +0 -42
- package/dist/quickAuth.js +0 -74
- package/dist/sdk.d.ts +0 -2
- package/dist/sdk.js +0 -182
- package/dist/sdkEmitter.d.ts +0 -15
- package/dist/sdkEmitter.js +0 -23
- package/dist/solanaProvider.d.ts +0 -3
- package/dist/solanaProvider.js +0 -19
- package/dist/types.d.ts +0 -74
- package/dist/types.js +0 -1
- package/src/back.ts +0 -143
- package/src/endpoint.ts +0 -34
- package/src/ethereumProvider.ts +0 -183
- package/src/frameHost.ts +0 -5
- package/src/navigation.d.ts +0 -191
- package/src/quickAuth.ts +0 -148
- package/src/sdk.ts +0 -191
- package/src/sdkEmitter.ts +0 -27
- package/src/solanaProvider.ts +0 -33
- package/src/types.ts +0 -107
package/dist/sdkEmitter.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import type { Emitter, EventMap } from './types.ts';
|
|
3
|
-
export declare function createEmitter(): Emitter;
|
|
4
|
-
export declare const emitter: {
|
|
5
|
-
eventNames: () => (keyof EventMap)[];
|
|
6
|
-
listeners: <T extends keyof EventMap>(event: T) => ((...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void)[];
|
|
7
|
-
listenerCount: (event: keyof EventMap) => number;
|
|
8
|
-
emit: <T extends keyof EventMap>(event: T, ...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => boolean;
|
|
9
|
-
on: <T extends keyof EventMap>(event: T, fn: (...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void, context?: any) => EventEmitter<EventMap, any>;
|
|
10
|
-
addListener: <T extends keyof EventMap>(event: T, fn: (...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void, context?: any) => EventEmitter<EventMap, any>;
|
|
11
|
-
once: <T extends keyof EventMap>(event: T, fn: (...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void, context?: any) => EventEmitter<EventMap, any>;
|
|
12
|
-
removeListener: <T extends keyof EventMap>(event: T, fn?: ((...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void) | undefined, context?: any, once?: boolean) => EventEmitter<EventMap, any>;
|
|
13
|
-
off: <T extends keyof EventMap>(event: T, fn?: ((...args: EventEmitter.ArgumentMap<EventMap>[Extract<T, keyof EventMap>]) => void) | undefined, context?: any, once?: boolean) => EventEmitter<EventMap, any>;
|
|
14
|
-
removeAllListeners: (event?: keyof EventMap | undefined) => EventEmitter<EventMap, any>;
|
|
15
|
-
};
|
package/dist/sdkEmitter.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3';
|
|
2
|
-
export function createEmitter() {
|
|
3
|
-
const emitter = new EventEmitter();
|
|
4
|
-
return {
|
|
5
|
-
get eventNames() {
|
|
6
|
-
return emitter.eventNames.bind(emitter);
|
|
7
|
-
},
|
|
8
|
-
get listenerCount() {
|
|
9
|
-
return emitter.listenerCount.bind(emitter);
|
|
10
|
-
},
|
|
11
|
-
get listeners() {
|
|
12
|
-
return emitter.listeners.bind(emitter);
|
|
13
|
-
},
|
|
14
|
-
addListener: emitter.addListener.bind(emitter),
|
|
15
|
-
emit: emitter.emit.bind(emitter),
|
|
16
|
-
off: emitter.off.bind(emitter),
|
|
17
|
-
on: emitter.on.bind(emitter),
|
|
18
|
-
once: emitter.once.bind(emitter),
|
|
19
|
-
removeAllListeners: emitter.removeAllListeners.bind(emitter),
|
|
20
|
-
removeListener: emitter.removeListener.bind(emitter),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export const emitter = createEmitter();
|
package/dist/solanaProvider.d.ts
DELETED
package/dist/solanaProvider.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createSolanaWalletProvider, unwrapSolanaProviderRequest, } from '@farcaster/frame-core';
|
|
2
|
-
import { frameHost } from "./frameHost.js";
|
|
3
|
-
const { solanaProviderRequest } = frameHost;
|
|
4
|
-
let solanaProvider;
|
|
5
|
-
if (solanaProviderRequest) {
|
|
6
|
-
solanaProvider = createSolanaWalletProvider(unwrapSolanaProviderRequest(solanaProviderRequest));
|
|
7
|
-
}
|
|
8
|
-
async function getSolanaProvider() {
|
|
9
|
-
let capabilities;
|
|
10
|
-
try {
|
|
11
|
-
capabilities = await frameHost.getCapabilities();
|
|
12
|
-
}
|
|
13
|
-
catch { }
|
|
14
|
-
if (!capabilities?.includes('wallet.getSolanaProvider')) {
|
|
15
|
-
return undefined;
|
|
16
|
-
}
|
|
17
|
-
return solanaProvider;
|
|
18
|
-
}
|
|
19
|
-
export { getSolanaProvider };
|
package/dist/types.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import type { AddMiniApp, ComposeCast, Context, FrameNotificationDetails, GetCapabilities, GetChains, ImpactOccurred, NotificationOccurred, Ready, SelectionChanged, SendToken, SetPrimaryButtonOptions, SignIn, SolanaWalletProvider, SwapToken, ViewCast, ViewProfile, ViewToken } from '@farcaster/frame-core';
|
|
2
|
-
import type { EventEmitter } from 'eventemitter3';
|
|
3
|
-
import type * as Provider from 'ox/Provider';
|
|
4
|
-
import type { Back } from './back.ts';
|
|
5
|
-
import type { QuickAuth } from './quickAuth.ts';
|
|
6
|
-
declare global {
|
|
7
|
-
interface Window {
|
|
8
|
-
ReactNativeWebView: {
|
|
9
|
-
postMessage: (message: string) => void;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/** Combines members of an intersection into a readable type. */
|
|
14
|
-
type Compute<type> = {
|
|
15
|
-
[key in keyof type]: type[key];
|
|
16
|
-
} & unknown;
|
|
17
|
-
export type EventMap = {
|
|
18
|
-
primaryButtonClicked: () => void;
|
|
19
|
-
frameAdded: ({ notificationDetails, }: {
|
|
20
|
-
notificationDetails?: FrameNotificationDetails;
|
|
21
|
-
}) => void;
|
|
22
|
-
frameAddRejected: ({ reason, }: {
|
|
23
|
-
reason: AddMiniApp.AddMiniAppRejectedReason;
|
|
24
|
-
}) => void;
|
|
25
|
-
frameRemoved: () => void;
|
|
26
|
-
notificationsEnabled: ({ notificationDetails, }: {
|
|
27
|
-
notificationDetails: FrameNotificationDetails;
|
|
28
|
-
}) => void;
|
|
29
|
-
notificationsDisabled: () => void;
|
|
30
|
-
backNavigationTriggered: () => void;
|
|
31
|
-
};
|
|
32
|
-
export type Emitter = Compute<EventEmitter<EventMap>>;
|
|
33
|
-
type SetPrimaryButton = (options: SetPrimaryButtonOptions) => Promise<void>;
|
|
34
|
-
export type FrameSDK = {
|
|
35
|
-
getCapabilities: GetCapabilities;
|
|
36
|
-
getChains: GetChains;
|
|
37
|
-
isInMiniApp: () => Promise<boolean>;
|
|
38
|
-
context: Promise<Context.FrameContext>;
|
|
39
|
-
back: Back;
|
|
40
|
-
quickAuth: QuickAuth;
|
|
41
|
-
actions: {
|
|
42
|
-
ready: (options?: Partial<Ready.ReadyOptions>) => Promise<void>;
|
|
43
|
-
openUrl: (url: string) => Promise<void>;
|
|
44
|
-
close: () => Promise<void>;
|
|
45
|
-
setPrimaryButton: SetPrimaryButton;
|
|
46
|
-
addFrame: AddMiniApp.AddMiniApp;
|
|
47
|
-
addMiniApp: AddMiniApp.AddMiniApp;
|
|
48
|
-
signIn: SignIn.SignIn;
|
|
49
|
-
viewCast: ViewCast.ViewCast;
|
|
50
|
-
viewProfile: ViewProfile.ViewProfile;
|
|
51
|
-
composeCast: <close extends boolean | undefined = undefined>(options?: ComposeCast.Options<close>) => Promise<ComposeCast.Result<close>>;
|
|
52
|
-
viewToken: ViewToken.ViewToken;
|
|
53
|
-
sendToken: SendToken.SendToken;
|
|
54
|
-
swapToken: SwapToken.SwapToken;
|
|
55
|
-
};
|
|
56
|
-
experimental: {
|
|
57
|
-
getSolanaProvider: () => Promise<SolanaWalletProvider | undefined>;
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated - use `sdk.quickAuth.getToken`
|
|
60
|
-
*/
|
|
61
|
-
quickAuth: QuickAuth['getToken'];
|
|
62
|
-
};
|
|
63
|
-
wallet: {
|
|
64
|
-
ethProvider: Provider.Provider;
|
|
65
|
-
getEthereumProvider: () => Promise<Provider.Provider | undefined>;
|
|
66
|
-
getSolanaProvider: () => Promise<SolanaWalletProvider | undefined>;
|
|
67
|
-
};
|
|
68
|
-
haptics: {
|
|
69
|
-
impactOccurred: ImpactOccurred;
|
|
70
|
-
notificationOccurred: NotificationOccurred;
|
|
71
|
-
selectionChanged: SelectionChanged;
|
|
72
|
-
};
|
|
73
|
-
} & Emitter;
|
|
74
|
-
export {};
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/back.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import type { WireFrameHost } from '@farcaster/frame-core'
|
|
2
|
-
import type { Remote } from 'comlink'
|
|
3
|
-
import type { Emitter } from './types.ts'
|
|
4
|
-
|
|
5
|
-
export type Back = {
|
|
6
|
-
visible: boolean
|
|
7
|
-
show: () => Promise<void>
|
|
8
|
-
hide: () => Promise<void>
|
|
9
|
-
onback: (() => unknown) | null
|
|
10
|
-
enableWebNavigation: () => Promise<void>
|
|
11
|
-
disableWebNavigation: () => Promise<void>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const createBack: (options: {
|
|
15
|
-
emitter: Emitter
|
|
16
|
-
frameHost: Remote<WireFrameHost>
|
|
17
|
-
}) => Back = ({ frameHost, emitter }) => {
|
|
18
|
-
let teardownWebNavigation: (() => void) | undefined = undefined
|
|
19
|
-
let backCb: (() => unknown) | null = null
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
visible: false,
|
|
23
|
-
get onback() {
|
|
24
|
-
return backCb
|
|
25
|
-
},
|
|
26
|
-
set onback(cb) {
|
|
27
|
-
if (backCb) {
|
|
28
|
-
emitter.removeListener('backNavigationTriggered', backCb)
|
|
29
|
-
}
|
|
30
|
-
backCb = cb
|
|
31
|
-
if (cb) {
|
|
32
|
-
emitter.addListener('backNavigationTriggered', cb)
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
async show() {
|
|
36
|
-
await frameHost.updateBackState({
|
|
37
|
-
visible: true,
|
|
38
|
-
})
|
|
39
|
-
this.visible = true
|
|
40
|
-
},
|
|
41
|
-
async hide() {
|
|
42
|
-
await frameHost.updateBackState({
|
|
43
|
-
visible: false,
|
|
44
|
-
})
|
|
45
|
-
this.visible = false
|
|
46
|
-
},
|
|
47
|
-
async enableWebNavigation() {
|
|
48
|
-
teardownWebNavigation = setupWebBack({
|
|
49
|
-
back: this,
|
|
50
|
-
emitter,
|
|
51
|
-
})
|
|
52
|
-
},
|
|
53
|
-
async disableWebNavigation() {
|
|
54
|
-
teardownWebNavigation?.()
|
|
55
|
-
teardownWebNavigation = undefined
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function setupWebBack({
|
|
61
|
-
emitter,
|
|
62
|
-
back,
|
|
63
|
-
}: {
|
|
64
|
-
emitter: Emitter
|
|
65
|
-
back: Back
|
|
66
|
-
}) {
|
|
67
|
-
const navigation = getWebNavigation()
|
|
68
|
-
if (navigation) {
|
|
69
|
-
return setupNavigationApi({ emitter, back, navigation })
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (typeof window !== 'undefined') {
|
|
73
|
-
return setupFallback({ emitter, back, window })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getWebNavigation(): Navigation | undefined {
|
|
78
|
-
if (typeof window !== 'undefined' && window.navigation !== undefined) {
|
|
79
|
-
return window.navigation
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function setupNavigationApi({
|
|
84
|
-
emitter,
|
|
85
|
-
back,
|
|
86
|
-
navigation,
|
|
87
|
-
}: {
|
|
88
|
-
emitter: Emitter
|
|
89
|
-
back: Back
|
|
90
|
-
navigation: Navigation
|
|
91
|
-
}) {
|
|
92
|
-
function handleNavigateSuccess() {
|
|
93
|
-
if (navigation.canGoBack) {
|
|
94
|
-
back.show()
|
|
95
|
-
} else {
|
|
96
|
-
back.hide()
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function handleBackNavigationTriggered() {
|
|
101
|
-
if (back.visible && navigation.canGoBack) {
|
|
102
|
-
navigation.back()
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
navigation.addEventListener('navigatesuccess', handleNavigateSuccess)
|
|
107
|
-
emitter.addListener('backNavigationTriggered', handleBackNavigationTriggered)
|
|
108
|
-
|
|
109
|
-
return () => {
|
|
110
|
-
navigation.removeEventListener('navigatesuccess', handleNavigateSuccess)
|
|
111
|
-
emitter.removeListener(
|
|
112
|
-
'backNavigationTriggered',
|
|
113
|
-
handleBackNavigationTriggered,
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function setupFallback({
|
|
119
|
-
emitter,
|
|
120
|
-
back,
|
|
121
|
-
window,
|
|
122
|
-
}: {
|
|
123
|
-
emitter: Emitter
|
|
124
|
-
back: Back
|
|
125
|
-
window: Window
|
|
126
|
-
}) {
|
|
127
|
-
back.show()
|
|
128
|
-
|
|
129
|
-
function handleBackNavigationTriggered() {
|
|
130
|
-
if (back.visible) {
|
|
131
|
-
window.history.back()
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
emitter.addListener('backNavigationTriggered', handleBackNavigationTriggered)
|
|
136
|
-
|
|
137
|
-
return () => {
|
|
138
|
-
emitter.removeListener(
|
|
139
|
-
'backNavigationTriggered',
|
|
140
|
-
handleBackNavigationTriggered,
|
|
141
|
-
)
|
|
142
|
-
}
|
|
143
|
-
}
|
package/src/endpoint.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { type Endpoint, windowEndpoint } from 'comlink'
|
|
2
|
-
|
|
3
|
-
const mockEndpoint: Endpoint = {
|
|
4
|
-
postMessage() {
|
|
5
|
-
// noop
|
|
6
|
-
},
|
|
7
|
-
addEventListener: () => {
|
|
8
|
-
// noop
|
|
9
|
-
},
|
|
10
|
-
removeEventListener: () => {
|
|
11
|
-
// noop
|
|
12
|
-
},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const webViewEndpoint: Endpoint = {
|
|
16
|
-
postMessage: (data: unknown) => {
|
|
17
|
-
console.debug('[webview:req]', data)
|
|
18
|
-
window.ReactNativeWebView.postMessage(JSON.stringify(data))
|
|
19
|
-
},
|
|
20
|
-
addEventListener: (_, listener, ...args) => {
|
|
21
|
-
document.addEventListener('FarcasterFrameCallback', listener, ...args)
|
|
22
|
-
},
|
|
23
|
-
removeEventListener: (_, listener) => {
|
|
24
|
-
document.removeEventListener('FarcasterFrameCallback', listener)
|
|
25
|
-
},
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const endpoint = (() => {
|
|
29
|
-
// No actions are actually gonna take place during SSR, thus it's safe to return mocked endpoint
|
|
30
|
-
if (typeof window === 'undefined') return mockEndpoint
|
|
31
|
-
return window?.ReactNativeWebView
|
|
32
|
-
? webViewEndpoint
|
|
33
|
-
: windowEndpoint(window?.parent ?? window)
|
|
34
|
-
})()
|
package/src/ethereumProvider.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
EthProviderWireEvent,
|
|
3
|
-
FrameClientEvent,
|
|
4
|
-
MiniAppHostCapability,
|
|
5
|
-
} from '@farcaster/frame-core'
|
|
6
|
-
import type {
|
|
7
|
-
AnnounceProviderParameters,
|
|
8
|
-
AnnounceProviderReturnType,
|
|
9
|
-
EIP1193Provider,
|
|
10
|
-
EIP6963ProviderDetail,
|
|
11
|
-
} from 'mipd'
|
|
12
|
-
import * as Provider from 'ox/Provider'
|
|
13
|
-
import * as RpcRequest from 'ox/RpcRequest'
|
|
14
|
-
import * as RpcResponse from 'ox/RpcResponse'
|
|
15
|
-
import { frameHost } from './frameHost.ts'
|
|
16
|
-
|
|
17
|
-
const emitter = Provider.createEmitter()
|
|
18
|
-
const store = RpcRequest.createStore()
|
|
19
|
-
|
|
20
|
-
type GenericProviderRpcError = {
|
|
21
|
-
code: number
|
|
22
|
-
details?: string
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function toProviderRpcError({
|
|
26
|
-
code,
|
|
27
|
-
details,
|
|
28
|
-
}: GenericProviderRpcError): Provider.ProviderRpcError {
|
|
29
|
-
switch (code) {
|
|
30
|
-
case 4001:
|
|
31
|
-
return new Provider.UserRejectedRequestError()
|
|
32
|
-
case 4100:
|
|
33
|
-
return new Provider.UnauthorizedError()
|
|
34
|
-
case 4200:
|
|
35
|
-
return new Provider.UnsupportedMethodError()
|
|
36
|
-
case 4900:
|
|
37
|
-
return new Provider.DisconnectedError()
|
|
38
|
-
case 4901:
|
|
39
|
-
return new Provider.ChainDisconnectedError()
|
|
40
|
-
default:
|
|
41
|
-
return new Provider.ProviderRpcError(
|
|
42
|
-
code,
|
|
43
|
-
details ?? 'Unknown provider RPC error',
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const ethereumProvider: Provider.Provider = Provider.from({
|
|
49
|
-
...emitter,
|
|
50
|
-
async request(args) {
|
|
51
|
-
// @ts-expect-error
|
|
52
|
-
const request = store.prepare(args)
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const response = await frameHost
|
|
56
|
-
.ethProviderRequestV2(request)
|
|
57
|
-
.then((res) => RpcResponse.parse(res, { request, raw: true }))
|
|
58
|
-
|
|
59
|
-
if (response.error) {
|
|
60
|
-
throw toProviderRpcError(response.error)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return response.result
|
|
64
|
-
} catch (e) {
|
|
65
|
-
// ethProviderRequestV2 not supported, fall back to v1
|
|
66
|
-
if (
|
|
67
|
-
e instanceof Error &&
|
|
68
|
-
e.message.match(/cannot read property 'apply'/i)
|
|
69
|
-
) {
|
|
70
|
-
return await frameHost.ethProviderRequest(request)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
e instanceof Provider.ProviderRpcError ||
|
|
75
|
-
e instanceof RpcResponse.BaseError
|
|
76
|
-
) {
|
|
77
|
-
throw e
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
throw new RpcResponse.InternalError({
|
|
81
|
-
message: e instanceof Error ? e.message : undefined,
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
export async function getEthereumProvider(): Promise<
|
|
88
|
-
Provider.Provider | undefined
|
|
89
|
-
> {
|
|
90
|
-
try {
|
|
91
|
-
const capabilities = await frameHost.getCapabilities()
|
|
92
|
-
if (
|
|
93
|
-
!capabilities.includes('wallet.getEthereumProvider') &&
|
|
94
|
-
!capabilities.includes('wallet.getEvmProvider' as MiniAppHostCapability)
|
|
95
|
-
) {
|
|
96
|
-
// We used getEvmProvider for a short period before getEthereumProvider.
|
|
97
|
-
// In case we're talking to an old host, we check the old key.
|
|
98
|
-
return undefined
|
|
99
|
-
}
|
|
100
|
-
return ethereumProvider
|
|
101
|
-
} catch {
|
|
102
|
-
// If this is an old frame host that doesn't support getCapabilities,
|
|
103
|
-
// getEthereumProvider will assume that it's supported
|
|
104
|
-
return ethereumProvider
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function announceEvmProvider(
|
|
109
|
-
detail: AnnounceProviderParameters,
|
|
110
|
-
): AnnounceProviderReturnType {
|
|
111
|
-
const event: CustomEvent<EIP6963ProviderDetail> = new CustomEvent(
|
|
112
|
-
'eip6963:announceProvider',
|
|
113
|
-
{ detail: Object.freeze(detail) },
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
window.dispatchEvent(event)
|
|
117
|
-
|
|
118
|
-
const handler = () => window.dispatchEvent(event)
|
|
119
|
-
window.addEventListener('eip6963:requestProvider', handler)
|
|
120
|
-
return () => window.removeEventListener('eip6963:requestProvider', handler)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Required to pass SSR
|
|
124
|
-
if (typeof document !== 'undefined') {
|
|
125
|
-
// forward eip6963:requestProvider events to the host
|
|
126
|
-
document.addEventListener('eip6963:requestProvider', () => {
|
|
127
|
-
frameHost.eip6963RequestProvider()
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// react native webview events
|
|
131
|
-
document.addEventListener('FarcasterFrameEthProviderEvent', (event) => {
|
|
132
|
-
if (event instanceof MessageEvent) {
|
|
133
|
-
const ethProviderEvent = event.data as EthProviderWireEvent
|
|
134
|
-
// @ts-expect-error
|
|
135
|
-
emitter.emit(ethProviderEvent.event, ...ethProviderEvent.params)
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
document.addEventListener('FarcasterFrameEvent', (event) => {
|
|
140
|
-
if (event instanceof MessageEvent) {
|
|
141
|
-
const frameEvent = event.data as FrameClientEvent
|
|
142
|
-
if (frameEvent.event === 'eip6963:announceProvider') {
|
|
143
|
-
announceEvmProvider({
|
|
144
|
-
info: frameEvent.info,
|
|
145
|
-
provider: ethereumProvider as EIP1193Provider,
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Required to pass SSR
|
|
153
|
-
if (typeof window !== 'undefined') {
|
|
154
|
-
// forward eip6963:requestProvider events to the host
|
|
155
|
-
window.addEventListener('eip6963:requestProvider', () => {
|
|
156
|
-
frameHost.eip6963RequestProvider()
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
// web events
|
|
160
|
-
window.addEventListener('message', (event) => {
|
|
161
|
-
if (event instanceof MessageEvent) {
|
|
162
|
-
if (event.data.type === 'frameEthProviderEvent') {
|
|
163
|
-
const ethProviderEvent = event.data as EthProviderWireEvent
|
|
164
|
-
// @ts-expect-error
|
|
165
|
-
emitter.emit(ethProviderEvent.event, ...ethProviderEvent.params)
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
window.addEventListener('message', (event) => {
|
|
171
|
-
if (event instanceof MessageEvent) {
|
|
172
|
-
if (event.data.type === 'frameEvent') {
|
|
173
|
-
const frameEvent = event.data.event as FrameClientEvent
|
|
174
|
-
if (frameEvent.event === 'eip6963:announceProvider') {
|
|
175
|
-
announceEvmProvider({
|
|
176
|
-
info: frameEvent.info,
|
|
177
|
-
provider: ethereumProvider as EIP1193Provider,
|
|
178
|
-
})
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
}
|
package/src/frameHost.ts
DELETED
package/src/navigation.d.ts
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
interface Window {
|
|
2
|
-
readonly navigation?: Navigation
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
interface NavigationEventMap {
|
|
6
|
-
navigate: NavigateEvent
|
|
7
|
-
navigatesuccess: Event
|
|
8
|
-
navigateerror: ErrorEvent
|
|
9
|
-
currententrychange: NavigationCurrentEntryChangeEvent
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface NavigationResult {
|
|
13
|
-
committed: Promise<NavigationHistoryEntry>
|
|
14
|
-
finished: Promise<NavigationHistoryEntry>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare class Navigation extends EventTarget {
|
|
18
|
-
entries(): NavigationHistoryEntry[]
|
|
19
|
-
readonly currentEntry: NavigationHistoryEntry | null
|
|
20
|
-
updateCurrentEntry(options: NavigationUpdateCurrentEntryOptions): void
|
|
21
|
-
readonly transition: NavigationTransition | null
|
|
22
|
-
|
|
23
|
-
readonly canGoBack: boolean
|
|
24
|
-
readonly canGoForward: boolean
|
|
25
|
-
|
|
26
|
-
navigate(url: string, options?: NavigationNavigateOptions): NavigationResult
|
|
27
|
-
reload(options?: NavigationReloadOptions): NavigationResult
|
|
28
|
-
|
|
29
|
-
traverseTo(key: string, options?: NavigationOptions): NavigationResult
|
|
30
|
-
back(options?: NavigationOptions): NavigationResult
|
|
31
|
-
forward(options?: NavigationOptions): NavigationResult
|
|
32
|
-
|
|
33
|
-
onnavigate: ((this: Navigation, ev: NavigateEvent) => any) | null
|
|
34
|
-
onnavigatesuccess: ((this: Navigation, ev: Event) => any) | null
|
|
35
|
-
onnavigateerror: ((this: Navigation, ev: ErrorEvent) => any) | null
|
|
36
|
-
oncurrententrychange:
|
|
37
|
-
| ((this: Navigation, ev: NavigationCurrentEntryChangeEvent) => any)
|
|
38
|
-
| null
|
|
39
|
-
|
|
40
|
-
addEventListener<K extends keyof NavigationEventMap>(
|
|
41
|
-
type: K,
|
|
42
|
-
listener: (this: Navigation, ev: NavigationEventMap[K]) => any,
|
|
43
|
-
options?: boolean | AddEventListenerOptions,
|
|
44
|
-
): void
|
|
45
|
-
addEventListener(
|
|
46
|
-
type: string,
|
|
47
|
-
listener: EventListenerOrEventListenerObject,
|
|
48
|
-
options?: boolean | AddEventListenerOptions,
|
|
49
|
-
): void
|
|
50
|
-
removeEventListener<K extends keyof NavigationEventMap>(
|
|
51
|
-
type: K,
|
|
52
|
-
listener: (this: Navigation, ev: NavigationEventMap[K]) => any,
|
|
53
|
-
options?: boolean | EventListenerOptions,
|
|
54
|
-
): void
|
|
55
|
-
removeEventListener(
|
|
56
|
-
type: string,
|
|
57
|
-
listener: EventListenerOrEventListenerObject,
|
|
58
|
-
options?: boolean | EventListenerOptions,
|
|
59
|
-
): void
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
declare class NavigationTransition {
|
|
63
|
-
readonly navigationType: NavigationTypeString
|
|
64
|
-
readonly from: NavigationHistoryEntry
|
|
65
|
-
readonly finished: Promise<void>
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
interface NavigationHistoryEntryEventMap {
|
|
69
|
-
dispose: Event
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
interface NavigationHistoryEntry extends EventTarget {
|
|
73
|
-
readonly key: string
|
|
74
|
-
readonly id: string
|
|
75
|
-
readonly url: string | null
|
|
76
|
-
readonly index: number
|
|
77
|
-
readonly sameDocument: boolean
|
|
78
|
-
|
|
79
|
-
getState(): unknown
|
|
80
|
-
|
|
81
|
-
ondispose: ((this: NavigationHistoryEntry, ev: Event) => any) | null
|
|
82
|
-
|
|
83
|
-
addEventListener<K extends keyof NavigationHistoryEntryEventMap>(
|
|
84
|
-
type: K,
|
|
85
|
-
listener: (
|
|
86
|
-
this: NavigationHistoryEntry,
|
|
87
|
-
ev: NavigationHistoryEntryEventMap[K],
|
|
88
|
-
) => any,
|
|
89
|
-
options?: boolean | AddEventListenerOptions,
|
|
90
|
-
): void
|
|
91
|
-
addEventListener(
|
|
92
|
-
type: string,
|
|
93
|
-
listener: EventListenerOrEventListenerObject,
|
|
94
|
-
options?: boolean | AddEventListenerOptions,
|
|
95
|
-
): void
|
|
96
|
-
removeEventListener<K extends keyof NavigationHistoryEntryEventMap>(
|
|
97
|
-
type: K,
|
|
98
|
-
listener: (
|
|
99
|
-
this: NavigationHistoryEntry,
|
|
100
|
-
ev: NavigationHistoryEntryEventMap[K],
|
|
101
|
-
) => any,
|
|
102
|
-
options?: boolean | EventListenerOptions,
|
|
103
|
-
): void
|
|
104
|
-
removeEventListener(
|
|
105
|
-
type: string,
|
|
106
|
-
listener: EventListenerOrEventListenerObject,
|
|
107
|
-
options?: boolean | EventListenerOptions,
|
|
108
|
-
): void
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
declare let NavigationHistoryEntry: {
|
|
112
|
-
prototype: NavigationHistoryEntry
|
|
113
|
-
new (): NavigationHistoryEntry
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
type NavigationTypeString = 'reload' | 'push' | 'replace' | 'traverse'
|
|
117
|
-
|
|
118
|
-
interface NavigationUpdateCurrentEntryOptions {
|
|
119
|
-
state: unknown
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
interface NavigationOptions {
|
|
123
|
-
info?: unknown
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
interface NavigationNavigateOptions extends NavigationOptions {
|
|
127
|
-
state?: unknown
|
|
128
|
-
history?: 'auto' | 'push' | 'replace'
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
interface NavigationReloadOptions extends NavigationOptions {
|
|
132
|
-
state?: unknown
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
declare class NavigationCurrentEntryChangeEvent extends Event {
|
|
136
|
-
constructor(type: string, eventInit?: NavigationCurrentEntryChangeEventInit)
|
|
137
|
-
|
|
138
|
-
readonly navigationType: NavigationTypeString | null
|
|
139
|
-
readonly from: NavigationHistoryEntry
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
interface NavigationCurrentEntryChangeEventInit extends EventInit {
|
|
143
|
-
navigationType?: NavigationTypeString | null
|
|
144
|
-
from: NavigationHistoryEntry
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
declare class NavigateEvent extends Event {
|
|
148
|
-
constructor(type: string, eventInit?: NavigateEventInit)
|
|
149
|
-
|
|
150
|
-
readonly navigationType: NavigationTypeString
|
|
151
|
-
readonly canIntercept: boolean
|
|
152
|
-
readonly userInitiated: boolean
|
|
153
|
-
readonly hashChange: boolean
|
|
154
|
-
readonly hasUAVisualTransition: boolean
|
|
155
|
-
readonly destination: NavigationDestination
|
|
156
|
-
readonly signal: AbortSignal
|
|
157
|
-
readonly formData: FormData | null
|
|
158
|
-
readonly downloadRequest: string | null
|
|
159
|
-
readonly info?: unknown
|
|
160
|
-
|
|
161
|
-
intercept(options?: NavigationInterceptOptions): void
|
|
162
|
-
scroll(): void
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
interface NavigateEventInit extends EventInit {
|
|
166
|
-
navigationType?: NavigationTypeString
|
|
167
|
-
canIntercept?: boolean
|
|
168
|
-
userInitiated?: boolean
|
|
169
|
-
hashChange?: boolean
|
|
170
|
-
destination: NavigationDestination
|
|
171
|
-
signal: AbortSignal
|
|
172
|
-
formData?: FormData | null
|
|
173
|
-
downloadRequest?: string | null
|
|
174
|
-
info?: unknown
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
interface NavigationInterceptOptions {
|
|
178
|
-
handler?: () => Promise<void>
|
|
179
|
-
focusReset?: 'after-transition' | 'manual'
|
|
180
|
-
scroll?: 'after-transition' | 'manual'
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
declare class NavigationDestination {
|
|
184
|
-
readonly url: string
|
|
185
|
-
readonly key: string | null
|
|
186
|
-
readonly id: string | null
|
|
187
|
-
readonly index: number
|
|
188
|
-
readonly sameDocument: boolean
|
|
189
|
-
|
|
190
|
-
getState(): unknown
|
|
191
|
-
}
|