use-cardano
Advanced tools
Comparing version 1.0.0-beta.14 to 1.0.0-beta.15
{ | ||
"name": "use-cardano", | ||
"type": "module", | ||
"version": "1.0.0-beta.14", | ||
"version": "1.0.0-beta.15", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": "^16.15.0 || ^17.0.0 || ^18.0.0" |
# use-cardano | ||
use-cardano is a react context, hook, and set of components that makes interacting with the Cardano blockchain easy. It allows you to build web3 applications, connect wallets and performing tasks such as signing transactions and interacting with smart contracts. | ||
use-cardano is a react context, hook, and set of components that makes interacting with the Cardano blockchain easy. It allows you to build web3 applications, connect wallets and performing tasks such as signing transactions, and interacting with smart contracts. Visit the official [documentation](https://use-cardano.alangaming.com/) for installation instructions, configuration options, and live examples. | ||
## Documentation | ||
The package leverages [lucid](https://github.com/spacebudz/lucid) for transaction building and off-chain code to interact with smart contracts. For more information on that, visit the [lucid documentation](https://lucid.spacebudz.io/). | ||
Visit the [documentation site](https://use-cardano.alangaming.com/) for installation instructions, configuration options, and live examples. | ||
## Minimal Example | ||
## Contributing / Development | ||
```tsx filename="minimal-example.tsx" copy | ||
import "use-cardano/styles/use-cardano.css" | ||
import { useCardano, CardanoProvider, CardanoWalletSelector, CardanoToaster } from "use-cardano" | ||
This repository contains the source code for [use-cardano](https://www.npmjs.com/package/use-cardano), a react hook that makes interacting with the Cardano blockchain easy. | ||
const Content = () => { | ||
const { account } = useCardano() | ||
Feel free to contribute in any capacity, either by opening an issue, creating a pull request or by giving feedback. | ||
return ( | ||
<> | ||
<CardanoWalletSelector /> | ||
_Are you new to Open Source development, or the Cardano dApps eco system? I know it can be daunting, but do not be afraid to reach out in an issue. Any and all contributions are welcome._ | ||
<div>Connected Address: {account.address}</div> | ||
</> | ||
) | ||
} | ||
## Running the project in development mode | ||
const App = () => ( | ||
<CardanoProvider options={options}> | ||
<Content /> | ||
_We highly recommend pnpm over yarn and npm since it handles local project linking, as well as being very performant._ | ||
<CardanoToaster /> | ||
</CardanoProvider> | ||
) | ||
``` | ||
1. `git clone git@github.com:use-cardano/use-cardano.git` | ||
1. `npm i -g pnpm` | ||
1. `cd example && pnpm i && cd ..` | ||
- _Installs example dependencies_ | ||
1. `pnpm link ./example/node_modules/react ./example/node_modules/lucid-cardano` | ||
- _Links the libraries peer dependencies_ | ||
1. `pnpm i` | ||
- _Installs library dependencies_ | ||
1. `pnpm dev` | ||
- _Runs the library in watch mode, and launches the example app_ | ||
## Contributing / Development | ||
## Reverse Proxy | ||
See the [contributing](/docs/CONTRIBUTING) doc for instructions on how to contribute to the development of the library. | ||
When running the project locally, the examples site will be automatically served on `http://localhost:4200`. | ||
## LICENSE | ||
Some wallet providers (gerowallet) will not inject itself in the CIP-0030 web bridge if the page is not served over https. To get around this, the site is automatically also served over a reverse proxy using [localtunnel](https://www.npmjs.com/package/localtunnel). The proxied site will launch automatically in your default browser, and you will be informed that it's being proxied and prompted to continue. | ||
## Example app | ||
There is an example app in the `/example` folder. It is a simple Next.js app that serves both as a testbed and as a reference. Changes to both the `use-cardano` package as well as the example app will be hot-reloaded during development. | ||
MIT, see [LICENSE](/LICENSE) for more information. |
import { useCardano } from "contexts/CardanoContext" | ||
import { disallowedNetworkError } from "lib/errors" | ||
import { getInfo, getText } from "lib/get-toaster-texts" | ||
import { noLiveNetworkChangeWarning } from "lib/warnings" | ||
@@ -9,4 +10,18 @@ import { isNil } from "lodash" | ||
export const useNetworkId = (allowedNetworks: number[], testnetNetwork: TestnetNetwork) => { | ||
const { setNetworkId, setNetworkWarning, setNetworkError, walletApi, showToaster } = useCardano() | ||
const { | ||
setNetworkId, | ||
setNetworkWarning, | ||
setNetworkError, | ||
walletApi, | ||
showToaster, | ||
walletProvider, | ||
} = useCardano() | ||
const showToasterWithNetworkInfo = useCallback(() => { | ||
const text = walletProvider ? getText(walletProvider) : undefined | ||
const info = walletProvider ? getInfo(walletProvider) : undefined | ||
showToaster(text, info) | ||
}, [walletProvider]) | ||
const onNetworkChange = useCallback( | ||
@@ -22,5 +37,5 @@ (id: unknown) => { | ||
setNetworkId(networkId) | ||
showToaster() | ||
showToasterWithNetworkInfo() | ||
}, | ||
[allowedNetworks] | ||
[allowedNetworks, showToasterWithNetworkInfo] | ||
) | ||
@@ -27,0 +42,0 @@ |
@@ -92,2 +92,3 @@ declare module "use-cardano" { | ||
toasterIsShowing: boolean | ||
toasterShowCount: number | ||
showToaster: (text?: string, info?: string) => void | ||
@@ -94,0 +95,0 @@ hideToaster: () => void |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1731893
87
20166