wallet-connect-web-examples/wallets/react-wallet-v2
Jonathan Conn a48d4b6aa9
feat: added selector tags for e2e testing (#240)
* feat: added selector tags for e2e testing

* Update wallets/react-wallet-v2/README.md

Co-authored-by: Ben Kremer <ben@walletconnect.com>

* Update wallets/react-wallet-v2/README.md

Co-authored-by: Ben Kremer <ben@walletconnect.com>

* Update wallets/react-wallet-v2/src/components/Navigation.tsx

Co-authored-by: Ben Kremer <ben@walletconnect.com>

---------

Co-authored-by: Ben Kremer <ben@walletconnect.com>
2023-07-13 23:10:06 -04:00
..
public feat: adds zk sync era (#211) 2023-06-30 16:31:28 +02:00
src feat: added selector tags for e2e testing (#240) 2023-07-13 23:10:06 -04:00
.env.local.example Add Tezos Support (#127) 2023-03-31 10:35:53 +02:00
.eslintrc.json Set up dev tooling 2022-02-03 11:24:35 +02:00
.gitignore Beta 100 (#27) 2022-05-30 11:46:15 +02:00
.prettierrc.json Set up dev tooling 2022-02-03 11:24:35 +02:00
next-env.d.ts scope wallet examples under one folder 2022-02-03 11:14:39 +02:00
next.config.js feat: adds Elrond support (#67) 2022-10-31 11:21:33 +01:00
package.json chore(deps): update dependency @walletconnect/types to v2.9.0 (#235) 2023-07-11 16:25:13 +02:00
README.md feat: added selector tags for e2e testing (#240) 2023-07-13 23:10:06 -04:00
tsconfig.json refactor(dapp-v2): splits requested methods between required/optional (#196) 2023-06-28 09:51:13 +02:00
yarn.lock chore(deps): update dependency @walletconnect/types to v2.9.0 (#235) 2023-07-11 16:25:13 +02:00

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
🔗 Live dapp - https://react-app.walletconnect.com
📚 WalletConnect docs - https://docs.walletconnect.com/2.0

Getting started

Example is built atop of NextJS 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 and obtain a project id

  2. Add your project details in WalletConnectUtil.ts file

  3. Install dependencies yarn install or npm install

  4. Setup your environment variables

cp .env.local.example .env.local

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

  1. Run yarn dev or npm run dev to start local development

Navigating through example

  1. Initial setup and initializations happen in _app.ts file
  2. WalletConnect client, ethers and cosmos wallets are initialized in useInitialization.ts hook
  3. Subscription and handling of WalletConnect events happens in useWalletConnectEventsManager.ts hook, that opens related Modal views and passes them all necessary data
  4. Modal 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 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

Sessions Page

url: /session

Key Description
session-${topic} Session cards can be accessed by topic

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-delete-${topic} Delete pairing by topic

Accounts Page

url: /

Key Description
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