Skip to content

Commit 5a552f6

Browse files
committed
Merge branch 'master' into release-1.6
2 parents a7c0c26 + 8f4b06f commit 5a552f6

File tree

5 files changed

+84
-66
lines changed

5 files changed

+84
-66
lines changed

packages/fcl/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
- @onflow/types@1.2.0-alpha.0
2020
- @onflow/rlp@1.2.0-alpha.0
2121
- @onflow/sdk@1.3.0-alpha.0
22+
## 1.5.1
23+
24+
### Patch Changes
25+
26+
- [#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
27+
28+
- [#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`
2229

2330
## 1.5.0
2431

-672 KB
Binary file not shown.

packages/fcl/src/exec/mutate.js

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,67 @@ import {prepTemplateOpts} from "./utils/prep-template-opts.js"
55
import {preMutate} from "./utils/pre.js"
66
import {isNumber} from "./utils/is"
77

8-
/**
9-
* @description
10-
* Allows you to submit transactions to the blockchain to potentially mutate the state.
11-
*
12-
* @param {object} opts - Mutation Options and configuration
13-
* @param {string} opts.platform - platform that runs the function
14-
* @param {string} opts.cadence - Cadence Transaction used to mutate Flow
15-
* @param {import("../fcl").ArgsFn} [opts.args] - Arguments passed to cadence transaction
16-
* @param {object} [opts.template] - Interaction Template for a transaction
17-
* @param {number} [opts.limit] - Compute Limit for transaction
18-
* @returns {Promise<string>} Transaction Id
19-
*
20-
* @example
21-
* fcl.mutate({
22-
* cadence: `
23-
* transaction(a: Int, b: Int, c: Address) {
24-
* prepare(acct: AuthAccount) {
25-
* log(acct)
26-
* log(a)
27-
* log(b)
28-
* log(c)
29-
* }
30-
* }
31-
* `,
32-
* args: (arg, t) => [
33-
* arg(6, t.Int),
34-
* arg(7, t.Int),
35-
* arg("0xba1132bc08f82fe2", t.Address),
36-
* ],
37-
* })
38-
*
39-
*
40-
* Options:
41-
* type Options = {
42-
* template: InteractionTemplate | String // InteractionTemplate or url to one
43-
* cadence: String!,
44-
* args: (arg, t) => Array<Arg>,
45-
* limit: Number,
46-
* authz: AuthzFn, // will overload the trinity of signatory roles
47-
* proposer: AuthzFn, // will overload the proposer signatory role
48-
* payer: AuthzFn, // will overload the payer signatory role
49-
* authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles
50-
* }
51-
*/
52-
export const getMutate = ({platform}) => async (opts = {}) => {
53-
var txid
54-
try {
55-
await preMutate(opts)
56-
opts = await prepTemplateOpts(opts)
57-
const currentUser = getCurrentUser({platform})
58-
// Allow for a config to overwrite the authorization function.
59-
// prettier-ignore
60-
const authz = await sdk.config().get("fcl.authz", currentUser().authorization)
61-
62-
txid = sdk.config().overload(opts.dependencies || {}, async () =>
8+
export const getMutate = ({platform}) => {
9+
/**
10+
* @description
11+
* Allows you to submit transactions to the blockchain to potentially mutate the state.
12+
*
13+
* @param {object} [opts] - Mutation Options and configuration
14+
* @param {string} [opts.cadence] - Cadence Transaction used to mutate Flow
15+
* @param {import("../shared-exports").ArgsFn} [opts.args] - Arguments passed to cadence transaction
16+
* @param {object | string} [opts.template] - Interaction Template for a transaction
17+
* @param {number} [opts.limit] - Compute Limit for transaction
18+
* @param {Function} [opts.authz] - Authorization function for transaction
19+
* @param {Function} [opts.proposer] - Proposer Authorization function for transaction
20+
* @param {Function} [opts.payer] - Payer Authorization function for transaction
21+
* @param {Array<Function>} [opts.authorizations] - Authorizations function for transaction
22+
* @returns {Promise<string>} Transaction Id
23+
*
24+
* @example
25+
* fcl.mutate({
26+
* cadence: `
27+
* transaction(a: Int, b: Int, c: Address) {
28+
* prepare(acct: AuthAccount) {
29+
* log(acct)
30+
* log(a)
31+
* log(b)
32+
* log(c)
33+
* }
34+
* }
35+
* `,
36+
* args: (arg, t) => [
37+
* arg(6, t.Int),
38+
* arg(7, t.Int),
39+
* arg("0xba1132bc08f82fe2", t.Address),
40+
* ],
41+
* })
42+
*
43+
*
44+
* Options:
45+
* type Options = {
46+
* template: InteractionTemplate | String // InteractionTemplate or url to one
47+
* cadence: String!,
48+
* args: (arg, t) => Array<Arg>,
49+
* limit: Number,
50+
* authz: AuthzFn, // will overload the trinity of signatory roles
51+
* proposer: AuthzFn, // will overload the proposer signatory role
52+
* payer: AuthzFn, // will overload the payer signatory role
53+
* authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles
54+
* }
55+
*/
56+
const mutate = async (opts = {}) => {
57+
var txid
58+
try {
59+
await preMutate(opts)
60+
opts = await prepTemplateOpts(opts)
61+
const currentUser = getCurrentUser({platform})
62+
// Allow for a config to overwrite the authorization function.
6363
// prettier-ignore
64-
sdk.send([
64+
const authz = await sdk.config().get("fcl.authz", currentUser().authorization)
65+
66+
txid = sdk.config().overload(opts.dependencies || {}, async () =>
67+
// prettier-ignore
68+
sdk.send([
6569
sdk.transaction(opts.cadence),
6670

6771
sdk.args(normalizeArgs(opts.args || [])),
@@ -77,10 +81,13 @@ export const getMutate = ({platform}) => async (opts = {}) => {
7781
// opts.authorizations > [opts.authz > authz]
7882
sdk.authorizations(opts.authorizations || [opts.authz || authz]),
7983
]).then(sdk.decode)
80-
)
84+
)
8185

82-
return txid
83-
} catch (error) {
84-
throw error
86+
return txid
87+
} catch (error) {
88+
throw error
89+
}
8590
}
91+
92+
return mutate
8693
}

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export * from './shared-exports';
1+
export * from "./shared-exports"
22

33
import {getMutate} from "./exec/mutate"
4-
export const mutate = getMutate({platform: "web"})
4+
export const mutate = getMutate({platform: "react-native"})
55

66
import {getCurrentUser} from "./current-user"
7-
const currentUser = getCurrentUser({platform:"react-native"})
7+
const currentUser = getCurrentUser({platform: "react-native"})
88

99
export {currentUser}
1010

@@ -20,9 +20,14 @@ export const logIn = (opts = {}) => currentUser().authenticate(opts)
2020
export const authz = currentUser().authorization
2121

2222
import {config} from "@onflow/config"
23-
import {coreStrategies, getDefaultConfig, useServiceDiscovery, ServiceDiscovery} from "./utils/react-native"
23+
import {
24+
coreStrategies,
25+
getDefaultConfig,
26+
useServiceDiscovery,
27+
ServiceDiscovery,
28+
} from "./utils/react-native"
2429
import {initServiceRegistry} from "./current-user/exec-service/plugins"
25-
import {setIsReactNative} from './utils/is-react-native';
30+
import {setIsReactNative} from "./utils/is-react-native"
2631

2732
config(getDefaultConfig())
2833

packages/fcl/src/shared-exports.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export {params, param} from "@onflow/sdk"
6969
export {validator} from "@onflow/sdk"
7070
export {invariant} from "@onflow/sdk"
7171

72-
7372
/**
7473
* @typedef {object} Types
7574
* @property {any} Identity - Represents the Identity type.

0 commit comments

Comments
 (0)