@vue-solana/vue 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +179 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.mts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.mjs +168 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 vue-solana
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# @vue-solana/vue
|
|
2
|
+
|
|
3
|
+
Vue plugin and composables for Solana applications.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @vue-solana/vue @vue-solana/core @solana/web3-compat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createApp } from 'vue'
|
|
15
|
+
import { createSolanaPlugin } from '@vue-solana/vue'
|
|
16
|
+
|
|
17
|
+
createApp(App).use(createSolanaPlugin({
|
|
18
|
+
cluster: 'devnet'
|
|
19
|
+
}))
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Known TypeScript Issue
|
|
23
|
+
|
|
24
|
+
`@solana/web3-compat@0.0.21` currently has broken TypeScript metadata. Runtime imports still use the real package, but TypeScript consumers may need a local declaration shim.
|
|
25
|
+
|
|
26
|
+
Add `types/web3-compat.d.ts` to your app if TypeScript cannot resolve `@solana/web3-compat`. See the repository README for the full workaround.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const web3Compat = require('@solana/web3-compat');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
const core = require('@vue-solana/core');
|
|
6
|
+
|
|
7
|
+
const solanaInjectionKey = Symbol("VueSolana");
|
|
8
|
+
|
|
9
|
+
function useSolana() {
|
|
10
|
+
const context = vue.inject(solanaInjectionKey);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("Vue Solana plugin is not installed");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function useRpc() {
|
|
18
|
+
const solana = useSolana();
|
|
19
|
+
return {
|
|
20
|
+
cluster: vue.computed(() => solana.cluster),
|
|
21
|
+
endpoint: vue.computed(() => solana.endpoint),
|
|
22
|
+
wsEndpoint: vue.computed(() => solana.wsEndpoint),
|
|
23
|
+
status: solana.status,
|
|
24
|
+
error: solana.error,
|
|
25
|
+
latestBlockhash: solana.latestBlockhash,
|
|
26
|
+
checkConnection: solana.checkConnection,
|
|
27
|
+
connection: solana.connection
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function useConnection() {
|
|
32
|
+
return useRpc().connection;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function useBalance(address, commitment) {
|
|
36
|
+
const connection = useConnection();
|
|
37
|
+
const balance = vue.ref(null);
|
|
38
|
+
const loading = vue.ref(false);
|
|
39
|
+
const error = vue.ref(null);
|
|
40
|
+
async function refresh() {
|
|
41
|
+
const value = vue.toValue(address);
|
|
42
|
+
if (!value) {
|
|
43
|
+
balance.value = null;
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
loading.value = true;
|
|
47
|
+
error.value = null;
|
|
48
|
+
try {
|
|
49
|
+
const publicKey = typeof value === "string" ? new web3Compat.PublicKey(value) : value;
|
|
50
|
+
balance.value = await connection.getBalance(publicKey, commitment);
|
|
51
|
+
return balance.value;
|
|
52
|
+
} catch (cause) {
|
|
53
|
+
error.value = cause;
|
|
54
|
+
throw cause;
|
|
55
|
+
} finally {
|
|
56
|
+
loading.value = false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
vue.watch(() => vue.toValue(address), () => {
|
|
60
|
+
void refresh();
|
|
61
|
+
}, { immediate: true });
|
|
62
|
+
return {
|
|
63
|
+
balance,
|
|
64
|
+
loading,
|
|
65
|
+
error,
|
|
66
|
+
refresh
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function useWallet() {
|
|
71
|
+
const solana = useSolana();
|
|
72
|
+
const wallet = solana.wallet;
|
|
73
|
+
return {
|
|
74
|
+
wallet,
|
|
75
|
+
publicKey: vue.computed(() => wallet.value?.publicKey ?? null),
|
|
76
|
+
connected: vue.computed(() => Boolean(wallet.value?.connected && wallet.value.publicKey)),
|
|
77
|
+
connecting: vue.computed(() => Boolean(wallet.value?.connecting)),
|
|
78
|
+
setWallet: solana.setWallet,
|
|
79
|
+
connect: () => wallet.value?.connect() ?? Promise.reject(new Error("No Solana wallet is configured")),
|
|
80
|
+
disconnect: () => wallet.value?.disconnect() ?? Promise.resolve()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function useTransaction(handler) {
|
|
85
|
+
const signature = vue.ref(null);
|
|
86
|
+
const loading = vue.ref(false);
|
|
87
|
+
const error = vue.ref(null);
|
|
88
|
+
async function execute(...args) {
|
|
89
|
+
loading.value = true;
|
|
90
|
+
error.value = null;
|
|
91
|
+
try {
|
|
92
|
+
signature.value = await handler(...args);
|
|
93
|
+
return signature.value;
|
|
94
|
+
} catch (cause) {
|
|
95
|
+
error.value = cause;
|
|
96
|
+
throw cause;
|
|
97
|
+
} finally {
|
|
98
|
+
loading.value = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
signature,
|
|
103
|
+
loading,
|
|
104
|
+
error,
|
|
105
|
+
execute
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function useSignAndSendTransaction() {
|
|
110
|
+
const connection = useConnection();
|
|
111
|
+
const { wallet } = useWallet();
|
|
112
|
+
return useTransaction((transaction, options) => {
|
|
113
|
+
if (!wallet.value) {
|
|
114
|
+
return Promise.reject(new Error("No Solana wallet is configured"));
|
|
115
|
+
}
|
|
116
|
+
return core.signAndSendTransaction(connection, wallet.value, transaction, options);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function createSolanaPlugin(options = {}) {
|
|
121
|
+
return {
|
|
122
|
+
install(app) {
|
|
123
|
+
const context = core.createSolanaContext(options);
|
|
124
|
+
const wallet = vue.shallowRef(options.wallet ?? null);
|
|
125
|
+
const status = vue.ref("idle");
|
|
126
|
+
const error = vue.ref(null);
|
|
127
|
+
const latestBlockhash = vue.ref(null);
|
|
128
|
+
async function checkConnection() {
|
|
129
|
+
status.value = "checking";
|
|
130
|
+
error.value = null;
|
|
131
|
+
console.info("[Vue Solana] Checking RPC connection", {
|
|
132
|
+
cluster: context.cluster,
|
|
133
|
+
endpoint: context.endpoint,
|
|
134
|
+
wsEndpoint: context.wsEndpoint
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
const blockhash = await context.connection.getLatestBlockhash();
|
|
138
|
+
latestBlockhash.value = blockhash.blockhash;
|
|
139
|
+
status.value = "connected";
|
|
140
|
+
console.info("[Vue Solana] Connected", {
|
|
141
|
+
cluster: context.cluster,
|
|
142
|
+
endpoint: context.endpoint,
|
|
143
|
+
wsEndpoint: context.wsEndpoint,
|
|
144
|
+
blockhash
|
|
145
|
+
});
|
|
146
|
+
} catch (cause) {
|
|
147
|
+
status.value = "error";
|
|
148
|
+
error.value = cause instanceof Error ? cause.message : String(cause);
|
|
149
|
+
console.error("[Vue Solana] Connection failed", cause);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const vueContext = {
|
|
153
|
+
...context,
|
|
154
|
+
wallet,
|
|
155
|
+
status,
|
|
156
|
+
error,
|
|
157
|
+
latestBlockhash,
|
|
158
|
+
checkConnection,
|
|
159
|
+
setWallet(nextWallet) {
|
|
160
|
+
wallet.value = nextWallet;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
app.provide(solanaInjectionKey, vueContext);
|
|
164
|
+
void checkConnection();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const VueSolana = createSolanaPlugin;
|
|
169
|
+
|
|
170
|
+
exports.VueSolana = VueSolana;
|
|
171
|
+
exports.createSolanaPlugin = createSolanaPlugin;
|
|
172
|
+
exports.solanaInjectionKey = solanaInjectionKey;
|
|
173
|
+
exports.useBalance = useBalance;
|
|
174
|
+
exports.useConnection = useConnection;
|
|
175
|
+
exports.useRpc = useRpc;
|
|
176
|
+
exports.useSignAndSendTransaction = useSignAndSendTransaction;
|
|
177
|
+
exports.useSolana = useSolana;
|
|
178
|
+
exports.useTransaction = useTransaction;
|
|
179
|
+
exports.useWallet = useWallet;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter, Ref, InjectionKey, App } from 'vue';
|
|
3
|
+
import { PublicKey, Commitment, TransactionSignature } from '@solana/web3-compat';
|
|
4
|
+
import * as _vue_solana_core from '@vue-solana/core';
|
|
5
|
+
import { SendTransactionOptions, SolanaContext, SolanaWallet, SolanaConfig } from '@vue-solana/core';
|
|
6
|
+
|
|
7
|
+
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
8
|
+
balance: vue.Ref<number | null, number | null>;
|
|
9
|
+
loading: vue.Ref<boolean, boolean>;
|
|
10
|
+
error: vue.Ref<unknown, unknown>;
|
|
11
|
+
refresh: () => Promise<number | null>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare function useConnection(): Connection;
|
|
15
|
+
|
|
16
|
+
declare function useRpc(): {
|
|
17
|
+
cluster: vue.ComputedRef<_vue_solana_core.SolanaCluster>;
|
|
18
|
+
endpoint: vue.ComputedRef<string>;
|
|
19
|
+
wsEndpoint: vue.ComputedRef<string>;
|
|
20
|
+
status: vue.Ref<SolanaConnectionStatus, SolanaConnectionStatus>;
|
|
21
|
+
error: vue.Ref<string | null, string | null>;
|
|
22
|
+
latestBlockhash: vue.Ref<string | null, string | null>;
|
|
23
|
+
checkConnection: () => Promise<void>;
|
|
24
|
+
connection: Connection;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function useSignAndSendTransaction(): {
|
|
28
|
+
signature: any;
|
|
29
|
+
loading: vue.Ref<boolean, boolean>;
|
|
30
|
+
error: vue.Ref<unknown, unknown>;
|
|
31
|
+
execute: (transaction: any, options?: SendTransactionOptions | undefined) => Promise<any>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
declare function useSolana(): VueSolanaContext;
|
|
35
|
+
|
|
36
|
+
declare function useTransaction<TArgs extends unknown[]>(handler: (...args: TArgs) => Promise<TransactionSignature>): {
|
|
37
|
+
signature: any;
|
|
38
|
+
loading: vue.Ref<boolean, boolean>;
|
|
39
|
+
error: vue.Ref<unknown, unknown>;
|
|
40
|
+
execute: (...args: TArgs) => Promise<any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
declare function useWallet(): {
|
|
44
|
+
wallet: vue.Ref<_vue_solana_core.SolanaWallet | null, _vue_solana_core.SolanaWallet | null>;
|
|
45
|
+
publicKey: vue.ComputedRef<any>;
|
|
46
|
+
connected: vue.ComputedRef<boolean>;
|
|
47
|
+
connecting: vue.ComputedRef<boolean>;
|
|
48
|
+
setWallet: (wallet: _vue_solana_core.SolanaWallet | null) => void;
|
|
49
|
+
connect: () => Promise<void>;
|
|
50
|
+
disconnect: () => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type SolanaConnectionStatus = 'idle' | 'checking' | 'connected' | 'error';
|
|
54
|
+
interface VueSolanaContext extends SolanaContext {
|
|
55
|
+
wallet: Ref<SolanaWallet | null>;
|
|
56
|
+
status: Ref<SolanaConnectionStatus>;
|
|
57
|
+
error: Ref<string | null>;
|
|
58
|
+
latestBlockhash: Ref<string | null>;
|
|
59
|
+
checkConnection: () => Promise<void>;
|
|
60
|
+
setWallet: (wallet: SolanaWallet | null) => void;
|
|
61
|
+
}
|
|
62
|
+
declare const solanaInjectionKey: InjectionKey<VueSolanaContext>;
|
|
63
|
+
|
|
64
|
+
interface VueSolanaPluginOptions extends SolanaConfig {
|
|
65
|
+
wallet?: SolanaWallet | null;
|
|
66
|
+
}
|
|
67
|
+
declare function createSolanaPlugin(options?: VueSolanaPluginOptions): {
|
|
68
|
+
install(app: App): void;
|
|
69
|
+
};
|
|
70
|
+
declare const VueSolana: typeof createSolanaPlugin;
|
|
71
|
+
|
|
72
|
+
export { VueSolana, createSolanaPlugin, solanaInjectionKey, useBalance, useConnection, useRpc, useSignAndSendTransaction, useSolana, useTransaction, useWallet };
|
|
73
|
+
export type { SolanaConnectionStatus, VueSolanaContext, VueSolanaPluginOptions };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter, Ref, InjectionKey, App } from 'vue';
|
|
3
|
+
import { PublicKey, Commitment, TransactionSignature } from '@solana/web3-compat';
|
|
4
|
+
import * as _vue_solana_core from '@vue-solana/core';
|
|
5
|
+
import { SendTransactionOptions, SolanaContext, SolanaWallet, SolanaConfig } from '@vue-solana/core';
|
|
6
|
+
|
|
7
|
+
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
8
|
+
balance: vue.Ref<number | null, number | null>;
|
|
9
|
+
loading: vue.Ref<boolean, boolean>;
|
|
10
|
+
error: vue.Ref<unknown, unknown>;
|
|
11
|
+
refresh: () => Promise<number | null>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare function useConnection(): Connection;
|
|
15
|
+
|
|
16
|
+
declare function useRpc(): {
|
|
17
|
+
cluster: vue.ComputedRef<_vue_solana_core.SolanaCluster>;
|
|
18
|
+
endpoint: vue.ComputedRef<string>;
|
|
19
|
+
wsEndpoint: vue.ComputedRef<string>;
|
|
20
|
+
status: vue.Ref<SolanaConnectionStatus, SolanaConnectionStatus>;
|
|
21
|
+
error: vue.Ref<string | null, string | null>;
|
|
22
|
+
latestBlockhash: vue.Ref<string | null, string | null>;
|
|
23
|
+
checkConnection: () => Promise<void>;
|
|
24
|
+
connection: Connection;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function useSignAndSendTransaction(): {
|
|
28
|
+
signature: any;
|
|
29
|
+
loading: vue.Ref<boolean, boolean>;
|
|
30
|
+
error: vue.Ref<unknown, unknown>;
|
|
31
|
+
execute: (transaction: any, options?: SendTransactionOptions | undefined) => Promise<any>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
declare function useSolana(): VueSolanaContext;
|
|
35
|
+
|
|
36
|
+
declare function useTransaction<TArgs extends unknown[]>(handler: (...args: TArgs) => Promise<TransactionSignature>): {
|
|
37
|
+
signature: any;
|
|
38
|
+
loading: vue.Ref<boolean, boolean>;
|
|
39
|
+
error: vue.Ref<unknown, unknown>;
|
|
40
|
+
execute: (...args: TArgs) => Promise<any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
declare function useWallet(): {
|
|
44
|
+
wallet: vue.Ref<_vue_solana_core.SolanaWallet | null, _vue_solana_core.SolanaWallet | null>;
|
|
45
|
+
publicKey: vue.ComputedRef<any>;
|
|
46
|
+
connected: vue.ComputedRef<boolean>;
|
|
47
|
+
connecting: vue.ComputedRef<boolean>;
|
|
48
|
+
setWallet: (wallet: _vue_solana_core.SolanaWallet | null) => void;
|
|
49
|
+
connect: () => Promise<void>;
|
|
50
|
+
disconnect: () => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type SolanaConnectionStatus = 'idle' | 'checking' | 'connected' | 'error';
|
|
54
|
+
interface VueSolanaContext extends SolanaContext {
|
|
55
|
+
wallet: Ref<SolanaWallet | null>;
|
|
56
|
+
status: Ref<SolanaConnectionStatus>;
|
|
57
|
+
error: Ref<string | null>;
|
|
58
|
+
latestBlockhash: Ref<string | null>;
|
|
59
|
+
checkConnection: () => Promise<void>;
|
|
60
|
+
setWallet: (wallet: SolanaWallet | null) => void;
|
|
61
|
+
}
|
|
62
|
+
declare const solanaInjectionKey: InjectionKey<VueSolanaContext>;
|
|
63
|
+
|
|
64
|
+
interface VueSolanaPluginOptions extends SolanaConfig {
|
|
65
|
+
wallet?: SolanaWallet | null;
|
|
66
|
+
}
|
|
67
|
+
declare function createSolanaPlugin(options?: VueSolanaPluginOptions): {
|
|
68
|
+
install(app: App): void;
|
|
69
|
+
};
|
|
70
|
+
declare const VueSolana: typeof createSolanaPlugin;
|
|
71
|
+
|
|
72
|
+
export { VueSolana, createSolanaPlugin, solanaInjectionKey, useBalance, useConnection, useRpc, useSignAndSendTransaction, useSolana, useTransaction, useWallet };
|
|
73
|
+
export type { SolanaConnectionStatus, VueSolanaContext, VueSolanaPluginOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter, Ref, InjectionKey, App } from 'vue';
|
|
3
|
+
import { PublicKey, Commitment, TransactionSignature } from '@solana/web3-compat';
|
|
4
|
+
import * as _vue_solana_core from '@vue-solana/core';
|
|
5
|
+
import { SendTransactionOptions, SolanaContext, SolanaWallet, SolanaConfig } from '@vue-solana/core';
|
|
6
|
+
|
|
7
|
+
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
8
|
+
balance: vue.Ref<number | null, number | null>;
|
|
9
|
+
loading: vue.Ref<boolean, boolean>;
|
|
10
|
+
error: vue.Ref<unknown, unknown>;
|
|
11
|
+
refresh: () => Promise<number | null>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare function useConnection(): Connection;
|
|
15
|
+
|
|
16
|
+
declare function useRpc(): {
|
|
17
|
+
cluster: vue.ComputedRef<_vue_solana_core.SolanaCluster>;
|
|
18
|
+
endpoint: vue.ComputedRef<string>;
|
|
19
|
+
wsEndpoint: vue.ComputedRef<string>;
|
|
20
|
+
status: vue.Ref<SolanaConnectionStatus, SolanaConnectionStatus>;
|
|
21
|
+
error: vue.Ref<string | null, string | null>;
|
|
22
|
+
latestBlockhash: vue.Ref<string | null, string | null>;
|
|
23
|
+
checkConnection: () => Promise<void>;
|
|
24
|
+
connection: Connection;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
declare function useSignAndSendTransaction(): {
|
|
28
|
+
signature: any;
|
|
29
|
+
loading: vue.Ref<boolean, boolean>;
|
|
30
|
+
error: vue.Ref<unknown, unknown>;
|
|
31
|
+
execute: (transaction: any, options?: SendTransactionOptions | undefined) => Promise<any>;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
declare function useSolana(): VueSolanaContext;
|
|
35
|
+
|
|
36
|
+
declare function useTransaction<TArgs extends unknown[]>(handler: (...args: TArgs) => Promise<TransactionSignature>): {
|
|
37
|
+
signature: any;
|
|
38
|
+
loading: vue.Ref<boolean, boolean>;
|
|
39
|
+
error: vue.Ref<unknown, unknown>;
|
|
40
|
+
execute: (...args: TArgs) => Promise<any>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
declare function useWallet(): {
|
|
44
|
+
wallet: vue.Ref<_vue_solana_core.SolanaWallet | null, _vue_solana_core.SolanaWallet | null>;
|
|
45
|
+
publicKey: vue.ComputedRef<any>;
|
|
46
|
+
connected: vue.ComputedRef<boolean>;
|
|
47
|
+
connecting: vue.ComputedRef<boolean>;
|
|
48
|
+
setWallet: (wallet: _vue_solana_core.SolanaWallet | null) => void;
|
|
49
|
+
connect: () => Promise<void>;
|
|
50
|
+
disconnect: () => Promise<void>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type SolanaConnectionStatus = 'idle' | 'checking' | 'connected' | 'error';
|
|
54
|
+
interface VueSolanaContext extends SolanaContext {
|
|
55
|
+
wallet: Ref<SolanaWallet | null>;
|
|
56
|
+
status: Ref<SolanaConnectionStatus>;
|
|
57
|
+
error: Ref<string | null>;
|
|
58
|
+
latestBlockhash: Ref<string | null>;
|
|
59
|
+
checkConnection: () => Promise<void>;
|
|
60
|
+
setWallet: (wallet: SolanaWallet | null) => void;
|
|
61
|
+
}
|
|
62
|
+
declare const solanaInjectionKey: InjectionKey<VueSolanaContext>;
|
|
63
|
+
|
|
64
|
+
interface VueSolanaPluginOptions extends SolanaConfig {
|
|
65
|
+
wallet?: SolanaWallet | null;
|
|
66
|
+
}
|
|
67
|
+
declare function createSolanaPlugin(options?: VueSolanaPluginOptions): {
|
|
68
|
+
install(app: App): void;
|
|
69
|
+
};
|
|
70
|
+
declare const VueSolana: typeof createSolanaPlugin;
|
|
71
|
+
|
|
72
|
+
export { VueSolana, createSolanaPlugin, solanaInjectionKey, useBalance, useConnection, useRpc, useSignAndSendTransaction, useSolana, useTransaction, useWallet };
|
|
73
|
+
export type { SolanaConnectionStatus, VueSolanaContext, VueSolanaPluginOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3-compat';
|
|
2
|
+
import { inject, computed, ref, watch, toValue, shallowRef } from 'vue';
|
|
3
|
+
import { signAndSendTransaction, createSolanaContext } from '@vue-solana/core';
|
|
4
|
+
|
|
5
|
+
const solanaInjectionKey = Symbol("VueSolana");
|
|
6
|
+
|
|
7
|
+
function useSolana() {
|
|
8
|
+
const context = inject(solanaInjectionKey);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error("Vue Solana plugin is not installed");
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function useRpc() {
|
|
16
|
+
const solana = useSolana();
|
|
17
|
+
return {
|
|
18
|
+
cluster: computed(() => solana.cluster),
|
|
19
|
+
endpoint: computed(() => solana.endpoint),
|
|
20
|
+
wsEndpoint: computed(() => solana.wsEndpoint),
|
|
21
|
+
status: solana.status,
|
|
22
|
+
error: solana.error,
|
|
23
|
+
latestBlockhash: solana.latestBlockhash,
|
|
24
|
+
checkConnection: solana.checkConnection,
|
|
25
|
+
connection: solana.connection
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function useConnection() {
|
|
30
|
+
return useRpc().connection;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function useBalance(address, commitment) {
|
|
34
|
+
const connection = useConnection();
|
|
35
|
+
const balance = ref(null);
|
|
36
|
+
const loading = ref(false);
|
|
37
|
+
const error = ref(null);
|
|
38
|
+
async function refresh() {
|
|
39
|
+
const value = toValue(address);
|
|
40
|
+
if (!value) {
|
|
41
|
+
balance.value = null;
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
loading.value = true;
|
|
45
|
+
error.value = null;
|
|
46
|
+
try {
|
|
47
|
+
const publicKey = typeof value === "string" ? new PublicKey(value) : value;
|
|
48
|
+
balance.value = await connection.getBalance(publicKey, commitment);
|
|
49
|
+
return balance.value;
|
|
50
|
+
} catch (cause) {
|
|
51
|
+
error.value = cause;
|
|
52
|
+
throw cause;
|
|
53
|
+
} finally {
|
|
54
|
+
loading.value = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
watch(() => toValue(address), () => {
|
|
58
|
+
void refresh();
|
|
59
|
+
}, { immediate: true });
|
|
60
|
+
return {
|
|
61
|
+
balance,
|
|
62
|
+
loading,
|
|
63
|
+
error,
|
|
64
|
+
refresh
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function useWallet() {
|
|
69
|
+
const solana = useSolana();
|
|
70
|
+
const wallet = solana.wallet;
|
|
71
|
+
return {
|
|
72
|
+
wallet,
|
|
73
|
+
publicKey: computed(() => wallet.value?.publicKey ?? null),
|
|
74
|
+
connected: computed(() => Boolean(wallet.value?.connected && wallet.value.publicKey)),
|
|
75
|
+
connecting: computed(() => Boolean(wallet.value?.connecting)),
|
|
76
|
+
setWallet: solana.setWallet,
|
|
77
|
+
connect: () => wallet.value?.connect() ?? Promise.reject(new Error("No Solana wallet is configured")),
|
|
78
|
+
disconnect: () => wallet.value?.disconnect() ?? Promise.resolve()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function useTransaction(handler) {
|
|
83
|
+
const signature = ref(null);
|
|
84
|
+
const loading = ref(false);
|
|
85
|
+
const error = ref(null);
|
|
86
|
+
async function execute(...args) {
|
|
87
|
+
loading.value = true;
|
|
88
|
+
error.value = null;
|
|
89
|
+
try {
|
|
90
|
+
signature.value = await handler(...args);
|
|
91
|
+
return signature.value;
|
|
92
|
+
} catch (cause) {
|
|
93
|
+
error.value = cause;
|
|
94
|
+
throw cause;
|
|
95
|
+
} finally {
|
|
96
|
+
loading.value = false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
signature,
|
|
101
|
+
loading,
|
|
102
|
+
error,
|
|
103
|
+
execute
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function useSignAndSendTransaction() {
|
|
108
|
+
const connection = useConnection();
|
|
109
|
+
const { wallet } = useWallet();
|
|
110
|
+
return useTransaction((transaction, options) => {
|
|
111
|
+
if (!wallet.value) {
|
|
112
|
+
return Promise.reject(new Error("No Solana wallet is configured"));
|
|
113
|
+
}
|
|
114
|
+
return signAndSendTransaction(connection, wallet.value, transaction, options);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createSolanaPlugin(options = {}) {
|
|
119
|
+
return {
|
|
120
|
+
install(app) {
|
|
121
|
+
const context = createSolanaContext(options);
|
|
122
|
+
const wallet = shallowRef(options.wallet ?? null);
|
|
123
|
+
const status = ref("idle");
|
|
124
|
+
const error = ref(null);
|
|
125
|
+
const latestBlockhash = ref(null);
|
|
126
|
+
async function checkConnection() {
|
|
127
|
+
status.value = "checking";
|
|
128
|
+
error.value = null;
|
|
129
|
+
console.info("[Vue Solana] Checking RPC connection", {
|
|
130
|
+
cluster: context.cluster,
|
|
131
|
+
endpoint: context.endpoint,
|
|
132
|
+
wsEndpoint: context.wsEndpoint
|
|
133
|
+
});
|
|
134
|
+
try {
|
|
135
|
+
const blockhash = await context.connection.getLatestBlockhash();
|
|
136
|
+
latestBlockhash.value = blockhash.blockhash;
|
|
137
|
+
status.value = "connected";
|
|
138
|
+
console.info("[Vue Solana] Connected", {
|
|
139
|
+
cluster: context.cluster,
|
|
140
|
+
endpoint: context.endpoint,
|
|
141
|
+
wsEndpoint: context.wsEndpoint,
|
|
142
|
+
blockhash
|
|
143
|
+
});
|
|
144
|
+
} catch (cause) {
|
|
145
|
+
status.value = "error";
|
|
146
|
+
error.value = cause instanceof Error ? cause.message : String(cause);
|
|
147
|
+
console.error("[Vue Solana] Connection failed", cause);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const vueContext = {
|
|
151
|
+
...context,
|
|
152
|
+
wallet,
|
|
153
|
+
status,
|
|
154
|
+
error,
|
|
155
|
+
latestBlockhash,
|
|
156
|
+
checkConnection,
|
|
157
|
+
setWallet(nextWallet) {
|
|
158
|
+
wallet.value = nextWallet;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
app.provide(solanaInjectionKey, vueContext);
|
|
162
|
+
void checkConnection();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
const VueSolana = createSolanaPlugin;
|
|
167
|
+
|
|
168
|
+
export { VueSolana, createSolanaPlugin, solanaInjectionKey, useBalance, useConnection, useRpc, useSignAndSendTransaction, useSolana, useTransaction, useWallet };
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue-solana/vue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vue plugin and composables for Solana applications.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"solana",
|
|
8
|
+
"vue",
|
|
9
|
+
"vue3",
|
|
10
|
+
"composables",
|
|
11
|
+
"web3",
|
|
12
|
+
"wallet"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/vue-solana/vue-solana#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/vue-solana/vue-solana/issues"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/vue-solana/vue-solana.git",
|
|
21
|
+
"directory": "packages/vue"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.cjs",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"require": "./dist/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@vue-solana/core": "0.1.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@solana/web3-compat": "^0.0.21",
|
|
45
|
+
"vue": "^3.5.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@solana/web3-compat": "^0.0.21",
|
|
49
|
+
"typescript": "^5.8.3",
|
|
50
|
+
"unbuild": "^3.5.0",
|
|
51
|
+
"vue": "^3.5.16"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "unbuild",
|
|
55
|
+
"dev": "unbuild --stub",
|
|
56
|
+
"typecheck": "tsc --noEmit",
|
|
57
|
+
"clean": "rm -rf dist"
|
|
58
|
+
}
|
|
59
|
+
}
|