Skip to content

Commit

Permalink
chore: format all files according tolatest prettier config:wq
Browse files Browse the repository at this point in the history
  • Loading branch information
danforbes authored and krzysu committed Oct 29, 2024
1 parent 169b12c commit f3a81e1
Show file tree
Hide file tree
Showing 35 changed files with 328 additions and 374 deletions.
100 changes: 50 additions & 50 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,53 @@ on:
- '**'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: yarn
node-version: '18'
- name: Install deps
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Lint
run: yarn run lint
- name: Tests
run: yarn run test

maybe-release:
name: release
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: release-please-action
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true}]'
- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}
- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 18
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}
- run: yarn install --frozen-lockfile
if: ${{ steps.release.outputs.release_created }}
- run: yarn build
if: ${{ steps.release.outputs.release_created }}

- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
cache: yarn
node-version: '18'
- name: Install deps
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Lint
run: yarn run lint
- name: Tests
run: yarn run test

maybe-release:
name: release
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: release-please-action
changelog-types: '[{"type":"feat","section":"Features","hidden":false},{"type":"fix","section":"Bug Fixes","hidden":false},{"type":"chore","section":"Miscellaneous","hidden":true}]'

- uses: actions/checkout@v3
if: ${{ steps.release.outputs.release_created }}

- uses: actions/setup-node@v3
with:
cache: 'yarn'
node-version: 18
registry-url: 'https://registry.npmjs.org'
if: ${{ steps.release.outputs.release_created }}

- run: yarn install --frozen-lockfile
if: ${{ steps.release.outputs.release_created }}

- run: yarn build
if: ${{ steps.release.outputs.release_created }}

- run: yarn publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
if: ${{ steps.release.outputs.release_created }}
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ permissions:
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
group: 'pages'
cancel-in-progress: false

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr_title.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Semantic PR"
name: 'Semantic PR'

on:
pull_request_target:
Expand Down
8 changes: 7 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"trailingComma": "all"
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"printWidth": 90,
"tabWidth": 2,
"endOfLine": "auto",
"bracketSpacing": true
}
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pnpm add web3-plugin-wallet-rpc
### Register plugin

```typescript
import { Web3 } from "web3";
import { WalletRpcPlugin } from "web3-plugin-wallet-rpc";
import { Web3 } from 'web3';
import { WalletRpcPlugin } from 'web3-plugin-wallet-rpc';

const web3 = new Web3("https://eth.llamarpc.com");
const web3 = new Web3('https://eth.llamarpc.com');
web3.registerPlugin(new WalletRpcPlugin());
```

Expand All @@ -51,15 +51,15 @@ Invokes the `wallet_addEthereumChain` method as defined in [EIP-3085](https://ei
```typescript
await web3.walletRpc.addEthereumChain({
chainId: 5000,
blockExplorerUrls: ["https://mantlescan.xyz"],
chainName: "Mantle",
iconUrls: ["https://icons.llamao.fi/icons/chains/rsz_mantle.jpg"],
blockExplorerUrls: ['https://mantlescan.xyz'],
chainName: 'Mantle',
iconUrls: ['https://icons.llamao.fi/icons/chains/rsz_mantle.jpg'],
nativeCurrency: {
name: "Mantle",
symbol: "MNT",
name: 'Mantle',
symbol: 'MNT',
decimals: 18,
},
rpcUrls: ["https://rpc.mantle.xyz"],
rpcUrls: ['https://rpc.mantle.xyz'],
});
```

Expand All @@ -77,10 +77,10 @@ Invokes the `wallet_watchAsset` method as defined in [EIP-747](https://eips.ethe

```typescript
await web3.walletRpc.watchAsset({
type: "ERC20",
type: 'ERC20',
options: {
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
symbol: "USDC",
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
symbol: 'USDC',
},
});
```
Expand Down Expand Up @@ -122,14 +122,14 @@ Invokes the `wallet_updateEthereumChain` method as defined in [EIP-2015](https:/
```typescript
await web3.walletRpc.updateEthereumChain({
chainId: 5000,
blockExplorerUrls: ["https://mantlescan.xyz"],
chainName: "Mantle",
blockExplorerUrls: ['https://mantlescan.xyz'],
chainName: 'Mantle',
nativeCurrency: {
name: "Mantle",
symbol: "MNT",
name: 'Mantle',
symbol: 'MNT',
decimals: 18,
},
rpcUrls: ["https://rpc.mantle.xyz"],
rpcUrls: ['https://rpc.mantle.xyz'],
});
```

Expand All @@ -139,7 +139,7 @@ Invokes the `wallet_getOwnedAssets` method as defined in [EIP-2256](https://eips

```typescript
const ownedAssets = await web3.walletRpc.getOwnedAssets({
address: "0xa5653e88D9c352387deDdC79bcf99f0ada62e9c6",
address: '0xa5653e88D9c352387deDdC79bcf99f0ada62e9c6',
});
```

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
],
"packageManager": "[email protected]",
"scripts": {
"lint": "cd packages/web3-plugin-wallet-rpc && yarn lint",
"build": "cd packages/web3-plugin-wallet-rpc && yarn build",
"build:docs": "cd packages/web3-plugin-wallet-rpc && yarn build:docs",
"test": "cd packages/web3-plugin-wallet-rpc && yarn test",
"lint": "yarn lint:plugin && yarn lint:example",
"lint:plugin": "cd packages/web3-plugin-wallet-rpc && yarn lint",
"lint:example": "cd packages/example-react-app && yarn lint",
"format": "prettier --write .",
"start:example": "cd packages/example-react-app && yarn start"
},
"devDependencies": {
"prettier": "^3.3.3"
}
}
18 changes: 10 additions & 8 deletions packages/example-react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
],
"license": "MIT",
"dependencies": {
"@types/node": "^16.18.108",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"typescript": "5.3.x",
"uuid": "^10.0.0",
"web3": "^4.14.0",
"web3-eth": "^4.9.0",
"web3-plugin-wallet-rpc": "*"
},
"devDependencies": {
"@types/node": "^16.18.108",
"@types/react": "^18.3.8",
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
"eslint": "8",
"react-scripts": "5.0.1",
"typescript": "5.3.x"
},
"scripts": {
"start": "react-scripts start",
"lint": "eslint 'src/**/*.{ts,tsx}'"
"lint": "eslint 'src/**/*.{js,ts,tsx}'"
},
"eslintConfig": {
"extends": [
Expand Down
7 changes: 2 additions & 5 deletions packages/example-react-app/public/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web3.js Wallet RPC Methods Demonstration dApp"
/>
<meta name="description" content="Web3.js Wallet RPC Methods Demonstration dApp" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand Down
29 changes: 10 additions & 19 deletions packages/example-react-app/src/AccountDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
type MutableRefObject,
useContext,
useEffect,
useRef,
useState,
} from "react";
import { type MutableRefObject, useContext, useEffect, useRef, useState } from 'react';

import { type IWeb3Context, Web3Context } from "./web3/Web3Context";
import { type IWeb3Context, Web3Context } from './web3/Web3Context';

function AccountDetail({ address }: { address: string }) {
const web3Context: IWeb3Context = useContext(Web3Context);

const [balance, setBalance] = useState<number>(NaN);
const subscriptionId: MutableRefObject<string | undefined> =
useRef(undefined);
const subscriptionId: MutableRefObject<string | undefined> = useRef(undefined);

// update balance
useEffect(() => {
Expand All @@ -23,25 +16,23 @@ function AccountDetail({ address }: { address: string }) {
return;
}

web3Context.web3.eth
.subscribe("newBlockHeaders")
.then((newBlockSubscription) => {
subscriptionId.current = newBlockSubscription.id;
newBlockSubscription.on("data", () => {
updateBalance();
});
web3Context.web3.eth.subscribe('newBlockHeaders').then((newBlockSubscription) => {
subscriptionId.current = newBlockSubscription.id;
newBlockSubscription.on('data', () => {
updateBalance();
});
});

return () => {
web3Context.web3.eth.subscriptionManager.unsubscribe(
({ id }) => subscriptionId.current === id
({ id }) => subscriptionId.current === id,
);
};
});

function updateBalance(): void {
web3Context.web3.eth.getBalance(address).then((balance: bigint) => {
setBalance(parseFloat(web3Context.web3.utils.fromWei(balance, "ether")));
setBalance(parseFloat(web3Context.web3.utils.fromWei(balance, 'ether')));
});
}

Expand Down
19 changes: 6 additions & 13 deletions packages/example-react-app/src/Accounts.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useContext } from "react";
import { AccountContext, type IAccountContext } from "./web3/AccountContext";
import AccountDetail from "./AccountDetail";
import { useContext } from 'react';
import { AccountContext, type IAccountContext } from './web3/AccountContext';
import AccountDetail from './AccountDetail';

function Accounts() {
const accountContext: IAccountContext = useContext(AccountContext);
Expand All @@ -10,23 +10,16 @@ function Accounts() {
<h2>Accounts</h2>
<div>
{accountContext.selectedAccount === undefined ? (
<button onClick={accountContext.requestAccounts}>
Connect Accounts
</button>
<button onClick={accountContext.requestAccounts}>Connect Accounts</button>
) : (
<>
<h3>Selected Account</h3>
<AccountDetail
address={accountContext.selectedAccount}
></AccountDetail>
<AccountDetail address={accountContext.selectedAccount}></AccountDetail>
{accountContext.accounts.length > 1 ? (
<>
<h3>Other Accounts</h3>
{accountContext.accounts.slice(1).map((account: string) => (
<AccountDetail
address={account}
key={account}
></AccountDetail>
<AccountDetail address={account} key={account}></AccountDetail>
))}
</>
) : null}
Expand Down
Loading

0 comments on commit f3a81e1

Please sign in to comment.