Skip to content

Commit

Permalink
Merge branch 'master' into release-1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Aug 14, 2023
2 parents a7c0c26 + 8f4b06f commit 5a552f6
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 66 deletions.
7 changes: 7 additions & 0 deletions packages/fcl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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
}
15 changes: 10 additions & 5 deletions packages/fcl/src/fcl-react-native.ts
Original file line number Diff line number Diff line change
@@ -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}

Expand All @@ -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())

Expand Down
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 5a552f6

Please sign in to comment.