Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKG -- [FCL-WC] Add notifications for pending WC/RPC requests #1970

Merged
merged 14 commits into from
Nov 21, 2024
5 changes: 5 additions & 0 deletions .changeset/brown-bobcats-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl-bundle": minor
---

Add `rollup-plugin-postcss` & `@rollup/plugin-image`
5 changes: 5 additions & 0 deletions .changeset/little-spies-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl-wc": minor
---

Add UI notifications for pending requests
5 changes: 5 additions & 0 deletions .changeset/poor-carrots-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": minor
---

Add `walletconnect.disableNotifications` config option to disable WC notification UI
5 changes: 5 additions & 0 deletions .changeset/rare-apes-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/typedefs": patch
---

Fix CurrentUser services type
5 changes: 5 additions & 0 deletions .changeset/rotten-paws-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl-core": patch
---

Pass missing fields to service redirects in execService
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"semi": false,
"trailingComma": "es5",
"bracketSpacing": false,
"arrowParens": "avoid"
"arrowParens": "avoid",
"plugins": ["prettier-plugin-tailwindcss", "prettier-plugin-classnames"]
}
10,316 changes: 4,652 additions & 5,664 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"jest-environment-jsdom": "^29.7.0",
"lerna": "^8.1.8",
"prettier": "^3.3.3",
"prettier-plugin-classnames": "^0.7.3",
"prettier-plugin-tailwindcss": "^0.6.8",
"ts-jest": "^29.2.5",
"typescript": "^5.6.3"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/fcl-bundle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ A source configuration can be provided in one of three ways:
## Features
- Replace `PACKAGE_CURRENT_VERSION` in bundled code with the current `version` of the package being bundled from `package.json`
- Bundles dependencies with UMD builds for use in browser
- Transpiles output bundles using `@babel/preset-env` and [babel rollup plugin](https://www.npmjs.com/package/@rollup/plugin-babel)
- Transpiles output bundles using `@babel/preset-env` and [babel rollup plugin](https://www.npmjs.com/package/@rollup/plugin-babel)
- PostCSS support for CSS bundling, must include a `postcss.config.js` in the root of the package
- Images are bundled with the `@rollup/plugin-image` plugin as base64 strings
- Minification of bundles with `terser` if output paths end in ".min.js"
- TypeScript support if entry point is a `.ts` file
5 changes: 5 additions & 0 deletions packages/fcl-bundle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@
"@babel/preset-typescript": "^7.25.7",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^28.0.1",
"@rollup/plugin-image": "^3.0.3",
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-replace": "^6.0.1",
"@rollup/plugin-terser": "^0.4.4",
"commander": "^12.1.0",
"lodash": "^4.17.21",
"rollup": "^4.24.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-typescript2": "^0.36.0"
},
"bin": {
"fcl-bundle": "src/cli.js"
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "^4.26.0"
}
}
30 changes: 27 additions & 3 deletions packages/fcl-bundle/src/build/get-input-options.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const _ = require("lodash")

const path = require("path")
const fs = require("fs")
const builtinModules = require("node:module").builtinModules

const commonjs = require("@rollup/plugin-commonjs")
const replace = require("@rollup/plugin-replace")
const {nodeResolve} = require("@rollup/plugin-node-resolve")
const {babel} = require("@rollup/plugin-babel")
const terser = require("@rollup/plugin-terser")
const typescript = require("rollup-plugin-typescript2")
const postcss = require("rollup-plugin-postcss")
const imagePlugin = require("@rollup/plugin-image")
const {DEFAULT_EXTENSIONS} = require("@babel/core")

const builtinModules = require("node:module").builtinModules
const {getPackageRoot} = require("../util")

const SUPPRESSED_WARNING_CODES = [
"MISSING_GLOBAL_NAME",
Expand Down Expand Up @@ -59,7 +64,15 @@ module.exports = function getInputOptions(package, build) {
),
]

const extensions = DEFAULT_EXTENSIONS.concat([".ts", ".tsx", ".mts", ".cts"])
const extensions = DEFAULT_EXTENSIONS.concat([
".ts",
".tsx",
".mts",
".cts",
".svg",
])

const postcssConfigPath = path.resolve(getPackageRoot(), "postcss.config.js")

let options = {
input: build.source,
Expand All @@ -69,12 +82,23 @@ module.exports = function getInputOptions(package, build) {
console.warn(message.toString())
},
plugins: [
imagePlugin(),
nodeResolve({
browser: true,
preferBuiltins: build.type !== "umd",
resolveOnly,
extensions,
}),
fs.existsSync(postcssConfigPath)
? postcss({
inject: false,
extensions: [".css"],
minimize: true,
config: {
path: postcssConfigPath,
},
})
: null,
commonjs(),
build.type !== "umd" &&
isTypeScript &&
Expand Down
5 changes: 3 additions & 2 deletions packages/fcl-bundle/src/get-package-json.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const {existsSync, readFileSync} = require("fs")
const {resolve} = require("path")
const {getPackageRoot} = require("./util")

module.exports = function getPackageJSON(cwd = process.cwd()) {
const pathPackageJSON = resolve(cwd, "package.json")
module.exports = function getPackageJSON() {
const pathPackageJSON = resolve(getPackageRoot(), "package.json")
if (existsSync(pathPackageJSON)) {
return JSON.parse(readFileSync(pathPackageJSON))
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/fcl-bundle/src/package-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require("assert")
const {resolve, dirname, basename, join} = require("path")
const {isArray, isObject, isString} = require("./util")
const {isArray, isObject, isString, getPackageRoot} = require("./util")
const {existsSync, mkdirSync} = require("fs")

function determineBuildPaths(package, outputs, entryName) {
Expand Down Expand Up @@ -53,7 +53,7 @@ function determineBuildPaths(package, outputs, entryName) {

return Object.keys(outputs).map(type => ({
type,
dir: resolve(join(process.cwd(), dirname(outputs[type]))),
dir: resolve(join(getPackageRoot(), dirname(outputs[type]))),
entry: basename(outputs[type]),
}))
}
Expand Down
6 changes: 6 additions & 0 deletions packages/fcl-bundle/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ function isString(obj) {
return typeof obj === "string" || obj instanceof String
}

// Get the root path of the package that the bundle is being built for
function getPackageRoot() {
return process.cwd()
}

module.exports = {
isArray,
isObject,
isString,
getPackageRoot,
}
4 changes: 3 additions & 1 deletion packages/fcl-core/src/current-user/exec-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const execStrategy = async ({
config,
abortSignal,
customRpc,
opts,
user,
opts,
}) => {
const strategy = getServiceRegistry().getStrategy(service.method)
return strategy({service, body, config, abortSignal, customRpc, opts, user})
Expand Down Expand Up @@ -70,6 +70,8 @@ export async function execService({
config: execConfig,
opts,
abortSignal,
platform,
user,
})
} else {
return res
Expand Down
19 changes: 18 additions & 1 deletion packages/fcl-wc/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
{
"presets": [["@babel/preset-env"], "@babel/preset-typescript"]
"presets": [
["@babel/preset-env"],
[
"@babel/preset-typescript",
{
"allowDeclareFields": true
}
]
],
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"importSource": "preact",
"runtime": "automatic"
}
]
]
}
10 changes: 10 additions & 0 deletions packages/fcl-wc/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const config = {
preset: "jest-preset-preact",
moduleNameMapper: {
"\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$":
"<rootDir>/src/mocks/file-mock.ts",
"\\.(css|less)$": "<rootDir>/src/mocks/file-mock.ts",
},
}

module.exports = config
12 changes: 10 additions & 2 deletions packages/fcl-wc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@
"lint": "eslint ."
},
"devDependencies": {
"@babel/plugin-transform-react-jsx": "^7.25.9",
"@babel/preset-typescript": "^7.25.7",
"@onflow/fcl-bundle": "1.5.1-alpha.0",
"@onflow/typedefs": "^1.4.0-alpha.1",
"autoprefixer": "^10.4.20",
"eslint": "^8.57.1",
"eslint-plugin-jsdoc": "^46.10.1",
"jest": "^29.7.0"
"jest": "^29.7.0",
"jest-preset-preact": "^4.1.1"
},
"dependencies": {
"@babel/runtime": "^7.25.7",
Expand All @@ -42,7 +47,10 @@
"@walletconnect/modal-core": "^2.6.2",
"@walletconnect/sign-client": "^2.17.1",
"@walletconnect/types": "^2.8.1",
"@walletconnect/utils": "^2.8.1"
"@walletconnect/utils": "^2.8.1",
"postcss-cli": "^11.0.0",
"preact": "^10.24.3",
"tailwindcss": "^3.4.14"
},
"peerDependencies": {
"@onflow/fcl-core": "1.13.0-alpha.4"
Expand Down
7 changes: 7 additions & 0 deletions packages/fcl-wc/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const tailwindcss = require("tailwindcss")
const tailwindConfig = require("./tailwind.config.js")
const autoprefixer = require("autoprefixer")

module.exports = {
plugins: [tailwindcss(tailwindConfig), autoprefixer],
}
23 changes: 7 additions & 16 deletions packages/fcl-wc/src/fcl-wc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface FclWalletConnectConfig {
wcRequestHook?: any
pairingModalOverride?: any
wallets?: any[]
disableNotifications?: boolean
}

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

const initHelper = ({
projectId,
metadata,
includeBaseWC = false,
wcRequestHook = null,
pairingModalOverride = null,
wallets = [],
}: FclWalletConnectConfig) => {
const initHelper = (config: FclWalletConnectConfig) => {
if (typeof window === "undefined") {
throw new Error(
"FCL Wallet Connect Plugin can only be initialized in the browser"
Expand All @@ -94,7 +88,10 @@ const initHelper = ({
if (_client) {
return _client
} else {
return initClient({projectId, metadata})
return initClient({
projectId: config.projectId,
metadata: config.metadata,
})
}
})
.catch(e => {
Expand All @@ -106,13 +103,7 @@ const initHelper = ({
throw e
})

const FclWcServicePlugin = makeServicePlugin(clientPromise, {
projectId,
includeBaseWC,
wcRequestHook,
pairingModalOverride,
wallets,
})
const FclWcServicePlugin = makeServicePlugin(clientPromise, config)

return {
FclWcServicePlugin,
Expand Down
1 change: 1 addition & 0 deletions packages/fcl-wc/src/mocks/file-mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "mocked-file"
Loading
Loading