-
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
Create README.md #31
Merged
Merged
Create README.md #31
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# UI Kit | ||
Components and tools for building graphical UIs for Agoric dapps | ||
|
||
## Setup | ||
|
||
These packages require SES ([learn more](https://github.com/endojs/endo/tree/master/packages/ses)). | ||
See this [example](https://github.com/Agoric/dapp-inter/blob/main/src/main.tsx#L1) for enabling SES in your application. | ||
Setup may vary by environment. | ||
|
||
## Reading Contract Data (vstorage) | ||
|
||
`makeAgoricChainStorageWatcher` can be used to subscribe to updates to vstorage. | ||
It polls the RPC periodically, automatically batching and de-duping requests for efficiency. | ||
|
||
See https://github.com/p2p-org/p2p-agoric-vstorage-viewer to explore vstorage more. | ||
|
||
```ts | ||
import { | ||
makeAgoricChainStorageWatcher, | ||
AgoricChainStoragePathKind as Kind | ||
} from '@agoric/rpc'; | ||
|
||
const watcher = makeAgoricChainStorageWatcher(rpc, chainName); | ||
|
||
// Watch vstorage children at a given node. | ||
const stopWatching = watcher.watchLatest<string[]>( | ||
[Kind.Children, 'published.vaultFactory.managers'], | ||
managerIds => { | ||
console.log('Got vault manager IDs:', managerIds); | ||
} | ||
) | ||
|
||
// Stop watching. | ||
stopWatching(); | ||
|
||
// Watch vstorage data at a given node. | ||
watcher.watchLatest<Brands>( | ||
[Kind.Data, 'published.agoricNames.brand'], | ||
brands => { | ||
console.log('Do something with the brands'); | ||
} | ||
) | ||
``` | ||
|
||
## Connecting to User's Account (Keplr) | ||
|
||
```ts | ||
import { subscribeLatest } from '@agoric/notifier'; | ||
import { makeAgoricChainStorageWatcher } from '@agoric/rpc'; | ||
import { makeAgoricWalletConnection } from '@agoric/web-components'; | ||
|
||
const watcher = makeAgoricChainStorageWatcher(rpc, chainName); | ||
const connection = await makeAgoricWalletConnection(watcher); | ||
const {pursesNotifier, publicSubscribersNotifier} = chainConnection; | ||
|
||
for await (const purses of subscribeLatest(pursesNotifier)) { | ||
console.log('Got purses:', purses); | ||
} | ||
``` | ||
|
||
## Executing Offers | ||
|
||
```ts | ||
import { makeAgoricChainStorageWatcher } from '@agoric/rpc'; | ||
import { makeAgoricWalletConnection } from '@agoric/web-components'; | ||
|
||
const watcher = makeAgoricChainStorageWatcher(rpc, chainName); | ||
const connection = await makeAgoricWalletConnection(watcher); | ||
|
||
const amountToGive = {brand: someBrand, value: 123n}; | ||
const amountToWant = {brand: someOtherBrand, value: 456n}; | ||
|
||
connection.makeOffer( | ||
{ | ||
source: 'agoricContract', | ||
instancePath: ['SimpleSwapExampleInstance'], | ||
callPipe: [ | ||
['getSwapManagerForBrand', [amountToGive.brand]], | ||
['makeSwapOffer'] | ||
] | ||
}, | ||
{ | ||
give: { In: amountToGive }, | ||
want: { Out: amountToWant }, | ||
}, | ||
{ exampleArg: 'foo' }, | ||
({ status, data }) => { | ||
if (status === 'error') { | ||
console.error('Offer error', data); | ||
} | ||
if (status === 'seated') { | ||
console.log('Transaction submitted:', data.txn); | ||
console.log('Offer id:', data.offerId); | ||
} | ||
if (status === 'refunded') { | ||
console.log('Offer refunded'); | ||
} | ||
if (status === 'accepted') { | ||
console.log('Offer accepted'); | ||
} | ||
}, | ||
); | ||
``` | ||
|
||
|
||
|
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,21 @@ | ||
For more complete examples and setup see [Agoric/ui-kit](https://github.com/Agoric/ui-kit) | ||
|
||
```ts | ||
import { | ||
makeAgoricChainStorageWatcher, | ||
AgoricChainStoragePathKind as Kind | ||
} from '@agoric/rpc'; | ||
|
||
const watcher = makeAgoricChainStorageWatcher(rpc, chainName); | ||
|
||
// Watch vstorage children at a given node. | ||
const stopWatching = watcher.watchLatest<string[]>( | ||
[Kind.Children, 'published.vaultFactory.managers'], | ||
managerIds => { | ||
console.log('Got vault manager IDs:', managerIds); | ||
} | ||
) | ||
|
||
// Stop watching. | ||
stopWatching(); | ||
``` |
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,18 @@ | ||
## Linting and formatting | ||
|
||
To scan the package for linting and formatting errors, run | ||
|
||
```bash | ||
yarn lint | ||
``` | ||
|
||
To automatically fix linting and formatting errors, run | ||
|
||
```bash | ||
yarn format | ||
``` | ||
|
||
## Tooling configs | ||
|
||
For most of the tools, the configuration is in the `package.json` to minimize | ||
the amount of files in this package. |
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,18 +1,19 @@ | ||
## Linting and formatting | ||
For complete examples and setup see [Agoric/ui-kit](https://github.com/Agoric/ui-kit) | ||
|
||
To scan the package for linting and formatting errors, run | ||
```ts | ||
import { subscribeLatest } from '@agoric/notifier'; | ||
import { makeAgoricChainStorageWatcher } from '@agoric/rpc'; | ||
import { makeAgoricWalletConnection } from '@agoric/web-components'; | ||
|
||
```bash | ||
yarn lint | ||
``` | ||
const watcher = makeAgoricChainStorageWatcher(rpc, chainName); | ||
const connection = await makeAgoricWalletConnection(watcher); | ||
const {pursesNotifier, publicSubscribersNotifier} = chainConnection; | ||
|
||
To automatically fix linting and formatting errors, run | ||
// Sign an on-chain offer transaction. | ||
connection.makeOffer(...offer); | ||
|
||
```bash | ||
yarn format | ||
// Read the user's token balances. | ||
for await (const purses of subscribeLatest(pursesNotifier)) { | ||
console.log('Got user purses:', purses); | ||
} | ||
``` | ||
|
||
## Tooling configs | ||
|
||
For most of the tools, the configuration is in the `package.json` to minimize | ||
the amount of files in this package. |
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.
I'm used to passing network access (
fetch
) in explicitly. I don't expect to change that here, but it's worth indexing under Agoric/agoric-sdk#2160