-
Notifications
You must be signed in to change notification settings - Fork 3
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
Update readme #89
Merged
Merged
Update readme #89
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2894ab0
chore: add vscode configuration script
samsiegart b503e56
chore: document custom signer in README
samsiegart 634a826
chore: update README with new interfaces
samsiegart fbcf832
chore: fill out README for react-components
samsiegart 40095eb
chore: update README with custom ChainProvider guidance
samsiegart a965eff
Merge branch 'main' into update-readme
samsiegart 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 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 |
---|---|---|
|
@@ -131,3 +131,6 @@ dist | |
|
||
# Other build output | ||
compiled | ||
|
||
# Vscode Settings | ||
.vscode/ |
This file contains 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 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,101 @@ | ||
#!/bin/sh | ||
|
||
# Configures the .vscode directory (which is .gitignored so that everyone can tailor it) | ||
|
||
die() { | ||
echo "$*" >&2 | ||
exit 1 | ||
} | ||
|
||
# Run at the top level of the repository | ||
cd "$(git rev-parse --show-toplevel)" || | ||
die "Could not cd to top-level directory" | ||
|
||
mkdir -p .vscode || | ||
die "Could not create .vscode/" | ||
|
||
# General settings | ||
|
||
cat >.vscode/settings.json.new <<\EOF || | ||
{ | ||
// Automatically format with Prettier on save | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
|
||
"typescript.preferences.importModuleSpecifierEnding": "js", | ||
"typescript.tsdk": "node_modules/typescript/lib", | ||
|
||
// ESLint config | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
}, | ||
"eslint.rules.customizations": [ | ||
// Leave this to Prettier itself | ||
{ "rule": "prettier/*", "severity": "off" }, | ||
// Error in CI but a common state while coding in IDE | ||
{ "rule": "no-unused-vars", "severity": "warn" }, | ||
// Imports are auto-fixed on save | ||
{ "rule": "import/newline-after-import", "severity": "off" }, | ||
{ "rule": "import/order", "severity": "off" }, | ||
], | ||
"eslint.useESLintClass": true, | ||
"eslint.packageManager": "yarn" | ||
} | ||
EOF | ||
die "Could not write settings.json" | ||
|
||
cat > .vscode/launch.json.new <<\EOF || | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "pwa-node", | ||
"request": "launch", | ||
"name": "Debug AVA file", | ||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", | ||
"runtimeArgs": [ | ||
"${file}" | ||
], | ||
"outputCapture": "std", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
}, | ||
{ | ||
"type": "pwa-node", | ||
"request": "launch", | ||
"name": "Debug AVA matches", | ||
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/ava", | ||
"runtimeArgs": [ | ||
"${file}", | ||
"-m", | ||
"${selectedText}" | ||
], | ||
"outputCapture": "std", | ||
"skipFiles": [ | ||
"<node_internals>/**" | ||
], | ||
} | ||
] | ||
} | ||
EOF | ||
die "Could not write launch.json" | ||
|
||
for file in .vscode/launch.json .vscode/settings.json; do | ||
printf "\nComparing %s\n" $file | ||
if test -f $file; then | ||
if git diff --no-index --quiet --exit-code $file $file.new; then | ||
echo "Your existing configuration matches the recommendations." | ||
rm $file.new | ||
else | ||
printf "The file %s.new has these changes:\n\n" $file | ||
git --no-pager diff --no-index $file $file.new | ||
printf "\n\nTo overwrite yours:\n\n mv %s.new %s\n\n" $file $file | ||
fi | ||
else | ||
mv $file.new $file | ||
fi | ||
done |
This file contains 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 +1,84 @@ | ||
# Agoric React Components | ||
# Agoric React Components | ||
|
||
React hooks and utilities that make writing an Agoric dapp as quick and painless as possible. | ||
|
||
## Prequisites | ||
|
||
See [Agoric/ui-kit#setup](https://github.com/Agoric/ui-kit?tab=readme-ov-file#setup) for setup instructions, as well as more pointers for using the `chainStorageWatcher` and `walletConnection`. | ||
|
||
## Integrating | ||
|
||
Getting set up is as easy as using the `AgoricProvider`. Under the hood, it uses [`cosmos-kit/react`](https://docs.cosmology.zone/cosmos-kit) to connect to your wallet provider of choice. | ||
|
||
```tsx | ||
import { AgoricProvider, ConnectWalletButton } from '@agoric/react-components'; | ||
import { wallets } from 'cosmos-kit'; | ||
import '@agoric/react-components/dist/style.css'; | ||
|
||
const App = () => { | ||
return ( | ||
<AgoricProvider | ||
wallets={wallets.extension} | ||
defaultNetworkConfig={{ | ||
// testChain is optional, defaulting to Agoric mainnet otherwise. | ||
testChain: { | ||
chainId: 'agoriclocal', | ||
chainName: 'agoric-local', | ||
}, | ||
apis: { | ||
rest: ['http://localhost:1317'], | ||
rpc: ['http://localhost:26657'], | ||
}, | ||
}} | ||
> | ||
<ConnectWalletButton /> | ||
</AgoricProvider> | ||
); | ||
}; | ||
``` | ||
|
||
## Connecting without `ConnectWalletButton` | ||
|
||
```tsx | ||
import { useAgoric } from '@agoric/react-components'; | ||
|
||
const MyCustomConnectButton = () => { | ||
const agoric = useAgoric(); | ||
|
||
return <button onClick={agoric.connect}>Connect</button>; | ||
}; | ||
``` | ||
|
||
## Node Selector | ||
|
||
To let a user choose their own API endpoints, separate from those provided in `defaultNetworkConfig`, the `NodeSelectorModal` can be provided: | ||
|
||
```tsx | ||
import { useState } from 'react'; | ||
import { NodeSelectorModal } from '@agoric/react-components'; | ||
|
||
const NodeSelector = () => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<button onClick={() => setIsOpen(true)}> | ||
Configure Endpoints | ||
</button> | ||
<NodeSelectorModal isOpen={isOpen} onClose={() => setIsOpen(false)}> | ||
</> | ||
); | ||
}; | ||
``` | ||
|
||
The modal will persist the user's chosen API endpoints in local storage, and override whichever endpoints are in `defaultNetworkConfig`. | ||
|
||
## Agoric Context | ||
|
||
All Agoric-related state is accessible through the `useAgoric` hook. See [`AgoricContext`](https://github.com/Agoric/ui-kit/blob/585b47d158a983643659a2cfccd76f772933db7e/packages/react-components/src/lib/context/AgoricContext.ts#L28-L39) for the full interface. | ||
|
||
For more details on making offers and reading chain data with `AgoricWalletConnection` and `ChainStorageWatcher`, see [Agoric/ui-kit](https://github.com/Agoric/ui-kit). | ||
|
||
## Using a Custom `ChainProvider` | ||
|
||
If you need to configure `ChainProvider` more, or have an existing `cosmos-kit` dapp that you want to add Agoric functionality to, the [`AgoricProviderLite`](https://github.com/Agoric/ui-kit/blob/585b47d158a983643659a2cfccd76f772933db7e/packages/react-components/src/lib/context/AgoricProviderLite.tsx) component can be used directly inside your own `ChainProvider`. [Under the hood](https://github.com/Agoric/ui-kit/blob/585b47d158a983643659a2cfccd76f772933db7e/packages/react-components/src/lib/context/AgoricProvider.tsx#L27-L61), `AgoricProvider` provides a default `ChainProvider` implementation and wraps `AgoricProviderLite`. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question
Just curious, why is this file needed here if it's already in Agoric/agoric-sdk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
.vscode/settings.json
file that this script produces only applies when it's at the root of the currently opened workspace, so running it fromagoric-sdk
wouldn't apply the settings to this repo unless they were opened together in the same workspace.We could point to the
agoric-sdk
repo and ask people to copy that.vscode/settings.json
into this workspace when working with this repo, but it's more convenient to just have it here and allows us to tweak things specific to this repo.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://code.visualstudio.com/docs/getstarted/settings#_workspace-settingsjson-location