@vue-solana/vue 1.2.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -23
- package/dist/buffer-polyfill.d.cts +0 -1
- package/dist/buffer-polyfill.d.mts +0 -1
- package/dist/buffer-polyfill.d.ts +0 -1
- package/dist/index.cjs +62 -22
- package/dist/index.d.cts +29 -13
- package/dist/index.d.mts +29 -13
- package/dist/index.d.ts +29 -13
- package/dist/index.mjs +41 -21
- package/dist/kit.d.cts +1 -1
- package/dist/kit.d.mts +1 -1
- package/dist/kit.d.ts +1 -1
- package/dist/shared/vue.5euWd6-V.mjs +59 -0
- package/dist/shared/vue.9TPxZPMf.cjs +59 -0
- package/dist/shared/vue.B4-LEdSE.cjs +102 -0
- package/dist/shared/{vue.C0uCLjJ6.cjs → vue.B6ainw2G.cjs} +1 -1
- package/dist/shared/vue.B8LptjZP.mjs +32 -0
- package/dist/shared/vue.B8pLQ8P4.cjs +105 -0
- package/dist/shared/vue.B8ub540p.mjs +109 -0
- package/dist/shared/{vue.D0ycWj82.mjs → vue.BD6Gm1nl.mjs} +9 -9
- package/dist/shared/{vue.BEesxsrA.cjs → vue.BGxz4dru.cjs} +7 -3
- package/dist/shared/{vue.DDxhSi72.mjs → vue.BINkrA8h.mjs} +9 -9
- package/dist/shared/{vue.COPnX5fq.cjs → vue.BIxphCAq.cjs} +1 -1
- package/dist/shared/{vue.CKTUFwSI.mjs → vue.BOpgWr43.mjs} +9 -10
- package/dist/shared/vue.BQRpjwKl.mjs +80 -0
- package/dist/shared/vue.BVaMoz9y.cjs +9 -0
- package/dist/shared/vue.BVj9lWBK.cjs +111 -0
- package/dist/shared/vue.BY0qpgYr.cjs +35 -0
- package/dist/shared/vue.Bfu1dCKe.mjs +10 -0
- package/dist/shared/vue.Bk5xjlUx.cjs +61 -0
- package/dist/shared/{vue.BtUKvuQw.mjs → vue.BsGwt78R.mjs} +2 -2
- package/dist/shared/{vue.BbX3ePDY.cjs → vue.Bwd1sGAM.cjs} +9 -10
- package/dist/shared/vue.ByxbBC3y.mjs +57 -0
- package/dist/shared/{vue.CPjEwHSg.mjs → vue.C13umiQi.mjs} +20 -8
- package/dist/shared/vue.C5FVoEZT.mjs +99 -0
- package/dist/shared/vue.CATOh_9G.mjs +42 -0
- package/dist/shared/{vue.Bhdhmz8d.cjs → vue.CIs8QhCw.cjs} +18 -74
- package/dist/shared/vue.CMohL_Cz.mjs +58 -0
- package/dist/shared/{vue.CYKT65tB.mjs → vue.CQh3AUE8.mjs} +2 -6
- package/dist/shared/{vue.DzKfcfpX.cjs → vue.CWZSMVnB.cjs} +6 -6
- package/dist/shared/{vue.B12Pt1PQ.mjs → vue.CXB4NEMA.mjs} +18 -74
- package/dist/shared/{vue.DFbay4mm.mjs → vue.C_4qJDiF.mjs} +1 -1
- package/dist/shared/vue.CoaIWGPT.cjs +38 -0
- package/dist/shared/vue.CogzzQXM.mjs +171 -0
- package/dist/shared/vue.CpkwC8Th.mjs +7 -0
- package/dist/shared/vue.CrkK_T15.cjs +86 -0
- package/dist/shared/vue.D-qi8PSL.cjs +82 -0
- package/dist/shared/{vue.B2AQR2bE.mjs → vue.D218Ow7t.mjs} +8 -4
- package/dist/shared/{vue.QHAHFnw8.mjs → vue.D3Y0PWbF.mjs} +3 -3
- package/dist/shared/vue.D5U1yLG3.mjs +83 -0
- package/dist/shared/{vue.j1vB3h1n.cjs → vue.DAg5wC1G.cjs} +9 -9
- package/dist/shared/vue.DDbVk0Zh.cjs +180 -0
- package/dist/shared/{vue.BE4KHksm.cjs → vue.DE3emjSF.cjs} +2 -7
- package/dist/shared/vue.DEHxNvUX.cjs +7 -0
- package/dist/shared/vue.DFaMJLAQ.cjs +60 -0
- package/dist/shared/vue.DImwKTwJ.mjs +103 -0
- package/dist/shared/{vue.G9t8pE0J.cjs → vue.DKyQ7J67.cjs} +1 -1
- package/dist/shared/vue.DNxOpDXz.cjs +12 -0
- package/dist/shared/vue.DXQVIRZA.mjs +174 -0
- package/dist/shared/vue.DYk0Xfr3.mjs +36 -0
- package/dist/shared/vue.D_P5SqqD.mjs +5 -0
- package/dist/shared/{vue.B14U1xmP.cjs → vue.Di7yjJ-R.cjs} +20 -8
- package/dist/shared/vue.DtCbCcPd.cjs +173 -0
- package/dist/shared/{vue.CM_uqVc0.mjs → vue.Dyi1OCI1.mjs} +6 -6
- package/dist/shared/{vue.BsD6AAmO.cjs → vue.E_npPFoV.cjs} +8 -8
- package/dist/shared/{vue.LNhX07HB.cjs → vue.FiMmnMHr.cjs} +2 -2
- package/dist/shared/{vue.CSzg70vB.mjs → vue.JUWqu6kD.mjs} +1 -1
- package/dist/shared/{vue.By1CUlOU.mjs → vue.Mxc8w6Qk.mjs} +1 -1
- package/dist/shared/{vue.ByUemLSf.cjs → vue.Sbbm9JSu.cjs} +3 -3
- package/dist/shared/vue.g8fnm_ca.cjs +45 -0
- package/dist/swr.cjs +136 -0
- package/dist/swr.d.cts +41 -0
- package/dist/swr.d.mts +41 -0
- package/dist/swr.d.ts +41 -0
- package/dist/swr.mjs +131 -0
- package/dist/useAccountInfo.cjs +7 -5
- package/dist/useAccountInfo.d.cts +12 -8
- package/dist/useAccountInfo.d.mts +12 -8
- package/dist/useAccountInfo.d.ts +12 -8
- package/dist/useAccountInfo.mjs +7 -5
- package/dist/useAction.cjs +9 -0
- package/dist/useAction.d.cts +45 -0
- package/dist/useAction.d.mts +45 -0
- package/dist/useAction.d.ts +45 -0
- package/dist/useAction.mjs +3 -0
- package/dist/useBalance.cjs +5 -4
- package/dist/useBalance.d.cts +4 -2
- package/dist/useBalance.d.mts +4 -2
- package/dist/useBalance.d.ts +4 -2
- package/dist/useBalance.mjs +5 -4
- package/dist/useClientCapability.cjs +12 -0
- package/dist/useClientCapability.d.cts +39 -0
- package/dist/useClientCapability.d.mts +39 -0
- package/dist/useClientCapability.d.ts +39 -0
- package/dist/useClientCapability.mjs +5 -0
- package/dist/useConnection.cjs +4 -3
- package/dist/useConnection.d.cts +9 -2
- package/dist/useConnection.d.mts +9 -2
- package/dist/useConnection.d.ts +9 -2
- package/dist/useConnection.mjs +4 -3
- package/dist/useIdentity.cjs +12 -0
- package/dist/useIdentity.d.cts +3 -0
- package/dist/useIdentity.d.mts +3 -0
- package/dist/useIdentity.d.ts +3 -0
- package/dist/useIdentity.mjs +6 -0
- package/dist/usePayer.cjs +13 -0
- package/dist/usePayer.d.cts +18 -0
- package/dist/usePayer.d.mts +18 -0
- package/dist/usePayer.d.ts +18 -0
- package/dist/usePayer.mjs +6 -0
- package/dist/usePlanTransaction.cjs +14 -0
- package/dist/usePlanTransaction.d.cts +37 -0
- package/dist/usePlanTransaction.d.mts +37 -0
- package/dist/usePlanTransaction.d.ts +37 -0
- package/dist/usePlanTransaction.mjs +7 -0
- package/dist/usePlanTransactions.cjs +13 -0
- package/dist/usePlanTransactions.d.cts +4 -0
- package/dist/usePlanTransactions.d.mts +4 -0
- package/dist/usePlanTransactions.d.ts +4 -0
- package/dist/usePlanTransactions.mjs +7 -0
- package/dist/useProgramAccounts.cjs +7 -5
- package/dist/useProgramAccounts.d.cts +24 -9
- package/dist/useProgramAccounts.d.mts +24 -9
- package/dist/useProgramAccounts.d.ts +24 -9
- package/dist/useProgramAccounts.mjs +7 -5
- package/dist/useRequest.cjs +11 -0
- package/dist/useRequest.d.cts +57 -0
- package/dist/useRequest.d.mts +57 -0
- package/dist/useRequest.d.ts +57 -0
- package/dist/useRequest.mjs +5 -0
- package/dist/useRpc.cjs +3 -2
- package/dist/useRpc.d.cts +5 -2
- package/dist/useRpc.d.mts +5 -2
- package/dist/useRpc.d.ts +5 -2
- package/dist/useRpc.mjs +3 -2
- package/dist/useSelectedWalletAccount.cjs +13 -0
- package/dist/useSelectedWalletAccount.d.cts +117 -0
- package/dist/useSelectedWalletAccount.d.mts +117 -0
- package/dist/useSelectedWalletAccount.d.ts +117 -0
- package/dist/useSelectedWalletAccount.mjs +3 -0
- package/dist/useSignAndSendTransaction.cjs +7 -6
- package/dist/useSignAndSendTransaction.d.cts +18 -24
- package/dist/useSignAndSendTransaction.d.mts +18 -24
- package/dist/useSignAndSendTransaction.d.ts +18 -24
- package/dist/useSignAndSendTransaction.mjs +7 -6
- package/dist/useSignAndSendTransactions.cjs +15 -0
- package/dist/useSignAndSendTransactions.d.cts +35 -0
- package/dist/useSignAndSendTransactions.d.mts +35 -0
- package/dist/useSignAndSendTransactions.d.ts +35 -0
- package/dist/useSignAndSendTransactions.mjs +8 -0
- package/dist/useSignIn.cjs +13 -0
- package/dist/useSignIn.d.cts +23 -0
- package/dist/useSignIn.d.mts +23 -0
- package/dist/useSignIn.d.ts +23 -0
- package/dist/useSignIn.mjs +7 -0
- package/dist/useSignMessage.cjs +4 -3
- package/dist/useSignMessage.mjs +4 -3
- package/dist/useSignTransactions.cjs +13 -0
- package/dist/useSignTransactions.d.cts +24 -0
- package/dist/useSignTransactions.d.mts +24 -0
- package/dist/useSignTransactions.d.ts +24 -0
- package/dist/useSignTransactions.mjs +7 -0
- package/dist/useSignatureStatus.cjs +5 -4
- package/dist/useSignatureStatus.d.cts +9 -5
- package/dist/useSignatureStatus.d.mts +9 -5
- package/dist/useSignatureStatus.d.ts +9 -5
- package/dist/useSignatureStatus.mjs +5 -4
- package/dist/useSolana.cjs +2 -1
- package/dist/useSolana.mjs +2 -1
- package/dist/useSolanaClient.cjs +3 -2
- package/dist/useSolanaClient.mjs +3 -2
- package/dist/useSubscription.cjs +9 -0
- package/dist/useSubscription.d.cts +58 -0
- package/dist/useSubscription.d.mts +58 -0
- package/dist/useSubscription.d.ts +58 -0
- package/dist/useSubscription.mjs +3 -0
- package/dist/useTokenAccounts.cjs +7 -6
- package/dist/useTokenAccounts.d.cts +6 -6
- package/dist/useTokenAccounts.d.mts +6 -6
- package/dist/useTokenAccounts.d.ts +6 -6
- package/dist/useTokenAccounts.mjs +7 -6
- package/dist/useTokenBalance.cjs +7 -6
- package/dist/useTokenBalance.d.cts +2 -2
- package/dist/useTokenBalance.d.mts +2 -2
- package/dist/useTokenBalance.d.ts +2 -2
- package/dist/useTokenBalance.mjs +7 -6
- package/dist/useTrackedData.cjs +10 -0
- package/dist/useTrackedData.d.cts +86 -0
- package/dist/useTrackedData.d.mts +86 -0
- package/dist/useTrackedData.d.ts +86 -0
- package/dist/useTrackedData.mjs +4 -0
- package/dist/useTransaction.cjs +2 -1
- package/dist/useTransaction.d.cts +13 -3
- package/dist/useTransaction.d.mts +13 -3
- package/dist/useTransaction.d.ts +13 -3
- package/dist/useTransaction.mjs +2 -1
- package/dist/useTransactionConfirmation.cjs +5 -4
- package/dist/useTransactionConfirmation.d.cts +18 -24
- package/dist/useTransactionConfirmation.d.mts +18 -24
- package/dist/useTransactionConfirmation.d.ts +18 -24
- package/dist/useTransactionConfirmation.mjs +5 -4
- package/dist/useWallet.cjs +3 -2
- package/dist/useWallet.d.cts +2 -2
- package/dist/useWallet.d.mts +2 -2
- package/dist/useWallet.d.ts +2 -2
- package/dist/useWallet.mjs +3 -2
- package/dist/useWallets.cjs +3 -2
- package/dist/useWallets.mjs +3 -2
- package/package.json +73 -9
- package/dist/shared/vue.C4d2JA8U.mjs +0 -44
- package/dist/shared/vue.CE5i8KZZ.cjs +0 -46
- package/dist/shared/vue.CfrVAzEf.mjs +0 -129
- package/dist/shared/vue.DCgByzxg.cjs +0 -9
- package/dist/shared/vue.DiNn3XHm.mjs +0 -7
- package/dist/shared/vue._CAClzAz.cjs +0 -131
- package/dist/web3.cjs +0 -13
- package/dist/web3.d.cts +0 -1
- package/dist/web3.d.mts +0 -1
- package/dist/web3.d.ts +0 -1
- package/dist/web3.mjs +0 -1
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
2
|
+
import { shallowRef, watch, isRef, onMounted, getCurrentInstance, onScopeDispose, computed } from 'vue';
|
|
3
|
+
|
|
4
|
+
function useSubscription(source, options = {}) {
|
|
5
|
+
const data = shallowRef(void 0);
|
|
6
|
+
const error = shallowRef(null);
|
|
7
|
+
const status = shallowRef("loading");
|
|
8
|
+
const disposables = [];
|
|
9
|
+
let connectionCount = 0;
|
|
10
|
+
let disposed = false;
|
|
11
|
+
let activeSource;
|
|
12
|
+
let activeStore;
|
|
13
|
+
function applyState(state) {
|
|
14
|
+
if (state.status === "loaded") {
|
|
15
|
+
data.value = state.data;
|
|
16
|
+
error.value = null;
|
|
17
|
+
status.value = "loaded";
|
|
18
|
+
} else if (state.status === "error") {
|
|
19
|
+
error.value = normalizeSolanaError(state.error, "RPC_FAILURE");
|
|
20
|
+
status.value = "error";
|
|
21
|
+
options.onError?.(state.error);
|
|
22
|
+
} else if (state.status === "loading") {
|
|
23
|
+
status.value = data.value === void 0 ? "loading" : status.value;
|
|
24
|
+
} else if (state.status === "idle") {
|
|
25
|
+
data.value = void 0;
|
|
26
|
+
error.value = null;
|
|
27
|
+
status.value = "loading";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function openConnection(store) {
|
|
31
|
+
activeStore = store;
|
|
32
|
+
connectionCount += 1;
|
|
33
|
+
const connection = connectionCount;
|
|
34
|
+
const callerSignal = options.getAbortSignal?.(connection);
|
|
35
|
+
applyState(store.getState());
|
|
36
|
+
disposables.push(
|
|
37
|
+
store.subscribe(() => {
|
|
38
|
+
applyState(store.getState());
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
if (callerSignal?.aborted) {
|
|
42
|
+
applyState({ data: store.getState().data, error: callerSignal.reason, status: "error" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (callerSignal) {
|
|
46
|
+
store.withSignal(callerSignal).connect();
|
|
47
|
+
} else {
|
|
48
|
+
store.connect();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function disconnect() {
|
|
52
|
+
disposables.forEach((dispose) => {
|
|
53
|
+
dispose();
|
|
54
|
+
});
|
|
55
|
+
disposables.length = 0;
|
|
56
|
+
if (activeStore) {
|
|
57
|
+
activeStore.reset();
|
|
58
|
+
activeStore = void 0;
|
|
59
|
+
}
|
|
60
|
+
activeSource = void 0;
|
|
61
|
+
}
|
|
62
|
+
function connectCurrent() {
|
|
63
|
+
if (disposed) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const resolved = isRef(source) ? source.value : source;
|
|
67
|
+
if (resolved === null || resolved === void 0) {
|
|
68
|
+
disconnect();
|
|
69
|
+
data.value = void 0;
|
|
70
|
+
error.value = null;
|
|
71
|
+
status.value = "disabled";
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (activeSource === resolved && activeStore) {
|
|
75
|
+
openConnection(activeStore);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
disconnect();
|
|
79
|
+
activeSource = resolved;
|
|
80
|
+
openConnection(resolved.reactiveStore());
|
|
81
|
+
}
|
|
82
|
+
watch(
|
|
83
|
+
() => isRef(source) ? source.value : source,
|
|
84
|
+
() => {
|
|
85
|
+
connectCurrent();
|
|
86
|
+
},
|
|
87
|
+
{ flush: "sync" }
|
|
88
|
+
);
|
|
89
|
+
onMounted(() => {
|
|
90
|
+
connectCurrent();
|
|
91
|
+
});
|
|
92
|
+
if (!getCurrentInstance()) {
|
|
93
|
+
connectCurrent();
|
|
94
|
+
}
|
|
95
|
+
onScopeDispose(() => {
|
|
96
|
+
disposed = true;
|
|
97
|
+
disconnect();
|
|
98
|
+
});
|
|
99
|
+
return {
|
|
100
|
+
data: computed(() => data.value),
|
|
101
|
+
error: computed(() => error.value),
|
|
102
|
+
reconnect: () => {
|
|
103
|
+
connectCurrent();
|
|
104
|
+
},
|
|
105
|
+
status: computed(() => status.value)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { useSubscription as u };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { parsePublicKey } from '@vue-solana/core/address';
|
|
2
|
-
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
1
|
import { getTokenBalance } from '@vue-solana/core/token-accounts';
|
|
2
|
+
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
|
+
import { parseAddress } from '@vue-solana/core/address';
|
|
4
4
|
import { shallowRef, onMounted, watch, toValue } from 'vue';
|
|
5
|
-
import { u as useConnection } from './vue.
|
|
6
|
-
import { t as tryUseSolana } from './vue.
|
|
5
|
+
import { u as useConnection } from './vue.CpkwC8Th.mjs';
|
|
6
|
+
import { t as tryUseSolana } from './vue.CQh3AUE8.mjs';
|
|
7
7
|
|
|
8
|
-
function useTokenBalance(mint, owner) {
|
|
8
|
+
function useTokenBalance(mint, owner, commitment) {
|
|
9
9
|
const solana = tryUseSolana();
|
|
10
|
-
const
|
|
10
|
+
const client = solana?.client ?? useConnection();
|
|
11
11
|
const balance = shallowRef(null);
|
|
12
12
|
const decimals = shallowRef(null);
|
|
13
13
|
const loading = shallowRef(false);
|
|
@@ -27,15 +27,15 @@ function useTokenBalance(mint, owner) {
|
|
|
27
27
|
loading.value = true;
|
|
28
28
|
error.value = null;
|
|
29
29
|
try {
|
|
30
|
-
const mintKey =
|
|
31
|
-
const ownerKey =
|
|
30
|
+
const mintKey = parseAddress(mintValue);
|
|
31
|
+
const ownerKey = parseAddress(ownerValue);
|
|
32
32
|
if (!mintKey || !ownerKey) {
|
|
33
33
|
balance.value = null;
|
|
34
34
|
decimals.value = null;
|
|
35
35
|
loading.value = false;
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
|
-
const nextBalance = await getTokenBalance(
|
|
38
|
+
const nextBalance = await getTokenBalance(client, mintKey, ownerKey, commitment);
|
|
39
39
|
if (requestId === refreshId) {
|
|
40
40
|
balance.value = nextBalance?.amount ?? null;
|
|
41
41
|
decimals.value = nextBalance?.decimals ?? null;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const errors = require('@vue-solana/core/errors');
|
|
4
4
|
const wallet = require('@vue-solana/core/wallet');
|
|
5
5
|
const vue = require('vue');
|
|
6
|
-
const useSolana = require('./vue.
|
|
6
|
+
const useSolana = require('./vue.DE3emjSF.cjs');
|
|
7
7
|
|
|
8
8
|
function useWallet() {
|
|
9
9
|
const solana = useSolana.useSolana();
|
|
@@ -11,6 +11,9 @@ function useWallet() {
|
|
|
11
11
|
const connecting = vue.ref(false);
|
|
12
12
|
const disconnecting = vue.ref(false);
|
|
13
13
|
async function connect() {
|
|
14
|
+
if (connecting.value || wallet$1.value?.connecting) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
14
17
|
const activeWallet = wallet$1.value;
|
|
15
18
|
if (!activeWallet) {
|
|
16
19
|
throw wallet.createNoWalletSelectedError();
|
|
@@ -20,9 +23,10 @@ function useWallet() {
|
|
|
20
23
|
const connection = activeWallet.connect();
|
|
21
24
|
vue.triggerRef(wallet$1);
|
|
22
25
|
await connection;
|
|
26
|
+
wallet.assertWalletConnected(activeWallet);
|
|
23
27
|
vue.triggerRef(wallet$1);
|
|
24
28
|
console.info("[Vue Solana] Wallet connected", {
|
|
25
|
-
publicKey: activeWallet.publicKey
|
|
29
|
+
publicKey: activeWallet.publicKey ?? null
|
|
26
30
|
});
|
|
27
31
|
} catch (error) {
|
|
28
32
|
const normalizedError = errors.normalizeSolanaError(error, "RPC_FAILURE");
|
|
@@ -38,7 +42,7 @@ function useWallet() {
|
|
|
38
42
|
if (!activeWallet) {
|
|
39
43
|
return;
|
|
40
44
|
}
|
|
41
|
-
const publicKey = activeWallet.publicKey
|
|
45
|
+
const publicKey = activeWallet.publicKey ?? null;
|
|
42
46
|
disconnecting.value = true;
|
|
43
47
|
try {
|
|
44
48
|
await activeWallet.disconnect();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseAddress } from '@vue-solana/core/address';
|
|
2
2
|
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
3
|
import { shallowRef, onMounted, watch, toValue } from 'vue';
|
|
4
|
-
import { u as useConnection } from './vue.
|
|
5
|
-
import { t as tryUseSolana } from './vue.
|
|
4
|
+
import { u as useConnection } from './vue.CpkwC8Th.mjs';
|
|
5
|
+
import { t as tryUseSolana } from './vue.CQh3AUE8.mjs';
|
|
6
6
|
|
|
7
7
|
function useBalance(address, commitment) {
|
|
8
8
|
const solana = tryUseSolana();
|
|
9
|
-
const
|
|
9
|
+
const client = solana?.client ?? useConnection();
|
|
10
10
|
const balance = shallowRef(null);
|
|
11
11
|
const loading = shallowRef(false);
|
|
12
12
|
const error = shallowRef(null);
|
|
@@ -23,16 +23,16 @@ function useBalance(address, commitment) {
|
|
|
23
23
|
loading.value = true;
|
|
24
24
|
error.value = null;
|
|
25
25
|
try {
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
26
|
+
const parsedAddress = parseAddress(value);
|
|
27
|
+
if (!parsedAddress) {
|
|
28
28
|
balance.value = null;
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const { value: lamports } = await client.rpc.getBalance(parsedAddress, commitment ? { commitment } : void 0).send();
|
|
32
32
|
if (requestId === refreshId) {
|
|
33
|
-
balance.value =
|
|
33
|
+
balance.value = Number(lamports);
|
|
34
34
|
}
|
|
35
|
-
return
|
|
35
|
+
return Number(lamports);
|
|
36
36
|
} catch (cause) {
|
|
37
37
|
const normalizedError = normalizeSolanaError(cause, "RPC_FAILURE");
|
|
38
38
|
if (requestId === refreshId) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { parsePublicKey } from '@vue-solana/core/address';
|
|
2
|
-
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
1
|
import { getTokenAccountsByOwner } from '@vue-solana/core/token-accounts';
|
|
2
|
+
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
|
+
import { parseAddress } from '@vue-solana/core/address';
|
|
4
4
|
import { shallowRef, onMounted, watch, toValue } from 'vue';
|
|
5
|
-
import { u as useConnection } from './vue.
|
|
6
|
-
import { t as tryUseSolana } from './vue.
|
|
5
|
+
import { u as useConnection } from './vue.CpkwC8Th.mjs';
|
|
6
|
+
import { t as tryUseSolana } from './vue.CQh3AUE8.mjs';
|
|
7
7
|
|
|
8
8
|
function useTokenAccounts(owner, options) {
|
|
9
9
|
const solana = tryUseSolana();
|
|
10
|
-
const
|
|
10
|
+
const client = solana?.client ?? useConnection();
|
|
11
11
|
const tokenAccounts = shallowRef([]);
|
|
12
12
|
const loading = shallowRef(false);
|
|
13
13
|
const error = shallowRef(null);
|
|
@@ -24,17 +24,16 @@ function useTokenAccounts(owner, options) {
|
|
|
24
24
|
loading.value = true;
|
|
25
25
|
error.value = null;
|
|
26
26
|
try {
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
27
|
+
const parsedAddress = parseAddress(value);
|
|
28
|
+
if (!parsedAddress) {
|
|
29
29
|
tokenAccounts.value = [];
|
|
30
30
|
loading.value = false;
|
|
31
31
|
return [];
|
|
32
32
|
}
|
|
33
|
-
const
|
|
33
|
+
const nextAccounts = await getTokenAccountsByOwner(client, parsedAddress, {
|
|
34
34
|
commitment: options?.commitment,
|
|
35
35
|
programId: options?.programId
|
|
36
|
-
};
|
|
37
|
-
const nextAccounts = await getTokenAccountsByOwner(connection, publicKey, opts);
|
|
36
|
+
});
|
|
38
37
|
if (requestId === refreshId) {
|
|
39
38
|
tokenAccounts.value = nextAccounts;
|
|
40
39
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
2
|
+
import { shallowRef, onMounted, watch, toValue } from 'vue';
|
|
3
|
+
import { parseAddress } from '@vue-solana/core/address';
|
|
4
|
+
import { u as useConnection } from './vue.CpkwC8Th.mjs';
|
|
5
|
+
import { t as tryUseSolana } from './vue.CQh3AUE8.mjs';
|
|
6
|
+
import { d as decodeBase64 } from './vue.Bfu1dCKe.mjs';
|
|
7
|
+
|
|
8
|
+
function useAccountInfo(address, options = {}) {
|
|
9
|
+
const solana = tryUseSolana();
|
|
10
|
+
const client = solana?.client ?? useConnection();
|
|
11
|
+
const accountInfo = shallowRef(null);
|
|
12
|
+
const loading = shallowRef(false);
|
|
13
|
+
const error = shallowRef(null);
|
|
14
|
+
let refreshId = 0;
|
|
15
|
+
async function refresh() {
|
|
16
|
+
const requestId = ++refreshId;
|
|
17
|
+
const value = toValue(address);
|
|
18
|
+
if (!value || !solana) {
|
|
19
|
+
accountInfo.value = null;
|
|
20
|
+
loading.value = false;
|
|
21
|
+
error.value = null;
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
loading.value = true;
|
|
25
|
+
error.value = null;
|
|
26
|
+
try {
|
|
27
|
+
const parsedAddress = parseAddress(value);
|
|
28
|
+
if (!parsedAddress) {
|
|
29
|
+
accountInfo.value = null;
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const { value: account } = await client.rpc.getAccountInfo(parsedAddress, {
|
|
33
|
+
encoding: "base64",
|
|
34
|
+
commitment: options.commitment
|
|
35
|
+
}).send();
|
|
36
|
+
const nextAccountInfo = account ? normalizeAccountInfo(account) : null;
|
|
37
|
+
if (requestId === refreshId) {
|
|
38
|
+
accountInfo.value = nextAccountInfo;
|
|
39
|
+
}
|
|
40
|
+
return nextAccountInfo;
|
|
41
|
+
} catch (cause) {
|
|
42
|
+
const normalizedError = normalizeSolanaError(cause, "RPC_FAILURE");
|
|
43
|
+
if (requestId === refreshId) {
|
|
44
|
+
accountInfo.value = null;
|
|
45
|
+
error.value = normalizedError;
|
|
46
|
+
}
|
|
47
|
+
throw normalizedError;
|
|
48
|
+
} finally {
|
|
49
|
+
if (requestId === refreshId) {
|
|
50
|
+
loading.value = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
void refresh().catch(() => void 0);
|
|
56
|
+
});
|
|
57
|
+
watch(
|
|
58
|
+
() => toValue(address),
|
|
59
|
+
() => {
|
|
60
|
+
void refresh().catch(() => void 0);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
return {
|
|
64
|
+
accountInfo,
|
|
65
|
+
loading,
|
|
66
|
+
error,
|
|
67
|
+
refresh
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function normalizeAccountInfo(account) {
|
|
71
|
+
return {
|
|
72
|
+
executable: account.executable,
|
|
73
|
+
lamports: Number(account.lamports),
|
|
74
|
+
owner: account.owner,
|
|
75
|
+
space: Number(account.space),
|
|
76
|
+
data: decodeBase64(account.data[0])
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { useAccountInfo as u };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const errors = require('@vue-solana/core/errors');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
|
|
6
|
+
function useSubscription(source, options = {}) {
|
|
7
|
+
const data = vue.shallowRef(void 0);
|
|
8
|
+
const error = vue.shallowRef(null);
|
|
9
|
+
const status = vue.shallowRef("loading");
|
|
10
|
+
const disposables = [];
|
|
11
|
+
let connectionCount = 0;
|
|
12
|
+
let disposed = false;
|
|
13
|
+
let activeSource;
|
|
14
|
+
let activeStore;
|
|
15
|
+
function applyState(state) {
|
|
16
|
+
if (state.status === "loaded") {
|
|
17
|
+
data.value = state.data;
|
|
18
|
+
error.value = null;
|
|
19
|
+
status.value = "loaded";
|
|
20
|
+
} else if (state.status === "error") {
|
|
21
|
+
error.value = errors.normalizeSolanaError(state.error, "RPC_FAILURE");
|
|
22
|
+
status.value = "error";
|
|
23
|
+
options.onError?.(state.error);
|
|
24
|
+
} else if (state.status === "loading") {
|
|
25
|
+
status.value = data.value === void 0 ? "loading" : status.value;
|
|
26
|
+
} else if (state.status === "idle") {
|
|
27
|
+
data.value = void 0;
|
|
28
|
+
error.value = null;
|
|
29
|
+
status.value = "loading";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function openConnection(store) {
|
|
33
|
+
activeStore = store;
|
|
34
|
+
connectionCount += 1;
|
|
35
|
+
const connection = connectionCount;
|
|
36
|
+
const callerSignal = options.getAbortSignal?.(connection);
|
|
37
|
+
applyState(store.getState());
|
|
38
|
+
disposables.push(
|
|
39
|
+
store.subscribe(() => {
|
|
40
|
+
applyState(store.getState());
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
if (callerSignal?.aborted) {
|
|
44
|
+
applyState({ data: store.getState().data, error: callerSignal.reason, status: "error" });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (callerSignal) {
|
|
48
|
+
store.withSignal(callerSignal).connect();
|
|
49
|
+
} else {
|
|
50
|
+
store.connect();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function disconnect() {
|
|
54
|
+
disposables.forEach((dispose) => {
|
|
55
|
+
dispose();
|
|
56
|
+
});
|
|
57
|
+
disposables.length = 0;
|
|
58
|
+
if (activeStore) {
|
|
59
|
+
activeStore.reset();
|
|
60
|
+
activeStore = void 0;
|
|
61
|
+
}
|
|
62
|
+
activeSource = void 0;
|
|
63
|
+
}
|
|
64
|
+
function connectCurrent() {
|
|
65
|
+
if (disposed) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const resolved = vue.isRef(source) ? source.value : source;
|
|
69
|
+
if (resolved === null || resolved === void 0) {
|
|
70
|
+
disconnect();
|
|
71
|
+
data.value = void 0;
|
|
72
|
+
error.value = null;
|
|
73
|
+
status.value = "disabled";
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (activeSource === resolved && activeStore) {
|
|
77
|
+
openConnection(activeStore);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
disconnect();
|
|
81
|
+
activeSource = resolved;
|
|
82
|
+
openConnection(resolved.reactiveStore());
|
|
83
|
+
}
|
|
84
|
+
vue.watch(
|
|
85
|
+
() => vue.isRef(source) ? source.value : source,
|
|
86
|
+
() => {
|
|
87
|
+
connectCurrent();
|
|
88
|
+
},
|
|
89
|
+
{ flush: "sync" }
|
|
90
|
+
);
|
|
91
|
+
vue.onMounted(() => {
|
|
92
|
+
connectCurrent();
|
|
93
|
+
});
|
|
94
|
+
if (!vue.getCurrentInstance()) {
|
|
95
|
+
connectCurrent();
|
|
96
|
+
}
|
|
97
|
+
vue.onScopeDispose(() => {
|
|
98
|
+
disposed = true;
|
|
99
|
+
disconnect();
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
data: vue.computed(() => data.value),
|
|
103
|
+
error: vue.computed(() => error.value),
|
|
104
|
+
reconnect: () => {
|
|
105
|
+
connectCurrent();
|
|
106
|
+
},
|
|
107
|
+
status: vue.computed(() => status.value)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.useSubscription = useSubscription;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const useSolanaClient = require('./vue.BIxphCAq.cjs');
|
|
4
|
+
|
|
5
|
+
class MissingClientCapabilityError extends Error {
|
|
6
|
+
/** Name of the hook that requested the capability, e.g. `usePayer`. */
|
|
7
|
+
hookName;
|
|
8
|
+
/** Human guidance for installing the capability on the client. */
|
|
9
|
+
providerHint;
|
|
10
|
+
/** The missing capability name(s). */
|
|
11
|
+
capabilities;
|
|
12
|
+
constructor(hookName, capabilities, providerHint) {
|
|
13
|
+
super(
|
|
14
|
+
`${hookName} requires the ${capabilities.map((capability) => `\`${capability}\``).join(" and ")} capabilit${capabilities.length === 1 ? "y" : "ies"} on the Solana client, but none ${capabilities.length === 1 ? "was" : "were"} found. ` + providerHint
|
|
15
|
+
);
|
|
16
|
+
this.name = "MissingClientCapabilityError";
|
|
17
|
+
this.hookName = hookName;
|
|
18
|
+
this.capabilities = capabilities;
|
|
19
|
+
this.providerHint = providerHint;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function useClientCapability(capability, options = {}) {
|
|
23
|
+
const capabilities = Array.isArray(capability) ? [...capability] : [capability];
|
|
24
|
+
const hookName = options.hookName ?? "useClientCapability";
|
|
25
|
+
const providerHint = options.providerHint ?? "Install it by adding the corresponding @solana/kit plugin with `createClient().use(...)`.";
|
|
26
|
+
const { client } = useSolanaClient.useSolanaClient();
|
|
27
|
+
for (const name of capabilities) {
|
|
28
|
+
if (typeof client[name] === "undefined") {
|
|
29
|
+
throw new MissingClientCapabilityError(hookName, [name], providerHint);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.MissingClientCapabilityError = MissingClientCapabilityError;
|
|
35
|
+
exports.useClientCapability = useClientCapability;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function decodeBase64(value) {
|
|
2
|
+
const binary = atob(value);
|
|
3
|
+
const bytes = new Uint8Array(binary.length);
|
|
4
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
5
|
+
bytes[index] = binary.charCodeAt(index);
|
|
6
|
+
}
|
|
7
|
+
return bytes;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { decodeBase64 as d };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const action = require('@vue-solana/core/action');
|
|
4
|
+
const errors = require('@vue-solana/core/errors');
|
|
5
|
+
const timeout = require('@vue-solana/core/timeout');
|
|
6
|
+
const vue = require('vue');
|
|
7
|
+
|
|
8
|
+
const DEFAULT_TIMEOUT_MESSAGE = "Transaction did not return a result before timing out.";
|
|
9
|
+
function useTransaction(handler, options = {}) {
|
|
10
|
+
const signature = vue.shallowRef(null);
|
|
11
|
+
const loading = vue.ref(false);
|
|
12
|
+
const error = vue.ref(null);
|
|
13
|
+
const store = action.createSolanaActionStore(async (_signal, ...args) => {
|
|
14
|
+
const attempt = timeout.withSolanaTimeout(
|
|
15
|
+
handler(...args),
|
|
16
|
+
options.timeoutMs,
|
|
17
|
+
options.timeoutMessage ?? DEFAULT_TIMEOUT_MESSAGE
|
|
18
|
+
);
|
|
19
|
+
attempt.catch(() => void 0);
|
|
20
|
+
return attempt;
|
|
21
|
+
});
|
|
22
|
+
const unsubscribe = store.subscribe(() => {
|
|
23
|
+
const state = store.getState();
|
|
24
|
+
if (state.status === "running") {
|
|
25
|
+
loading.value = true;
|
|
26
|
+
} else if (state.status === "success") {
|
|
27
|
+
signature.value = state.data;
|
|
28
|
+
loading.value = false;
|
|
29
|
+
error.value = null;
|
|
30
|
+
} else if (state.status === "error") {
|
|
31
|
+
error.value = errors.normalizeSolanaError(state.error, "RPC_FAILURE");
|
|
32
|
+
loading.value = false;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (vue.getCurrentScope()) {
|
|
36
|
+
vue.onScopeDispose(() => {
|
|
37
|
+
unsubscribe();
|
|
38
|
+
store.reset();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function execute(...args) {
|
|
42
|
+
loading.value = true;
|
|
43
|
+
error.value = null;
|
|
44
|
+
try {
|
|
45
|
+
return await store.dispatchAsync(...args);
|
|
46
|
+
} catch (cause) {
|
|
47
|
+
if (action.isSolanaActionAborted(cause)) {
|
|
48
|
+
throw cause;
|
|
49
|
+
}
|
|
50
|
+
throw errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
signature,
|
|
55
|
+
loading,
|
|
56
|
+
error,
|
|
57
|
+
execute
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
exports.useTransaction = useTransaction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed } from 'vue';
|
|
2
|
-
import { u as useSolana } from './vue.
|
|
2
|
+
import { u as useSolana } from './vue.CQh3AUE8.mjs';
|
|
3
3
|
|
|
4
4
|
function useRpc() {
|
|
5
5
|
const solana = useSolana();
|
|
@@ -11,7 +11,7 @@ function useRpc() {
|
|
|
11
11
|
error: solana.error,
|
|
12
12
|
latestBlockhash: solana.latestBlockhash,
|
|
13
13
|
checkConnection: solana.checkConnection,
|
|
14
|
-
|
|
14
|
+
client: solana.client
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const address = require('@vue-solana/core/address');
|
|
4
|
-
const errors = require('@vue-solana/core/errors');
|
|
5
3
|
const tokenAccounts = require('@vue-solana/core/token-accounts');
|
|
4
|
+
const errors = require('@vue-solana/core/errors');
|
|
5
|
+
const address = require('@vue-solana/core/address');
|
|
6
6
|
const vue = require('vue');
|
|
7
|
-
const useConnection = require('./vue.
|
|
8
|
-
const useSolana = require('./vue.
|
|
7
|
+
const useConnection = require('./vue.BVaMoz9y.cjs');
|
|
8
|
+
const useSolana = require('./vue.DE3emjSF.cjs');
|
|
9
9
|
|
|
10
10
|
function useTokenAccounts(owner, options) {
|
|
11
11
|
const solana = useSolana.tryUseSolana();
|
|
12
|
-
const
|
|
12
|
+
const client = solana?.client ?? useConnection.useConnection();
|
|
13
13
|
const tokenAccounts$1 = vue.shallowRef([]);
|
|
14
14
|
const loading = vue.shallowRef(false);
|
|
15
15
|
const error = vue.shallowRef(null);
|
|
@@ -26,17 +26,16 @@ function useTokenAccounts(owner, options) {
|
|
|
26
26
|
loading.value = true;
|
|
27
27
|
error.value = null;
|
|
28
28
|
try {
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
29
|
+
const parsedAddress = address.parseAddress(value);
|
|
30
|
+
if (!parsedAddress) {
|
|
31
31
|
tokenAccounts$1.value = [];
|
|
32
32
|
loading.value = false;
|
|
33
33
|
return [];
|
|
34
34
|
}
|
|
35
|
-
const
|
|
35
|
+
const nextAccounts = await tokenAccounts.getTokenAccountsByOwner(client, parsedAddress, {
|
|
36
36
|
commitment: options?.commitment,
|
|
37
37
|
programId: options?.programId
|
|
38
|
-
};
|
|
39
|
-
const nextAccounts = await tokenAccounts.getTokenAccountsByOwner(connection, publicKey, opts);
|
|
38
|
+
});
|
|
40
39
|
if (requestId === refreshId) {
|
|
41
40
|
tokenAccounts$1.value = nextAccounts;
|
|
42
41
|
}
|