Skip to content

Commit

Permalink
PKG -- [fcl] Fix mutate typedef (#1754)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Aug 14, 2023
1 parent f7ebce6 commit c0ba4d2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 61 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-zebras-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": patch
---

Fix `fcl.mutate` typedef
Binary file removed packages/fcl/onflow-fcl-1.5.0-alpha.2.tgz
Binary file not shown.
127 changes: 67 additions & 60 deletions packages/fcl/src/exec/mutate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} 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<Arg>,
* 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<Function>} [opts.authorizations] - Authorizations function for transaction
* @returns {Promise<string>} 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<Arg>,
* 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 || [])),
Expand All @@ -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
}
1 change: 0 additions & 1 deletion packages/fcl/src/shared-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c0ba4d2

Please sign in to comment.