diff --git a/packages/fcl/CHANGELOG.md b/packages/fcl/CHANGELOG.md index 6f2ca6c3d..aa4850dd9 100644 --- a/packages/fcl/CHANGELOG.md +++ b/packages/fcl/CHANGELOG.md @@ -19,6 +19,13 @@ - @onflow/types@1.2.0-alpha.0 - @onflow/rlp@1.2.0-alpha.0 - @onflow/sdk@1.3.0-alpha.0 +## 1.5.1 + +### Patch Changes + +- [#1754](https://github.com/onflow/fcl-js/pull/1754) [`c0ba4d26`](https://github.com/onflow/fcl-js/commit/c0ba4d268ce307ddbd83b812db5136f0f29afdc4) Thanks [@jribbink](https://github.com/jribbink)! - Fix `fcl.mutate` typedef + +- [#1755](https://github.com/onflow/fcl-js/pull/1755) [`28d16a13`](https://github.com/onflow/fcl-js/commit/28d16a134f9afea265400b49df81f77ac02a520d) Thanks [@jribbink](https://github.com/jribbink)! - Fix react-native platform for `fcl.mutate` ## 1.5.0 diff --git a/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz b/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz deleted file mode 100644 index 7c980acd7..000000000 Binary files a/packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz and /dev/null differ diff --git a/packages/fcl/src/exec/mutate.js b/packages/fcl/src/exec/mutate.js index 4238194a8..c1dae1eec 100644 --- a/packages/fcl/src/exec/mutate.js +++ b/packages/fcl/src/exec/mutate.js @@ -5,63 +5,67 @@ import {prepTemplateOpts} from "./utils/prep-template-opts.js" import {preMutate} from "./utils/pre.js" import {isNumber} from "./utils/is" -/** - * @description - * Allows you to submit transactions to the blockchain to potentially mutate the state. - * - * @param {object} opts - Mutation Options and configuration - * @param {string} opts.platform - platform that runs the function - * @param {string} opts.cadence - Cadence Transaction used to mutate Flow - * @param {import("../fcl").ArgsFn} [opts.args] - Arguments passed to cadence transaction - * @param {object} [opts.template] - Interaction Template for a transaction - * @param {number} [opts.limit] - Compute Limit for transaction - * @returns {Promise} Transaction Id - * - * @example - * fcl.mutate({ - * cadence: ` - * transaction(a: Int, b: Int, c: Address) { - * prepare(acct: AuthAccount) { - * log(acct) - * log(a) - * log(b) - * log(c) - * } - * } - * `, - * args: (arg, t) => [ - * arg(6, t.Int), - * arg(7, t.Int), - * arg("0xba1132bc08f82fe2", t.Address), - * ], - * }) - * - * - * Options: - * type Options = { - * template: InteractionTemplate | String // InteractionTemplate or url to one - * cadence: String!, - * args: (arg, t) => Array, - * limit: Number, - * authz: AuthzFn, // will overload the trinity of signatory roles - * proposer: AuthzFn, // will overload the proposer signatory role - * payer: AuthzFn, // will overload the payer signatory role - * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles - * } - */ -export const getMutate = ({platform}) => async (opts = {}) => { - var txid - try { - await preMutate(opts) - opts = await prepTemplateOpts(opts) - const currentUser = getCurrentUser({platform}) - // Allow for a config to overwrite the authorization function. - // prettier-ignore - const authz = await sdk.config().get("fcl.authz", currentUser().authorization) - - txid = sdk.config().overload(opts.dependencies || {}, async () => +export const getMutate = ({platform}) => { + /** + * @description + * Allows you to submit transactions to the blockchain to potentially mutate the state. + * + * @param {object} [opts] - Mutation Options and configuration + * @param {string} [opts.cadence] - Cadence Transaction used to mutate Flow + * @param {import("../shared-exports").ArgsFn} [opts.args] - Arguments passed to cadence transaction + * @param {object | string} [opts.template] - Interaction Template for a transaction + * @param {number} [opts.limit] - Compute Limit for transaction + * @param {Function} [opts.authz] - Authorization function for transaction + * @param {Function} [opts.proposer] - Proposer Authorization function for transaction + * @param {Function} [opts.payer] - Payer Authorization function for transaction + * @param {Array} [opts.authorizations] - Authorizations function for transaction + * @returns {Promise} Transaction Id + * + * @example + * fcl.mutate({ + * cadence: ` + * transaction(a: Int, b: Int, c: Address) { + * prepare(acct: AuthAccount) { + * log(acct) + * log(a) + * log(b) + * log(c) + * } + * } + * `, + * args: (arg, t) => [ + * arg(6, t.Int), + * arg(7, t.Int), + * arg("0xba1132bc08f82fe2", t.Address), + * ], + * }) + * + * + * Options: + * type Options = { + * template: InteractionTemplate | String // InteractionTemplate or url to one + * cadence: String!, + * args: (arg, t) => Array, + * limit: Number, + * authz: AuthzFn, // will overload the trinity of signatory roles + * proposer: AuthzFn, // will overload the proposer signatory role + * payer: AuthzFn, // will overload the payer signatory role + * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles + * } + */ + const mutate = async (opts = {}) => { + var txid + try { + await preMutate(opts) + opts = await prepTemplateOpts(opts) + const currentUser = getCurrentUser({platform}) + // Allow for a config to overwrite the authorization function. // prettier-ignore - sdk.send([ + const authz = await sdk.config().get("fcl.authz", currentUser().authorization) + + txid = sdk.config().overload(opts.dependencies || {}, async () => + // prettier-ignore + sdk.send([ sdk.transaction(opts.cadence), sdk.args(normalizeArgs(opts.args || [])), @@ -77,10 +81,13 @@ export const getMutate = ({platform}) => async (opts = {}) => { // opts.authorizations > [opts.authz > authz] sdk.authorizations(opts.authorizations || [opts.authz || authz]), ]).then(sdk.decode) - ) + ) - return txid - } catch (error) { - throw error + return txid + } catch (error) { + throw error + } } + + return mutate } diff --git a/packages/fcl/src/fcl-react-native.ts b/packages/fcl/src/fcl-react-native.ts index 12389bf50..0ecf8a8b8 100644 --- a/packages/fcl/src/fcl-react-native.ts +++ b/packages/fcl/src/fcl-react-native.ts @@ -1,10 +1,10 @@ -export * from './shared-exports'; +export * from "./shared-exports" import {getMutate} from "./exec/mutate" -export const mutate = getMutate({platform: "web"}) +export const mutate = getMutate({platform: "react-native"}) import {getCurrentUser} from "./current-user" -const currentUser = getCurrentUser({platform:"react-native"}) +const currentUser = getCurrentUser({platform: "react-native"}) export {currentUser} @@ -20,9 +20,14 @@ export const logIn = (opts = {}) => currentUser().authenticate(opts) export const authz = currentUser().authorization import {config} from "@onflow/config" -import {coreStrategies, getDefaultConfig, useServiceDiscovery, ServiceDiscovery} from "./utils/react-native" +import { + coreStrategies, + getDefaultConfig, + useServiceDiscovery, + ServiceDiscovery, +} from "./utils/react-native" import {initServiceRegistry} from "./current-user/exec-service/plugins" -import {setIsReactNative} from './utils/is-react-native'; +import {setIsReactNative} from "./utils/is-react-native" config(getDefaultConfig()) diff --git a/packages/fcl/src/shared-exports.js b/packages/fcl/src/shared-exports.js index 6af05770f..35b0e1090 100644 --- a/packages/fcl/src/shared-exports.js +++ b/packages/fcl/src/shared-exports.js @@ -69,7 +69,6 @@ export {params, param} from "@onflow/sdk" export {validator} from "@onflow/sdk" export {invariant} from "@onflow/sdk" - /** * @typedef {object} Types * @property {any} Identity - Represents the Identity type.