@vue-solana/vue 0.2.1 → 0.2.3
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/README.md +25 -4
- package/dist/index.cjs +86 -195
- package/dist/index.d.cts +14 -77
- package/dist/index.d.mts +14 -77
- package/dist/index.d.ts +14 -77
- package/dist/index.mjs +74 -183
- package/dist/shared/vue.1M_c5FWA.mjs +46 -0
- package/dist/shared/vue.BMUEDN2t.mjs +28 -0
- package/dist/shared/vue.BSVxQ9Yi.cjs +30 -0
- package/dist/shared/vue.BqDzSepb.mjs +18 -0
- package/dist/shared/vue.C4tLiG3R.cjs +50 -0
- package/dist/shared/vue.COyyrsQU.cjs +20 -0
- package/dist/shared/vue.CTM6XQ47.cjs +19 -0
- package/dist/shared/vue.CjKm-Cw1.cjs +47 -0
- package/dist/shared/vue.CwPjPFN6.cjs +69 -0
- package/dist/shared/vue.CwhEmATP.cjs +9 -0
- package/dist/shared/vue.D81obqiN.mjs +45 -0
- package/dist/shared/vue.DGhodYJh.d.cts +20 -0
- package/dist/shared/vue.DGhodYJh.d.mts +20 -0
- package/dist/shared/vue.DGhodYJh.d.ts +20 -0
- package/dist/shared/vue.DYf_CRDv.mjs +67 -0
- package/dist/shared/vue.DlEAL2G8.mjs +7 -0
- package/dist/shared/vue.P9tgeC5S.cjs +15 -0
- package/dist/shared/vue.PoQ8Vpmy.mjs +17 -0
- package/dist/shared/vue.h-uS8MXN.mjs +13 -0
- package/dist/useBalance.cjs +11 -0
- package/dist/useBalance.d.cts +12 -0
- package/dist/useBalance.d.mts +12 -0
- package/dist/useBalance.d.ts +12 -0
- package/dist/useBalance.mjs +5 -0
- package/dist/useConnection.cjs +10 -0
- package/dist/useConnection.d.cts +3 -0
- package/dist/useConnection.d.mts +3 -0
- package/dist/useConnection.d.ts +3 -0
- package/dist/useConnection.mjs +4 -0
- package/dist/useRpc.cjs +9 -0
- package/dist/useRpc.d.cts +16 -0
- package/dist/useRpc.d.mts +16 -0
- package/dist/useRpc.d.ts +16 -0
- package/dist/useRpc.mjs +3 -0
- package/dist/useSignAndSendTransaction.cjs +14 -0
- package/dist/useSignAndSendTransaction.d.cts +11 -0
- package/dist/useSignAndSendTransaction.d.mts +11 -0
- package/dist/useSignAndSendTransaction.d.ts +11 -0
- package/dist/useSignAndSendTransaction.mjs +8 -0
- package/dist/useSolana.cjs +9 -0
- package/dist/useSolana.d.cts +8 -0
- package/dist/useSolana.d.mts +8 -0
- package/dist/useSolana.d.ts +8 -0
- package/dist/useSolana.mjs +2 -0
- package/dist/useTransaction.cjs +8 -0
- package/dist/useTransaction.d.cts +11 -0
- package/dist/useTransaction.d.mts +11 -0
- package/dist/useTransaction.d.ts +11 -0
- package/dist/useTransaction.mjs +2 -0
- package/dist/useWallet.cjs +9 -0
- package/dist/useWallet.d.cts +16 -0
- package/dist/useWallet.d.mts +16 -0
- package/dist/useWallet.d.ts +16 -0
- package/dist/useWallet.mjs +3 -0
- package/dist/useWallets.cjs +9 -0
- package/dist/useWallets.d.cts +11 -0
- package/dist/useWallets.d.mts +11 -0
- package/dist/useWallets.d.ts +11 -0
- package/dist/useWallets.mjs +3 -0
- package/package.json +41 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,78 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
disconnecting: vue.ComputedRef<boolean>;
|
|
49
|
-
loading: vue.ComputedRef<boolean>;
|
|
50
|
-
setWallet: (wallet: _vue_solana_core.SolanaWallet | null) => void;
|
|
51
|
-
connect: () => Promise<void>;
|
|
52
|
-
disconnect: () => Promise<void>;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare function useWallets(): {
|
|
56
|
-
wallets: vue.Ref<_vue_solana_core.SolanaWalletInfo[], _vue_solana_core.SolanaWalletInfo[]>;
|
|
57
|
-
selectedWallet: vue.Ref<_vue_solana_core.SolanaWalletInfo | null, _vue_solana_core.SolanaWalletInfo | null>;
|
|
58
|
-
refreshWallets: () => void;
|
|
59
|
-
selectWallet: (wallet: _vue_solana_core.SolanaWalletInfo | null) => void;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
type SolanaConnectionStatus = "idle" | "checking" | "connected" | "error";
|
|
63
|
-
interface VueSolanaContext extends SolanaContext {
|
|
64
|
-
wallet: Ref<SolanaWallet | null>;
|
|
65
|
-
status: Ref<SolanaConnectionStatus>;
|
|
66
|
-
error: Ref<string | null>;
|
|
67
|
-
latestBlockhash: Ref<string | null>;
|
|
68
|
-
wallets: Ref<SolanaWalletInfo[]>;
|
|
69
|
-
selectedWallet: Ref<SolanaWalletInfo | null>;
|
|
70
|
-
checkConnection: () => Promise<void>;
|
|
71
|
-
setWallet: (wallet: SolanaWallet | null) => void;
|
|
72
|
-
refreshWallets: () => void;
|
|
73
|
-
selectWallet: (wallet: SolanaWalletInfo | null) => void;
|
|
74
|
-
}
|
|
75
|
-
declare const solanaInjectionKey: InjectionKey<VueSolanaContext>;
|
|
1
|
+
export { useBalance } from './useBalance.js';
|
|
2
|
+
export { useConnection } from './useConnection.js';
|
|
3
|
+
export { useRpc } from './useRpc.js';
|
|
4
|
+
export { useSignAndSendTransaction } from './useSignAndSendTransaction.js';
|
|
5
|
+
export { tryUseSolana, useSolana } from './useSolana.js';
|
|
6
|
+
export { useTransaction } from './useTransaction.js';
|
|
7
|
+
export { useWallet } from './useWallet.js';
|
|
8
|
+
export { useWallets } from './useWallets.js';
|
|
9
|
+
export { S as SolanaConnectionStatus, V as VueSolanaContext, s as solanaInjectionKey } from './shared/vue.DGhodYJh.js';
|
|
10
|
+
import { SolanaConfig, SolanaWallet } from '@vue-solana/core/types';
|
|
11
|
+
import { App } from 'vue';
|
|
12
|
+
import '@solana/web3-compat';
|
|
76
13
|
|
|
77
14
|
interface VueSolanaPluginOptions extends SolanaConfig {
|
|
78
15
|
wallet?: SolanaWallet | null;
|
|
@@ -82,5 +19,5 @@ declare function createSolanaPlugin(options?: VueSolanaPluginOptions): {
|
|
|
82
19
|
};
|
|
83
20
|
declare const VueSolana: typeof createSolanaPlugin;
|
|
84
21
|
|
|
85
|
-
export { VueSolana, createSolanaPlugin
|
|
86
|
-
export type {
|
|
22
|
+
export { VueSolana, createSolanaPlugin };
|
|
23
|
+
export type { VueSolanaPluginOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,182 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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(
|
|
58
|
-
() => toValue(address),
|
|
59
|
-
() => {
|
|
60
|
-
void refresh().catch(() => void 0);
|
|
61
|
-
},
|
|
62
|
-
{ immediate: true }
|
|
63
|
-
);
|
|
64
|
-
return {
|
|
65
|
-
balance,
|
|
66
|
-
loading,
|
|
67
|
-
error,
|
|
68
|
-
refresh
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function useWallet() {
|
|
73
|
-
const solana = useSolana();
|
|
74
|
-
const wallet = solana.wallet;
|
|
75
|
-
const connecting = ref(false);
|
|
76
|
-
const disconnecting = ref(false);
|
|
77
|
-
async function connect() {
|
|
78
|
-
const activeWallet = wallet.value;
|
|
79
|
-
if (!activeWallet) {
|
|
80
|
-
throw new Error("No Solana wallet is configured");
|
|
81
|
-
}
|
|
82
|
-
connecting.value = true;
|
|
83
|
-
try {
|
|
84
|
-
const connection = activeWallet.connect();
|
|
85
|
-
triggerRef(wallet);
|
|
86
|
-
await connection;
|
|
87
|
-
triggerRef(wallet);
|
|
88
|
-
console.info("[Vue Solana] Wallet connected", {
|
|
89
|
-
publicKey: activeWallet.publicKey?.toBase58() ?? null
|
|
90
|
-
});
|
|
91
|
-
} catch (error) {
|
|
92
|
-
triggerRef(wallet);
|
|
93
|
-
console.error("[Vue Solana] Wallet connection failed", error);
|
|
94
|
-
throw error;
|
|
95
|
-
} finally {
|
|
96
|
-
connecting.value = false;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async function disconnect() {
|
|
100
|
-
const activeWallet = wallet.value;
|
|
101
|
-
if (!activeWallet) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
const publicKey = activeWallet.publicKey?.toBase58() ?? null;
|
|
105
|
-
disconnecting.value = true;
|
|
106
|
-
try {
|
|
107
|
-
await activeWallet.disconnect();
|
|
108
|
-
triggerRef(wallet);
|
|
109
|
-
console.info("[Vue Solana] Wallet disconnected", { publicKey });
|
|
110
|
-
} catch (error) {
|
|
111
|
-
triggerRef(wallet);
|
|
112
|
-
console.error("[Vue Solana] Wallet disconnection failed", error);
|
|
113
|
-
throw error;
|
|
114
|
-
} finally {
|
|
115
|
-
disconnecting.value = false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const isConnecting = computed(() => Boolean(connecting.value || wallet.value?.connecting));
|
|
119
|
-
const isDisconnecting = computed(
|
|
120
|
-
() => Boolean(disconnecting.value || wallet.value?.disconnecting)
|
|
121
|
-
);
|
|
122
|
-
return {
|
|
123
|
-
wallet,
|
|
124
|
-
publicKey: computed(() => wallet.value?.publicKey ?? null),
|
|
125
|
-
connected: computed(() => Boolean(wallet.value?.connected && wallet.value.publicKey)),
|
|
126
|
-
connecting: isConnecting,
|
|
127
|
-
disconnecting: isDisconnecting,
|
|
128
|
-
loading: computed(() => isConnecting.value || isDisconnecting.value),
|
|
129
|
-
setWallet: solana.setWallet,
|
|
130
|
-
connect,
|
|
131
|
-
disconnect
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function useTransaction(handler) {
|
|
136
|
-
const signature = ref(null);
|
|
137
|
-
const loading = ref(false);
|
|
138
|
-
const error = ref(null);
|
|
139
|
-
async function execute(...args) {
|
|
140
|
-
loading.value = true;
|
|
141
|
-
error.value = null;
|
|
142
|
-
try {
|
|
143
|
-
signature.value = await handler(...args);
|
|
144
|
-
return signature.value;
|
|
145
|
-
} catch (cause) {
|
|
146
|
-
error.value = cause;
|
|
147
|
-
throw cause;
|
|
148
|
-
} finally {
|
|
149
|
-
loading.value = false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
signature,
|
|
154
|
-
loading,
|
|
155
|
-
error,
|
|
156
|
-
execute
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function useSignAndSendTransaction() {
|
|
161
|
-
const connection = useConnection();
|
|
162
|
-
const { wallet } = useWallet();
|
|
163
|
-
return useTransaction((transaction, options) => {
|
|
164
|
-
if (!wallet.value) {
|
|
165
|
-
return Promise.reject(new Error("No Solana wallet is configured"));
|
|
166
|
-
}
|
|
167
|
-
return signAndSendTransaction(connection, wallet.value, transaction, options);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function useWallets() {
|
|
172
|
-
const solana = useSolana();
|
|
173
|
-
return {
|
|
174
|
-
wallets: solana.wallets,
|
|
175
|
-
selectedWallet: solana.selectedWallet,
|
|
176
|
-
refreshWallets: solana.refreshWallets,
|
|
177
|
-
selectWallet: solana.selectWallet
|
|
178
|
-
};
|
|
179
|
-
}
|
|
1
|
+
export { u as useBalance } from './shared/vue.D81obqiN.mjs';
|
|
2
|
+
export { u as useConnection } from './shared/vue.DlEAL2G8.mjs';
|
|
3
|
+
export { u as useRpc } from './shared/vue.BqDzSepb.mjs';
|
|
4
|
+
export { u as useSignAndSendTransaction } from './shared/vue.PoQ8Vpmy.mjs';
|
|
5
|
+
import { s as solanaInjectionKey } from './shared/vue.1M_c5FWA.mjs';
|
|
6
|
+
export { t as tryUseSolana, u as useSolana } from './shared/vue.1M_c5FWA.mjs';
|
|
7
|
+
export { u as useTransaction } from './shared/vue.BMUEDN2t.mjs';
|
|
8
|
+
export { u as useWallet } from './shared/vue.DYf_CRDv.mjs';
|
|
9
|
+
export { u as useWallets } from './shared/vue.h-uS8MXN.mjs';
|
|
10
|
+
import { subscribeSolanaWallets, getRegisteredSolanaWallets, adaptSolanaStandardWallet, getSolanaChain } from '@vue-solana/core/wallet-standard';
|
|
11
|
+
import { createSolanaContext } from '@vue-solana/core/rpc';
|
|
12
|
+
import { shallowRef, ref, triggerRef } from 'vue';
|
|
13
|
+
import '@vue-solana/core/transaction';
|
|
180
14
|
|
|
181
15
|
const RPC_CHECK_TIMEOUT_MS = 1e4;
|
|
182
16
|
function createSolanaPlugin(options = {}) {
|
|
@@ -189,6 +23,7 @@ function createSolanaPlugin(options = {}) {
|
|
|
189
23
|
const status = ref("idle");
|
|
190
24
|
const error = ref(null);
|
|
191
25
|
const latestBlockhash = ref(null);
|
|
26
|
+
const adaptedWallets = /* @__PURE__ */ new WeakMap();
|
|
192
27
|
let unsubscribeWallets = null;
|
|
193
28
|
let rpcCheckId = 0;
|
|
194
29
|
async function checkConnection() {
|
|
@@ -238,10 +73,61 @@ function createSolanaPlugin(options = {}) {
|
|
|
238
73
|
}
|
|
239
74
|
function selectWallet(nextWallet) {
|
|
240
75
|
selectedWallet.value = nextWallet;
|
|
241
|
-
wallet.value = nextWallet ?
|
|
76
|
+
wallet.value = nextWallet ? getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
77
|
+
}
|
|
78
|
+
function getAdaptedWallet(walletInfo) {
|
|
79
|
+
if (!isObject(walletInfo.wallet)) {
|
|
80
|
+
return adaptSolanaStandardWallet(walletInfo, {
|
|
81
|
+
chain: getSolanaChain(context.cluster),
|
|
82
|
+
onChange: () => triggerRef(wallet)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
86
|
+
if (cachedWallet) {
|
|
87
|
+
return cachedWallet;
|
|
88
|
+
}
|
|
89
|
+
const adaptedWallet = adaptSolanaStandardWallet(walletInfo, {
|
|
242
90
|
chain: getSolanaChain(context.cluster),
|
|
243
91
|
onChange: () => triggerRef(wallet)
|
|
244
|
-
})
|
|
92
|
+
});
|
|
93
|
+
const cachedAdapter = {
|
|
94
|
+
get publicKey() {
|
|
95
|
+
return adaptedWallet.publicKey;
|
|
96
|
+
},
|
|
97
|
+
get connected() {
|
|
98
|
+
return adaptedWallet.connected;
|
|
99
|
+
},
|
|
100
|
+
get connecting() {
|
|
101
|
+
return adaptedWallet.connecting;
|
|
102
|
+
},
|
|
103
|
+
get disconnecting() {
|
|
104
|
+
return adaptedWallet.disconnecting;
|
|
105
|
+
},
|
|
106
|
+
async connect() {
|
|
107
|
+
await adaptedWallet.connect();
|
|
108
|
+
await Promise.all(
|
|
109
|
+
Array.from(getCachedWallets()).map(
|
|
110
|
+
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
disconnect: () => adaptedWallet.disconnect(),
|
|
115
|
+
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
116
|
+
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
117
|
+
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
118
|
+
};
|
|
119
|
+
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
120
|
+
return cachedAdapter;
|
|
121
|
+
}
|
|
122
|
+
function* getCachedWallets() {
|
|
123
|
+
for (const walletInfo of wallets.value) {
|
|
124
|
+
if (isObject(walletInfo.wallet)) {
|
|
125
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
126
|
+
if (cachedWallet) {
|
|
127
|
+
yield cachedWallet;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
245
131
|
}
|
|
246
132
|
const vueContext = {
|
|
247
133
|
...context,
|
|
@@ -260,10 +146,15 @@ function createSolanaPlugin(options = {}) {
|
|
|
260
146
|
}
|
|
261
147
|
};
|
|
262
148
|
app.provide(solanaInjectionKey, vueContext);
|
|
263
|
-
|
|
149
|
+
if (typeof window !== "undefined") {
|
|
150
|
+
void checkConnection();
|
|
151
|
+
}
|
|
264
152
|
}
|
|
265
153
|
};
|
|
266
154
|
}
|
|
155
|
+
function isObject(value) {
|
|
156
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
157
|
+
}
|
|
267
158
|
const VueSolana = createSolanaPlugin;
|
|
268
159
|
function withTimeout(promise, timeoutMs, message) {
|
|
269
160
|
let timeoutId;
|
|
@@ -279,4 +170,4 @@ function withTimeout(promise, timeoutMs, message) {
|
|
|
279
170
|
});
|
|
280
171
|
}
|
|
281
172
|
|
|
282
|
-
export { VueSolana, createSolanaPlugin, solanaInjectionKey
|
|
173
|
+
export { VueSolana, createSolanaPlugin, solanaInjectionKey };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { inject, shallowRef, ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
const solanaInjectionKey = Symbol("VueSolana");
|
|
4
|
+
|
|
5
|
+
let ssrContext;
|
|
6
|
+
function tryUseSolana() {
|
|
7
|
+
return inject(solanaInjectionKey, null);
|
|
8
|
+
}
|
|
9
|
+
function useSolana() {
|
|
10
|
+
return tryUseSolana() ?? getSsrContext();
|
|
11
|
+
}
|
|
12
|
+
function getSsrContext() {
|
|
13
|
+
ssrContext ??= {
|
|
14
|
+
cluster: "devnet",
|
|
15
|
+
endpoint: "",
|
|
16
|
+
wsEndpoint: "",
|
|
17
|
+
connection: createUnavailableConnection(),
|
|
18
|
+
wallet: shallowRef(null),
|
|
19
|
+
status: ref("idle"),
|
|
20
|
+
error: ref(null),
|
|
21
|
+
latestBlockhash: ref(null),
|
|
22
|
+
wallets: shallowRef([]),
|
|
23
|
+
selectedWallet: shallowRef(null),
|
|
24
|
+
async checkConnection() {
|
|
25
|
+
},
|
|
26
|
+
setWallet() {
|
|
27
|
+
},
|
|
28
|
+
refreshWallets() {
|
|
29
|
+
},
|
|
30
|
+
selectWallet() {
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return ssrContext;
|
|
34
|
+
}
|
|
35
|
+
function createUnavailableConnection() {
|
|
36
|
+
return new Proxy(
|
|
37
|
+
{},
|
|
38
|
+
{
|
|
39
|
+
get() {
|
|
40
|
+
throw new Error("Vue Solana plugin is not installed");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { solanaInjectionKey as s, tryUseSolana as t, useSolana as u };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
function useTransaction(handler) {
|
|
4
|
+
const signature = ref(null);
|
|
5
|
+
const loading = ref(false);
|
|
6
|
+
const error = ref(null);
|
|
7
|
+
async function execute(...args) {
|
|
8
|
+
loading.value = true;
|
|
9
|
+
error.value = null;
|
|
10
|
+
try {
|
|
11
|
+
signature.value = await handler(...args);
|
|
12
|
+
return signature.value;
|
|
13
|
+
} catch (cause) {
|
|
14
|
+
error.value = cause;
|
|
15
|
+
throw cause;
|
|
16
|
+
} finally {
|
|
17
|
+
loading.value = false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
signature,
|
|
22
|
+
loading,
|
|
23
|
+
error,
|
|
24
|
+
execute
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { useTransaction as u };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
|
|
5
|
+
function useTransaction(handler) {
|
|
6
|
+
const signature = vue.ref(null);
|
|
7
|
+
const loading = vue.ref(false);
|
|
8
|
+
const error = vue.ref(null);
|
|
9
|
+
async function execute(...args) {
|
|
10
|
+
loading.value = true;
|
|
11
|
+
error.value = null;
|
|
12
|
+
try {
|
|
13
|
+
signature.value = await handler(...args);
|
|
14
|
+
return signature.value;
|
|
15
|
+
} catch (cause) {
|
|
16
|
+
error.value = cause;
|
|
17
|
+
throw cause;
|
|
18
|
+
} finally {
|
|
19
|
+
loading.value = false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
signature,
|
|
24
|
+
loading,
|
|
25
|
+
error,
|
|
26
|
+
execute
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.useTransaction = useTransaction;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { computed } from 'vue';
|
|
2
|
+
import { u as useSolana } from './vue.1M_c5FWA.mjs';
|
|
3
|
+
|
|
4
|
+
function useRpc() {
|
|
5
|
+
const solana = useSolana();
|
|
6
|
+
return {
|
|
7
|
+
cluster: computed(() => solana.cluster),
|
|
8
|
+
endpoint: computed(() => solana.endpoint),
|
|
9
|
+
wsEndpoint: computed(() => solana.wsEndpoint),
|
|
10
|
+
status: solana.status,
|
|
11
|
+
error: solana.error,
|
|
12
|
+
latestBlockhash: solana.latestBlockhash,
|
|
13
|
+
checkConnection: solana.checkConnection,
|
|
14
|
+
connection: solana.connection
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useRpc as u };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
|
|
5
|
+
const solanaInjectionKey = Symbol("VueSolana");
|
|
6
|
+
|
|
7
|
+
let ssrContext;
|
|
8
|
+
function tryUseSolana() {
|
|
9
|
+
return vue.inject(solanaInjectionKey, null);
|
|
10
|
+
}
|
|
11
|
+
function useSolana() {
|
|
12
|
+
return tryUseSolana() ?? getSsrContext();
|
|
13
|
+
}
|
|
14
|
+
function getSsrContext() {
|
|
15
|
+
ssrContext ??= {
|
|
16
|
+
cluster: "devnet",
|
|
17
|
+
endpoint: "",
|
|
18
|
+
wsEndpoint: "",
|
|
19
|
+
connection: createUnavailableConnection(),
|
|
20
|
+
wallet: vue.shallowRef(null),
|
|
21
|
+
status: vue.ref("idle"),
|
|
22
|
+
error: vue.ref(null),
|
|
23
|
+
latestBlockhash: vue.ref(null),
|
|
24
|
+
wallets: vue.shallowRef([]),
|
|
25
|
+
selectedWallet: vue.shallowRef(null),
|
|
26
|
+
async checkConnection() {
|
|
27
|
+
},
|
|
28
|
+
setWallet() {
|
|
29
|
+
},
|
|
30
|
+
refreshWallets() {
|
|
31
|
+
},
|
|
32
|
+
selectWallet() {
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
return ssrContext;
|
|
36
|
+
}
|
|
37
|
+
function createUnavailableConnection() {
|
|
38
|
+
return new Proxy(
|
|
39
|
+
{},
|
|
40
|
+
{
|
|
41
|
+
get() {
|
|
42
|
+
throw new Error("Vue Solana plugin is not installed");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.solanaInjectionKey = solanaInjectionKey;
|
|
49
|
+
exports.tryUseSolana = tryUseSolana;
|
|
50
|
+
exports.useSolana = useSolana;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const useSolana = require('./vue.C4tLiG3R.cjs');
|
|
5
|
+
|
|
6
|
+
function useRpc() {
|
|
7
|
+
const solana = useSolana.useSolana();
|
|
8
|
+
return {
|
|
9
|
+
cluster: vue.computed(() => solana.cluster),
|
|
10
|
+
endpoint: vue.computed(() => solana.endpoint),
|
|
11
|
+
wsEndpoint: vue.computed(() => solana.wsEndpoint),
|
|
12
|
+
status: solana.status,
|
|
13
|
+
error: solana.error,
|
|
14
|
+
latestBlockhash: solana.latestBlockhash,
|
|
15
|
+
checkConnection: solana.checkConnection,
|
|
16
|
+
connection: solana.connection
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
exports.useRpc = useRpc;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const transaction = require('@vue-solana/core/transaction');
|
|
4
|
+
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
5
|
+
const useWallet = require('./vue.CwPjPFN6.cjs');
|
|
6
|
+
const useTransaction = require('./vue.BSVxQ9Yi.cjs');
|
|
7
|
+
|
|
8
|
+
function useSignAndSendTransaction() {
|
|
9
|
+
const connection = useConnection.useConnection();
|
|
10
|
+
const { wallet } = useWallet.useWallet();
|
|
11
|
+
return useTransaction.useTransaction((transaction$1, options) => {
|
|
12
|
+
if (!wallet.value) {
|
|
13
|
+
return Promise.reject(new Error("No Solana wallet is configured"));
|
|
14
|
+
}
|
|
15
|
+
return transaction.signAndSendTransaction(connection, wallet.value, transaction$1, options);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.useSignAndSendTransaction = useSignAndSendTransaction;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
5
|
+
const useSolana = require('./vue.C4tLiG3R.cjs');
|
|
6
|
+
|
|
7
|
+
function useBalance(address, commitment) {
|
|
8
|
+
const solana = useSolana.tryUseSolana();
|
|
9
|
+
const connection = solana?.connection ?? useConnection.useConnection();
|
|
10
|
+
const balance = vue.ref(null);
|
|
11
|
+
const loading = vue.ref(false);
|
|
12
|
+
const error = vue.ref(null);
|
|
13
|
+
async function refresh() {
|
|
14
|
+
const value = vue.toValue(address);
|
|
15
|
+
if (!value || !solana) {
|
|
16
|
+
balance.value = null;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
loading.value = true;
|
|
20
|
+
error.value = null;
|
|
21
|
+
try {
|
|
22
|
+
const publicKey = typeof value === "string" ? new (await import('@solana/web3-compat')).PublicKey(value) : value;
|
|
23
|
+
balance.value = await connection.getBalance(publicKey, commitment);
|
|
24
|
+
return balance.value;
|
|
25
|
+
} catch (cause) {
|
|
26
|
+
error.value = cause;
|
|
27
|
+
throw cause;
|
|
28
|
+
} finally {
|
|
29
|
+
loading.value = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
vue.watch(
|
|
33
|
+
() => vue.toValue(address),
|
|
34
|
+
() => {
|
|
35
|
+
void refresh().catch(() => void 0);
|
|
36
|
+
},
|
|
37
|
+
{ immediate: true }
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
balance,
|
|
41
|
+
loading,
|
|
42
|
+
error,
|
|
43
|
+
refresh
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.useBalance = useBalance;
|