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

Rocky/web wallet #774

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions advanced/wallets/reown-web-wallet/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NEXT_PUBLIC_PROJECT_ID=
NEXT_PUBLIC_RELAY_URL=wss://relay.walletconnect.com
NEXT_PUBLIC_PIMLICO_KEY=
NEXT_PUBLIC_ZERODEV_PROJECT_ID=
12 changes: 12 additions & 0 deletions advanced/wallets/reown-web-wallet/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["next/core-web-vitals","prettier"],
"ignorePatterns": ["next.config.js"],
"overrides": [
{
"extends": ["plugin:package-json/recommended"],
"files": ["package.json"],
"parser": "jsonc-eslint-parser",
"plugins": ["package-json"]
}
]
}
36 changes: 36 additions & 0 deletions advanced/wallets/reown-web-wallet/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

.DS_Store

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
5 changes: 5 additions & 0 deletions advanced/wallets/reown-web-wallet/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.changeset
coverage
.idea
.next
node_modules
9 changes: 9 additions & 0 deletions advanced/wallets/reown-web-wallet/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"arrowParens": "avoid",
"parser": "typescript",
"printWidth": 100,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"semi": false
}
139 changes: 139 additions & 0 deletions advanced/wallets/reown-web-wallet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Wallet Example (React, Typescript, Ethers, NextJS, Cosmos)

This example aims to demonstrate basic and advanced use cases enabled by WalletConnect's Sign SDK.

**The wallet implements Sign v1 and v2 side-by-side**, to serve as a reference for wallet developers
aiming to support both major versions for backwards compatibility. **All files containing code for the legacy
v1 implementation are prefixed with `Legacy...`.**

Please only use this for reference and development purposes, otherwise you are at risk of losing your funds.

# Useful links

🔗 Live wallet app - https://react-wallet.walletconnect.com <br />
🔗 Live dapp - https://react-app.walletconnect.com <br />
📚 WalletConnect docs - https://docs.walletconnect.com/2.0

## Getting started

Example is built atop of [NextJS](https://nextjs.org/) in order to abstract complexity of setting up bundlers, routing etc. So there are few steps you need to follow in order to set everything up

1. Go to [WalletConnect Cloud](https://cloud.walletconnect.com/sign-in) and obtain a project id

2. Add your project details in [WalletConnectUtil.ts](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/utils/WalletConnectUtil.ts) file

3. Install dependencies `yarn install` or `npm install`

4. Setup your environment variables

```bash
cp .env.local.example .env.local
```

Your `.env.local` now contains the following environment variables:

- `NEXT_PUBLIC_PROJECT_ID` (placeholder) - You can generate your own ProjectId at https://cloud.walletconnect.com
- `NEXT_PUBLIC_RELAY_URL` (already set)

5. Run `yarn dev` or `npm run dev` to start local development

## Navigating through example

1. Initial setup and initializations happen in [_app.ts](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/pages/_app.tsx) file
2. WalletConnect client, ethers and cosmos wallets are initialized in [useInitialization.ts ](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/hooks/useInitialization.ts) hook
3. Subscription and handling of WalletConnect events happens in [useWalletConnectEventsManager.ts](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/hooks/useWalletConnectEventsManager.ts) hook, that opens related [Modal views](https://github.com/WalletConnect/web-examples/tree/main/wallets/react-wallet-v2/src/views) and passes them all necessary data
4. [Modal views](https://github.com/WalletConnect/web-examples/tree/main/wallets/react-wallet-v2/src/views) are responsible for data display and handling approval or rejection actions
5. Upon approval or rejection, modals pass the request data to [RequestHandlerUtil.ts](https://github.com/WalletConnect/web-examples/blob/main/wallets/react-wallet-v2/src/utils/RequestHandlerUtil.ts) that performs all necessary work based on the request method and returns formated json rpc result data that can be then used for WalletConnect client responses

## Preview of wallet and dapp examples in action

https://user-images.githubusercontent.com/3154053/156764521-3492c232-7a93-47ba-88bd-2cee3f8366d4.mp4

## DOM Tags
This section is a key of the DOM elements used for internal E2E testing
Accessible with `data-testid`

### Navbar
| Key | Description |
| ----------- | ----------- |
| `accounts` | Accounts page |
| `sessions` | Sessions page |
| `wc-connect` | WC Connect page |
| `pairings` | Pairings page |
| `settings` | Settings Page |

### WC Connect Page
url: `/walletconnect`
| Key | Description |
| ----------- | ----------- |
| `uri-input` | Uri textbox |
| `uri-connect-button` | Uri connect button |
| `qrcode-button` | Use qrcode button |

### Sessions Page
url: `/session`
| Key | Description |
| ----------- | ----------- |
| `session-card` | Session cards can be accessed by topic |
| `session-icon` | Icon used on session card |
| `session-text` | Text listed on session card |
| `session-link` | Link listed on session card |

### Session Details Page
url: `/session?topic=`
| Key | Description |
| ----------- | ----------- |
| `session-card-${chain}` | Session chain info card |
| `session-delete-button` | Session delete button |
| `session-ping-button` | Session ping button |
| `session-emit-button` | Session emit button |
| `session-update-button` | Session update button |

### Pairing Page
url: `/pairings`
| Key | Description |
| ----------- | ----------- |
| `pairing-${topic}` | Pairing cards can be accessed by topic |
| `pairing-text-${topic}` | Pairing card text in label |
| `pairing-url-${topic}` | Pairing card link in label|
| `pairing-delete-${topic}` | Delete pairing by topic |


### Accounts Page
url: `/`
| Key | Description |
| ----------- | ----------- |
| `account-picker` | Account drop down selector|
| `chain-card-${chain id}` | Chain card by chain id |
| `chain-switch-button-${chain id}` | Chain switch button |
| `chain-switch-button-${chain id}` | Chain copy button |

### Settings Page
url: `/settings`
| Key | Description |
| ----------- | ----------- |
| `settings-toggle-testnets` | Toggle testnet support on/off |
| `settings-region-select` | Select relayer region |

### Session Proposal View
| Key | Description |
| ----------- | ----------- |
| `session-approve-button` | Session approve button |
| `session-reject-button` | Session reject button |
| `session-info-card-text` | Session text info in header |
| `session-info-card-url` | Session info url in header |
| `session-info-card-verify` | Session info verify api in header |
| `session-proposal-card-req-{chain}` | Session card for each required chain |
| `session-proposal-card-opt-{chain}` | Session card for each optional chain |
| `account-select-card-${req/opt}-${index}` | Account selection checkbox by account index|
| `account-select-text-${req/opt}-${index}` | Account selection text by account index |


### Sign Request View
| Key | Description |
| ----------- | ----------- |
| `request-details-chain` | List of chains in the request |
| `request-details-relay-protocol` | Protocol used for request |
| `request-methods` | Methods requested |
| `request-button-reject` | Reject button |
| `request-button-approve` | Approve button |
5 changes: 5 additions & 0 deletions advanced/wallets/reown-web-wallet/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
11 changes: 11 additions & 0 deletions advanced/wallets/reown-web-wallet/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
reactStrictMode: true,
webpack(config) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false
}

return config
}
}
69 changes: 69 additions & 0 deletions advanced/wallets/reown-web-wallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "react-wallet-v2",
"private": true,
"scripts": {
"dev": "next dev -p 3001",
"build": "next build",
"start": "next start",
"lint": "next lint",
"prettier": "prettier --check '**/*.{js,ts,jsx,tsx}'",
"prettier:write": "prettier --write '**/*.{js,ts,jsx,tsx}'"
},
"dependencies": {
"@cosmjs/amino": "0.32.3",
"@cosmjs/encoding": "0.32.3",
"@cosmjs/proto-signing": "0.32.3",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@json-rpc-tools/utils": "1.7.6",
"@kadena/cryptography-utils": "^0.4.0",
"@kadena/types": "^0.6.0",
"@material-ui/core": "^4.12.4",
"@material-ui/icons": "^4.11.3",
"@mui/icons-material": "^5.14.9",
"@mui/material": "^5.14.10",
"@multiversx/sdk-core": "12.18.0",
"@multiversx/sdk-wallet": "4.2.0",
"@near-wallet-selector/wallet-utils": "^8.0.0",
"@nextui-org/react": "1.0.8-beta.5",
"@polkadot/keyring": "^10.1.2",
"@polkadot/types": "^9.3.3",
"@solana/web3.js": "1.89.2",
"@taquito/signer": "^15.1.0",
"@taquito/taquito": "^15.1.0",
"@types/semver": "^7.5.8",
"@walletconnect/core": "^2.13.1",
"@walletconnect/web3wallet": "1.12.0",
"@reown/appkit": "1.4.1",
"@reown/appkit-adapter-ethers": "1.4.1",
"@zerodev/ecdsa-validator": "5.2.3",
"@zerodev/presets": "5.2.2",
"@zerodev/sdk": "5.2.11",
"@zerodev/session-key": "5.2.2",
"@zerodev/weighted-ecdsa-validator": "5.2.4",
"borsh": "^1.0.0",
"bs58": "5.0.0",
"ethers": "^6.13.0",
"framer-motion": "6.5.1",
"next": "13",
"permissionless": "0.1.21",
"react": "^18.3.1",
"react-code-blocks": "0.1.5",
"react-dom": "^18.3.1",
"react-hot-toast": "^2.4.1",
"react-qr-reader-es6": "2.2.1-2",
"valtio": "1.11.2",
"viem": "2.9.29"
},
"devDependencies": {
"@types/node": "17.0.35",
"@types/react": "17.0.2",
"eslint": "8.15.0",
"eslint-config-next": "13",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-package-json": "^0.13.1",
"jsonc-eslint-parser": "^2.4.0",
"prettier": "2.6.2",
"typescript": "5.2.2"
}
}
Loading