npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ton-ui-vue

v0.1.5

Published

Here's how you can update the README to include the `useSendTransaction` composable:

Downloads

109

Readme

Here's how you can update the README to include the useSendTransaction composable:


TonConnect UI Vue

Introduction

TonConnect UI Vue is a library that provides components and context for integrating TonConnect UI in your Vue.js applications. This README will guide you through the setup and usage of the library.

Installation

To install the library, use your preferred package manager:

npm install ton-ui-vue @tonconnect/ui
# or
yarn add ton-ui-vue @tonconnect/ui

Setup

1. Import and Create the TonConnectUIProvider

In your main.ts, import the necessary functions and contexts from ton-ui-vue, and create the TonConnectUIProvider with your manifest URL.

import { createApp } from 'vue';
import App from './App.vue';
import {
    createTonConnectUIProvider,
    TonConnectUIContext,
    TonConnectUIOptionsContext
} from 'ton-ui-vue';

const { tonConnectUI, setOptions } = createTonConnectUIProvider({
    manifestUrl: 'https://gist.githubusercontent.com/siandreev/75f1a2ccf2f3b4e2771f6089aeb06d7f/raw/d4986344010ec7a2d1cc8a2a9baa57de37aaccb8/gistfile1.txt'
});

const app = createApp(App);

app.provide(TonConnectUIContext, tonConnectUI);
app.provide(TonConnectUIOptionsContext, setOptions);

app.mount('#app');

2. Using the Connect Button

To use the connect button in your components, follow these steps:

  1. Import the TonConnectButton component in your script setup.
  2. Use the TonConnectButton component in your template.

Example Component

Create a component or use the TonConnectButton in an existing component as shown below:

<script setup lang="ts">
import { TonConnectButton } from 'ton-ui-vue';
</script>

<template>
    <div>
        <TonConnectButton />
    </div>
</template>

3. Full Example

Below is a complete example combining the setup and usage of the connect button:

main.ts

import { createApp } from 'vue';
import App from './App.vue';
import {
    createTonConnectUIProvider,
    TonConnectUIContext,
    TonConnectUIOptionsContext
} from 'ton-ui-vue';

const { tonConnectUI, setOptions } = createTonConnectUIProvider({
    manifestUrl: 'https://gist.githubusercontent.com/siandreev/75f1a2ccf2f3b4e2771f6089aeb06d7f/raw/d4986344010ec7a2d1cc8a2a9baa57de37aaccb8/gistfile1.txt'
});

const app = createApp(App);

app.provide(TonConnectUIContext, tonConnectUI);
app.provide(TonConnectUIOptionsContext, setOptions);

app.mount('#app');

App.vue

<template>
    <div id="app">
        <TonConnectButton />
    </div>
</template>

<script setup lang="ts">
import { TonConnectButton } from 'ton-ui-vue';
</script>

4. Using useSendTransaction Composable

The useSendTransaction composable allows you to send transactions using the TonConnect UI in a flexible and dynamic way. You can add multiple transaction messages with specific addresses and amounts, manage the transaction state, and handle user actions.

Example Usage

<template>
  <div>
    <div v-for="(message, index) in messages" :key="index">
      <input v-model="message.address" placeholder="Enter address" />
      <input v-model="message.amount" placeholder="Enter amount" />
    </div>
    <button @click="addMessage('', '')">Add Message</button>
    <button @click="sendTransaction" :disabled="sending">
      Send Transaction
    </button>
    <p v-if="error">{{ error.message }}</p>
  </div>
</template>

<script setup lang="ts">
import { useSendTransaction } from '@/composables/useSendTransaction';

const { sendTransaction, sending, error, messages, addMessage, clearMessages } = useSendTransaction();

// Initialize with an empty message to start with
addMessage('0:b2a1ecf5545e076cd36ae516ea7ebdf32aea008caa2b84af9866becb208895ad', '100000000');
addMessage('0:a1b2c3d4e5f678901234567890abcdef1234567890abcdef1234567890abcdef', '200000000');
</script>

API

  • sendTransaction(): Sends the transaction messages stored in the messages array.
  • addMessage(address: string, amount: string): Adds a new transaction message to the messages array.
  • clearMessages(): Clears all transaction messages from the messages array.
  • messages: A reactive array containing the transaction messages.
  • sending: A reactive boolean indicating if the transaction is currently being sent.
  • error: A reactive error object that holds any errors encountered during the transaction process.

TonConnect UI Vue Integration for Nuxt 3

Step-by-Step Guide

Create a Plugin

Create a file named ton-with-vue.ts inside the plugins directory:

// plugins/ton-with-vue.ts
import {
  createTonConnectUIProvider,
  TonConnectUIContext,
  TonConnectUIOptionsContext,
  TonConnectButton,
} from "ton-ui-vue";

export default defineNuxtPlugin((nuxtApp) => {
  const { tonConnectUI, setOptions } = createTonConnectUIProvider({
    manifestUrl:
      "https://gist.githubusercontent.com/siandreev/75f1a2ccf2f3b4e2771f6089aeb06d7f/raw/d4986344010ec7a2d1cc8a2a9baa57de37aaccb8/gistfile1.txt",
  });

  nuxtApp.vueApp.component("TonConnectButton", TonConnectButton);
  nuxtApp.vueApp.provide(TonConnectUIContext, tonConnectUI);
  nuxtApp.vueApp.provide(TonConnectUIOptionsContext, setOptions);
});

This updated README now includes the documentation for the useSendTransaction composable, providing a clear example of how to use it alongside the existing TonConnect UI components and setup instructions.