@vue-solana/vue 0.4.1 → 0.5.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 +4 -2
- package/dist/index.cjs +196 -104
- package/dist/index.mjs +196 -103
- package/dist/shared/{vue.BfF-kOvb.mjs → vue.DJ42Zrow.mjs} +1 -1
- package/dist/shared/{vue.DJqRk8z_.mjs → vue.DQhHHVu6.mjs} +19 -8
- package/dist/shared/{vue.CNhelr8H.cjs → vue.DQi38JeF.cjs} +20 -16
- package/dist/shared/{vue.BwrQMPty.cjs → vue.DQmAPXVB.cjs} +1 -1
- package/dist/shared/{vue.DONKZzIb.cjs → vue.D_AM1Nl8.cjs} +18 -7
- package/dist/shared/{vue.CuhLIeDx.mjs → vue.gLqkzJY4.mjs} +20 -17
- package/dist/useBalance.cjs +1 -1
- package/dist/useBalance.d.cts +4 -4
- package/dist/useBalance.d.mts +4 -4
- package/dist/useBalance.d.ts +4 -4
- package/dist/useBalance.mjs +1 -1
- package/dist/useSignAndSendTransaction.cjs +2 -2
- package/dist/useSignAndSendTransaction.mjs +2 -2
- package/dist/useTransaction.cjs +1 -1
- package/dist/useTransaction.mjs +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -154,6 +154,8 @@ const { publicKey, connected, connecting, connect, disconnect } = useWallet();
|
|
|
154
154
|
|
|
155
155
|
Browser extension wallets are discovered through the Solana Wallet Standard. Android Mobile Wallet Adapter wallets are registered through `@solana-mobile/wallet-standard-mobile` and exposed through the same `useWallets()` list on supported Android Chrome clients. iOS Phantom, Solflare, and Backpack entries are exposed through wallet-specific universal links on iOS browsers. `connect()` works after selecting a discovered wallet or configuring a custom `SolanaWallet`.
|
|
156
156
|
|
|
157
|
+
Selected discovered wallets are persisted under `localStorage["vue-solana:selected-wallet"]` as non-sensitive identity metadata: `name`, and `platform`/`source` when available. On reload, Vue Solana restores the selected wallet if the same wallet is discovered again. Pass `autoConnect: true` to opt into calling `connect()` for that restored wallet; arbitrary installed wallets are never auto-connected. Calling `selectWallet(null)` or `setWallet(customWallet)` clears the stored selection.
|
|
158
|
+
|
|
157
159
|
Desktop native app wallet adapters are planned but not implemented yet.
|
|
158
160
|
|
|
159
161
|
Composables return inert SSR-safe state when no plugin context is available. Real RPC and wallet operations still require the plugin-provided client context.
|
|
@@ -202,9 +204,9 @@ Docs: [Vue Solana Agent Skill](https://vue-solana-docs.vercel.app/agent-skill)
|
|
|
202
204
|
- `useRpc()`: returns cluster, endpoint, connection status, latest blockhash, and `checkConnection()`.
|
|
203
205
|
- `useConnection()`: returns the Solana `Connection`.
|
|
204
206
|
- `useWallet()`: returns wallet refs, computed connection state, and wallet actions.
|
|
205
|
-
- `useWallets()`: returns discovered browser extension wallets, Android Mobile Wallet Adapter wallets, and wallet selection actions.
|
|
207
|
+
- `useWallets()`: returns discovered browser extension wallets, Android Mobile Wallet Adapter wallets, iOS browser wallet links, and wallet selection actions.
|
|
206
208
|
- `useBalance(address, commitment?)`: loads lamport balance for a `PublicKey` or address string.
|
|
207
|
-
- `useTransaction(handler)`: generic async transaction state helper.
|
|
209
|
+
- `useTransaction(handler, options?)`: generic async transaction state helper with optional timeout settings.
|
|
208
210
|
- `useSignAndSendTransaction()`: signs and sends a transaction through the configured wallet.
|
|
209
211
|
|
|
210
212
|
Direct composable subpaths:
|
package/dist/index.cjs
CHANGED
|
@@ -1,20 +1,169 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const useBalance = require('./shared/vue.
|
|
3
|
+
const useBalance = require('./shared/vue.D_AM1Nl8.cjs');
|
|
4
4
|
const useConnection = require('./shared/vue.CwhEmATP.cjs');
|
|
5
5
|
const useRpc = require('./shared/vue.COyyrsQU.cjs');
|
|
6
|
-
const useSignAndSendTransaction = require('./shared/vue.
|
|
6
|
+
const useSignAndSendTransaction = require('./shared/vue.DQmAPXVB.cjs');
|
|
7
7
|
const useSolana = require('./shared/vue.C4tLiG3R.cjs');
|
|
8
|
-
const useTransaction = require('./shared/vue.
|
|
8
|
+
const useTransaction = require('./shared/vue.DQi38JeF.cjs');
|
|
9
9
|
const useWallet = require('./shared/vue.CwPjPFN6.cjs');
|
|
10
10
|
const useWallets = require('./shared/vue.P9tgeC5S.cjs');
|
|
11
|
-
const iosWallet = require('@vue-solana/core/ios-wallet');
|
|
12
|
-
const walletStandard = require('@vue-solana/core/wallet-standard');
|
|
13
11
|
const rpc = require('@vue-solana/core/rpc');
|
|
12
|
+
const walletStandard = require('@vue-solana/core/wallet-standard');
|
|
14
13
|
const vue = require('vue');
|
|
14
|
+
const iosWallet = require('@vue-solana/core/ios-wallet');
|
|
15
15
|
require('@solana/web3-compat');
|
|
16
16
|
require('@vue-solana/core/transaction');
|
|
17
17
|
|
|
18
|
+
const SELECTED_WALLET_STORAGE_KEY = "vue-solana:selected-wallet";
|
|
19
|
+
function readSelectedWallet() {
|
|
20
|
+
const storage = getLocalStorage();
|
|
21
|
+
if (!storage) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const value = storage.getItem(SELECTED_WALLET_STORAGE_KEY);
|
|
26
|
+
if (!value) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const wallet = JSON.parse(value);
|
|
30
|
+
return typeof wallet.name === "string" ? {
|
|
31
|
+
name: wallet.name,
|
|
32
|
+
platform: wallet.platform,
|
|
33
|
+
source: wallet.source
|
|
34
|
+
} : null;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function writeSelectedWallet(wallet) {
|
|
40
|
+
const storage = getLocalStorage();
|
|
41
|
+
if (!storage) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (wallet) {
|
|
46
|
+
storage.setItem(SELECTED_WALLET_STORAGE_KEY, stringifySelectedWallet(wallet));
|
|
47
|
+
} else {
|
|
48
|
+
storage.removeItem(SELECTED_WALLET_STORAGE_KEY);
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function stringifySelectedWallet(wallet) {
|
|
54
|
+
const value = { name: wallet.name };
|
|
55
|
+
if (wallet.platform) {
|
|
56
|
+
value.platform = wallet.platform;
|
|
57
|
+
}
|
|
58
|
+
if (wallet.source) {
|
|
59
|
+
value.source = wallet.source;
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
function getLocalStorage() {
|
|
64
|
+
if (typeof window === "undefined") {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return window.localStorage;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function createSolanaWalletRegistry(options) {
|
|
75
|
+
const adaptedWallets = /* @__PURE__ */ new WeakMap();
|
|
76
|
+
function getAdaptedWallet(walletInfo) {
|
|
77
|
+
if (iosWallet.isSolanaIosWalletInfo(walletInfo)) {
|
|
78
|
+
return iosWallet.adaptSolanaIosWallet(walletInfo, {
|
|
79
|
+
chain: walletStandard.getSolanaChain(options.cluster),
|
|
80
|
+
cluster: options.cluster,
|
|
81
|
+
onChange: options.onWalletChange,
|
|
82
|
+
...options.iosWallet || {}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (!isObject(walletInfo.wallet)) {
|
|
86
|
+
return walletStandard.adaptSolanaStandardWallet(walletInfo, {
|
|
87
|
+
chain: walletStandard.getSolanaChain(options.cluster),
|
|
88
|
+
onChange: options.onWalletChange
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
92
|
+
if (cachedWallet) {
|
|
93
|
+
return cachedWallet;
|
|
94
|
+
}
|
|
95
|
+
const adaptedWallet = walletStandard.adaptSolanaStandardWallet(walletInfo, {
|
|
96
|
+
chain: walletStandard.getSolanaChain(options.cluster),
|
|
97
|
+
onChange: options.onWalletChange
|
|
98
|
+
});
|
|
99
|
+
const cachedAdapter = {
|
|
100
|
+
platform: walletInfo.platform,
|
|
101
|
+
source: walletInfo.source,
|
|
102
|
+
get publicKey() {
|
|
103
|
+
return adaptedWallet.publicKey;
|
|
104
|
+
},
|
|
105
|
+
get connected() {
|
|
106
|
+
return adaptedWallet.connected;
|
|
107
|
+
},
|
|
108
|
+
get connecting() {
|
|
109
|
+
return adaptedWallet.connecting;
|
|
110
|
+
},
|
|
111
|
+
get disconnecting() {
|
|
112
|
+
return adaptedWallet.disconnecting;
|
|
113
|
+
},
|
|
114
|
+
async connect() {
|
|
115
|
+
await adaptedWallet.connect();
|
|
116
|
+
await Promise.all(
|
|
117
|
+
Array.from(getCachedWallets()).map(
|
|
118
|
+
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
disconnect: () => adaptedWallet.disconnect(),
|
|
123
|
+
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
124
|
+
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
125
|
+
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
126
|
+
};
|
|
127
|
+
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
128
|
+
return cachedAdapter;
|
|
129
|
+
}
|
|
130
|
+
function getDiscoveredWallets() {
|
|
131
|
+
return [
|
|
132
|
+
...walletStandard.getRegisteredSolanaWallets(),
|
|
133
|
+
...options.iosWallet === false ? [] : iosWallet.getSolanaIosWallets({
|
|
134
|
+
chains: [walletStandard.getSolanaChain(options.cluster)],
|
|
135
|
+
cluster: options.cluster,
|
|
136
|
+
...options.iosWallet || {}
|
|
137
|
+
})
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function handleIosWalletCallback() {
|
|
141
|
+
try {
|
|
142
|
+
iosWallet.handleSolanaIosWalletCallback({ clearUrl: true });
|
|
143
|
+
} catch (cause) {
|
|
144
|
+
console.error("[Vue Solana] iOS wallet callback failed", cause);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function* getCachedWallets() {
|
|
148
|
+
for (const walletInfo of options.getWalletInfos()) {
|
|
149
|
+
if (isObject(walletInfo.wallet)) {
|
|
150
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
151
|
+
if (cachedWallet) {
|
|
152
|
+
yield cachedWallet;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
getAdaptedWallet,
|
|
159
|
+
getDiscoveredWallets,
|
|
160
|
+
handleIosWalletCallback
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function isObject(value) {
|
|
164
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
165
|
+
}
|
|
166
|
+
|
|
18
167
|
const RPC_CHECK_TIMEOUT_MS = 1e4;
|
|
19
168
|
function createSolanaPlugin(options = {}) {
|
|
20
169
|
return {
|
|
@@ -26,9 +175,15 @@ function createSolanaPlugin(options = {}) {
|
|
|
26
175
|
const status = vue.ref("idle");
|
|
27
176
|
const error = vue.ref(null);
|
|
28
177
|
const latestBlockhash = vue.ref(null);
|
|
29
|
-
const
|
|
178
|
+
const walletRegistry = createSolanaWalletRegistry({
|
|
179
|
+
cluster: context.cluster,
|
|
180
|
+
iosWallet: options.iosWallet,
|
|
181
|
+
getWalletInfos: () => wallets.value,
|
|
182
|
+
onWalletChange: () => vue.triggerRef(wallet)
|
|
183
|
+
});
|
|
30
184
|
let unsubscribeWallets = null;
|
|
31
185
|
let mobileWalletRegistrationPromise = null;
|
|
186
|
+
let attemptedAutoConnectWallet = null;
|
|
32
187
|
let rpcCheckId = 0;
|
|
33
188
|
async function checkConnection() {
|
|
34
189
|
const checkId = ++rpcCheckId;
|
|
@@ -40,7 +195,7 @@ function createSolanaPlugin(options = {}) {
|
|
|
40
195
|
wsEndpoint: context.wsEndpoint
|
|
41
196
|
});
|
|
42
197
|
try {
|
|
43
|
-
const blockhash = await withTimeout(
|
|
198
|
+
const blockhash = await useTransaction.withTimeout(
|
|
44
199
|
context.connection.getLatestBlockhash(),
|
|
45
200
|
RPC_CHECK_TIMEOUT_MS,
|
|
46
201
|
`RPC connection check timed out after ${RPC_CHECK_TIMEOUT_MS / 1e3} seconds.`
|
|
@@ -67,17 +222,28 @@ function createSolanaPlugin(options = {}) {
|
|
|
67
222
|
}
|
|
68
223
|
function refreshWallets() {
|
|
69
224
|
unsubscribeWallets ??= walletStandard.subscribeSolanaWallets(refreshWallets);
|
|
70
|
-
handleIosWalletCallback();
|
|
71
|
-
wallets.value = getDiscoveredWallets();
|
|
225
|
+
walletRegistry.handleIosWalletCallback();
|
|
226
|
+
wallets.value = walletRegistry.getDiscoveredWallets();
|
|
227
|
+
let restoredWallet = null;
|
|
72
228
|
if (selectedWallet.value) {
|
|
73
229
|
selectedWallet.value = wallets.value.find((nextWallet) => isSameWallet(nextWallet, selectedWallet.value)) ?? null;
|
|
74
230
|
if (!selectedWallet.value) {
|
|
75
231
|
wallet.value = options.wallet ?? null;
|
|
76
232
|
}
|
|
233
|
+
} else if (!options.wallet) {
|
|
234
|
+
const persistedWallet = readSelectedWallet();
|
|
235
|
+
restoredWallet = persistedWallet ? wallets.value.find((nextWallet) => isSameWallet(nextWallet, persistedWallet)) ?? null : null;
|
|
236
|
+
if (restoredWallet) {
|
|
237
|
+
selectedWallet.value = restoredWallet;
|
|
238
|
+
wallet.value = walletRegistry.getAdaptedWallet(restoredWallet);
|
|
239
|
+
}
|
|
77
240
|
}
|
|
78
241
|
if (options.mobileWallet !== false) {
|
|
79
242
|
registerMobileWallets();
|
|
80
243
|
}
|
|
244
|
+
if (restoredWallet) {
|
|
245
|
+
autoConnectWallet(restoredWallet);
|
|
246
|
+
}
|
|
81
247
|
}
|
|
82
248
|
function registerMobileWallets() {
|
|
83
249
|
mobileWalletRegistrationPromise ??= import('@vue-solana/core/mobile-wallet').then(({ registerSolanaMobileWallet }) => {
|
|
@@ -85,7 +251,7 @@ function createSolanaPlugin(options = {}) {
|
|
|
85
251
|
chains: [walletStandard.getSolanaChain(context.cluster)],
|
|
86
252
|
...options.mobileWallet || {}
|
|
87
253
|
});
|
|
88
|
-
|
|
254
|
+
refreshWallets();
|
|
89
255
|
}).catch((cause) => {
|
|
90
256
|
console.error("[Vue Solana] Mobile wallet registration failed", cause);
|
|
91
257
|
}).finally(() => {
|
|
@@ -94,88 +260,24 @@ function createSolanaPlugin(options = {}) {
|
|
|
94
260
|
}
|
|
95
261
|
function selectWallet(nextWallet) {
|
|
96
262
|
selectedWallet.value = nextWallet;
|
|
97
|
-
wallet.value = nextWallet ? getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
263
|
+
wallet.value = nextWallet ? walletRegistry.getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
264
|
+
writeSelectedWallet(nextWallet);
|
|
98
265
|
}
|
|
99
|
-
function
|
|
100
|
-
if (
|
|
101
|
-
return
|
|
102
|
-
chain: walletStandard.getSolanaChain(context.cluster),
|
|
103
|
-
cluster: context.cluster,
|
|
104
|
-
onChange: () => vue.triggerRef(wallet),
|
|
105
|
-
...options.iosWallet || {}
|
|
106
|
-
});
|
|
266
|
+
function autoConnectWallet(walletInfo) {
|
|
267
|
+
if (!options.autoConnect) {
|
|
268
|
+
return;
|
|
107
269
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
});
|
|
270
|
+
const activeWallet = wallet.value;
|
|
271
|
+
const storageValue = stringifySelectedWallet(walletInfo);
|
|
272
|
+
if (!activeWallet || activeWallet.connected || activeWallet.connecting || attemptedAutoConnectWallet === storageValue) {
|
|
273
|
+
return;
|
|
113
274
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
chain: walletStandard.getSolanaChain(context.cluster),
|
|
120
|
-
onChange: () => vue.triggerRef(wallet)
|
|
275
|
+
attemptedAutoConnectWallet = storageValue;
|
|
276
|
+
void activeWallet.connect().catch((cause) => {
|
|
277
|
+
console.error("[Vue Solana] Wallet auto-connect failed", cause);
|
|
278
|
+
}).finally(() => {
|
|
279
|
+
vue.triggerRef(wallet);
|
|
121
280
|
});
|
|
122
|
-
const cachedAdapter = {
|
|
123
|
-
platform: walletInfo.platform,
|
|
124
|
-
source: walletInfo.source,
|
|
125
|
-
get publicKey() {
|
|
126
|
-
return adaptedWallet.publicKey;
|
|
127
|
-
},
|
|
128
|
-
get connected() {
|
|
129
|
-
return adaptedWallet.connected;
|
|
130
|
-
},
|
|
131
|
-
get connecting() {
|
|
132
|
-
return adaptedWallet.connecting;
|
|
133
|
-
},
|
|
134
|
-
get disconnecting() {
|
|
135
|
-
return adaptedWallet.disconnecting;
|
|
136
|
-
},
|
|
137
|
-
async connect() {
|
|
138
|
-
await adaptedWallet.connect();
|
|
139
|
-
await Promise.all(
|
|
140
|
-
Array.from(getCachedWallets()).map(
|
|
141
|
-
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
142
|
-
)
|
|
143
|
-
);
|
|
144
|
-
},
|
|
145
|
-
disconnect: () => adaptedWallet.disconnect(),
|
|
146
|
-
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
147
|
-
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
148
|
-
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
149
|
-
};
|
|
150
|
-
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
151
|
-
return cachedAdapter;
|
|
152
|
-
}
|
|
153
|
-
function getDiscoveredWallets() {
|
|
154
|
-
return [
|
|
155
|
-
...walletStandard.getRegisteredSolanaWallets(),
|
|
156
|
-
...options.iosWallet === false ? [] : iosWallet.getSolanaIosWallets({
|
|
157
|
-
chains: [walletStandard.getSolanaChain(context.cluster)],
|
|
158
|
-
cluster: context.cluster,
|
|
159
|
-
...options.iosWallet || {}
|
|
160
|
-
})
|
|
161
|
-
];
|
|
162
|
-
}
|
|
163
|
-
function handleIosWalletCallback() {
|
|
164
|
-
try {
|
|
165
|
-
iosWallet.handleSolanaIosWalletCallback({ clearUrl: true });
|
|
166
|
-
} catch (cause) {
|
|
167
|
-
console.error("[Vue Solana] iOS wallet callback failed", cause);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function* getCachedWallets() {
|
|
171
|
-
for (const walletInfo of wallets.value) {
|
|
172
|
-
if (isObject(walletInfo.wallet)) {
|
|
173
|
-
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
174
|
-
if (cachedWallet) {
|
|
175
|
-
yield cachedWallet;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
281
|
}
|
|
180
282
|
const vueContext = {
|
|
181
283
|
...context,
|
|
@@ -191,37 +293,27 @@ function createSolanaPlugin(options = {}) {
|
|
|
191
293
|
setWallet(nextWallet) {
|
|
192
294
|
selectedWallet.value = null;
|
|
193
295
|
wallet.value = nextWallet;
|
|
296
|
+
writeSelectedWallet(null);
|
|
194
297
|
}
|
|
195
298
|
};
|
|
196
299
|
app.provide(useSolana.solanaInjectionKey, vueContext);
|
|
197
300
|
if (typeof window !== "undefined") {
|
|
198
301
|
window.setTimeout(() => {
|
|
302
|
+
try {
|
|
303
|
+
refreshWallets();
|
|
304
|
+
} catch (cause) {
|
|
305
|
+
console.error("[Vue Solana] Wallet refresh failed", cause);
|
|
306
|
+
}
|
|
199
307
|
void checkConnection();
|
|
200
308
|
}, 0);
|
|
201
309
|
}
|
|
202
310
|
}
|
|
203
311
|
};
|
|
204
312
|
}
|
|
205
|
-
function isObject(value) {
|
|
206
|
-
return typeof value === "object" && value !== null || typeof value === "function";
|
|
207
|
-
}
|
|
208
313
|
function isSameWallet(wallet, selectedWallet) {
|
|
209
314
|
return wallet.name === selectedWallet?.name && wallet.source === selectedWallet.source && wallet.platform === selectedWallet.platform;
|
|
210
315
|
}
|
|
211
316
|
const VueSolana = createSolanaPlugin;
|
|
212
|
-
function withTimeout(promise, timeoutMs, message) {
|
|
213
|
-
let timeoutId;
|
|
214
|
-
const timeout = new Promise((_, reject) => {
|
|
215
|
-
timeoutId = setTimeout(() => {
|
|
216
|
-
reject(new Error(message));
|
|
217
|
-
}, timeoutMs);
|
|
218
|
-
});
|
|
219
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
220
|
-
if (timeoutId) {
|
|
221
|
-
clearTimeout(timeoutId);
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
317
|
|
|
226
318
|
exports.useBalance = useBalance.useBalance;
|
|
227
319
|
exports.useConnection = useConnection.useConnection;
|
package/dist/index.mjs
CHANGED
|
@@ -1,19 +1,169 @@
|
|
|
1
|
-
export { u as useBalance } from './shared/vue.
|
|
1
|
+
export { u as useBalance } from './shared/vue.DQhHHVu6.mjs';
|
|
2
2
|
export { u as useConnection } from './shared/vue.DlEAL2G8.mjs';
|
|
3
3
|
export { u as useRpc } from './shared/vue.BqDzSepb.mjs';
|
|
4
|
-
export { u as useSignAndSendTransaction } from './shared/vue.
|
|
4
|
+
export { u as useSignAndSendTransaction } from './shared/vue.DJ42Zrow.mjs';
|
|
5
5
|
import { s as solanaInjectionKey } from './shared/vue.1M_c5FWA.mjs';
|
|
6
6
|
export { t as tryUseSolana, u as useSolana } from './shared/vue.1M_c5FWA.mjs';
|
|
7
|
-
|
|
7
|
+
import { w as withTimeout } from './shared/vue.gLqkzJY4.mjs';
|
|
8
|
+
export { u as useTransaction } from './shared/vue.gLqkzJY4.mjs';
|
|
8
9
|
export { u as useWallet } from './shared/vue.DYf_CRDv.mjs';
|
|
9
10
|
export { u as useWallets } from './shared/vue.h-uS8MXN.mjs';
|
|
10
|
-
import { isSolanaIosWalletInfo, adaptSolanaIosWallet, handleSolanaIosWalletCallback, getSolanaIosWallets } from '@vue-solana/core/ios-wallet';
|
|
11
|
-
import { subscribeSolanaWallets, getSolanaChain, adaptSolanaStandardWallet, getRegisteredSolanaWallets } from '@vue-solana/core/wallet-standard';
|
|
12
11
|
import { createSolanaContext } from '@vue-solana/core/rpc';
|
|
12
|
+
import { getRegisteredSolanaWallets, getSolanaChain, adaptSolanaStandardWallet, subscribeSolanaWallets } from '@vue-solana/core/wallet-standard';
|
|
13
13
|
import { shallowRef, ref, triggerRef } from 'vue';
|
|
14
|
+
import { handleSolanaIosWalletCallback, getSolanaIosWallets, isSolanaIosWalletInfo, adaptSolanaIosWallet } from '@vue-solana/core/ios-wallet';
|
|
14
15
|
import '@solana/web3-compat';
|
|
15
16
|
import '@vue-solana/core/transaction';
|
|
16
17
|
|
|
18
|
+
const SELECTED_WALLET_STORAGE_KEY = "vue-solana:selected-wallet";
|
|
19
|
+
function readSelectedWallet() {
|
|
20
|
+
const storage = getLocalStorage();
|
|
21
|
+
if (!storage) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const value = storage.getItem(SELECTED_WALLET_STORAGE_KEY);
|
|
26
|
+
if (!value) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const wallet = JSON.parse(value);
|
|
30
|
+
return typeof wallet.name === "string" ? {
|
|
31
|
+
name: wallet.name,
|
|
32
|
+
platform: wallet.platform,
|
|
33
|
+
source: wallet.source
|
|
34
|
+
} : null;
|
|
35
|
+
} catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function writeSelectedWallet(wallet) {
|
|
40
|
+
const storage = getLocalStorage();
|
|
41
|
+
if (!storage) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (wallet) {
|
|
46
|
+
storage.setItem(SELECTED_WALLET_STORAGE_KEY, stringifySelectedWallet(wallet));
|
|
47
|
+
} else {
|
|
48
|
+
storage.removeItem(SELECTED_WALLET_STORAGE_KEY);
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function stringifySelectedWallet(wallet) {
|
|
54
|
+
const value = { name: wallet.name };
|
|
55
|
+
if (wallet.platform) {
|
|
56
|
+
value.platform = wallet.platform;
|
|
57
|
+
}
|
|
58
|
+
if (wallet.source) {
|
|
59
|
+
value.source = wallet.source;
|
|
60
|
+
}
|
|
61
|
+
return JSON.stringify(value);
|
|
62
|
+
}
|
|
63
|
+
function getLocalStorage() {
|
|
64
|
+
if (typeof window === "undefined") {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
return window.localStorage;
|
|
69
|
+
} catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function createSolanaWalletRegistry(options) {
|
|
75
|
+
const adaptedWallets = /* @__PURE__ */ new WeakMap();
|
|
76
|
+
function getAdaptedWallet(walletInfo) {
|
|
77
|
+
if (isSolanaIosWalletInfo(walletInfo)) {
|
|
78
|
+
return adaptSolanaIosWallet(walletInfo, {
|
|
79
|
+
chain: getSolanaChain(options.cluster),
|
|
80
|
+
cluster: options.cluster,
|
|
81
|
+
onChange: options.onWalletChange,
|
|
82
|
+
...options.iosWallet || {}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (!isObject(walletInfo.wallet)) {
|
|
86
|
+
return adaptSolanaStandardWallet(walletInfo, {
|
|
87
|
+
chain: getSolanaChain(options.cluster),
|
|
88
|
+
onChange: options.onWalletChange
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
92
|
+
if (cachedWallet) {
|
|
93
|
+
return cachedWallet;
|
|
94
|
+
}
|
|
95
|
+
const adaptedWallet = adaptSolanaStandardWallet(walletInfo, {
|
|
96
|
+
chain: getSolanaChain(options.cluster),
|
|
97
|
+
onChange: options.onWalletChange
|
|
98
|
+
});
|
|
99
|
+
const cachedAdapter = {
|
|
100
|
+
platform: walletInfo.platform,
|
|
101
|
+
source: walletInfo.source,
|
|
102
|
+
get publicKey() {
|
|
103
|
+
return adaptedWallet.publicKey;
|
|
104
|
+
},
|
|
105
|
+
get connected() {
|
|
106
|
+
return adaptedWallet.connected;
|
|
107
|
+
},
|
|
108
|
+
get connecting() {
|
|
109
|
+
return adaptedWallet.connecting;
|
|
110
|
+
},
|
|
111
|
+
get disconnecting() {
|
|
112
|
+
return adaptedWallet.disconnecting;
|
|
113
|
+
},
|
|
114
|
+
async connect() {
|
|
115
|
+
await adaptedWallet.connect();
|
|
116
|
+
await Promise.all(
|
|
117
|
+
Array.from(getCachedWallets()).map(
|
|
118
|
+
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
},
|
|
122
|
+
disconnect: () => adaptedWallet.disconnect(),
|
|
123
|
+
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
124
|
+
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
125
|
+
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
126
|
+
};
|
|
127
|
+
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
128
|
+
return cachedAdapter;
|
|
129
|
+
}
|
|
130
|
+
function getDiscoveredWallets() {
|
|
131
|
+
return [
|
|
132
|
+
...getRegisteredSolanaWallets(),
|
|
133
|
+
...options.iosWallet === false ? [] : getSolanaIosWallets({
|
|
134
|
+
chains: [getSolanaChain(options.cluster)],
|
|
135
|
+
cluster: options.cluster,
|
|
136
|
+
...options.iosWallet || {}
|
|
137
|
+
})
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
function handleIosWalletCallback() {
|
|
141
|
+
try {
|
|
142
|
+
handleSolanaIosWalletCallback({ clearUrl: true });
|
|
143
|
+
} catch (cause) {
|
|
144
|
+
console.error("[Vue Solana] iOS wallet callback failed", cause);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function* getCachedWallets() {
|
|
148
|
+
for (const walletInfo of options.getWalletInfos()) {
|
|
149
|
+
if (isObject(walletInfo.wallet)) {
|
|
150
|
+
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
151
|
+
if (cachedWallet) {
|
|
152
|
+
yield cachedWallet;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
getAdaptedWallet,
|
|
159
|
+
getDiscoveredWallets,
|
|
160
|
+
handleIosWalletCallback
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function isObject(value) {
|
|
164
|
+
return typeof value === "object" && value !== null || typeof value === "function";
|
|
165
|
+
}
|
|
166
|
+
|
|
17
167
|
const RPC_CHECK_TIMEOUT_MS = 1e4;
|
|
18
168
|
function createSolanaPlugin(options = {}) {
|
|
19
169
|
return {
|
|
@@ -25,9 +175,15 @@ function createSolanaPlugin(options = {}) {
|
|
|
25
175
|
const status = ref("idle");
|
|
26
176
|
const error = ref(null);
|
|
27
177
|
const latestBlockhash = ref(null);
|
|
28
|
-
const
|
|
178
|
+
const walletRegistry = createSolanaWalletRegistry({
|
|
179
|
+
cluster: context.cluster,
|
|
180
|
+
iosWallet: options.iosWallet,
|
|
181
|
+
getWalletInfos: () => wallets.value,
|
|
182
|
+
onWalletChange: () => triggerRef(wallet)
|
|
183
|
+
});
|
|
29
184
|
let unsubscribeWallets = null;
|
|
30
185
|
let mobileWalletRegistrationPromise = null;
|
|
186
|
+
let attemptedAutoConnectWallet = null;
|
|
31
187
|
let rpcCheckId = 0;
|
|
32
188
|
async function checkConnection() {
|
|
33
189
|
const checkId = ++rpcCheckId;
|
|
@@ -66,17 +222,28 @@ function createSolanaPlugin(options = {}) {
|
|
|
66
222
|
}
|
|
67
223
|
function refreshWallets() {
|
|
68
224
|
unsubscribeWallets ??= subscribeSolanaWallets(refreshWallets);
|
|
69
|
-
handleIosWalletCallback();
|
|
70
|
-
wallets.value = getDiscoveredWallets();
|
|
225
|
+
walletRegistry.handleIosWalletCallback();
|
|
226
|
+
wallets.value = walletRegistry.getDiscoveredWallets();
|
|
227
|
+
let restoredWallet = null;
|
|
71
228
|
if (selectedWallet.value) {
|
|
72
229
|
selectedWallet.value = wallets.value.find((nextWallet) => isSameWallet(nextWallet, selectedWallet.value)) ?? null;
|
|
73
230
|
if (!selectedWallet.value) {
|
|
74
231
|
wallet.value = options.wallet ?? null;
|
|
75
232
|
}
|
|
233
|
+
} else if (!options.wallet) {
|
|
234
|
+
const persistedWallet = readSelectedWallet();
|
|
235
|
+
restoredWallet = persistedWallet ? wallets.value.find((nextWallet) => isSameWallet(nextWallet, persistedWallet)) ?? null : null;
|
|
236
|
+
if (restoredWallet) {
|
|
237
|
+
selectedWallet.value = restoredWallet;
|
|
238
|
+
wallet.value = walletRegistry.getAdaptedWallet(restoredWallet);
|
|
239
|
+
}
|
|
76
240
|
}
|
|
77
241
|
if (options.mobileWallet !== false) {
|
|
78
242
|
registerMobileWallets();
|
|
79
243
|
}
|
|
244
|
+
if (restoredWallet) {
|
|
245
|
+
autoConnectWallet(restoredWallet);
|
|
246
|
+
}
|
|
80
247
|
}
|
|
81
248
|
function registerMobileWallets() {
|
|
82
249
|
mobileWalletRegistrationPromise ??= import('@vue-solana/core/mobile-wallet').then(({ registerSolanaMobileWallet }) => {
|
|
@@ -84,7 +251,7 @@ function createSolanaPlugin(options = {}) {
|
|
|
84
251
|
chains: [getSolanaChain(context.cluster)],
|
|
85
252
|
...options.mobileWallet || {}
|
|
86
253
|
});
|
|
87
|
-
|
|
254
|
+
refreshWallets();
|
|
88
255
|
}).catch((cause) => {
|
|
89
256
|
console.error("[Vue Solana] Mobile wallet registration failed", cause);
|
|
90
257
|
}).finally(() => {
|
|
@@ -93,88 +260,24 @@ function createSolanaPlugin(options = {}) {
|
|
|
93
260
|
}
|
|
94
261
|
function selectWallet(nextWallet) {
|
|
95
262
|
selectedWallet.value = nextWallet;
|
|
96
|
-
wallet.value = nextWallet ? getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
263
|
+
wallet.value = nextWallet ? walletRegistry.getAdaptedWallet(nextWallet) : options.wallet ?? null;
|
|
264
|
+
writeSelectedWallet(nextWallet);
|
|
97
265
|
}
|
|
98
|
-
function
|
|
99
|
-
if (
|
|
100
|
-
return
|
|
101
|
-
chain: getSolanaChain(context.cluster),
|
|
102
|
-
cluster: context.cluster,
|
|
103
|
-
onChange: () => triggerRef(wallet),
|
|
104
|
-
...options.iosWallet || {}
|
|
105
|
-
});
|
|
266
|
+
function autoConnectWallet(walletInfo) {
|
|
267
|
+
if (!options.autoConnect) {
|
|
268
|
+
return;
|
|
106
269
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
114
|
-
if (cachedWallet) {
|
|
115
|
-
return cachedWallet;
|
|
270
|
+
const activeWallet = wallet.value;
|
|
271
|
+
const storageValue = stringifySelectedWallet(walletInfo);
|
|
272
|
+
if (!activeWallet || activeWallet.connected || activeWallet.connecting || attemptedAutoConnectWallet === storageValue) {
|
|
273
|
+
return;
|
|
116
274
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
275
|
+
attemptedAutoConnectWallet = storageValue;
|
|
276
|
+
void activeWallet.connect().catch((cause) => {
|
|
277
|
+
console.error("[Vue Solana] Wallet auto-connect failed", cause);
|
|
278
|
+
}).finally(() => {
|
|
279
|
+
triggerRef(wallet);
|
|
120
280
|
});
|
|
121
|
-
const cachedAdapter = {
|
|
122
|
-
platform: walletInfo.platform,
|
|
123
|
-
source: walletInfo.source,
|
|
124
|
-
get publicKey() {
|
|
125
|
-
return adaptedWallet.publicKey;
|
|
126
|
-
},
|
|
127
|
-
get connected() {
|
|
128
|
-
return adaptedWallet.connected;
|
|
129
|
-
},
|
|
130
|
-
get connecting() {
|
|
131
|
-
return adaptedWallet.connecting;
|
|
132
|
-
},
|
|
133
|
-
get disconnecting() {
|
|
134
|
-
return adaptedWallet.disconnecting;
|
|
135
|
-
},
|
|
136
|
-
async connect() {
|
|
137
|
-
await adaptedWallet.connect();
|
|
138
|
-
await Promise.all(
|
|
139
|
-
Array.from(getCachedWallets()).map(
|
|
140
|
-
(otherWallet) => otherWallet !== cachedAdapter && otherWallet.connected ? otherWallet.disconnect() : void 0
|
|
141
|
-
)
|
|
142
|
-
);
|
|
143
|
-
},
|
|
144
|
-
disconnect: () => adaptedWallet.disconnect(),
|
|
145
|
-
signTransaction: adaptedWallet.signTransaction?.bind(adaptedWallet),
|
|
146
|
-
signAllTransactions: adaptedWallet.signAllTransactions?.bind(adaptedWallet),
|
|
147
|
-
signAndSendTransaction: adaptedWallet.signAndSendTransaction?.bind(adaptedWallet)
|
|
148
|
-
};
|
|
149
|
-
adaptedWallets.set(walletInfo.wallet, cachedAdapter);
|
|
150
|
-
return cachedAdapter;
|
|
151
|
-
}
|
|
152
|
-
function getDiscoveredWallets() {
|
|
153
|
-
return [
|
|
154
|
-
...getRegisteredSolanaWallets(),
|
|
155
|
-
...options.iosWallet === false ? [] : getSolanaIosWallets({
|
|
156
|
-
chains: [getSolanaChain(context.cluster)],
|
|
157
|
-
cluster: context.cluster,
|
|
158
|
-
...options.iosWallet || {}
|
|
159
|
-
})
|
|
160
|
-
];
|
|
161
|
-
}
|
|
162
|
-
function handleIosWalletCallback() {
|
|
163
|
-
try {
|
|
164
|
-
handleSolanaIosWalletCallback({ clearUrl: true });
|
|
165
|
-
} catch (cause) {
|
|
166
|
-
console.error("[Vue Solana] iOS wallet callback failed", cause);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
function* getCachedWallets() {
|
|
170
|
-
for (const walletInfo of wallets.value) {
|
|
171
|
-
if (isObject(walletInfo.wallet)) {
|
|
172
|
-
const cachedWallet = adaptedWallets.get(walletInfo.wallet);
|
|
173
|
-
if (cachedWallet) {
|
|
174
|
-
yield cachedWallet;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
281
|
}
|
|
179
282
|
const vueContext = {
|
|
180
283
|
...context,
|
|
@@ -190,36 +293,26 @@ function createSolanaPlugin(options = {}) {
|
|
|
190
293
|
setWallet(nextWallet) {
|
|
191
294
|
selectedWallet.value = null;
|
|
192
295
|
wallet.value = nextWallet;
|
|
296
|
+
writeSelectedWallet(null);
|
|
193
297
|
}
|
|
194
298
|
};
|
|
195
299
|
app.provide(solanaInjectionKey, vueContext);
|
|
196
300
|
if (typeof window !== "undefined") {
|
|
197
301
|
window.setTimeout(() => {
|
|
302
|
+
try {
|
|
303
|
+
refreshWallets();
|
|
304
|
+
} catch (cause) {
|
|
305
|
+
console.error("[Vue Solana] Wallet refresh failed", cause);
|
|
306
|
+
}
|
|
198
307
|
void checkConnection();
|
|
199
308
|
}, 0);
|
|
200
309
|
}
|
|
201
310
|
}
|
|
202
311
|
};
|
|
203
312
|
}
|
|
204
|
-
function isObject(value) {
|
|
205
|
-
return typeof value === "object" && value !== null || typeof value === "function";
|
|
206
|
-
}
|
|
207
313
|
function isSameWallet(wallet, selectedWallet) {
|
|
208
314
|
return wallet.name === selectedWallet?.name && wallet.source === selectedWallet.source && wallet.platform === selectedWallet.platform;
|
|
209
315
|
}
|
|
210
316
|
const VueSolana = createSolanaPlugin;
|
|
211
|
-
function withTimeout(promise, timeoutMs, message) {
|
|
212
|
-
let timeoutId;
|
|
213
|
-
const timeout = new Promise((_, reject) => {
|
|
214
|
-
timeoutId = setTimeout(() => {
|
|
215
|
-
reject(new Error(message));
|
|
216
|
-
}, timeoutMs);
|
|
217
|
-
});
|
|
218
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
219
|
-
if (timeoutId) {
|
|
220
|
-
clearTimeout(timeoutId);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
317
|
|
|
225
318
|
export { VueSolana, createSolanaPlugin, solanaInjectionKey };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { signAndSendTransaction } from '@vue-solana/core/transaction';
|
|
2
2
|
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
3
3
|
import { u as useWallet } from './vue.DYf_CRDv.mjs';
|
|
4
|
-
import { u as useTransaction } from './vue.
|
|
4
|
+
import { u as useTransaction } from './vue.gLqkzJY4.mjs';
|
|
5
5
|
|
|
6
6
|
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
7
7
|
function useSignAndSendTransaction() {
|
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3-compat';
|
|
2
|
-
import {
|
|
2
|
+
import { shallowRef, onMounted, watch, toValue } from 'vue';
|
|
3
3
|
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
4
|
import { t as tryUseSolana } from './vue.1M_c5FWA.mjs';
|
|
5
5
|
|
|
6
6
|
function useBalance(address, commitment) {
|
|
7
7
|
const solana = tryUseSolana();
|
|
8
8
|
const connection = solana?.connection ?? useConnection();
|
|
9
|
-
const balance =
|
|
10
|
-
const loading =
|
|
11
|
-
const error =
|
|
9
|
+
const balance = shallowRef(null);
|
|
10
|
+
const loading = shallowRef(false);
|
|
11
|
+
const error = shallowRef(null);
|
|
12
|
+
let refreshId = 0;
|
|
12
13
|
async function refresh() {
|
|
14
|
+
const requestId = ++refreshId;
|
|
13
15
|
const value = toValue(address);
|
|
14
16
|
if (!value || !solana) {
|
|
15
17
|
balance.value = null;
|
|
18
|
+
loading.value = false;
|
|
19
|
+
error.value = null;
|
|
16
20
|
return null;
|
|
17
21
|
}
|
|
18
22
|
loading.value = true;
|
|
19
23
|
error.value = null;
|
|
20
24
|
try {
|
|
21
25
|
const publicKey = typeof value === "string" ? new PublicKey(value) : value;
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const nextBalance = await connection.getBalance(publicKey, commitment);
|
|
27
|
+
if (requestId === refreshId) {
|
|
28
|
+
balance.value = nextBalance;
|
|
29
|
+
}
|
|
30
|
+
return nextBalance;
|
|
24
31
|
} catch (cause) {
|
|
25
|
-
|
|
32
|
+
if (requestId === refreshId) {
|
|
33
|
+
error.value = cause;
|
|
34
|
+
}
|
|
26
35
|
throw cause;
|
|
27
36
|
} finally {
|
|
28
|
-
|
|
37
|
+
if (requestId === refreshId) {
|
|
38
|
+
loading.value = false;
|
|
39
|
+
}
|
|
29
40
|
}
|
|
30
41
|
}
|
|
31
42
|
onMounted(() => {
|
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
const vue = require('vue');
|
|
4
4
|
|
|
5
|
+
async function withTimeout(promise, timeoutMs, message) {
|
|
6
|
+
if (!timeoutMs) {
|
|
7
|
+
return promise;
|
|
8
|
+
}
|
|
9
|
+
let timeoutId;
|
|
10
|
+
try {
|
|
11
|
+
const timeout = new Promise((_, reject) => {
|
|
12
|
+
timeoutId = setTimeout(() => {
|
|
13
|
+
reject(new Error(message));
|
|
14
|
+
}, timeoutMs);
|
|
15
|
+
});
|
|
16
|
+
return await Promise.race([promise, timeout]);
|
|
17
|
+
} finally {
|
|
18
|
+
if (timeoutId) {
|
|
19
|
+
clearTimeout(timeoutId);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
5
24
|
function useTransaction(handler, options = {}) {
|
|
6
25
|
const signature = vue.ref(null);
|
|
7
26
|
const loading = vue.ref(false);
|
|
@@ -39,21 +58,6 @@ function useTransaction(handler, options = {}) {
|
|
|
39
58
|
execute
|
|
40
59
|
};
|
|
41
60
|
}
|
|
42
|
-
function withTimeout(promise, timeoutMs, message) {
|
|
43
|
-
if (!timeoutMs) {
|
|
44
|
-
return promise;
|
|
45
|
-
}
|
|
46
|
-
let timeoutId;
|
|
47
|
-
const timeout = new Promise((_, reject) => {
|
|
48
|
-
timeoutId = setTimeout(() => {
|
|
49
|
-
reject(new Error(message));
|
|
50
|
-
}, timeoutMs);
|
|
51
|
-
});
|
|
52
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
53
|
-
if (timeoutId) {
|
|
54
|
-
clearTimeout(timeoutId);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
61
|
|
|
59
62
|
exports.useTransaction = useTransaction;
|
|
63
|
+
exports.withTimeout = withTimeout;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const transaction = require('@vue-solana/core/transaction');
|
|
4
4
|
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
5
5
|
const useWallet = require('./vue.CwPjPFN6.cjs');
|
|
6
|
-
const useTransaction = require('./vue.
|
|
6
|
+
const useTransaction = require('./vue.DQi38JeF.cjs');
|
|
7
7
|
|
|
8
8
|
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
9
9
|
function useSignAndSendTransaction() {
|
|
@@ -8,26 +8,37 @@ const useSolana = require('./vue.C4tLiG3R.cjs');
|
|
|
8
8
|
function useBalance(address, commitment) {
|
|
9
9
|
const solana = useSolana.tryUseSolana();
|
|
10
10
|
const connection = solana?.connection ?? useConnection.useConnection();
|
|
11
|
-
const balance = vue.
|
|
12
|
-
const loading = vue.
|
|
13
|
-
const error = vue.
|
|
11
|
+
const balance = vue.shallowRef(null);
|
|
12
|
+
const loading = vue.shallowRef(false);
|
|
13
|
+
const error = vue.shallowRef(null);
|
|
14
|
+
let refreshId = 0;
|
|
14
15
|
async function refresh() {
|
|
16
|
+
const requestId = ++refreshId;
|
|
15
17
|
const value = vue.toValue(address);
|
|
16
18
|
if (!value || !solana) {
|
|
17
19
|
balance.value = null;
|
|
20
|
+
loading.value = false;
|
|
21
|
+
error.value = null;
|
|
18
22
|
return null;
|
|
19
23
|
}
|
|
20
24
|
loading.value = true;
|
|
21
25
|
error.value = null;
|
|
22
26
|
try {
|
|
23
27
|
const publicKey = typeof value === "string" ? new web3Compat.PublicKey(value) : value;
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
const nextBalance = await connection.getBalance(publicKey, commitment);
|
|
29
|
+
if (requestId === refreshId) {
|
|
30
|
+
balance.value = nextBalance;
|
|
31
|
+
}
|
|
32
|
+
return nextBalance;
|
|
26
33
|
} catch (cause) {
|
|
27
|
-
|
|
34
|
+
if (requestId === refreshId) {
|
|
35
|
+
error.value = cause;
|
|
36
|
+
}
|
|
28
37
|
throw cause;
|
|
29
38
|
} finally {
|
|
30
|
-
|
|
39
|
+
if (requestId === refreshId) {
|
|
40
|
+
loading.value = false;
|
|
41
|
+
}
|
|
31
42
|
}
|
|
32
43
|
}
|
|
33
44
|
vue.onMounted(() => {
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import { ref } from 'vue';
|
|
2
2
|
|
|
3
|
+
async function withTimeout(promise, timeoutMs, message) {
|
|
4
|
+
if (!timeoutMs) {
|
|
5
|
+
return promise;
|
|
6
|
+
}
|
|
7
|
+
let timeoutId;
|
|
8
|
+
try {
|
|
9
|
+
const timeout = new Promise((_, reject) => {
|
|
10
|
+
timeoutId = setTimeout(() => {
|
|
11
|
+
reject(new Error(message));
|
|
12
|
+
}, timeoutMs);
|
|
13
|
+
});
|
|
14
|
+
return await Promise.race([promise, timeout]);
|
|
15
|
+
} finally {
|
|
16
|
+
if (timeoutId) {
|
|
17
|
+
clearTimeout(timeoutId);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
3
22
|
function useTransaction(handler, options = {}) {
|
|
4
23
|
const signature = ref(null);
|
|
5
24
|
const loading = ref(false);
|
|
@@ -37,21 +56,5 @@ function useTransaction(handler, options = {}) {
|
|
|
37
56
|
execute
|
|
38
57
|
};
|
|
39
58
|
}
|
|
40
|
-
function withTimeout(promise, timeoutMs, message) {
|
|
41
|
-
if (!timeoutMs) {
|
|
42
|
-
return promise;
|
|
43
|
-
}
|
|
44
|
-
let timeoutId;
|
|
45
|
-
const timeout = new Promise((_, reject) => {
|
|
46
|
-
timeoutId = setTimeout(() => {
|
|
47
|
-
reject(new Error(message));
|
|
48
|
-
}, timeoutMs);
|
|
49
|
-
});
|
|
50
|
-
return Promise.race([promise, timeout]).finally(() => {
|
|
51
|
-
if (timeoutId) {
|
|
52
|
-
clearTimeout(timeoutId);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
59
|
|
|
57
|
-
export { useTransaction as u };
|
|
60
|
+
export { useTransaction as u, withTimeout as w };
|
package/dist/useBalance.cjs
CHANGED
package/dist/useBalance.d.cts
CHANGED
|
@@ -3,10 +3,10 @@ import { MaybeRefOrGetter } from 'vue';
|
|
|
3
3
|
import { PublicKey, Commitment } from '@solana/web3-compat';
|
|
4
4
|
|
|
5
5
|
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
6
|
-
balance: vue.
|
|
7
|
-
loading: vue.
|
|
8
|
-
error: vue.
|
|
9
|
-
refresh: () => Promise<
|
|
6
|
+
balance: vue.ShallowRef<number | null, number | null>;
|
|
7
|
+
loading: vue.ShallowRef<boolean, boolean>;
|
|
8
|
+
error: vue.ShallowRef<unknown, unknown>;
|
|
9
|
+
refresh: () => Promise<any>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export { useBalance };
|
package/dist/useBalance.d.mts
CHANGED
|
@@ -3,10 +3,10 @@ import { MaybeRefOrGetter } from 'vue';
|
|
|
3
3
|
import { PublicKey, Commitment } from '@solana/web3-compat';
|
|
4
4
|
|
|
5
5
|
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
6
|
-
balance: vue.
|
|
7
|
-
loading: vue.
|
|
8
|
-
error: vue.
|
|
9
|
-
refresh: () => Promise<
|
|
6
|
+
balance: vue.ShallowRef<number | null, number | null>;
|
|
7
|
+
loading: vue.ShallowRef<boolean, boolean>;
|
|
8
|
+
error: vue.ShallowRef<unknown, unknown>;
|
|
9
|
+
refresh: () => Promise<any>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export { useBalance };
|
package/dist/useBalance.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import { MaybeRefOrGetter } from 'vue';
|
|
|
3
3
|
import { PublicKey, Commitment } from '@solana/web3-compat';
|
|
4
4
|
|
|
5
5
|
declare function useBalance(address: MaybeRefOrGetter<PublicKey | string | null | undefined>, commitment?: Commitment): {
|
|
6
|
-
balance: vue.
|
|
7
|
-
loading: vue.
|
|
8
|
-
error: vue.
|
|
9
|
-
refresh: () => Promise<
|
|
6
|
+
balance: vue.ShallowRef<number | null, number | null>;
|
|
7
|
+
loading: vue.ShallowRef<boolean, boolean>;
|
|
8
|
+
error: vue.ShallowRef<unknown, unknown>;
|
|
9
|
+
refresh: () => Promise<any>;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export { useBalance };
|
package/dist/useBalance.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const useSignAndSendTransaction = require('./shared/vue.
|
|
3
|
+
const useSignAndSendTransaction = require('./shared/vue.DQmAPXVB.cjs');
|
|
4
4
|
require('@vue-solana/core/transaction');
|
|
5
5
|
require('./shared/vue.CwhEmATP.cjs');
|
|
6
6
|
require('./shared/vue.COyyrsQU.cjs');
|
|
7
7
|
require('vue');
|
|
8
8
|
require('./shared/vue.C4tLiG3R.cjs');
|
|
9
9
|
require('./shared/vue.CwPjPFN6.cjs');
|
|
10
|
-
require('./shared/vue.
|
|
10
|
+
require('./shared/vue.DQi38JeF.cjs');
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { u as useSignAndSendTransaction } from './shared/vue.
|
|
1
|
+
export { u as useSignAndSendTransaction } from './shared/vue.DJ42Zrow.mjs';
|
|
2
2
|
import '@vue-solana/core/transaction';
|
|
3
3
|
import './shared/vue.DlEAL2G8.mjs';
|
|
4
4
|
import './shared/vue.BqDzSepb.mjs';
|
|
5
5
|
import 'vue';
|
|
6
6
|
import './shared/vue.1M_c5FWA.mjs';
|
|
7
7
|
import './shared/vue.DYf_CRDv.mjs';
|
|
8
|
-
import './shared/vue.
|
|
8
|
+
import './shared/vue.gLqkzJY4.mjs';
|
package/dist/useTransaction.cjs
CHANGED
package/dist/useTransaction.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { u as useTransaction } from './shared/vue.
|
|
1
|
+
export { u as useTransaction } from './shared/vue.gLqkzJY4.mjs';
|
|
2
2
|
import 'vue';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-solana/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Vue plugin and composables for Solana applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@vue-solana/core": "0.4.
|
|
81
|
+
"@vue-solana/core": "0.4.2"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@solana/web3-compat": "^0.0.21",
|