-
Notifications
You must be signed in to change notification settings - Fork 1
Project improvements: correctness fixes, DRY refactors, logger, tests/CI, tooling #52
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c57ac32
fix: correctness fixes and rename yoroiProvider to cardanoProvider
Nebyt cb75f1f
refactor: memoize cardanoProvider and tidy index.js
Nebyt 5c50a61
refactor: add debug-gated logger, replace console.* calls
Nebyt 7e16a8a
feat: runtime on/off switch for logger via browser console
Nebyt 28f59e4
test: add smoke + util tests and CI workflow
Nebyt 1a33f28
refactor: extract runApiCall helper, collapse card handlers
Nebyt 9de376a
refactor: route card input fields through InputWithLabel
Nebyt 5cf31ce
refactor: extract useResponseState hook for subtabs
Nebyt 8dbb81a
refactor: extract buildCert helper for gov panels
Nebyt 2021b84
refactor: add hexArrayToBech32Addresses/hexArrayToUtxos helpers
Nebyt 650e1b2
refactor: extract parseCredential, ChainStatusMessage, AccessButtonShell
Nebyt f6cdcf7
feat: user-facing error toasts for wallet connect failures
Nebyt 8b9a38e
style: apply prettier to src
Nebyt a57c800
chore: tooling and docs — lint/format scripts, README, .env
Nebyt fd4b20f
refactor: shared connection-state machine + documented chain contract
Nebyt fd8513a
fix: network toggle unclickable — stop inactive TabPanels overlaying …
Nebyt c5640e4
refactor: share chunkMessageTo64Bytes; drop NFTTab char-based slicer
Nebyt 795e919
chore: bump version to 2.4.0
Nebyt 56a23dc
Potential fix for pull request finding 'CodeQL / Workflow does not co…
Nebyt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # Copy to `.env` to override defaults. Only variables prefixed with REACT_APP_ | ||
| # are exposed to the app (Create React App convention). | ||
|
|
||
| # Enable verbose debug/log output in production builds. | ||
| # - During local development (`npm start`) logs are ON by default regardless. | ||
| # - In production builds logs are OFF unless this is set to "true". | ||
| # - You can also toggle logs at runtime from the browser console, without | ||
| # rebuilding: dappLogs.on() / dappLogs.off() / dappLogs.toggle(). | ||
| REACT_APP_DEBUG=false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Read .nvmrc | ||
| id: nvm | ||
| run: echo "version=$(cat .nvmrc)" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Setup node | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '${{ steps.nvm.outputs.version }}' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm i | ||
|
|
||
| - name: Check formatting | ||
| run: npm run format:check | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Run tests | ||
| run: npm run test:ci | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,90 @@ | ||
| # dapp-example | ||
|
|
||
| The project is created with purpose to show how to work with yoroi dApp-connector. | ||
| A simple, multi-chain example dApp that shows how to interact with wallet | ||
| connectors — built for clarity, learning, testing, and extension. | ||
|
|
||
| It may not look good but it works and can be used as an example to other projects how to interact with the dApp-connector. | ||
| Live demo: https://dapp-example.yoroiwallet.com/ | ||
|
|
||
| You can find the dApp on this link https://dapp-example.yoroiwallet.com/ | ||
| > It may not look fancy, but it works and is meant as a reference for other | ||
| > projects on how to talk to wallet dApp-connectors. | ||
|
|
||
| ## Supported chains | ||
|
|
||
| - **Cardano** (CIP-30) — live, via browser wallet extensions (e.g. Yoroi) | ||
| - **Ethereum** (EIP-1193) — live, via `window.ethereum` | ||
| - **Bitcoin** — planned (provider is currently a stub) | ||
|
|
||
| ## Tech stack | ||
|
|
||
| - React 18 (functional components + hooks), JavaScript only (no TypeScript) | ||
| - Tailwind CSS + Material Tailwind | ||
| - Create React App + craco | ||
| - Cardano serialization via `@emurgo/cardano-serialization-lib-browser` | ||
|
|
||
| ## Getting started | ||
|
|
||
| Prerequisites: Node.js (see [`.nvmrc`](./.nvmrc)) and npm. | ||
|
|
||
| ```bash | ||
| npm install # install dependencies | ||
| npm start # run the dev server at http://localhost:3000 | ||
| npm run build # production build into ./build | ||
| ``` | ||
|
|
||
| A Cardano and/or Ethereum browser wallet extension is required to exercise the | ||
| connect flows. | ||
|
|
||
| ## Available scripts | ||
|
|
||
| | Script | Description | | ||
| | --- | --- | | ||
| | `npm start` | Start the development server | | ||
| | `npm run build` | Production build | | ||
| | `npm test` | Run tests in watch mode | | ||
| | `npm run test:ci` | Run tests once (CI mode) | | ||
| | `npm run lint` | Lint `src` with ESLint | | ||
| | `npm run lint:fix` | Lint and auto-fix | | ||
| | `npm run format` | Format `src` with Prettier | | ||
| | `npm run format:check` | Check formatting without writing | | ||
|
|
||
| ## Project structure | ||
|
|
||
| ``` | ||
| src/ | ||
| hooks/ # Providers (one per chain) + network toggle + shared hooks | ||
| components/ # UI: access buttons, tabs, cards, shared inputs | ||
| utils/ # Helpers and blockchain utilities (cslTools, ethereumUtils, ...) | ||
| ``` | ||
|
|
||
| Each chain follows the same flow: **Provider → Access Button → Main Tab → | ||
| Subtabs → Cards**. See [`CLAUDE.md`](./CLAUDE.md) for the full architecture and | ||
| conventions. | ||
|
|
||
| ## Logging | ||
|
|
||
| The app uses a small debug-gated logger (`src/utils/logger.js`): | ||
|
|
||
| - `debug` / `log` / `info` print only in development, or in a production build | ||
| started with `REACT_APP_DEBUG=true` (see [`.env.example`](./.env.example)). | ||
| - `warn` / `error` always print. | ||
|
|
||
| You can toggle logs live from the browser console — no rebuild needed: | ||
|
|
||
| ```js | ||
| dappLogs.on() // enable and remember across reloads | ||
| dappLogs.off() // disable and remember across reloads | ||
| dappLogs.toggle() // flip current state | ||
| dappLogs.status() // -> true | false | ||
| dappLogs.reset() // forget the override, fall back to the build default | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| Tests use Jest + React Testing Library (via CRA). Run `npm run test:ci` for a | ||
| single pass, or `npm test` to watch. Tests and linting run in CI on pushes to | ||
| `main` and on pull requests. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Copy [`.env.example`](./.env.example) to `.env` to override defaults. Only | ||
| variables prefixed with `REACT_APP_` are exposed to the app. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import React from 'react' | ||
|
|
||
| // Shared chrome for each chain's access button: dark background + centered grid. | ||
| const AccessButtonShell = ({children, innerClassName = 'grid justify-items-center py-3'}) => ( | ||
| <div className="mx-auto bg-gray-900"> | ||
| <div className={innerClassName}>{children}</div> | ||
| </div> | ||
| ) | ||
|
|
||
| export default AccessButtonShell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,14 @@ | ||
| import React from 'react' | ||
| import AccessButtonShell from './accessButtonShell' | ||
|
|
||
| const BitcoinAccessButton = () => { | ||
| return ( | ||
| <div className="mx-auto bg-gray-900"> | ||
| <div className="grid justify-items-center py-3"> | ||
| <button | ||
| className="rounded-md bg-orange-600 py-5 px-5 disabled:opacity-50 text-white font-semibold cursor-not-allowed" | ||
| disabled | ||
| > | ||
| Bitcoin (Coming Soon) | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
| const BitcoinAccessButton = () => ( | ||
| <AccessButtonShell> | ||
| <button | ||
| className="rounded-md bg-orange-600 py-5 px-5 disabled:opacity-50 text-white font-semibold cursor-not-allowed" | ||
| disabled | ||
| > | ||
| Bitcoin (Coming Soon) | ||
| </button> | ||
| </AccessButtonShell> | ||
| ) | ||
|
|
||
| export default BitcoinAccessButton |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.