diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 21e43ee7..4ccddfc9 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -19,7 +19,7 @@ jobs: # - macOS-latest node_version: # - 14 - - 16 + - 18 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/publish-packages.yml b/.github/workflows/publish-packages.yml index 7d2f5788..bcbdea1a 100644 --- a/.github/workflows/publish-packages.yml +++ b/.github/workflows/publish-packages.yml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-node@v2 with: - node-version: '16.x' + node-version: '18.x' registry-url: 'https://registry.npmjs.org' - name: Install Packages diff --git a/.github/workflows/test_web.yml b/.github/workflows/test_web.yml index 406e133e..5f68bb55 100644 --- a/.github/workflows/test_web.yml +++ b/.github/workflows/test_web.yml @@ -18,7 +18,7 @@ jobs: - name: Setup Environment uses: actions/setup-node@v2 with: - node-version: 16.x + node-version: 18.x registry-url: 'https://registry.npmjs.org' - name: Install Dependency diff --git a/README.md b/README.md index 3baf98b1..5517eae3 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,46 @@ [OneKey DApp Example](https://dapp-example.onekeytest.com/) -``` -# init monorepo + +# Init monorepo +```bash yarn yarn bootstrap yarn build +``` + +# Develop monorepo +```bash +# Clean cache +yarn clean && yarn bootstrap + +# Start watch and build all packages +yarn start -# watch and build -yarn clean && yarn bootstrap && yarn start +# check and configure .env file +# if not exist, copy .env.example to .env +# if exist, check and update APP_MONOREPO_LOCAL_PATH +APP_MONOREPO_LOCAL_PATH=/path/to/your/app-monorepo # watch and build `packages/injected`, then rsync local npm packages to app-monorepo # re-build `packages/injected` only, if you change others monorepo code, run `yarn build` +# open new terminal yarn gulp-watch +``` -# run dapp example web +# Run dapp example web +```bash yarn example +``` -# update all versions before publish +# Update all versions before publish +```bash yarn update-version 1.0.1 +``` -# publish to npmjs.com +# Publish to npmjs.com +```bash yarn publish-packages ``` + diff --git a/package.json b/package.json index 135f41d0..c3c29b62 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "private": true, "name": "cross-inpage-provider", "engines": { - "node": "^14 || ^16 || ^19" + "node": "^16 || ^18 || ^20" }, "scripts": { "bootstrap": "lerna bootstrap", @@ -13,7 +13,7 @@ "test": "jest", "build": "lerna run build --ignore @onekeyfe/cross-inpage-provider-example", "prestart": "yarn build", - "start": "lerna run start --parallel --ignore @onekeyfe/cross-inpage-provider-example", + "start": "cross-env NODE_OPTIONS=--openssl-legacy-provider lerna run start --parallel --ignore @onekeyfe/cross-inpage-provider-example", "start-all": "lerna run start --parallel", "dev": "yarn bootstrap && yarn start-all", "prepack": "yarn build", @@ -37,6 +37,7 @@ "@typescript-eslint/eslint-plugin": "^5.7.0", "@typescript-eslint/parser": "^5.7.0", "concurrently": "^7.1.0", + "cross-env": "^7.0.3", "dotenv": "^16.0.3", "eslint": "^8.4.1", "eslint-plugin-react": "^7.29.4", diff --git a/packages/core/src/versionInfo.ts b/packages/core/src/versionInfo.ts index eee7efd0..e53db754 100644 --- a/packages/core/src/versionInfo.ts +++ b/packages/core/src/versionInfo.ts @@ -1,5 +1,5 @@ -const version = '1.1.53'; +const version = '1.1.55'; const versionBuild = '2020-0101-1'; export default { diff --git a/packages/example/package.json b/packages/example/package.json index d40afdd8..b7d839cc 100644 --- a/packages/example/package.json +++ b/packages/example/package.json @@ -6,7 +6,7 @@ "postinstall": "patch-package", "dev": "next dev", "start": "next dev", - "build": "next build && next export", + "build": "cross-env NODE_OPTIONS=--openssl-legacy-provider next build && next export", "start-web": "next start", "lint": "next lint", "clean": "rm -rf ./node_modules && rm -rf ./.next && rm -rf ./out", @@ -66,6 +66,7 @@ "@types/node": "17.0.18", "@types/react": "18.2.37", "@types/uuid": "^8.3.4", + "cross-env": "^7.0.3", "eslint": "8.53.0", "eslint-config-next": "13.5.6", "next-compose-plugins": "^2.2.1", diff --git a/packages/providers/inpage-providers-hub/src/connectButtonHack/index.ts b/packages/providers/inpage-providers-hub/src/connectButtonHack/index.ts index d95e4c14..0b5a9761 100644 --- a/packages/providers/inpage-providers-hub/src/connectButtonHack/index.ts +++ b/packages/providers/inpage-providers-hub/src/connectButtonHack/index.ts @@ -25,4 +25,5 @@ import './sites/ord'; import './sites/ordinalswallet'; import './sites/ordinalsmarket'; import './sites/sating'; +import './sites/lidofi'; // TODO list ---------------------------------------------- diff --git a/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/_template.ts b/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/_template.ts new file mode 100644 index 00000000..b28ac8e5 --- /dev/null +++ b/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/_template.ts @@ -0,0 +1,65 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { createNewImageToContainer, hackConnectButton } from '../hackConnectButton'; +import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types'; +import { WALLET_CONNECT_INFO } from '../consts'; + +hackConnectButton({ + urls: ['stake.lido.fi'], // adapter to the site url, can have multiple urls. + providers: [IInjectedProviderNames.ethereum], // provider class, example: IInjectedProviderNames.ethereum、IInjectedProviderNames.btc + replaceMethod(options) { + const replaceFunc = ({ + findName, + icon, + text, + }: { + findName: string; + icon: string; + text: string; + }) => { + // find connect wallet button + document.querySelector('div'); + document.querySelectorAll('div'); + + // change button text + // #1 nodeValue + // element.nodeValue = text; + + // # 2 innerHTML + // element.innerHTML = text; + + // change icon + // #1 img element + // element.src = icon; + + // #2 svg element + // create new image + // const imgContainer = findButton.querySelector('container') as HTMLElement | undefined; + // if (imgContainer) { + // createNewImageToContainer({ + // container: imgContainer, + // icon: icon, + // removeSvg: true, + // onCreated(img) { + // img.style.maxWidth = '48px'; + // img.style.maxHeight = '48px'; + // }, + // }); + // } + }; + + // Check whether the provider is enabled in the app. + if (options?.providers?.includes(IInjectedProviderNames.ethereum)) { + // Replace the button text and icon. + replaceFunc({ + findName: 'MetaMask', + icon: WALLET_CONNECT_INFO.metamask.icon, + text: WALLET_CONNECT_INFO.metamask.text, + }); + replaceFunc({ + findName: 'WalletConnect', + icon: WALLET_CONNECT_INFO.walletconnect.icon, + text: WALLET_CONNECT_INFO.walletconnect.text, + }); + } + }, +}); diff --git a/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/lidofi.ts b/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/lidofi.ts new file mode 100644 index 00000000..f77ef687 --- /dev/null +++ b/packages/providers/inpage-providers-hub/src/connectButtonHack/sites/lidofi.ts @@ -0,0 +1,71 @@ +import { createNewImageToContainer, hackConnectButton } from '../hackConnectButton'; +import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types'; +import { WALLET_CONNECT_INFO } from '../consts'; + +hackConnectButton({ + urls: ['stake.lido.fi'], + providers: [IInjectedProviderNames.ethereum], + replaceMethod(options) { + const replaceFunc = ({ + findName, + icon, + text, + }: { + findName: string; + icon: string; + text: string; + }) => { + const buttons = Array.from( + document.querySelector('div.idjqeC')?.querySelectorAll('button') ?? [], + ); + + const findButton = buttons.find((button) => { + const span = button.querySelector('span > span > div') as HTMLElement | undefined; + if (span && span.innerText === findName) { + return button; + } + return undefined; + }); + + console.log('====findButton', findButton); + + + if (findButton) { + // change button text + const span = findButton.querySelector('div') as HTMLElement | undefined; + if (span) { + span.innerText = text; + } + + // change icon + const imgContainer = findButton.querySelector('span > span >span') as + | HTMLElement + | undefined; + if (imgContainer) { + createNewImageToContainer({ + container: imgContainer, + icon: icon, + removeSvg: true, + onCreated(img) { + img.style.maxWidth = '48px'; + img.style.maxHeight = '48px'; + }, + }); + } + } + }; + + if (options?.providers?.includes(IInjectedProviderNames.ethereum)) { + replaceFunc({ + findName: 'MetaMask', + icon: WALLET_CONNECT_INFO.metamask.icon, + text: WALLET_CONNECT_INFO.metamask.text, + }); + replaceFunc({ + findName: 'WalletConnect', + icon: WALLET_CONNECT_INFO.walletconnect.icon, + text: WALLET_CONNECT_INFO.walletconnect.text, + }); + } + }, +}); diff --git a/yarn.lock b/yarn.lock index ab493032..6ec9c532 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2805,7 +2805,14 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cross-spawn@^7.0.2, cross-spawn@^7.0.3: +cross-env@^7.0.3: + version "7.0.3" + resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf" + integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw== + dependencies: + cross-spawn "^7.0.1" + +cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6" integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==