Shuttle is an open-source npm package designed to turn wallet connections into a plug-and-play Lego brick for Cosmos dApps.
You can check out the documentation for more information.
npm install @delphi-labs/shuttle-react
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>
);
}
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} />
</>
)}
</>
)}
</>
);
}
pnpm install
pnpm run test
pnpm run prettier
pnpm run lint
pnpm run build
pnpm publish