@vue-solana/vue 2.0.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 +159 -21
- package/dist/index.cjs +58 -20
- package/dist/index.d.cts +25 -5
- package/dist/index.d.mts +25 -5
- package/dist/index.d.ts +25 -5
- package/dist/index.mjs +37 -19
- 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.CP1DPDX9.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.DP7qY8Rk.mjs → vue.BD6Gm1nl.mjs} +2 -2
- package/dist/shared/{vue.BAlo-tIh.cjs → vue.BGxz4dru.cjs} +5 -1
- package/dist/shared/{vue.stUBDBI9.mjs → vue.BINkrA8h.mjs} +2 -2
- package/dist/shared/{vue.k9Q6aN-0.cjs → vue.BIxphCAq.cjs} +1 -1
- package/dist/shared/{vue.yQcL1yMv.mjs → vue.BOpgWr43.mjs} +2 -2
- package/dist/shared/{vue.dPRo2X5y.mjs → vue.BQRpjwKl.mjs} +2 -2
- package/dist/shared/{vue.CZwftA0L.cjs → vue.BVaMoz9y.cjs} +1 -1
- package/dist/shared/vue.BVj9lWBK.cjs +111 -0
- package/dist/shared/vue.BY0qpgYr.cjs +35 -0
- package/dist/shared/vue.Bk5xjlUx.cjs +61 -0
- package/dist/shared/{vue.3VLZmw05.mjs → vue.BsGwt78R.mjs} +1 -1
- package/dist/shared/{vue.B_LRH8SM.cjs → vue.Bwd1sGAM.cjs} +2 -2
- package/dist/shared/vue.ByxbBC3y.mjs +57 -0
- package/dist/shared/{vue.BbMPRDeO.mjs → vue.C13umiQi.mjs} +2 -2
- package/dist/shared/vue.C5FVoEZT.mjs +99 -0
- package/dist/shared/vue.CATOh_9G.mjs +42 -0
- package/dist/shared/{vue.XQFqlMId.cjs → vue.CIs8QhCw.cjs} +2 -2
- package/dist/shared/vue.CMohL_Cz.mjs +58 -0
- package/dist/shared/{vue.CnUlZSe8.mjs → vue.CQh3AUE8.mjs} +2 -5
- package/dist/shared/{vue.CSJSK0Nq.cjs → vue.CWZSMVnB.cjs} +3 -3
- package/dist/shared/{vue.DL-yMCNc.mjs → vue.CXB4NEMA.mjs} +2 -2
- package/dist/shared/{vue.D7xFeC2m.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.ChujsB0B.mjs → vue.CpkwC8Th.mjs} +1 -1
- package/dist/shared/vue.CrkK_T15.cjs +86 -0
- package/dist/shared/{vue.BMencBpI.cjs → vue.D-qi8PSL.cjs} +2 -2
- package/dist/shared/{vue.PJjEncbP.mjs → vue.D218Ow7t.mjs} +6 -2
- package/dist/shared/{vue.B2sFJ1xI.mjs → vue.D3Y0PWbF.mjs} +1 -1
- package/dist/shared/vue.D5U1yLG3.mjs +83 -0
- package/dist/shared/{vue.CXHYdyKZ.cjs → vue.DAg5wC1G.cjs} +2 -2
- package/dist/shared/vue.DDbVk0Zh.cjs +180 -0
- package/dist/shared/{vue.BaR1VPhl.cjs → vue.DE3emjSF.cjs} +2 -6
- 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.DgCmU1RR.cjs → vue.DKyQ7J67.cjs} +1 -1
- 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.C7yR7Cs0.cjs → vue.Di7yjJ-R.cjs} +2 -2
- package/dist/shared/vue.DtCbCcPd.cjs +173 -0
- package/dist/shared/{vue.WugzPOca.mjs → vue.Dyi1OCI1.mjs} +3 -3
- package/dist/shared/{vue.CEn2purG.cjs → vue.E_npPFoV.cjs} +2 -2
- package/dist/shared/{vue.__r7YYZE.cjs → vue.FiMmnMHr.cjs} +1 -1
- package/dist/shared/{vue.CZO8TwJP.mjs → vue.JUWqu6kD.mjs} +1 -1
- package/dist/shared/{vue.BaFrF2PF.mjs → vue.Mxc8w6Qk.mjs} +1 -1
- package/dist/shared/{vue.C32ozdA1.cjs → vue.Sbbm9JSu.cjs} +1 -1
- 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 +5 -4
- package/dist/useAccountInfo.mjs +5 -4
- 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.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.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 +5 -4
- package/dist/useProgramAccounts.mjs +5 -4
- 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.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.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.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 +5 -4
- package/dist/useTokenAccounts.mjs +5 -4
- package/dist/useTokenBalance.cjs +5 -4
- package/dist/useTokenBalance.mjs +5 -4
- 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 +12 -1
- package/dist/useTransaction.d.mts +12 -1
- package/dist/useTransaction.d.ts +12 -1
- package/dist/useTransaction.mjs +2 -1
- package/dist/useTransactionConfirmation.cjs +5 -4
- package/dist/useTransactionConfirmation.mjs +5 -4
- package/dist/useWallet.cjs +3 -2
- package/dist/useWallet.mjs +3 -2
- package/dist/useWallets.cjs +3 -2
- package/dist/useWallets.mjs +3 -2
- package/package.json +73 -3
- package/dist/shared/vue.C4d2JA8U.mjs +0 -44
- package/dist/shared/vue.CE5i8KZZ.cjs +0 -46
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { createReactiveStoreWithInitialValueAndSlotTracking, getAbortablePromise } from '@vue-solana/core/kit';
|
|
2
|
+
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
|
+
import { shallowRef, watch, unref, onMounted, getCurrentInstance, onScopeDispose, computed } from 'vue';
|
|
4
|
+
|
|
5
|
+
function isActionSource(value) {
|
|
6
|
+
return typeof value === "object" && value !== null && "reactiveStore" in value && typeof value.reactiveStore === "function";
|
|
7
|
+
}
|
|
8
|
+
function useTrackedData(source, options = {}) {
|
|
9
|
+
const data = shallowRef(void 0);
|
|
10
|
+
const error = shallowRef(null);
|
|
11
|
+
const status = shallowRef("loading");
|
|
12
|
+
const disposables = [];
|
|
13
|
+
let connectionCount = 0;
|
|
14
|
+
let disposed = false;
|
|
15
|
+
let activeStore;
|
|
16
|
+
function applyState(state) {
|
|
17
|
+
if (state.status === "loaded") {
|
|
18
|
+
data.value = state.data;
|
|
19
|
+
error.value = null;
|
|
20
|
+
status.value = "loaded";
|
|
21
|
+
} else if (state.status === "error") {
|
|
22
|
+
error.value = normalizeSolanaError(state.error, "RPC_FAILURE");
|
|
23
|
+
status.value = "error";
|
|
24
|
+
options.onError?.(state.error);
|
|
25
|
+
} else if (state.status === "loading") {
|
|
26
|
+
status.value = data.value === void 0 ? "loading" : status.value;
|
|
27
|
+
} else if (state.status === "idle") {
|
|
28
|
+
error.value = null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function buildAndConnect() {
|
|
32
|
+
if (disposed) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let rpcRequest = unref(source.rpcRequest);
|
|
36
|
+
const rpcSubscriptionRequest = unref(source.rpcSubscriptionRequest);
|
|
37
|
+
if (!rpcRequest || !rpcSubscriptionRequest) {
|
|
38
|
+
disconnect();
|
|
39
|
+
data.value = void 0;
|
|
40
|
+
error.value = null;
|
|
41
|
+
status.value = "disabled";
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (!isActionSource(rpcRequest) && isSendSource(rpcRequest)) {
|
|
45
|
+
let runSend = function(abortSignal) {
|
|
46
|
+
controller?.abort();
|
|
47
|
+
controller = new AbortController();
|
|
48
|
+
const composed = abortSignal ? AbortSignal.any([controller.signal, abortSignal]) : controller.signal;
|
|
49
|
+
settle({ data: void 0, error: void 0, status: "running" });
|
|
50
|
+
const pending = Promise.resolve(sendSource.send({ abortSignal: composed }));
|
|
51
|
+
pending.then((response) => {
|
|
52
|
+
settle({ data: response, error: void 0, status: "success" });
|
|
53
|
+
}).catch((cause) => {
|
|
54
|
+
settle({ data: void 0, error: cause, status: "error" });
|
|
55
|
+
});
|
|
56
|
+
return getAbortablePromise(pending, composed);
|
|
57
|
+
};
|
|
58
|
+
const sendSource = rpcRequest;
|
|
59
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
60
|
+
let sendState = {
|
|
61
|
+
data: void 0,
|
|
62
|
+
error: void 0,
|
|
63
|
+
status: "idle"
|
|
64
|
+
};
|
|
65
|
+
let controller;
|
|
66
|
+
const emit = () => {
|
|
67
|
+
listeners.forEach((listener) => {
|
|
68
|
+
listener();
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const settle = (next) => {
|
|
72
|
+
sendState = next;
|
|
73
|
+
emit();
|
|
74
|
+
};
|
|
75
|
+
rpcRequest = {
|
|
76
|
+
reactiveStore: () => ({
|
|
77
|
+
dispatch() {
|
|
78
|
+
void runSend().catch(() => {
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
dispatchAsync: () => runSend(),
|
|
82
|
+
getState: () => sendState,
|
|
83
|
+
reset() {
|
|
84
|
+
controller?.abort();
|
|
85
|
+
settle({ data: void 0, error: void 0, status: "idle" });
|
|
86
|
+
},
|
|
87
|
+
subscribe(listener) {
|
|
88
|
+
listeners.add(listener);
|
|
89
|
+
return () => {
|
|
90
|
+
listeners.delete(listener);
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
withSignal(signal) {
|
|
94
|
+
return {
|
|
95
|
+
dispatch: () => {
|
|
96
|
+
void runSend(signal).catch(() => {
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
dispatchAsync: () => runSend(signal)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
connectionCount += 1;
|
|
106
|
+
const connection = connectionCount;
|
|
107
|
+
const callerSignal = options.getAbortSignal?.(connection);
|
|
108
|
+
const store = createReactiveStoreWithInitialValueAndSlotTracking({
|
|
109
|
+
initialValueMapper: source.rpcValueMapper,
|
|
110
|
+
initialValueSource: rpcRequest,
|
|
111
|
+
streamSource: rpcSubscriptionRequest,
|
|
112
|
+
streamValueMapper: source.rpcSubscriptionValueMapper
|
|
113
|
+
});
|
|
114
|
+
activeStore = store;
|
|
115
|
+
applyState(store.getState());
|
|
116
|
+
disposables.push(
|
|
117
|
+
store.subscribe(() => {
|
|
118
|
+
applyState(store.getState());
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
if (callerSignal?.aborted) {
|
|
122
|
+
applyState({ data: store.getState().data, error: callerSignal.reason, status: "error" });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (callerSignal) {
|
|
126
|
+
store.withSignal(callerSignal).connect();
|
|
127
|
+
} else {
|
|
128
|
+
store.connect();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function disconnect() {
|
|
132
|
+
disposables.forEach((dispose) => {
|
|
133
|
+
dispose();
|
|
134
|
+
});
|
|
135
|
+
disposables.length = 0;
|
|
136
|
+
if (activeStore) {
|
|
137
|
+
activeStore.reset();
|
|
138
|
+
activeStore = void 0;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
watch(
|
|
142
|
+
() => [unref(source.rpcRequest), unref(source.rpcSubscriptionRequest)],
|
|
143
|
+
() => {
|
|
144
|
+
buildAndConnect();
|
|
145
|
+
},
|
|
146
|
+
{ flush: "post" }
|
|
147
|
+
);
|
|
148
|
+
onMounted(() => {
|
|
149
|
+
buildAndConnect();
|
|
150
|
+
});
|
|
151
|
+
if (!getCurrentInstance()) {
|
|
152
|
+
buildAndConnect();
|
|
153
|
+
}
|
|
154
|
+
onScopeDispose(() => {
|
|
155
|
+
disposed = true;
|
|
156
|
+
disconnect();
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
data: computed(() => data.value),
|
|
160
|
+
error: computed(() => error.value),
|
|
161
|
+
refresh: () => {
|
|
162
|
+
buildAndConnect();
|
|
163
|
+
},
|
|
164
|
+
status: computed(() => status.value)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function isSendSource(value) {
|
|
168
|
+
return typeof value === "object" && value !== null && "send" in value && typeof value.send === "function";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { useTrackedData as u };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const errors = require('@vue-solana/core/errors');
|
|
4
|
+
const timeout = require('@vue-solana/core/timeout');
|
|
5
|
+
const wallet = require('@vue-solana/core/wallet');
|
|
6
|
+
const vue = require('vue');
|
|
7
|
+
const useWallet = require('./vue.BGxz4dru.cjs');
|
|
8
|
+
|
|
9
|
+
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
10
|
+
class PartialSignAndSendError extends errors.SolanaError {
|
|
11
|
+
constructor(cause, signatures) {
|
|
12
|
+
super(cause.code, cause.message, { cause: cause.cause, feature: cause.feature });
|
|
13
|
+
this.signatures = signatures;
|
|
14
|
+
this.name = "PartialSignAndSendError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function useSignAndSendTransactions() {
|
|
18
|
+
const { wallet: wallet$1 } = useWallet.useWallet();
|
|
19
|
+
const signatures = vue.shallowRef(null);
|
|
20
|
+
const status = vue.ref("idle");
|
|
21
|
+
const loading = vue.ref(false);
|
|
22
|
+
const error = vue.ref(null);
|
|
23
|
+
let executionId = 0;
|
|
24
|
+
async function execute(transactions, options) {
|
|
25
|
+
const currentExecutionId = ++executionId;
|
|
26
|
+
status.value = "sending";
|
|
27
|
+
loading.value = true;
|
|
28
|
+
error.value = null;
|
|
29
|
+
signatures.value = null;
|
|
30
|
+
const activeWallet = wallet$1.value;
|
|
31
|
+
if (!activeWallet) {
|
|
32
|
+
const normalizedError = wallet.createNoWalletSelectedError();
|
|
33
|
+
error.value = normalizedError;
|
|
34
|
+
status.value = "error";
|
|
35
|
+
loading.value = false;
|
|
36
|
+
throw normalizedError;
|
|
37
|
+
}
|
|
38
|
+
const sendSingularSequentially = async () => {
|
|
39
|
+
const collected = [];
|
|
40
|
+
for (const transaction of transactions) {
|
|
41
|
+
try {
|
|
42
|
+
const result = await activeWallet.signAndSendTransaction(transaction, options);
|
|
43
|
+
collected.push(result.signature);
|
|
44
|
+
} catch (cause) {
|
|
45
|
+
throw new PartialSignAndSendError(errors.normalizeSolanaError(cause, "RPC_FAILURE"), collected);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return collected;
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
wallet.assertWalletCanSignAndSendTransactions(activeWallet);
|
|
52
|
+
const send = timeout.withSolanaTimeout(
|
|
53
|
+
activeWallet.signAndSendTransactions ? activeWallet.signAndSendTransactions(transactions, options) : sendSingularSequentially(),
|
|
54
|
+
SIGN_AND_SEND_TIMEOUT_MS,
|
|
55
|
+
"Wallet transaction did not return a result. Check your wallet or explorer for the final status."
|
|
56
|
+
);
|
|
57
|
+
const result = await send;
|
|
58
|
+
if (currentExecutionId === executionId) {
|
|
59
|
+
signatures.value = result;
|
|
60
|
+
status.value = "sent";
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
} catch (cause) {
|
|
64
|
+
const normalizedError = errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
65
|
+
if (currentExecutionId === executionId) {
|
|
66
|
+
error.value = normalizedError;
|
|
67
|
+
status.value = "error";
|
|
68
|
+
}
|
|
69
|
+
throw normalizedError;
|
|
70
|
+
} finally {
|
|
71
|
+
if (currentExecutionId === executionId) {
|
|
72
|
+
loading.value = false;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
signatures,
|
|
78
|
+
status,
|
|
79
|
+
loading,
|
|
80
|
+
error,
|
|
81
|
+
execute
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.PartialSignAndSendError = PartialSignAndSendError;
|
|
86
|
+
exports.useSignAndSendTransactions = useSignAndSendTransactions;
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
const errors = require('@vue-solana/core/errors');
|
|
4
4
|
const vue = require('vue');
|
|
5
5
|
const address = require('@vue-solana/core/address');
|
|
6
|
-
const useConnection = require('./vue.
|
|
7
|
-
const useSolana = require('./vue.
|
|
6
|
+
const useConnection = require('./vue.BVaMoz9y.cjs');
|
|
7
|
+
const useSolana = require('./vue.DE3emjSF.cjs');
|
|
8
8
|
const decodeBase64 = require('./vue.DNxOpDXz.cjs');
|
|
9
9
|
|
|
10
10
|
function useAccountInfo(address$1, options = {}) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
2
|
-
import { createNoWalletSelectedError } from '@vue-solana/core/wallet';
|
|
2
|
+
import { createNoWalletSelectedError, assertWalletConnected } from '@vue-solana/core/wallet';
|
|
3
3
|
import { ref, computed, triggerRef } from 'vue';
|
|
4
|
-
import { u as useSolana } from './vue.
|
|
4
|
+
import { u as useSolana } from './vue.CQh3AUE8.mjs';
|
|
5
5
|
|
|
6
6
|
function useWallet() {
|
|
7
7
|
const solana = useSolana();
|
|
@@ -9,6 +9,9 @@ function useWallet() {
|
|
|
9
9
|
const connecting = ref(false);
|
|
10
10
|
const disconnecting = ref(false);
|
|
11
11
|
async function connect() {
|
|
12
|
+
if (connecting.value || wallet.value?.connecting) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
12
15
|
const activeWallet = wallet.value;
|
|
13
16
|
if (!activeWallet) {
|
|
14
17
|
throw createNoWalletSelectedError();
|
|
@@ -18,6 +21,7 @@ function useWallet() {
|
|
|
18
21
|
const connection = activeWallet.connect();
|
|
19
22
|
triggerRef(wallet);
|
|
20
23
|
await connection;
|
|
24
|
+
assertWalletConnected(activeWallet);
|
|
21
25
|
triggerRef(wallet);
|
|
22
26
|
console.info("[Vue Solana] Wallet connected", {
|
|
23
27
|
publicKey: activeWallet.publicKey ?? null
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { confirmTransactionSignature } from '@vue-solana/core/transaction';
|
|
2
2
|
import { normalizeSolanaError } from '@vue-solana/core/errors';
|
|
3
3
|
import { ref } from 'vue';
|
|
4
|
-
import { u as useConnection } from './vue.
|
|
4
|
+
import { u as useConnection } from './vue.CpkwC8Th.mjs';
|
|
5
5
|
|
|
6
6
|
function getConfirmedTransactionStatus(confirmation) {
|
|
7
7
|
if (confirmation.commitment === "finalized") {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SolanaError, normalizeSolanaError } from '@vue-solana/core/errors';
|
|
2
|
+
import { withSolanaTimeout } from '@vue-solana/core/timeout';
|
|
3
|
+
import { createNoWalletSelectedError, assertWalletCanSignAndSendTransactions } from '@vue-solana/core/wallet';
|
|
4
|
+
import { shallowRef, ref } from 'vue';
|
|
5
|
+
import { u as useWallet } from './vue.D218Ow7t.mjs';
|
|
6
|
+
|
|
7
|
+
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
8
|
+
class PartialSignAndSendError extends SolanaError {
|
|
9
|
+
constructor(cause, signatures) {
|
|
10
|
+
super(cause.code, cause.message, { cause: cause.cause, feature: cause.feature });
|
|
11
|
+
this.signatures = signatures;
|
|
12
|
+
this.name = "PartialSignAndSendError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function useSignAndSendTransactions() {
|
|
16
|
+
const { wallet } = useWallet();
|
|
17
|
+
const signatures = shallowRef(null);
|
|
18
|
+
const status = ref("idle");
|
|
19
|
+
const loading = ref(false);
|
|
20
|
+
const error = ref(null);
|
|
21
|
+
let executionId = 0;
|
|
22
|
+
async function execute(transactions, options) {
|
|
23
|
+
const currentExecutionId = ++executionId;
|
|
24
|
+
status.value = "sending";
|
|
25
|
+
loading.value = true;
|
|
26
|
+
error.value = null;
|
|
27
|
+
signatures.value = null;
|
|
28
|
+
const activeWallet = wallet.value;
|
|
29
|
+
if (!activeWallet) {
|
|
30
|
+
const normalizedError = createNoWalletSelectedError();
|
|
31
|
+
error.value = normalizedError;
|
|
32
|
+
status.value = "error";
|
|
33
|
+
loading.value = false;
|
|
34
|
+
throw normalizedError;
|
|
35
|
+
}
|
|
36
|
+
const sendSingularSequentially = async () => {
|
|
37
|
+
const collected = [];
|
|
38
|
+
for (const transaction of transactions) {
|
|
39
|
+
try {
|
|
40
|
+
const result = await activeWallet.signAndSendTransaction(transaction, options);
|
|
41
|
+
collected.push(result.signature);
|
|
42
|
+
} catch (cause) {
|
|
43
|
+
throw new PartialSignAndSendError(normalizeSolanaError(cause, "RPC_FAILURE"), collected);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return collected;
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
assertWalletCanSignAndSendTransactions(activeWallet);
|
|
50
|
+
const send = withSolanaTimeout(
|
|
51
|
+
activeWallet.signAndSendTransactions ? activeWallet.signAndSendTransactions(transactions, options) : sendSingularSequentially(),
|
|
52
|
+
SIGN_AND_SEND_TIMEOUT_MS,
|
|
53
|
+
"Wallet transaction did not return a result. Check your wallet or explorer for the final status."
|
|
54
|
+
);
|
|
55
|
+
const result = await send;
|
|
56
|
+
if (currentExecutionId === executionId) {
|
|
57
|
+
signatures.value = result;
|
|
58
|
+
status.value = "sent";
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
} catch (cause) {
|
|
62
|
+
const normalizedError = normalizeSolanaError(cause, "RPC_FAILURE");
|
|
63
|
+
if (currentExecutionId === executionId) {
|
|
64
|
+
error.value = normalizedError;
|
|
65
|
+
status.value = "error";
|
|
66
|
+
}
|
|
67
|
+
throw normalizedError;
|
|
68
|
+
} finally {
|
|
69
|
+
if (currentExecutionId === executionId) {
|
|
70
|
+
loading.value = false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
signatures,
|
|
76
|
+
status,
|
|
77
|
+
loading,
|
|
78
|
+
error,
|
|
79
|
+
execute
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { PartialSignAndSendError as P, useSignAndSendTransactions as u };
|
|
@@ -4,8 +4,8 @@ const tokenAccounts = require('@vue-solana/core/token-accounts');
|
|
|
4
4
|
const errors = require('@vue-solana/core/errors');
|
|
5
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 useTokenBalance(mint, owner, commitment) {
|
|
11
11
|
const solana = useSolana.tryUseSolana();
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const vue = require('vue');
|
|
4
|
+
const injection = require('./vue.DEHxNvUX.cjs');
|
|
5
|
+
|
|
6
|
+
const SELECTED_WALLET_ACCOUNT_STORAGE_KEY = "vue-solana:selected-wallet-account";
|
|
7
|
+
function createLocalStorageSelectedWalletAccountStorage(storage = defaultLocalStorage()) {
|
|
8
|
+
return {
|
|
9
|
+
storeSelectedWallet(key) {
|
|
10
|
+
try {
|
|
11
|
+
storage?.setItem(SELECTED_WALLET_ACCOUNT_STORAGE_KEY, key);
|
|
12
|
+
} catch {
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
getSelectedWallet() {
|
|
16
|
+
try {
|
|
17
|
+
return storage?.getItem(SELECTED_WALLET_ACCOUNT_STORAGE_KEY) ?? null;
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
deleteSelectedWallet() {
|
|
23
|
+
try {
|
|
24
|
+
storage?.removeItem(SELECTED_WALLET_ACCOUNT_STORAGE_KEY);
|
|
25
|
+
} catch {
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function defaultLocalStorage() {
|
|
31
|
+
if (typeof window === "undefined") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
return window.localStorage;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const selectedWalletAccountInjectionKey = Symbol.for("vue-solana:selected-wallet-account");
|
|
42
|
+
function provideSelectedWalletAccount(options = {}) {
|
|
43
|
+
const context = createSelectedWalletAccountContext(options);
|
|
44
|
+
vue.provide(selectedWalletAccountInjectionKey, context);
|
|
45
|
+
return context;
|
|
46
|
+
}
|
|
47
|
+
function createSelectedWalletAccountContext(options = {}, solanaContextOverride) {
|
|
48
|
+
const solanaContext = solanaContextOverride ?? vue.inject(injection.solanaInjectionKey, null);
|
|
49
|
+
const stateSync = options.stateSync === void 0 ? defaultStateSync() : options.stateSync;
|
|
50
|
+
const selectedWalletAccount = vue.ref(null);
|
|
51
|
+
const walletsValue = () => solanaContext?.wallets.value ?? [];
|
|
52
|
+
let pendingKey = null;
|
|
53
|
+
let selectionGeneration = 0;
|
|
54
|
+
function findAccount(key) {
|
|
55
|
+
const separatorIndex = key.lastIndexOf(":");
|
|
56
|
+
const walletName = separatorIndex === -1 ? key : key.slice(0, separatorIndex);
|
|
57
|
+
const address = separatorIndex === -1 ? "" : key.slice(separatorIndex + 1);
|
|
58
|
+
const wallet = walletsValue().find((candidate) => candidate.name === walletName);
|
|
59
|
+
const account = wallet?.accounts.find((candidate) => candidate.address === address);
|
|
60
|
+
if (!wallet || !account) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return { ...account, walletName: wallet.name };
|
|
64
|
+
}
|
|
65
|
+
function clearSelection() {
|
|
66
|
+
selectionGeneration += 1;
|
|
67
|
+
pendingKey = null;
|
|
68
|
+
selectedWalletAccount.value = null;
|
|
69
|
+
}
|
|
70
|
+
function applyExternalSelection(key) {
|
|
71
|
+
if (!key) {
|
|
72
|
+
clearSelection();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const account = findAccount(key);
|
|
76
|
+
if (account) {
|
|
77
|
+
selectionGeneration += 1;
|
|
78
|
+
pendingKey = null;
|
|
79
|
+
selectedWalletAccount.value = account;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
pendingKey = key;
|
|
83
|
+
}
|
|
84
|
+
function restoreIfAvailable() {
|
|
85
|
+
if (!pendingKey || selectedWalletAccount.value) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const account = findAccount(pendingKey);
|
|
89
|
+
if (account) {
|
|
90
|
+
selectedWalletAccount.value = account;
|
|
91
|
+
pendingKey = null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (stateSync) {
|
|
95
|
+
const generation = selectionGeneration;
|
|
96
|
+
void Promise.resolve(stateSync.getSelectedWallet()).then((key) => {
|
|
97
|
+
if (generation !== selectionGeneration || !key || selectedWalletAccount.value) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
pendingKey = key;
|
|
101
|
+
restoreIfAvailable();
|
|
102
|
+
}).catch(() => void 0);
|
|
103
|
+
}
|
|
104
|
+
if (solanaContext) {
|
|
105
|
+
vue.watch(
|
|
106
|
+
() => solanaContext.wallets.value,
|
|
107
|
+
() => restoreIfAvailable()
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (stateSync && typeof window !== "undefined") {
|
|
111
|
+
const onStorage = () => {
|
|
112
|
+
void Promise.resolve(stateSync.getSelectedWallet()).then((key) => applyExternalSelection(key)).catch(() => void 0);
|
|
113
|
+
};
|
|
114
|
+
window.addEventListener("storage", onStorage);
|
|
115
|
+
if (vue.getCurrentScope()) {
|
|
116
|
+
vue.onScopeDispose(() => window.removeEventListener("storage", onStorage));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const context = {
|
|
120
|
+
selectedWalletAccount,
|
|
121
|
+
setSelectedWalletAccount(account) {
|
|
122
|
+
selectionGeneration += 1;
|
|
123
|
+
selectedWalletAccount.value = account;
|
|
124
|
+
pendingKey = null;
|
|
125
|
+
if (!stateSync) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const persisted = account ? stateSync.storeSelectedWallet(`${account.walletName}:${account.address}`) : stateSync.deleteSelectedWallet();
|
|
129
|
+
void Promise.resolve(persisted).catch(() => void 0);
|
|
130
|
+
},
|
|
131
|
+
filteredWallets: vue.computed(() => {
|
|
132
|
+
const filter = options.filterWallet;
|
|
133
|
+
if (!filter) {
|
|
134
|
+
return walletsValue();
|
|
135
|
+
}
|
|
136
|
+
return walletsValue().map((wallet) => {
|
|
137
|
+
const accounts = wallet.accounts.filter((account) => filter(wallet.name, account));
|
|
138
|
+
return accounts.length === 0 ? null : { ...wallet, accounts };
|
|
139
|
+
}).filter((wallet) => wallet !== null);
|
|
140
|
+
})
|
|
141
|
+
};
|
|
142
|
+
return context;
|
|
143
|
+
}
|
|
144
|
+
function useSelectedWalletAccount() {
|
|
145
|
+
const context = vue.inject(selectedWalletAccountInjectionKey, null);
|
|
146
|
+
if (!context) {
|
|
147
|
+
throw new Error("useSelectedWalletAccount must be used inside a SelectedWalletAccountProvider");
|
|
148
|
+
}
|
|
149
|
+
return [context.selectedWalletAccount, context.setSelectedWalletAccount, context.filteredWallets];
|
|
150
|
+
}
|
|
151
|
+
function defaultStateSync() {
|
|
152
|
+
return createLocalStorageSelectedWalletAccountStorage();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const SelectedWalletAccountProvider = vue.defineComponent({
|
|
156
|
+
name: "SelectedWalletAccountProvider",
|
|
157
|
+
props: {
|
|
158
|
+
filterWallet: {
|
|
159
|
+
type: Function,
|
|
160
|
+
default: void 0
|
|
161
|
+
},
|
|
162
|
+
stateSync: {
|
|
163
|
+
type: [Object, null],
|
|
164
|
+
default: void 0
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
setup(props, { slots }) {
|
|
168
|
+
provideSelectedWalletAccount({
|
|
169
|
+
filterWallet: props.filterWallet,
|
|
170
|
+
stateSync: props.stateSync
|
|
171
|
+
});
|
|
172
|
+
return () => slots.default?.();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
exports.SelectedWalletAccountProvider = SelectedWalletAccountProvider;
|
|
177
|
+
exports.createSelectedWalletAccountContext = createSelectedWalletAccountContext;
|
|
178
|
+
exports.provideSelectedWalletAccount = provideSelectedWalletAccount;
|
|
179
|
+
exports.selectedWalletAccountInjectionKey = selectedWalletAccountInjectionKey;
|
|
180
|
+
exports.useSelectedWalletAccount = useSelectedWalletAccount;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const vue = require('vue');
|
|
4
|
-
|
|
5
|
-
const solanaInjectionKey = Symbol.for(
|
|
6
|
-
"vue-solana:context"
|
|
7
|
-
);
|
|
4
|
+
const injection = require('./vue.DEHxNvUX.cjs');
|
|
8
5
|
|
|
9
6
|
let ssrContext;
|
|
10
7
|
function tryUseSolana() {
|
|
11
|
-
return vue.inject(solanaInjectionKey, null);
|
|
8
|
+
return vue.inject(injection.solanaInjectionKey, null);
|
|
12
9
|
}
|
|
13
10
|
function useSolana() {
|
|
14
11
|
return tryUseSolana() ?? getSsrContext();
|
|
@@ -47,6 +44,5 @@ function createUnavailableProxy() {
|
|
|
47
44
|
);
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
exports.solanaInjectionKey = solanaInjectionKey;
|
|
51
47
|
exports.tryUseSolana = tryUseSolana;
|
|
52
48
|
exports.useSolana = useSolana;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const errors = require('@vue-solana/core/errors');
|
|
4
|
+
const wallet = require('@vue-solana/core/wallet');
|
|
5
|
+
const vue = require('vue');
|
|
6
|
+
const useWallet = require('./vue.BGxz4dru.cjs');
|
|
7
|
+
|
|
8
|
+
function useSignTransactions() {
|
|
9
|
+
const { wallet: wallet$1 } = useWallet.useWallet();
|
|
10
|
+
const signedTransactions = vue.shallowRef(null);
|
|
11
|
+
const status = vue.ref("idle");
|
|
12
|
+
const loading = vue.ref(false);
|
|
13
|
+
const error = vue.ref(null);
|
|
14
|
+
let executionId = 0;
|
|
15
|
+
async function execute(transactions) {
|
|
16
|
+
const currentExecutionId = ++executionId;
|
|
17
|
+
status.value = "signing";
|
|
18
|
+
loading.value = true;
|
|
19
|
+
error.value = null;
|
|
20
|
+
signedTransactions.value = null;
|
|
21
|
+
const activeWallet = wallet$1.value;
|
|
22
|
+
if (!activeWallet) {
|
|
23
|
+
const normalizedError = wallet.createNoWalletSelectedError();
|
|
24
|
+
error.value = normalizedError;
|
|
25
|
+
status.value = "error";
|
|
26
|
+
loading.value = false;
|
|
27
|
+
throw normalizedError;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
wallet.assertWalletCanSignTransactions(activeWallet);
|
|
31
|
+
const sign = activeWallet.signTransactions ? activeWallet.signTransactions.bind(activeWallet) : activeWallet.signAllTransactions.bind(activeWallet);
|
|
32
|
+
const result = await sign([...transactions]);
|
|
33
|
+
if (currentExecutionId === executionId) {
|
|
34
|
+
signedTransactions.value = result;
|
|
35
|
+
status.value = "signed";
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
const normalizedError = errors.normalizeSolanaError(cause, "RPC_FAILURE");
|
|
40
|
+
if (currentExecutionId === executionId) {
|
|
41
|
+
error.value = normalizedError;
|
|
42
|
+
status.value = "error";
|
|
43
|
+
}
|
|
44
|
+
throw normalizedError;
|
|
45
|
+
} finally {
|
|
46
|
+
if (currentExecutionId === executionId) {
|
|
47
|
+
loading.value = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
signedTransactions,
|
|
53
|
+
status,
|
|
54
|
+
loading,
|
|
55
|
+
error,
|
|
56
|
+
execute
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.useSignTransactions = useSignTransactions;
|