Skip to content

Commit 3b31f1c

Browse files
authored
PKG -- [FCL-WC] Add notifications for pending WC/RPC requests (#1970)
1 parent 2b5869a commit 3b31f1c

33 files changed

+5065
-5710
lines changed

.changeset/brown-bobcats-remain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/fcl-bundle": minor
3+
---
4+
5+
Add `rollup-plugin-postcss` & `@rollup/plugin-image`

.changeset/little-spies-glow.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/fcl-wc": minor
3+
---
4+
5+
Add UI notifications for pending requests

.changeset/poor-carrots-wink.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/fcl": minor
3+
---
4+
5+
Add `walletconnect.disableNotifications` config option to disable WC notification UI

.changeset/rare-apes-argue.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/typedefs": patch
3+
---
4+
5+
Fix CurrentUser services type

.changeset/rotten-paws-retire.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@onflow/fcl-core": patch
3+
---
4+
5+
Pass missing fields to service redirects in execService

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
"semi": false,
33
"trailingComma": "es5",
44
"bracketSpacing": false,
5-
"arrowParens": "avoid"
5+
"arrowParens": "avoid",
6+
"plugins": ["prettier-plugin-tailwindcss", "prettier-plugin-classnames"]
67
}

package-lock.json

+4,652-5,664
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"jest-environment-jsdom": "^29.7.0",
2727
"lerna": "^8.1.8",
2828
"prettier": "^3.3.3",
29+
"prettier-plugin-classnames": "^0.7.3",
30+
"prettier-plugin-tailwindcss": "^0.6.8",
2931
"ts-jest": "^29.2.5",
3032
"typescript": "^5.6.3"
3133
},

packages/fcl-bundle/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,8 @@ A source configuration can be provided in one of three ways:
9797
## Features
9898
- Replace `PACKAGE_CURRENT_VERSION` in bundled code with the current `version` of the package being bundled from `package.json`
9999
- Bundles dependencies with UMD builds for use in browser
100-
- Transpiles output bundles using `@babel/preset-env` and [babel rollup plugin](https://www.npmjs.com/package/@rollup/plugin-babel)
100+
- Transpiles output bundles using `@babel/preset-env` and [babel rollup plugin](https://www.npmjs.com/package/@rollup/plugin-babel)
101+
- PostCSS support for CSS bundling, must include a `postcss.config.js` in the root of the package
102+
- Images are bundled with the `@rollup/plugin-image` plugin as base64 strings
103+
- Minification of bundles with `terser` if output paths end in ".min.js"
104+
- TypeScript support if entry point is a `.ts` file

packages/fcl-bundle/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@
1818
"@babel/preset-typescript": "^7.25.7",
1919
"@rollup/plugin-babel": "^6.0.4",
2020
"@rollup/plugin-commonjs": "^28.0.1",
21+
"@rollup/plugin-image": "^3.0.3",
2122
"@rollup/plugin-node-resolve": "^15.3.0",
2223
"@rollup/plugin-replace": "^6.0.1",
2324
"@rollup/plugin-terser": "^0.4.4",
2425
"commander": "^12.1.0",
2526
"lodash": "^4.17.21",
2627
"rollup": "^4.24.0",
28+
"rollup-plugin-postcss": "^4.0.2",
2729
"rollup-plugin-typescript2": "^0.36.0"
2830
},
2931
"bin": {
3032
"fcl-bundle": "src/cli.js"
33+
},
34+
"optionalDependencies": {
35+
"@rollup/rollup-linux-x64-gnu": "^4.26.0"
3136
}
3237
}

packages/fcl-bundle/src/build/get-input-options.js

+27-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
const _ = require("lodash")
22

3+
const path = require("path")
4+
const fs = require("fs")
5+
const builtinModules = require("node:module").builtinModules
6+
37
const commonjs = require("@rollup/plugin-commonjs")
48
const replace = require("@rollup/plugin-replace")
59
const {nodeResolve} = require("@rollup/plugin-node-resolve")
610
const {babel} = require("@rollup/plugin-babel")
711
const terser = require("@rollup/plugin-terser")
812
const typescript = require("rollup-plugin-typescript2")
13+
const postcss = require("rollup-plugin-postcss")
14+
const imagePlugin = require("@rollup/plugin-image")
915
const {DEFAULT_EXTENSIONS} = require("@babel/core")
10-
11-
const builtinModules = require("node:module").builtinModules
16+
const {getPackageRoot} = require("../util")
1217

1318
const SUPPRESSED_WARNING_CODES = [
1419
"MISSING_GLOBAL_NAME",
@@ -59,7 +64,15 @@ module.exports = function getInputOptions(package, build) {
5964
),
6065
]
6166

62-
const extensions = DEFAULT_EXTENSIONS.concat([".ts", ".tsx", ".mts", ".cts"])
67+
const extensions = DEFAULT_EXTENSIONS.concat([
68+
".ts",
69+
".tsx",
70+
".mts",
71+
".cts",
72+
".svg",
73+
])
74+
75+
const postcssConfigPath = path.resolve(getPackageRoot(), "postcss.config.js")
6376

6477
let options = {
6578
input: build.source,
@@ -69,12 +82,23 @@ module.exports = function getInputOptions(package, build) {
6982
console.warn(message.toString())
7083
},
7184
plugins: [
85+
imagePlugin(),
7286
nodeResolve({
7387
browser: true,
7488
preferBuiltins: build.type !== "umd",
7589
resolveOnly,
7690
extensions,
7791
}),
92+
fs.existsSync(postcssConfigPath)
93+
? postcss({
94+
inject: false,
95+
extensions: [".css"],
96+
minimize: true,
97+
config: {
98+
path: postcssConfigPath,
99+
},
100+
})
101+
: null,
78102
commonjs(),
79103
build.type !== "umd" &&
80104
isTypeScript &&

packages/fcl-bundle/src/get-package-json.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const {existsSync, readFileSync} = require("fs")
22
const {resolve} = require("path")
3+
const {getPackageRoot} = require("./util")
34

4-
module.exports = function getPackageJSON(cwd = process.cwd()) {
5-
const pathPackageJSON = resolve(cwd, "package.json")
5+
module.exports = function getPackageJSON() {
6+
const pathPackageJSON = resolve(getPackageRoot(), "package.json")
67
if (existsSync(pathPackageJSON)) {
78
return JSON.parse(readFileSync(pathPackageJSON))
89
} else {

packages/fcl-bundle/src/package-config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const assert = require("assert")
22
const {resolve, dirname, basename, join} = require("path")
3-
const {isArray, isObject, isString} = require("./util")
3+
const {isArray, isObject, isString, getPackageRoot} = require("./util")
44
const {existsSync, mkdirSync} = require("fs")
55

66
function determineBuildPaths(package, outputs, entryName) {
@@ -53,7 +53,7 @@ function determineBuildPaths(package, outputs, entryName) {
5353

5454
return Object.keys(outputs).map(type => ({
5555
type,
56-
dir: resolve(join(process.cwd(), dirname(outputs[type]))),
56+
dir: resolve(join(getPackageRoot(), dirname(outputs[type]))),
5757
entry: basename(outputs[type]),
5858
}))
5959
}

packages/fcl-bundle/src/util.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ function isString(obj) {
1010
return typeof obj === "string" || obj instanceof String
1111
}
1212

13+
// Get the root path of the package that the bundle is being built for
14+
function getPackageRoot() {
15+
return process.cwd()
16+
}
17+
1318
module.exports = {
1419
isArray,
1520
isObject,
1621
isString,
22+
getPackageRoot,
1723
}

packages/fcl-core/src/current-user/exec-service/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const execStrategy = async ({
1515
config,
1616
abortSignal,
1717
customRpc,
18-
opts,
1918
user,
19+
opts,
2020
}) => {
2121
const strategy = getServiceRegistry().getStrategy(service.method)
2222
return strategy({service, body, config, abortSignal, customRpc, opts, user})
@@ -70,6 +70,8 @@ export async function execService({
7070
config: execConfig,
7171
opts,
7272
abortSignal,
73+
platform,
74+
user,
7375
})
7476
} else {
7577
return res

packages/fcl-wc/.babelrc

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
{
2-
"presets": [["@babel/preset-env"], "@babel/preset-typescript"]
2+
"presets": [
3+
["@babel/preset-env"],
4+
[
5+
"@babel/preset-typescript",
6+
{
7+
"allowDeclareFields": true
8+
}
9+
]
10+
],
11+
"plugins": [
12+
[
13+
"@babel/plugin-transform-react-jsx",
14+
{
15+
"importSource": "preact",
16+
"runtime": "automatic"
17+
}
18+
]
19+
]
320
}

packages/fcl-wc/jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const config = {
2+
preset: "jest-preset-preact",
3+
moduleNameMapper: {
4+
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
5+
"<rootDir>/src/mocks/file-mock.ts",
6+
"\\.(css|less)$": "<rootDir>/src/mocks/file-mock.ts",
7+
},
8+
}
9+
10+
module.exports = config

packages/fcl-wc/package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@
2828
"lint": "eslint ."
2929
},
3030
"devDependencies": {
31+
"@babel/plugin-transform-react-jsx": "^7.25.9",
32+
"@babel/preset-typescript": "^7.25.7",
3133
"@onflow/fcl-bundle": "1.5.1-alpha.0",
34+
"@onflow/typedefs": "^1.4.0-alpha.1",
35+
"autoprefixer": "^10.4.20",
3236
"eslint": "^8.57.1",
3337
"eslint-plugin-jsdoc": "^46.10.1",
34-
"jest": "^29.7.0"
38+
"jest": "^29.7.0",
39+
"jest-preset-preact": "^4.1.1"
3540
},
3641
"dependencies": {
3742
"@babel/runtime": "^7.25.7",
@@ -42,7 +47,10 @@
4247
"@walletconnect/modal-core": "^2.6.2",
4348
"@walletconnect/sign-client": "^2.17.1",
4449
"@walletconnect/types": "^2.8.1",
45-
"@walletconnect/utils": "^2.8.1"
50+
"@walletconnect/utils": "^2.8.1",
51+
"postcss-cli": "^11.0.0",
52+
"preact": "^10.24.3",
53+
"tailwindcss": "^3.4.14"
4654
},
4755
"peerDependencies": {
4856
"@onflow/fcl-core": "1.13.0-alpha.4"

packages/fcl-wc/postcss.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const tailwindcss = require("tailwindcss")
2+
const tailwindConfig = require("./tailwind.config.js")
3+
const autoprefixer = require("autoprefixer")
4+
5+
module.exports = {
6+
plugins: [tailwindcss(tailwindConfig), autoprefixer],
7+
}

packages/fcl-wc/src/fcl-wc.ts

+7-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface FclWalletConnectConfig {
1313
wcRequestHook?: any
1414
pairingModalOverride?: any
1515
wallets?: any[]
16+
disableNotifications?: boolean
1617
}
1718

1819
const DEFAULT_RELAY_URL = "wss://relay.walletconnect.com"
@@ -70,14 +71,7 @@ export const init = async (config: FclWalletConnectConfig) => {
7071
}
7172
}
7273

73-
const initHelper = ({
74-
projectId,
75-
metadata,
76-
includeBaseWC = false,
77-
wcRequestHook = null,
78-
pairingModalOverride = null,
79-
wallets = [],
80-
}: FclWalletConnectConfig) => {
74+
const initHelper = (config: FclWalletConnectConfig) => {
8175
if (typeof window === "undefined") {
8276
throw new Error(
8377
"FCL Wallet Connect Plugin can only be initialized in the browser"
@@ -94,7 +88,10 @@ const initHelper = ({
9488
if (_client) {
9589
return _client
9690
} else {
97-
return initClient({projectId, metadata})
91+
return initClient({
92+
projectId: config.projectId,
93+
metadata: config.metadata,
94+
})
9895
}
9996
})
10097
.catch(e => {
@@ -106,13 +103,7 @@ const initHelper = ({
106103
throw e
107104
})
108105

109-
const FclWcServicePlugin = makeServicePlugin(clientPromise, {
110-
projectId,
111-
includeBaseWC,
112-
wcRequestHook,
113-
pairingModalOverride,
114-
wallets,
115-
})
106+
const FclWcServicePlugin = makeServicePlugin(clientPromise, config)
116107

117108
return {
118109
FclWcServicePlugin,
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "mocked-file"

0 commit comments

Comments
 (0)