Skip to content

Commit 6f2b075

Browse files
authored
Fix currentUser config in fcl.mutate (#2004)
1 parent bac8c54 commit 6f2b075

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

packages/fcl-core/src/exec/mutate.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import {isNumber} from "../utils/is"
77

88
/**
99
* @description
10-
* Factory function that returns a mutate function.
10+
* Factory function that returns a mutate function for a given currentUser.
1111
*
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
1513
*/
16-
export const getMutate = ({platform, discovery}) => {
14+
export const getMutate = currentUserOrConfig => {
1715
/**
1816
* @description
1917
* Allows you to submit transactions to the blockchain to potentially mutate the state.
@@ -66,10 +64,12 @@ export const getMutate = ({platform, discovery}) => {
6664
try {
6765
await preMutate(opts)
6866
opts = await prepTemplateOpts(opts)
69-
const currentUser = getCurrentUser({platform, discovery})
7067
// Allow for a config to overwrite the authorization function.
7168
// 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)
7373

7474
txid = sdk
7575
.send([

packages/fcl-react-native/src/fcl-react-native.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,14 @@ import {
6969
initServiceRegistry,
7070
setIsReactNative,
7171
} from "@onflow/fcl-core"
72-
export const mutate = getMutate({platform: "react-native"})
7372

74-
const currentUser = getCurrentUser({
73+
export const currentUser = getCurrentUser({
7574
platform: "react-native",
7675
getStorageProvider: async () => {
7776
return (await config().get("fcl.storage")) || getAsyncStorage()
7877
},
7978
})
80-
81-
export {currentUser}
79+
export const mutate = getMutate(currentUser)
8280

8381
export const authenticate = (opts = {}) => currentUser().authenticate(opts)
8482
export const unauthenticate = () => currentUser().unauthenticate()

packages/fcl/src/fcl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const discoveryOpts = {
7575
execStrategy: execStrategyHook,
7676
}
7777

78-
export const mutate = getMutate({platform: "web", discovery: discoveryOpts})
7978
export const currentUser = getCurrentUser({
8079
platform: "web",
8180
discovery: discoveryOpts,
@@ -85,6 +84,7 @@ export const currentUser = getCurrentUser({
8584
)
8685
},
8786
})
87+
export const mutate = getMutate(currentUser)
8888

8989
export const authenticate = (opts = {}) => currentUser().authenticate(opts)
9090
export const unauthenticate = () => currentUser().unauthenticate()

0 commit comments

Comments
 (0)