4.3.0 • Published 5 months ago
@delphi-labs/shuttle-react v4.3.0
Shuttle (React)
Shuttle is an open-source npm package designed to turn wallet connections into a plug-and-play Lego brick for Cosmos dApps.
Docs
You can check out the documentation for more information.
How to get started
Install
npm install @delphi-labs/shuttle-reactSetup
import { ShuttleProvider } from "@delphi-labs/shuttle-react";
const WC_PROJECT_ID = "...";
const extensionProviders = [
// ...
];
const mobileProviders = [
// ...
];
function App() {
return (
<ShuttleProvider
walletConnectProjectId={WC_PROJECT_ID}
extensionProviders={extensionProviders}
mobileProviders={mobileProviders}
// Add the following prop if you want wallet connections
// to be persisted to local storage.
persistent
>
<Component {...pageProps} />
</ShuttleProvider>
);
}Use
import { useState } from "react";
import QRCode from "react-qr-code";
import { useShuttle, isAndroid, isIOS, isMobile } from "@delphi-labs/shuttle-react";
const currentNetworkId = "mars-1";
function Header() {
const { providers, connect, mobileProviders, mobileConnect, getWallets } = useShuttle();
const [qrCodeUrl, setQrCodeUrl] = useState("");
const wallet = getWallets({ chainId: currentNetworkId })[0];
return (
<>
{wallet && (
<>
<p>Address: {wallet.account.address}</p>
</>
)}
{!wallet && (
<>
{providers.map((provider) => {
return (
<button
key={provider.id}
onClick={() =>
connect({
providerId: provider.id,
chainId: currentNetworkId,
})
}
disabled={!provider.initialized}
>
{provider.name}
</button>
);
})}
{mobileProviders.map((mobileProvider) => {
return (
<button
key={mobileProvider.id}
onClick={async () => {
const urls = await mobileConnect({
mobileProviderId: mobileProvider.id,
chainId: currentNetworkId,
callback: () => {
setQrCodeUrl("");
},
});
if (isMobile()) {
if (isAndroid()) {
window.location.href = urls.androidUrl;
} else if (isIOS()) {
window.location.href = urls.iosUrl;
} else {
window.location.href = urls.androidUrl;
}
} else {
setQrCodeUrl(urls.qrCodeUrl);
}
}}
disabled={!mobileProvider.initialized}
>
{mobileProvider.name}
</button>
);
})}
{qrCodeUrl && (
<>
<QRCode value={qrCodeUrl} />
</>
)}
</>
)}
</>
);
}How to develop
Install
pnpm installTest
pnpm run testPrettier
pnpm run prettierLint
pnpm run lintBuild
pnpm run buildPublish
pnpm publish3.30.0
10 months ago
4.1.0
10 months ago
4.0.1
10 months ago
4.0.0
10 months ago
4.3.0
5 months ago
4.2.0
8 months ago
3.24.0
1 year ago
3.26.0
1 year ago
3.25.0
1 year ago
3.28.0
1 year ago
3.27.0
1 year ago
3.29.0
1 year ago
3.23.0
1 year ago
3.22.0
2 years ago
3.21.0
2 years ago
3.20.0
2 years ago
3.19.0
2 years ago
3.19.1
2 years ago
3.18.0
2 years ago
3.17.3
2 years ago
3.17.1
2 years ago
3.17.0
2 years ago
3.16.0
2 years ago
3.13.0
2 years ago
3.12.1
2 years ago
3.12.0
2 years ago
3.15.0
2 years ago
3.12.3
2 years ago
3.14.0
2 years ago
3.12.2
2 years ago
3.11.0
2 years ago
3.10.0
2 years ago
3.9.1
2 years ago
3.9.0
2 years ago
3.8.0
2 years ago
3.7.0
2 years ago
3.6.0
2 years ago
3.5.0
2 years ago
3.4.0
2 years ago
3.3.0
2 years ago
3.0.1-beta
2 years ago
3.0.0-beta
2 years ago
3.1.0
2 years ago
3.0.0
2 years ago