@frak-labs/react-sdk 0.0.19 → 0.1.0-beta.8d103039
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.cjs +1 -1
- package/dist/index.d.cts +66 -22
- package/dist/index.d.ts +66 -22
- package/dist/index.js +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var
|
|
1
|
+
"use strict";let __rslib_import_meta_url__="undefined"==typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var r in t)__webpack_require__.o(t,r)&&!__webpack_require__.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{useOpenSso:()=>useOpenSso,useWalletStatus:()=>useWalletStatus,useReferralInteraction:()=>useReferralInteraction,useSendTransactionAction:()=>useSendTransactionAction,FrakConfigProvider:()=>FrakConfigProvider,useSendInteraction:()=>useSendInteraction,useGetProductInformation:()=>useGetProductInformation,FrakConfigContext:()=>FrakConfigContext,useDisplayModal:()=>useDisplayModal,useFrakClient:()=>useFrakClient,FrakIFrameClientProvider:()=>FrakIFrameClientProvider,useFrakConfig:()=>useFrakConfig,usePrepareSso:()=>usePrepareSso,useSiweAuthenticate:()=>useSiweAuthenticate,FrakIFrameClientContext:()=>FrakIFrameClientContext});let external_react_namespaceObject=require("react"),FrakConfigContext=(0,external_react_namespaceObject.createContext)(void 0);function FrakConfigProvider(e){let{children:t,config:r}=e;return(0,external_react_namespaceObject.createElement)(FrakConfigContext.Provider,{value:{...r,walletUrl:r.walletUrl??"https://wallet.frak.id",domain:r.domain??("undefined"!=typeof window?window?.location?.host:void 0)??"not-found"}},t)}let core_sdk_namespaceObject=require("@frak-labs/core-sdk"),frame_connector_namespaceObject=require("@frak-labs/frame-connector");function useFrakConfig(){let e=(0,external_react_namespaceObject.useContext)(FrakConfigContext);if(!e)throw new frame_connector_namespaceObject.FrakRpcError(frame_connector_namespaceObject.RpcErrorCodes.configError,"Frak config not found");return e}let FrakIFrameClientContext=(0,external_react_namespaceObject.createContext)(void 0);function FrakIFrameClientProvider({style:e,children:t}){let r=useFrakConfig(),[a,n]=(0,external_react_namespaceObject.useState)(void 0),o=(0,external_react_namespaceObject.createElement)("iframe",{...core_sdk_namespaceObject.baseIframeProps,src:`${r.walletUrl}/listener`,style:e??core_sdk_namespaceObject.baseIframeProps.style,ref:e=>{e&&!a&&n((0,core_sdk_namespaceObject.createIFrameFrakClient)({iframe:e,config:r}))}}),c=(0,external_react_namespaceObject.createElement)(FrakIFrameClientContext.Provider,{value:a},t);return(0,external_react_namespaceObject.createElement)(external_react_namespaceObject.Fragment,null,o,c)}function useFrakClient(){return(0,external_react_namespaceObject.useContext)(FrakIFrameClientContext)}let actions_namespaceObject=require("@frak-labs/core-sdk/actions"),react_query_namespaceObject=require("@tanstack/react-query");function useWalletStatus(){let e=(0,react_query_namespaceObject.useQueryClient)(),t=useFrakClient(),r=(0,external_react_namespaceObject.useCallback)(t=>{e.setQueryData(["frak-sdk","wallet-status-listener"],t)},[e]);return(0,react_query_namespaceObject.useQuery)({gcTime:0,staleTime:0,queryKey:["frak-sdk","wallet-status-listener"],queryFn:async()=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.watchWalletStatus)(t,r)},enabled:!!t})}function useSendTransactionAction({mutations:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useMutation)({...e,mutationKey:["frak-sdk","send-transaction"],mutationFn:async e=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.sendTransaction)(t,e)}})}function useSendInteraction({mutations:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useMutation)({...e,mutationKey:["frak-sdk","send-interaction"],mutationFn:async e=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.sendInteraction)(t,e)}})}function useSiweAuthenticate({mutations:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useMutation)({...e,mutationKey:["frak-sdk","siwe-authenticate",t?.config.domain??"no-domain"],mutationFn:async e=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.siweAuthenticate)(t,e)}})}function useMounted(){let[e,t]=(0,external_react_namespaceObject.useState)(!1);return(0,external_react_namespaceObject.useEffect)(()=>{t(!0)},[]),e}function useWindowLocation(){let e=useMounted(),[t,r]=(0,external_react_namespaceObject.useState)(e?window.location:void 0);(0,external_react_namespaceObject.useEffect)(()=>{if(e)return t||a(),window.addEventListener("popstate",a),()=>{window.removeEventListener("popstate",a)};function a(){r(window.location)}},[e,t]);let a=(0,external_react_namespaceObject.useMemo)(()=>t?.href,[t?.href]);return{location:t,href:a}}function useFrakContext(){let{location:e}=useWindowLocation();return{frakContext:(0,external_react_namespaceObject.useMemo)(()=>e?.href?core_sdk_namespaceObject.FrakContextManager.parse({url:e.href}):null,[e?.href]),updateContext:(0,external_react_namespaceObject.useCallback)(t=>{console.log("Updating context",{newContext:t}),core_sdk_namespaceObject.FrakContextManager.replaceUrl({url:e?.href,context:t})},[e?.href])}}function useReferralInteraction({productId:e,modalConfig:t,options:r}={}){let a=useFrakClient(),{frakContext:n}=useFrakContext(),{data:o}=useWalletStatus(),{data:c,error:s,status:_}=(0,react_query_namespaceObject.useQuery)({gcTime:0,staleTime:0,queryKey:["frak-sdk","auto-referral-interaction",n?.r??"no-referrer",o?.key??"no-wallet-status",e??"no-product-id"],queryFn:()=>{if(!a)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.processReferral)(a,{walletStatus:o,frakContext:n,modalConfig:t,productId:e,options:r})},enabled:!!o});return(0,external_react_namespaceObject.useMemo)(()=>"pending"===_?"processing":"error"===_?s:c||"idle",[c,_,s])}function useDisplayModal({mutations:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useMutation)({...e,mutationKey:["frak-sdk","display-modal"],mutationFn:async e=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.displayModal)(t,e)}})}function useOpenSso({mutations:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useMutation)({...e,mutationKey:["frak-sdk","open-sso"],mutationFn:async e=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.openSso)(t,e)}})}function usePrepareSso(e){let t=useFrakClient();return(0,react_query_namespaceObject.useQuery)({queryKey:["frak-sdk","prepare-sso",e],queryFn:async()=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.prepareSso)(t,e)}})}function useGetProductInformation({query:e}={}){let t=useFrakClient();return(0,react_query_namespaceObject.useQuery)({...e,queryKey:["frak-sdk","get-product-information"],queryFn:async()=>{if(!t)throw new frame_connector_namespaceObject.ClientNotFound;return(0,actions_namespaceObject.getProductInformation)(t)}})}for(var __webpack_i__ in exports.FrakConfigContext=__webpack_exports__.FrakConfigContext,exports.FrakConfigProvider=__webpack_exports__.FrakConfigProvider,exports.FrakIFrameClientContext=__webpack_exports__.FrakIFrameClientContext,exports.FrakIFrameClientProvider=__webpack_exports__.FrakIFrameClientProvider,exports.useDisplayModal=__webpack_exports__.useDisplayModal,exports.useFrakClient=__webpack_exports__.useFrakClient,exports.useFrakConfig=__webpack_exports__.useFrakConfig,exports.useGetProductInformation=__webpack_exports__.useGetProductInformation,exports.useOpenSso=__webpack_exports__.useOpenSso,exports.usePrepareSso=__webpack_exports__.usePrepareSso,exports.useReferralInteraction=__webpack_exports__.useReferralInteraction,exports.useSendInteraction=__webpack_exports__.useSendInteraction,exports.useSendTransactionAction=__webpack_exports__.useSendTransactionAction,exports.useSiweAuthenticate=__webpack_exports__.useSiweAuthenticate,exports.useWalletStatus=__webpack_exports__.useWalletStatus,__webpack_exports__)-1===["FrakConfigContext","FrakConfigProvider","FrakIFrameClientContext","FrakIFrameClientProvider","useDisplayModal","useFrakClient","useFrakConfig","useGetProductInformation","useOpenSso","usePrepareSso","useReferralInteraction","useSendInteraction","useSendTransactionAction","useSiweAuthenticate","useWalletStatus"].indexOf(__webpack_i__)&&(exports[__webpack_i__]=__webpack_exports__[__webpack_i__]);Object.defineProperty(exports,"__esModule",{value:!0});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { Context } from 'react';
|
|
2
2
|
import { CSSProperties } from 'react';
|
|
3
|
-
import { DisplayEmbeddedWalletParamsType } from '@frak-labs/core-sdk';
|
|
4
|
-
import { DisplayModalParamsType } from '@frak-labs/core-sdk';
|
|
3
|
+
import type { DisplayEmbeddedWalletParamsType } from '@frak-labs/core-sdk';
|
|
4
|
+
import type { DisplayModalParamsType } from '@frak-labs/core-sdk';
|
|
5
5
|
import { FragmentProps } from 'react';
|
|
6
6
|
import { FrakClient } from '@frak-labs/core-sdk';
|
|
7
|
-
import { FrakRpcError } from '@frak-labs/
|
|
7
|
+
import { FrakRpcError } from '@frak-labs/frame-connector';
|
|
8
8
|
import { FrakWalletSdkConfig } from '@frak-labs/core-sdk';
|
|
9
9
|
import { FunctionComponentElement } from 'react';
|
|
10
|
-
import { GetProductInformationReturnType } from '@frak-labs/core-sdk';
|
|
10
|
+
import type { GetProductInformationReturnType } from '@frak-labs/core-sdk';
|
|
11
11
|
import { Hex } from 'viem';
|
|
12
|
-
import { ModalRpcStepsResultType } from '@frak-labs/core-sdk';
|
|
13
|
-
import { ModalStepTypes } from '@frak-labs/core-sdk';
|
|
14
|
-
import { OpenSsoParamsType } from '@frak-labs/core-sdk';
|
|
12
|
+
import type { ModalRpcStepsResultType } from '@frak-labs/core-sdk';
|
|
13
|
+
import type { ModalStepTypes } from '@frak-labs/core-sdk';
|
|
14
|
+
import type { OpenSsoParamsType } from '@frak-labs/core-sdk';
|
|
15
|
+
import type { OpenSsoReturnType } from '@frak-labs/core-sdk';
|
|
16
|
+
import type { PrepareSsoParamsType } from '@frak-labs/core-sdk';
|
|
15
17
|
import { ProcessReferralOptions } from '@frak-labs/core-sdk/actions';
|
|
16
18
|
import { PropsWithChildren } from 'react';
|
|
17
19
|
import { ProviderProps } from 'react';
|
|
18
20
|
import { ReactNode } from 'react';
|
|
19
|
-
import { SendInteractionParamsType } from '@frak-labs/core-sdk';
|
|
20
|
-
import { SendInteractionReturnType } from '@frak-labs/core-sdk';
|
|
21
|
+
import type { SendInteractionParamsType } from '@frak-labs/core-sdk';
|
|
22
|
+
import type { SendInteractionReturnType } from '@frak-labs/core-sdk';
|
|
21
23
|
import { SendTransactionParams } from '@frak-labs/core-sdk/actions';
|
|
22
|
-
import { SendTransactionReturnType } from '@frak-labs/core-sdk';
|
|
24
|
+
import type { SendTransactionReturnType } from '@frak-labs/core-sdk';
|
|
23
25
|
import { SiweAuthenticateModalParams } from '@frak-labs/core-sdk/actions';
|
|
24
|
-
import { SiweAuthenticateReturnType } from '@frak-labs/core-sdk';
|
|
26
|
+
import type { SiweAuthenticateReturnType } from '@frak-labs/core-sdk';
|
|
25
27
|
import { UseMutationOptions } from '@tanstack/react-query';
|
|
26
28
|
import { UseMutationResult } from '@tanstack/react-query';
|
|
27
29
|
import { UseQueryOptions } from '@tanstack/react-query';
|
|
28
30
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
29
|
-
import { WalletStatusReturnType } from '@frak-labs/core-sdk';
|
|
31
|
+
import type { WalletStatusReturnType } from '@frak-labs/core-sdk';
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* The context that will keep the Frak Wallet SDK configuration
|
|
@@ -104,7 +106,7 @@ declare type MutationOptions_3 = Omit<UseMutationOptions<SiweAuthenticateReturnT
|
|
|
104
106
|
declare type MutationOptions_4<T extends ModalStepTypes[]> = Omit<UseMutationOptions<ModalRpcStepsResultType<T>, FrakRpcError, DisplayModalParamsType<T>>, "mutationFn" | "mutationKey">;
|
|
105
107
|
|
|
106
108
|
/** @ignore */
|
|
107
|
-
declare type MutationOptions_5 = Omit<UseMutationOptions<
|
|
109
|
+
declare type MutationOptions_5 = Omit<UseMutationOptions<OpenSsoReturnType, FrakRpcError, OpenSsoParamsType>, "mutationFn" | "mutationKey">;
|
|
108
110
|
|
|
109
111
|
/** @ignore */
|
|
110
112
|
declare type QueryOptions = Omit<UseQueryOptions<GetProductInformationReturnType, FrakRpcError, undefined>, "queryKey" | "queryFn">;
|
|
@@ -203,7 +205,57 @@ declare interface UseGetProductInformationParams {
|
|
|
203
205
|
* @see {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} for more info about the underlying action
|
|
204
206
|
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
205
207
|
*/
|
|
206
|
-
export declare function useOpenSso({ mutations }?:
|
|
208
|
+
export declare function useOpenSso({ mutations }?: UseOpenSsoParams): UseMutationResult< {
|
|
209
|
+
wallet?: Hex;
|
|
210
|
+
}, FrakRpcError<undefined>, OpenSsoParamsType, unknown>;
|
|
211
|
+
|
|
212
|
+
/** @inline */
|
|
213
|
+
declare interface UseOpenSsoParams {
|
|
214
|
+
/**
|
|
215
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
216
|
+
*/
|
|
217
|
+
mutations?: MutationOptions_5;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Hook that generates SSO URL for popup flow
|
|
222
|
+
*
|
|
223
|
+
* This is a **synchronous** hook (no async calls) that generates the SSO URL
|
|
224
|
+
* client-side without communicating with the wallet iframe.
|
|
225
|
+
*
|
|
226
|
+
* @param params - SSO parameters for URL generation
|
|
227
|
+
*
|
|
228
|
+
* @group hooks
|
|
229
|
+
*
|
|
230
|
+
* @returns
|
|
231
|
+
* Object containing:
|
|
232
|
+
* - `ssoUrl`: Generated SSO URL (or undefined if client not ready)
|
|
233
|
+
* - `isReady`: Boolean indicating if URL is available
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```tsx
|
|
237
|
+
* function MyComponent() {
|
|
238
|
+
* const { data } = usePrepareSso({
|
|
239
|
+
* metadata: { logoUrl: "..." },
|
|
240
|
+
* directExit: true
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* const handleClick = () => {
|
|
244
|
+
* if (ssoUrl) {
|
|
245
|
+
* window.open(data?.ssoUrl, "_blank");
|
|
246
|
+
* }
|
|
247
|
+
* };
|
|
248
|
+
*
|
|
249
|
+
* return <button onClick={handleClick} disabled={!isReady}>Login</button>;
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @see {@link @frak-labs/core-sdk!actions.prepareSso | `prepareSso()`} for the underlying action
|
|
254
|
+
* @see {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} for the recommended high-level API
|
|
255
|
+
*/
|
|
256
|
+
export declare function usePrepareSso(params: PrepareSsoParamsType): UseQueryResult< {
|
|
257
|
+
ssoUrl: string;
|
|
258
|
+
}, Error>;
|
|
207
259
|
|
|
208
260
|
/**
|
|
209
261
|
* Helper hook to automatically submit a referral interaction when detected
|
|
@@ -256,14 +308,6 @@ declare interface UseSendInteractionParams {
|
|
|
256
308
|
mutations?: MutationOptions_2;
|
|
257
309
|
}
|
|
258
310
|
|
|
259
|
-
/** @inline */
|
|
260
|
-
declare interface UseSendInteractionParams_2 {
|
|
261
|
-
/**
|
|
262
|
-
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
263
|
-
*/
|
|
264
|
-
mutations?: MutationOptions_5;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
311
|
/**
|
|
268
312
|
* Hook that return a mutation helping to send a transaction
|
|
269
313
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { Context } from 'react';
|
|
2
2
|
import { CSSProperties } from 'react';
|
|
3
|
-
import { DisplayEmbeddedWalletParamsType } from '@frak-labs/core-sdk';
|
|
4
|
-
import { DisplayModalParamsType } from '@frak-labs/core-sdk';
|
|
3
|
+
import type { DisplayEmbeddedWalletParamsType } from '@frak-labs/core-sdk';
|
|
4
|
+
import type { DisplayModalParamsType } from '@frak-labs/core-sdk';
|
|
5
5
|
import { FragmentProps } from 'react';
|
|
6
6
|
import { FrakClient } from '@frak-labs/core-sdk';
|
|
7
|
-
import { FrakRpcError } from '@frak-labs/
|
|
7
|
+
import { FrakRpcError } from '@frak-labs/frame-connector';
|
|
8
8
|
import { FrakWalletSdkConfig } from '@frak-labs/core-sdk';
|
|
9
9
|
import { FunctionComponentElement } from 'react';
|
|
10
|
-
import { GetProductInformationReturnType } from '@frak-labs/core-sdk';
|
|
10
|
+
import type { GetProductInformationReturnType } from '@frak-labs/core-sdk';
|
|
11
11
|
import { Hex } from 'viem';
|
|
12
|
-
import { ModalRpcStepsResultType } from '@frak-labs/core-sdk';
|
|
13
|
-
import { ModalStepTypes } from '@frak-labs/core-sdk';
|
|
14
|
-
import { OpenSsoParamsType } from '@frak-labs/core-sdk';
|
|
12
|
+
import type { ModalRpcStepsResultType } from '@frak-labs/core-sdk';
|
|
13
|
+
import type { ModalStepTypes } from '@frak-labs/core-sdk';
|
|
14
|
+
import type { OpenSsoParamsType } from '@frak-labs/core-sdk';
|
|
15
|
+
import type { OpenSsoReturnType } from '@frak-labs/core-sdk';
|
|
16
|
+
import type { PrepareSsoParamsType } from '@frak-labs/core-sdk';
|
|
15
17
|
import { ProcessReferralOptions } from '@frak-labs/core-sdk/actions';
|
|
16
18
|
import { PropsWithChildren } from 'react';
|
|
17
19
|
import { ProviderProps } from 'react';
|
|
18
20
|
import { ReactNode } from 'react';
|
|
19
|
-
import { SendInteractionParamsType } from '@frak-labs/core-sdk';
|
|
20
|
-
import { SendInteractionReturnType } from '@frak-labs/core-sdk';
|
|
21
|
+
import type { SendInteractionParamsType } from '@frak-labs/core-sdk';
|
|
22
|
+
import type { SendInteractionReturnType } from '@frak-labs/core-sdk';
|
|
21
23
|
import { SendTransactionParams } from '@frak-labs/core-sdk/actions';
|
|
22
|
-
import { SendTransactionReturnType } from '@frak-labs/core-sdk';
|
|
24
|
+
import type { SendTransactionReturnType } from '@frak-labs/core-sdk';
|
|
23
25
|
import { SiweAuthenticateModalParams } from '@frak-labs/core-sdk/actions';
|
|
24
|
-
import { SiweAuthenticateReturnType } from '@frak-labs/core-sdk';
|
|
26
|
+
import type { SiweAuthenticateReturnType } from '@frak-labs/core-sdk';
|
|
25
27
|
import { UseMutationOptions } from '@tanstack/react-query';
|
|
26
28
|
import { UseMutationResult } from '@tanstack/react-query';
|
|
27
29
|
import { UseQueryOptions } from '@tanstack/react-query';
|
|
28
30
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
29
|
-
import { WalletStatusReturnType } from '@frak-labs/core-sdk';
|
|
31
|
+
import type { WalletStatusReturnType } from '@frak-labs/core-sdk';
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* The context that will keep the Frak Wallet SDK configuration
|
|
@@ -104,7 +106,7 @@ declare type MutationOptions_3 = Omit<UseMutationOptions<SiweAuthenticateReturnT
|
|
|
104
106
|
declare type MutationOptions_4<T extends ModalStepTypes[]> = Omit<UseMutationOptions<ModalRpcStepsResultType<T>, FrakRpcError, DisplayModalParamsType<T>>, "mutationFn" | "mutationKey">;
|
|
105
107
|
|
|
106
108
|
/** @ignore */
|
|
107
|
-
declare type MutationOptions_5 = Omit<UseMutationOptions<
|
|
109
|
+
declare type MutationOptions_5 = Omit<UseMutationOptions<OpenSsoReturnType, FrakRpcError, OpenSsoParamsType>, "mutationFn" | "mutationKey">;
|
|
108
110
|
|
|
109
111
|
/** @ignore */
|
|
110
112
|
declare type QueryOptions = Omit<UseQueryOptions<GetProductInformationReturnType, FrakRpcError, undefined>, "queryKey" | "queryFn">;
|
|
@@ -203,7 +205,57 @@ declare interface UseGetProductInformationParams {
|
|
|
203
205
|
* @see {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} for more info about the underlying action
|
|
204
206
|
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
205
207
|
*/
|
|
206
|
-
export declare function useOpenSso({ mutations }?:
|
|
208
|
+
export declare function useOpenSso({ mutations }?: UseOpenSsoParams): UseMutationResult< {
|
|
209
|
+
wallet?: Hex;
|
|
210
|
+
}, FrakRpcError<undefined>, OpenSsoParamsType, unknown>;
|
|
211
|
+
|
|
212
|
+
/** @inline */
|
|
213
|
+
declare interface UseOpenSsoParams {
|
|
214
|
+
/**
|
|
215
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
216
|
+
*/
|
|
217
|
+
mutations?: MutationOptions_5;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Hook that generates SSO URL for popup flow
|
|
222
|
+
*
|
|
223
|
+
* This is a **synchronous** hook (no async calls) that generates the SSO URL
|
|
224
|
+
* client-side without communicating with the wallet iframe.
|
|
225
|
+
*
|
|
226
|
+
* @param params - SSO parameters for URL generation
|
|
227
|
+
*
|
|
228
|
+
* @group hooks
|
|
229
|
+
*
|
|
230
|
+
* @returns
|
|
231
|
+
* Object containing:
|
|
232
|
+
* - `ssoUrl`: Generated SSO URL (or undefined if client not ready)
|
|
233
|
+
* - `isReady`: Boolean indicating if URL is available
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```tsx
|
|
237
|
+
* function MyComponent() {
|
|
238
|
+
* const { data } = usePrepareSso({
|
|
239
|
+
* metadata: { logoUrl: "..." },
|
|
240
|
+
* directExit: true
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* const handleClick = () => {
|
|
244
|
+
* if (ssoUrl) {
|
|
245
|
+
* window.open(data?.ssoUrl, "_blank");
|
|
246
|
+
* }
|
|
247
|
+
* };
|
|
248
|
+
*
|
|
249
|
+
* return <button onClick={handleClick} disabled={!isReady}>Login</button>;
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*
|
|
253
|
+
* @see {@link @frak-labs/core-sdk!actions.prepareSso | `prepareSso()`} for the underlying action
|
|
254
|
+
* @see {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} for the recommended high-level API
|
|
255
|
+
*/
|
|
256
|
+
export declare function usePrepareSso(params: PrepareSsoParamsType): UseQueryResult< {
|
|
257
|
+
ssoUrl: string;
|
|
258
|
+
}, Error>;
|
|
207
259
|
|
|
208
260
|
/**
|
|
209
261
|
* Helper hook to automatically submit a referral interaction when detected
|
|
@@ -256,14 +308,6 @@ declare interface UseSendInteractionParams {
|
|
|
256
308
|
mutations?: MutationOptions_2;
|
|
257
309
|
}
|
|
258
310
|
|
|
259
|
-
/** @inline */
|
|
260
|
-
declare interface UseSendInteractionParams_2 {
|
|
261
|
-
/**
|
|
262
|
-
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
263
|
-
*/
|
|
264
|
-
mutations?: MutationOptions_5;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
311
|
/**
|
|
268
312
|
* Hook that return a mutation helping to send a transaction
|
|
269
313
|
*
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Fragment as
|
|
1
|
+
import{Fragment as e,createContext as t,createElement as n,useCallback as r,useContext as o,useEffect as a,useMemo as i,useState as u}from"react";import{FrakContextManager as s,baseIframeProps as l,createIFrameFrakClient as f}from"@frak-labs/core-sdk";import{ClientNotFound as c,FrakRpcError as d,RpcErrorCodes as w}from"@frak-labs/frame-connector";import{displayModal as k,getProductInformation as m,openSso as y,prepareSso as p,processReferral as h,sendInteraction as F,sendTransaction as v,siweAuthenticate as g,watchWalletStatus as C}from"@frak-labs/core-sdk/actions";import{useMutation as q,useQuery as K,useQueryClient as x}from"@tanstack/react-query";let P=t(void 0);function S(e){let{children:t,config:r}=e;return n(P.Provider,{value:{...r,walletUrl:r.walletUrl??"https://wallet.frak.id",domain:r.domain??("undefined"!=typeof window?window?.location?.host:void 0)??"not-found"}},t)}function b(){let e=o(P);if(!e)throw new d(w.configError,"Frak config not found");return e}let I=t(void 0);function T({style:t,children:r}){let o=b(),[a,i]=u(void 0),s=n("iframe",{...l,src:`${o.walletUrl}/listener`,style:t??l.style,ref:e=>{e&&!a&&i(f({iframe:e,config:o}))}}),c=n(I.Provider,{value:a},r);return n(e,null,s,c)}function U(){return o(I)}function E(){let e=x(),t=U(),n=r(t=>{e.setQueryData(["frak-sdk","wallet-status-listener"],t)},[e]);return K({gcTime:0,staleTime:0,queryKey:["frak-sdk","wallet-status-listener"],queryFn:async()=>{if(!t)throw new c;return C(t,n)},enabled:!!t})}function A({mutations:e}={}){let t=U();return q({...e,mutationKey:["frak-sdk","send-transaction"],mutationFn:async e=>{if(!t)throw new c;return v(t,e)}})}function D({mutations:e}={}){let t=U();return q({...e,mutationKey:["frak-sdk","send-interaction"],mutationFn:async e=>{if(!t)throw new c;return F(t,e)}})}function L({mutations:e}={}){let t=U();return q({...e,mutationKey:["frak-sdk","siwe-authenticate",t?.config.domain??"no-domain"],mutationFn:async e=>{if(!t)throw new c;return g(t,e)}})}function G({productId:e,modalConfig:t,options:n}={}){let o=U(),{frakContext:l}=function(){let{location:e}=function(){let e=function(){let[e,t]=u(!1);return a(()=>{t(!0)},[]),e}(),[t,n]=u(e?window.location:void 0);a(()=>{if(e)return t||r(),window.addEventListener("popstate",r),()=>{window.removeEventListener("popstate",r)};function r(){n(window.location)}},[e,t]);let r=i(()=>t?.href,[t?.href]);return{location:t,href:r}}();return{frakContext:i(()=>e?.href?s.parse({url:e.href}):null,[e?.href]),updateContext:r(t=>{console.log("Updating context",{newContext:t}),s.replaceUrl({url:e?.href,context:t})},[e?.href])}}(),{data:f}=E(),{data:d,error:w,status:k}=K({gcTime:0,staleTime:0,queryKey:["frak-sdk","auto-referral-interaction",l?.r??"no-referrer",f?.key??"no-wallet-status",e??"no-product-id"],queryFn:()=>{if(!o)throw new c;return h(o,{walletStatus:f,frakContext:l,modalConfig:t,productId:e,options:n})},enabled:!!f});return i(()=>"pending"===k?"processing":"error"===k?w:d||"idle",[d,k,w])}function M({mutations:e}={}){let t=U();return q({...e,mutationKey:["frak-sdk","display-modal"],mutationFn:async e=>{if(!t)throw new c;return k(t,e)}})}function O({mutations:e}={}){let t=U();return q({...e,mutationKey:["frak-sdk","open-sso"],mutationFn:async e=>{if(!t)throw new c;return y(t,e)}})}function Q(e){let t=U();return K({queryKey:["frak-sdk","prepare-sso",e],queryFn:async()=>{if(!t)throw new c;return p(t,e)}})}function R({query:e}={}){let t=U();return K({...e,queryKey:["frak-sdk","get-product-information"],queryFn:async()=>{if(!t)throw new c;return m(t)}})}export{P as FrakConfigContext,S as FrakConfigProvider,I as FrakIFrameClientContext,T as FrakIFrameClientProvider,M as useDisplayModal,U as useFrakClient,b as useFrakConfig,R as useGetProductInformation,O as useOpenSso,Q as usePrepareSso,G as useReferralInteraction,D as useSendInteraction,A as useSendTransactionAction,L as useSiweAuthenticate,E as useWalletStatus};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.1.0-beta.8d103039",
|
|
15
15
|
"description": "React SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
|
|
16
16
|
"repository": {
|
|
17
17
|
"url": "https://github.com/frak-id/wallet",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"publish": "echo 'Publishing react...'"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@frak-labs/
|
|
65
|
+
"@frak-labs/frame-connector": "0.1.0",
|
|
66
|
+
"@frak-labs/core-sdk": "0.1.0"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"viem": "^2.x",
|