Skip to content

Commit

Permalink
Merge pull request #153 from OneKeyHQ/support/lido
Browse files Browse the repository at this point in the history
chore: modify readme & adapter lido icon
  • Loading branch information
originalix authored Mar 11, 2024
2 parents 8e6a18f + 914d352 commit 68eec3d
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# - macOS-latest
node_version:
# - 14
- 16
- 18

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```


5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"name": "cross-inpage-provider",
"engines": {
"node": "^14 || ^16 || ^19"
"node": "^16 || ^18 || ^20"
},
"scripts": {
"bootstrap": "lerna bootstrap",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/versionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const version = '1.1.53';
const version = '1.1.55';
const versionBuild = '2020-0101-1';

export default {
Expand Down
3 changes: 2 additions & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ import './sites/ord';
import './sites/ordinalswallet';
import './sites/ordinalsmarket';
import './sites/sating';
import './sites/lidofi';
// TODO list ----------------------------------------------
Original file line number Diff line number Diff line change
@@ -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,
});
}
},
});
Original file line number Diff line number Diff line change
@@ -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,
});
}
},
});
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 68eec3d

Please sign in to comment.