Skip to content

Commit

Permalink
Fix currentUser config in fcl.mutate (#2004)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Nov 14, 2024
1 parent bac8c54 commit 6f2b075
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/fcl-core/src/exec/mutate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import {isNumber} from "../utils/is"

/**
* @description
* Factory function that returns a mutate function.
* Factory function that returns a mutate function for a given currentUser.
*
* @param {object} opts - Configuration Options
* @param {string} opts.platform - Platform
* @param {object} [opts.discovery] - Discovery options
* @param {ReturnType<typeof import("../current-user").getCurrentUser> | import("../current-user").CurrentUserConfig} currentUserOrConfig - CurrentUser actor or configuration
*/
export const getMutate = ({platform, discovery}) => {
export const getMutate = currentUserOrConfig => {
/**
* @description
* Allows you to submit transactions to the blockchain to potentially mutate the state.
Expand Down Expand Up @@ -66,10 +64,12 @@ export const getMutate = ({platform, discovery}) => {
try {
await preMutate(opts)
opts = await prepTemplateOpts(opts)
const currentUser = getCurrentUser({platform, discovery})
// Allow for a config to overwrite the authorization function.
// prettier-ignore
const authz = await sdk.config().get("fcl.authz", currentUser().authorization)
const currentUser = typeof currentUserOrConfig === "function" ? currentUserOrConfig : getCurrentUser(currentUserOrConfig)
const authz = await sdk
.config()
.get("fcl.authz", currentUser().authorization)

txid = sdk
.send([
Expand Down
6 changes: 2 additions & 4 deletions packages/fcl-react-native/src/fcl-react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,14 @@ import {
initServiceRegistry,
setIsReactNative,
} from "@onflow/fcl-core"
export const mutate = getMutate({platform: "react-native"})

const currentUser = getCurrentUser({
export const currentUser = getCurrentUser({
platform: "react-native",
getStorageProvider: async () => {
return (await config().get("fcl.storage")) || getAsyncStorage()
},
})

export {currentUser}
export const mutate = getMutate(currentUser)

export const authenticate = (opts = {}) => currentUser().authenticate(opts)
export const unauthenticate = () => currentUser().unauthenticate()
Expand Down
2 changes: 1 addition & 1 deletion packages/fcl/src/fcl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ const discoveryOpts = {
execStrategy: execStrategyHook,
}

export const mutate = getMutate({platform: "web", discovery: discoveryOpts})
export const currentUser = getCurrentUser({
platform: "web",
discovery: discoveryOpts,
Expand All @@ -85,6 +84,7 @@ export const currentUser = getCurrentUser({
)
},
})
export const mutate = getMutate(currentUser)

export const authenticate = (opts = {}) => currentUser().authenticate(opts)
export const unauthenticate = () => currentUser().unauthenticate()
Expand Down

0 comments on commit 6f2b075

Please sign in to comment.