@vue-solana/vue 0.2.2 → 0.3.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/README.md +41 -8
- package/dist/index.cjs +93 -195
- package/dist/index.d.cts +16 -77
- package/dist/index.d.mts +16 -77
- package/dist/index.d.ts +16 -77
- package/dist/index.mjs +81 -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.CNkyBND6.cjs +49 -0
- package/dist/shared/vue.COyyrsQU.cjs +20 -0
- package/dist/shared/vue.CTM6XQ47.cjs +19 -0
- package/dist/shared/vue.CgR3nGpz.mjs +47 -0
- package/dist/shared/vue.CwPjPFN6.cjs +69 -0
- package/dist/shared/vue.CwhEmATP.cjs +9 -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 +42 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,86 +1,25 @@
|
|
|
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 { RegisterSolanaMobileWalletOptions } from '@vue-solana/core/mobile-wallet';
|
|
11
|
+
import { SolanaConfig, SolanaWallet } from '@vue-solana/core/types';
|
|
12
|
+
import { App } from 'vue';
|
|
13
|
+
import '@solana/web3-compat';
|
|
76
14
|
|
|
77
15
|
interface VueSolanaPluginOptions extends SolanaConfig {
|
|
78
16
|
wallet?: SolanaWallet | null;
|
|
17
|
+
mobileWallet?: false | RegisterSolanaMobileWalletOptions;
|
|
79
18
|
}
|
|
80
19
|
declare function createSolanaPlugin(options?: VueSolanaPluginOptions): {
|
|
81
20
|
install(app: App): void;
|
|
82
21
|
};
|
|
83
22
|
declare const VueSolana: typeof createSolanaPlugin;
|
|
84
23
|
|
|
85
|
-
export { VueSolana, createSolanaPlugin
|
|
86
|
-
export type {
|
|
24
|
+
export { VueSolana, createSolanaPlugin };
|
|
25
|
+
export type { VueSolanaPluginOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,182 +1,17 @@
|
|
|
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.CgR3nGpz.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 { getSolanaChain, subscribeSolanaWallets, getRegisteredSolanaWallets, adaptSolanaStandardWallet } from '@vue-solana/core/wallet-standard';
|
|
11
|
+
import { registerSolanaMobileWallet } from '@vue-solana/core/mobile-wallet';
|
|
12
|
+
import { createSolanaContext } from '@vue-solana/core/rpc';
|
|
13
|
+
import { shallowRef, ref, triggerRef } from 'vue';
|
|
14
|
+
import '@vue-solana/core/transaction';
|
|
180
15
|
|
|
181
16
|
const RPC_CHECK_TIMEOUT_MS = 1e4;
|
|
182
17
|
function createSolanaPlugin(options = {}) {
|
|
@@ -189,6 +24,7 @@ function createSolanaPlugin(options = {}) {
|
|
|
189
24
|
const status = ref("idle");
|
|
190
25
|
const error = ref(null);
|
|
191
26
|
const latestBlockhash = ref(null);
|
|
27
|
+
const adaptedWallets = /* @__PURE__ */ new WeakMap();
|
|
192
28
|
let unsubscribeWallets = null;
|
|
193
29
|
let rpcCheckId = 0;
|
|
194
30
|
async function checkConnection() {
|
|
@@ -227,6 +63,12 @@ function createSolanaPlugin(options = {}) {
|
|
|
227
63
|
}
|
|
228
64
|
}
|
|
229
65
|
function refreshWallets() {
|
|
66
|
+
if (options.mobileWallet !== false) {
|
|
67
|
+
registerSolanaMobileWallet({
|
|
68
|
+
chains: [getSolanaChain(context.cluster)],
|
|
69
|
+
...options.mobileWallet || {}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
230
72
|
unsubscribeWallets ??= subscribeSolanaWallets(refreshWallets);
|
|
231
73
|
wallets.value = getRegisteredSolanaWallets();
|
|
232
74
|
if (selectedWallet.value) {
|
|
@@ -238,10 +80,61 @@ function createSolanaPlugin(options = {}) {
|
|
|
238
80
|
}
|
|
239
81
|
function selectWallet(nextWallet) {
|
|
240
82
|
selectedWallet.value = nextWallet;
|
|
241
|
-
wallet.value = nextWallet ?
|
|
83
|
+
wallet.value = nextWallet ? getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
84
|
+
}
|
|
85
|
+
function getAdaptedWallet(walletInfo) {
|
|
86
|
+
if (!isObject(walletInfo.wallet)) {
|
|
87
|
+
return adaptSolanaStandardWallet(walletInfo, {
|
|
88
|
+
chain: getSolanaChain(context.cluster),
|
|
89
|
+
onChange: () => triggerRef(wallet)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
93
|
+
if (cachedWallet) {
|
|
94
|
+
return cachedWallet;
|
|
95
|
+
}
|
|
96
|
+
const adaptedWallet = adaptSolanaStandardWallet(walletInfo, {
|
|
242
97
|
chain: getSolanaChain(context.cluster),
|
|
243
98
|
onChange: () => triggerRef(wallet)
|
|
244
|
-
})
|
|
99
|
+
});
|
|
100
|
+
const cachedAdapter = {
|
|
101
|
+
get publicKey() {
|
|
102
|
+
return adaptedWallet.publicKey;
|
|
103
|
+
},
|
|
104
|
+
get connected() {
|
|
105
|
+
return adaptedWallet.connected;
|
|
106
|
+
},
|
|
107
|
+
get connecting() {
|
|
108
|
+
return adaptedWallet.connecting;
|
|
109
|
+
},
|
|
110
|
+
get disconnecting() {
|
|
111
|
+
return adaptedWallet.disconnecting;
|
|
112
|
+
},
|
|
113
|
+
async connect() {
|
|
114
|
+
await adaptedWallet.connect();
|
|
115
|
+
await Promise.all(
|
|
116
|
+
Array.from(getCachedWallets()).map(
|
|
117
|
+
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
},
|
|
121
|
+
disconnect: () => adaptedWallet.disconnect(),
|
|
122
|
+
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
123
|
+
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
124
|
+
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
125
|
+
};
|
|
126
|
+
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
127
|
+
return cachedAdapter;
|
|
128
|
+
}
|
|
129
|
+
function* getCachedWallets() {
|
|
130
|
+
for (const walletInfo of wallets.value) {
|
|
131
|
+
if (isObject(walletInfo.wallet)) {
|
|
132
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
133
|
+
if (cachedWallet) {
|
|
134
|
+
yield cachedWallet;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
245
138
|
}
|
|
246
139
|
const vueContext = {
|
|
247
140
|
...context,
|
|
@@ -261,11 +154,16 @@ function createSolanaPlugin(options = {}) {
|
|
|
261
154
|
};
|
|
262
155
|
app.provide(solanaInjectionKey, vueContext);
|
|
263
156
|
if (typeof window !== "undefined") {
|
|
264
|
-
|
|
157
|
+
window.setTimeout(() => {
|
|
158
|
+
void checkConnection();
|
|
159
|
+
}, 0);
|
|
265
160
|
}
|
|
266
161
|
}
|
|
267
162
|
};
|
|
268
163
|
}
|
|
164
|
+
function isObject(value) {
|
|
165
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
166
|
+
}
|
|
269
167
|
const VueSolana = createSolanaPlugin;
|
|
270
168
|
function withTimeout(promise, timeoutMs, message) {
|
|
271
169
|
let timeoutId;
|
|
@@ -281,4 +179,4 @@ function withTimeout(promise, timeoutMs, message) {
|
|
|
281
179
|
});
|
|
282
180
|
}
|
|
283
181
|
|
|
284
|
-
export { VueSolana, createSolanaPlugin, solanaInjectionKey
|
|
182
|
+
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,49 @@
|
|
|
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.onMounted(() => {
|
|
33
|
+
void refresh().catch(() => void 0);
|
|
34
|
+
});
|
|
35
|
+
vue.watch(
|
|
36
|
+
() => vue.toValue(address),
|
|
37
|
+
() => {
|
|
38
|
+
void refresh().catch(() => void 0);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
return {
|
|
42
|
+
balance,
|
|
43
|
+
loading,
|
|
44
|
+
error,
|
|
45
|
+
refresh
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
exports.useBalance = useBalance;
|
|
@@ -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;
|