File tree 3 files changed +10
-12
lines changed
3 files changed +10
-12
lines changed Original file line number Diff line number Diff line change @@ -7,13 +7,11 @@ import {isNumber} from "../utils/is"
7
7
8
8
/**
9
9
* @description
10
- * Factory function that returns a mutate function.
10
+ * Factory function that returns a mutate function for a given currentUser .
11
11
*
12
- * @param {object } opts - Configuration Options
13
- * @param {string } opts.platform - Platform
14
- * @param {object } [opts.discovery] - Discovery options
12
+ * @param {ReturnType<typeof import("../current-user").getCurrentUser> | import("../current-user").CurrentUserConfig } currentUserOrConfig - CurrentUser actor or configuration
15
13
*/
16
- export const getMutate = ( { platform , discovery } ) => {
14
+ export const getMutate = currentUserOrConfig => {
17
15
/**
18
16
* @description
19
17
* Allows you to submit transactions to the blockchain to potentially mutate the state.
@@ -66,10 +64,12 @@ export const getMutate = ({platform, discovery}) => {
66
64
try {
67
65
await preMutate ( opts )
68
66
opts = await prepTemplateOpts ( opts )
69
- const currentUser = getCurrentUser ( { platform, discovery} )
70
67
// Allow for a config to overwrite the authorization function.
71
68
// prettier-ignore
72
- const authz = await sdk . config ( ) . get ( "fcl.authz" , currentUser ( ) . authorization )
69
+ const currentUser = typeof currentUserOrConfig === "function" ? currentUserOrConfig : getCurrentUser ( currentUserOrConfig )
70
+ const authz = await sdk
71
+ . config ( )
72
+ . get ( "fcl.authz" , currentUser ( ) . authorization )
73
73
74
74
txid = sdk
75
75
. send ( [
Original file line number Diff line number Diff line change @@ -69,16 +69,14 @@ import {
69
69
initServiceRegistry ,
70
70
setIsReactNative ,
71
71
} from "@onflow/fcl-core"
72
- export const mutate = getMutate ( { platform : "react-native" } )
73
72
74
- const currentUser = getCurrentUser ( {
73
+ export const currentUser = getCurrentUser ( {
75
74
platform : "react-native" ,
76
75
getStorageProvider : async ( ) => {
77
76
return ( await config ( ) . get ( "fcl.storage" ) ) || getAsyncStorage ( )
78
77
} ,
79
78
} )
80
-
81
- export { currentUser }
79
+ export const mutate = getMutate ( currentUser )
82
80
83
81
export const authenticate = ( opts = { } ) => currentUser ( ) . authenticate ( opts )
84
82
export const unauthenticate = ( ) => currentUser ( ) . unauthenticate ( )
Original file line number Diff line number Diff line change @@ -75,7 +75,6 @@ const discoveryOpts = {
75
75
execStrategy : execStrategyHook ,
76
76
}
77
77
78
- export const mutate = getMutate ( { platform : "web" , discovery : discoveryOpts } )
79
78
export const currentUser = getCurrentUser ( {
80
79
platform : "web" ,
81
80
discovery : discoveryOpts ,
@@ -85,6 +84,7 @@ export const currentUser = getCurrentUser({
85
84
)
86
85
} ,
87
86
} )
87
+ export const mutate = getMutate ( currentUser )
88
88
89
89
export const authenticate = ( opts = { } ) => currentUser ( ) . authenticate ( opts )
90
90
export const unauthenticate = ( ) => currentUser ( ) . unauthenticate ( )
You can’t perform that action at this time.
0 commit comments