4.3.0 • Published 5 months ago

@delphi-labs/shuttle-vue v4.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Shuttle (Vue)

NPM version Build npm-typescriptLicense]github-license-url

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-vue

Setup

import { createApp } from "vue";
import { createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
import { createShuttle } from "@delphi-labs/shuttle-vue";

import App from "./App.vue";

export const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

const shuttle = createShuttle({
  pinia,
  walletConnectProjectId: "...",
  extensionProviders: [
    // ...
  ],
  mobileProviders: [
    // ...
  ],
});

const app = createApp(App);

app.use(pinia);
app.use(shuttle);

app.mount("#app");

Use

<script lang="ts" setup>
import { ref } from "vue";
import { WalletConnection, isAndroid, isIOS, isMobile, useShuttle } from "@delphi-labs/shuttle-vue";
import QrcodeVue from "qrcode.vue";

import { useShuttlePortStore } from "@/stores/shuttle-port";
import { networks } from "@/config/networks";
import useWallet from "@/composables/useWallet";

const shuttle = useShuttle();
const networkStore = useShuttlePortStore();
const wallet = useWallet();

async function connect(extensionProviderId: string) {
  await shuttle.connect({ extensionProviderId: extensionProviderId, chainId: networkStore.currentNetworkId });
}

const qrcodeUrl = ref<string | null>(null);

async function mobileConnect(mobileProviderId: string) {
  const urls = await shuttle.mobileConnect({
    mobileProviderId: mobileProviderId,
    chainId: networkStore.currentNetworkId,
    callback: () => {
      qrcodeUrl.value = null;
    },
  });

  if (isMobile()) {
    if (isAndroid()) {
      window.location.href = urls.androidUrl;
    } else if (isIOS()) {
      window.location.href = urls.iosUrl;
    } else {
      window.location.href = urls.androidUrl;
    }
  } else {
    qrcodeUrl.value = urls.qrCodeUrl;
  }
}

function disconnectWallet(wallet: WalletConnection) {
  shuttle.disconnectWallet(wallet);
}
</script>

<template>
  <header>
    <h1>Shuttle Port (Vue)</h1>

    <hr />

    <div>
      <label htmlFor="currentNetwork">Current network:</label>
      <select
        id="currentNetwork"
        :value="networkStore.currentNetworkId"
        @change="networkStore.switchNetwork(($event.target as HTMLInputElement).value)"
      >
        <option v-for="network in networks" :key="network.chainId" :value="network.chainId">{{ network.name }}</option>
      </select>
    </div>

    <hr />

    <div v-if="!wallet">
      <button
        v-for="extensionProvider in shuttle.extensionProviders.filter((provider) =>
          provider.networks.has(networkStore.currentNetworkId),
        )"
        :key="extensionProvider.id"
        @click="() => connect(extensionProvider.id)"
        :disabled="!shuttle.availableExtensionProviders.find((p) => p.id === extensionProvider.id)"
      >
        {{ extensionProvider.name }}
      </button>
      <button
        v-for="mobileProvider in shuttle.mobileProviders.filter((provider) =>
          provider.networks.has(networkStore.currentNetworkId),
        )"
        :key="mobileProvider.id"
        @click="() => mobileConnect(mobileProvider.id)"
        :disabled="!shuttle.availableMobileProviders.find((p) => p.id === mobileProvider.id)"
      >
        {{ mobileProvider.name }}
      </button>
    </div>
    <div v-else>
      <div>
        <p>Address: {{ wallet.account.address }}</p>
        <button @click="() => disconnectWallet(wallet!)">Disconnect</button>
      </div>
    </div>
    <hr />
  </header>

  <div v-if="qrcodeUrl" className="fixed inset-0 flex flex-col items-center justify-center">
    <div className="absolute inset-0 z-0 bg-black opacity-20" @click="qrcodeUrl = null"></div>
    <div
      className="relative flex min-h-[408px] min-w-[384px] flex-col items-center rounded-lg bg-white py-10 px-14 shadow-md"
    >
      <button className="absolute top-3 right-3 rounded bg-black p-1.5 text-white" @click="qrcodeUrl = null">
        Close
      </button>

      <h2 className="mb-2 text-xl">Wallet Connect</h2>

      <div className="flex flex-col items-center">
        <p className="mb-4 text-center text-sm text-gray-600">Scan this QR code with your mobile wallet</p>
        <QrcodeVue :value="qrcodeUrl" :size="250" />
      </div>
    </div>
  </div>
</template>

How to develop

Install

pnpm install

Test

pnpm run test

Prettier

pnpm run prettier

Lint

pnpm run lint

Build

pnpm run build

Publish

pnpm publish
3.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