@vue-solana/vue 0.6.0 → 0.7.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 +67 -3
- package/dist/index.cjs +13 -2
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +9 -2
- package/dist/shared/vue.7TzeDJZX.mjs +127 -0
- package/dist/shared/vue.BPnK_lsh.cjs +129 -0
- package/dist/shared/vue.BeuIPLGM.mjs +63 -0
- package/dist/shared/{vue.CwPjPFN6.cjs → vue.BwipRa1w.cjs} +21 -0
- package/dist/shared/{vue.DYf_CRDv.mjs → vue.CGVdFmYI.mjs} +21 -0
- package/dist/shared/{vue.RQ9fETnm.mjs → vue.CM6qb_s8.mjs} +10 -5
- package/dist/shared/vue.CUTLu1Gf.mjs +71 -0
- package/dist/shared/vue.D1knFN3X.cjs +65 -0
- package/dist/shared/vue.DUufwq8y.cjs +186 -0
- package/dist/shared/{vue.DEQJ23UM.cjs → vue.DWiQYhb8.cjs} +10 -5
- package/dist/shared/vue.JC5FdU2O.mjs +180 -0
- package/dist/shared/vue.dmuispJ3.cjs +73 -0
- package/dist/useAccountInfo.cjs +12 -0
- package/dist/useAccountInfo.d.cts +19 -0
- package/dist/useAccountInfo.d.mts +19 -0
- package/dist/useAccountInfo.d.ts +19 -0
- package/dist/useAccountInfo.mjs +6 -0
- package/dist/useProgramAccounts.cjs +12 -0
- package/dist/useProgramAccounts.d.cts +39 -0
- package/dist/useProgramAccounts.d.mts +39 -0
- package/dist/useProgramAccounts.d.ts +39 -0
- package/dist/useProgramAccounts.mjs +6 -0
- package/dist/useSignAndSendTransaction.cjs +2 -2
- package/dist/useSignAndSendTransaction.mjs +2 -2
- package/dist/useSignMessage.cjs +11 -0
- package/dist/useSignMessage.d.cts +235 -0
- package/dist/useSignMessage.d.mts +235 -0
- package/dist/useSignMessage.d.ts +235 -0
- package/dist/useSignMessage.mjs +5 -0
- package/dist/useSignatureStatus.cjs +12 -0
- package/dist/useSignatureStatus.d.cts +21 -0
- package/dist/useSignatureStatus.d.mts +21 -0
- package/dist/useSignatureStatus.d.ts +21 -0
- package/dist/useSignatureStatus.mjs +6 -0
- package/dist/useWallet.cjs +1 -1
- package/dist/useWallet.d.cts +14 -0
- package/dist/useWallet.d.mts +14 -0
- package/dist/useWallet.d.ts +14 -0
- package/dist/useWallet.mjs +1 -1
- package/package.json +23 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { signAndSendTransaction, confirmTransactionSignature } from '@vue-solana/core/transaction';
|
|
2
2
|
import { ref } from 'vue';
|
|
3
3
|
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
|
-
import { u as useWallet } from './vue.
|
|
4
|
+
import { u as useWallet } from './vue.CGVdFmYI.mjs';
|
|
5
5
|
import { g as getConfirmedTransactionStatus } from './vue.jOsz34kz.mjs';
|
|
6
6
|
|
|
7
7
|
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
@@ -22,12 +22,17 @@ function useSignAndSendTransaction() {
|
|
|
22
22
|
loading.value = true;
|
|
23
23
|
error.value = null;
|
|
24
24
|
confirmation.value = null;
|
|
25
|
+
const activeWallet = wallet.value;
|
|
26
|
+
if (!activeWallet) {
|
|
27
|
+
const cause = new Error("No Solana wallet is configured");
|
|
28
|
+
error.value = cause;
|
|
29
|
+
status.value = "error";
|
|
30
|
+
loading.value = false;
|
|
31
|
+
throw cause;
|
|
32
|
+
}
|
|
25
33
|
try {
|
|
26
|
-
if (!wallet.value) {
|
|
27
|
-
throw new Error("No Solana wallet is configured");
|
|
28
|
-
}
|
|
29
34
|
const nextSignature = await withWalletTransactionTimeout(
|
|
30
|
-
signAndSendTransaction(connection,
|
|
35
|
+
signAndSendTransaction(connection, activeWallet, transaction, transactionOptions)
|
|
31
36
|
);
|
|
32
37
|
if (currentExecutionId === executionId) {
|
|
33
38
|
signature.value = nextSignature;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { parsePublicKey } from '@vue-solana/core/address';
|
|
2
|
+
import { shallowRef, onMounted, onUnmounted, watch, toValue } from 'vue';
|
|
3
|
+
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
|
+
import { t as tryUseSolana } from './vue.1M_c5FWA.mjs';
|
|
5
|
+
|
|
6
|
+
function useProgramAccounts(programId, options = {}) {
|
|
7
|
+
const solana = tryUseSolana();
|
|
8
|
+
const connection = solana?.connection ?? useConnection();
|
|
9
|
+
const accounts = shallowRef([]);
|
|
10
|
+
const loading = shallowRef(false);
|
|
11
|
+
const error = shallowRef(null);
|
|
12
|
+
let refreshId = 0;
|
|
13
|
+
async function refresh() {
|
|
14
|
+
const requestId = ++refreshId;
|
|
15
|
+
const value = toValue(programId);
|
|
16
|
+
if (!value || !solana) {
|
|
17
|
+
accounts.value = [];
|
|
18
|
+
loading.value = false;
|
|
19
|
+
error.value = null;
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
loading.value = true;
|
|
23
|
+
error.value = null;
|
|
24
|
+
try {
|
|
25
|
+
const publicKey = parsePublicKey(value);
|
|
26
|
+
if (!publicKey) {
|
|
27
|
+
accounts.value = [];
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const nextAccounts = await connection.getProgramAccounts(publicKey, {
|
|
31
|
+
commitment: options.commitment,
|
|
32
|
+
dataSlice: options.dataSlice,
|
|
33
|
+
filters: options.filters
|
|
34
|
+
});
|
|
35
|
+
if (requestId === refreshId) {
|
|
36
|
+
accounts.value = nextAccounts;
|
|
37
|
+
}
|
|
38
|
+
return nextAccounts;
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
if (requestId === refreshId) {
|
|
41
|
+
accounts.value = [];
|
|
42
|
+
error.value = cause;
|
|
43
|
+
}
|
|
44
|
+
throw cause;
|
|
45
|
+
} finally {
|
|
46
|
+
if (requestId === refreshId) {
|
|
47
|
+
loading.value = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
onMounted(() => {
|
|
52
|
+
void refresh().catch(() => void 0);
|
|
53
|
+
});
|
|
54
|
+
onUnmounted(() => {
|
|
55
|
+
refreshId += 1;
|
|
56
|
+
});
|
|
57
|
+
watch(
|
|
58
|
+
() => toValue(programId),
|
|
59
|
+
() => {
|
|
60
|
+
void refresh().catch(() => void 0);
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
return {
|
|
64
|
+
accounts,
|
|
65
|
+
loading,
|
|
66
|
+
error,
|
|
67
|
+
refresh
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { useProgramAccounts as u };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const wallet = require('@vue-solana/core/wallet');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
const useWallet = require('./vue.BwipRa1w.cjs');
|
|
6
|
+
|
|
7
|
+
function useSignMessage() {
|
|
8
|
+
const { wallet: wallet$1 } = useWallet.useWallet();
|
|
9
|
+
const signedMessage = vue.ref(null);
|
|
10
|
+
const signature = vue.ref(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(message) {
|
|
16
|
+
const currentExecutionId = ++executionId;
|
|
17
|
+
status.value = "signing";
|
|
18
|
+
loading.value = true;
|
|
19
|
+
error.value = null;
|
|
20
|
+
signedMessage.value = null;
|
|
21
|
+
signature.value = null;
|
|
22
|
+
const activeWallet = wallet$1.value;
|
|
23
|
+
if (!activeWallet) {
|
|
24
|
+
const cause = new Error("No Solana wallet is configured");
|
|
25
|
+
error.value = cause;
|
|
26
|
+
status.value = "error";
|
|
27
|
+
loading.value = false;
|
|
28
|
+
throw cause;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
wallet.assertWalletCanSignMessage(activeWallet);
|
|
32
|
+
const result = await activeWallet.signMessage(message);
|
|
33
|
+
if (currentExecutionId === executionId) {
|
|
34
|
+
signedMessage.value = result.signedMessage;
|
|
35
|
+
signature.value = result.signature;
|
|
36
|
+
status.value = "signed";
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
const normalizedError = normalizeError(cause);
|
|
41
|
+
if (currentExecutionId === executionId) {
|
|
42
|
+
error.value = normalizedError;
|
|
43
|
+
status.value = "error";
|
|
44
|
+
}
|
|
45
|
+
throw normalizedError;
|
|
46
|
+
} finally {
|
|
47
|
+
if (currentExecutionId === executionId) {
|
|
48
|
+
loading.value = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
signedMessage,
|
|
54
|
+
signature,
|
|
55
|
+
status,
|
|
56
|
+
loading,
|
|
57
|
+
error,
|
|
58
|
+
execute
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function normalizeError(cause) {
|
|
62
|
+
return cause instanceof Error ? cause : new Error(String(cause));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
exports.useSignMessage = useSignMessage;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const bs58 = require('bs58');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
6
|
+
const useSolana = require('./vue.C4tLiG3R.cjs');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
+
|
|
10
|
+
const bs58__default = /*#__PURE__*/_interopDefaultCompat(bs58);
|
|
11
|
+
|
|
12
|
+
function useSignatureStatus(signature, options = {}) {
|
|
13
|
+
const solana = useSolana.tryUseSolana();
|
|
14
|
+
const connection = solana?.connection ?? useConnection.useConnection();
|
|
15
|
+
const status = vue.shallowRef(null);
|
|
16
|
+
const loading = vue.shallowRef(false);
|
|
17
|
+
const error = vue.shallowRef(null);
|
|
18
|
+
let refreshId = 0;
|
|
19
|
+
let subscriptionStartId = 0;
|
|
20
|
+
let pollId = null;
|
|
21
|
+
let subscriptionId = null;
|
|
22
|
+
let manuallyStoppedPolling = false;
|
|
23
|
+
let manuallyStoppedSubscription = false;
|
|
24
|
+
async function refresh() {
|
|
25
|
+
const requestId = ++refreshId;
|
|
26
|
+
const value = vue.toValue(signature);
|
|
27
|
+
if (!value || !solana) {
|
|
28
|
+
status.value = null;
|
|
29
|
+
loading.value = false;
|
|
30
|
+
error.value = null;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
loading.value = true;
|
|
34
|
+
error.value = null;
|
|
35
|
+
try {
|
|
36
|
+
const validSignature = parseTransactionSignature(value);
|
|
37
|
+
const response = await connection.getSignatureStatuses([validSignature], {
|
|
38
|
+
searchTransactionHistory: options.searchTransactionHistory
|
|
39
|
+
});
|
|
40
|
+
const nextStatus = response.value[0] ?? null;
|
|
41
|
+
if (requestId === refreshId) {
|
|
42
|
+
status.value = nextStatus;
|
|
43
|
+
}
|
|
44
|
+
return nextStatus;
|
|
45
|
+
} catch (cause) {
|
|
46
|
+
if (requestId === refreshId) {
|
|
47
|
+
status.value = null;
|
|
48
|
+
error.value = cause;
|
|
49
|
+
}
|
|
50
|
+
throw cause;
|
|
51
|
+
} finally {
|
|
52
|
+
if (requestId === refreshId) {
|
|
53
|
+
loading.value = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function stopPolling() {
|
|
58
|
+
manuallyStoppedPolling = true;
|
|
59
|
+
stopCurrentPolling();
|
|
60
|
+
}
|
|
61
|
+
function stopCurrentPolling() {
|
|
62
|
+
if (pollId === null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
clearInterval(pollId);
|
|
66
|
+
pollId = null;
|
|
67
|
+
}
|
|
68
|
+
function startPolling() {
|
|
69
|
+
stopCurrentPolling();
|
|
70
|
+
const value = vue.toValue(signature);
|
|
71
|
+
if (manuallyStoppedPolling || !options.pollIntervalMs || !value || !solana) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (options.pollIntervalMs <= 0) {
|
|
75
|
+
error.value = new RangeError("pollIntervalMs must be greater than 0");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
parseTransactionSignature(value);
|
|
80
|
+
} catch (cause) {
|
|
81
|
+
error.value = cause;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
pollId = setInterval(() => {
|
|
85
|
+
void refresh().catch(() => void 0);
|
|
86
|
+
}, options.pollIntervalMs);
|
|
87
|
+
}
|
|
88
|
+
async function stopSubscription() {
|
|
89
|
+
manuallyStoppedSubscription = true;
|
|
90
|
+
subscriptionStartId += 1;
|
|
91
|
+
await stopCurrentSubscription();
|
|
92
|
+
}
|
|
93
|
+
async function stopCurrentSubscription() {
|
|
94
|
+
if (subscriptionId === null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const currentSubscriptionId = subscriptionId;
|
|
98
|
+
subscriptionId = null;
|
|
99
|
+
try {
|
|
100
|
+
await connection.removeSignatureListener(currentSubscriptionId);
|
|
101
|
+
} catch (cause) {
|
|
102
|
+
error.value = cause;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
async function startSubscription() {
|
|
106
|
+
const requestId = ++subscriptionStartId;
|
|
107
|
+
await stopCurrentSubscription();
|
|
108
|
+
if (requestId !== subscriptionStartId) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const value = vue.toValue(signature);
|
|
112
|
+
if (manuallyStoppedSubscription || !options.subscribe || !value || !solana) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
try {
|
|
116
|
+
const validSignature = parseTransactionSignature(value);
|
|
117
|
+
const nextSubscriptionId = connection.onSignature(
|
|
118
|
+
validSignature,
|
|
119
|
+
(notification, context) => {
|
|
120
|
+
if (requestId !== subscriptionStartId) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
status.value = {
|
|
124
|
+
slot: context.slot,
|
|
125
|
+
confirmations: null,
|
|
126
|
+
err: notification.err,
|
|
127
|
+
confirmationStatus: options.commitment ?? "confirmed"
|
|
128
|
+
};
|
|
129
|
+
error.value = null;
|
|
130
|
+
},
|
|
131
|
+
options.commitment
|
|
132
|
+
);
|
|
133
|
+
if (requestId !== subscriptionStartId) {
|
|
134
|
+
await connection.removeSignatureListener(nextSubscriptionId);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
subscriptionId = nextSubscriptionId;
|
|
138
|
+
} catch (cause) {
|
|
139
|
+
if (requestId === subscriptionStartId) {
|
|
140
|
+
error.value = cause;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function resetIntervals() {
|
|
145
|
+
startPolling();
|
|
146
|
+
void startSubscription();
|
|
147
|
+
}
|
|
148
|
+
vue.onMounted(() => {
|
|
149
|
+
void refresh().catch(() => void 0);
|
|
150
|
+
resetIntervals();
|
|
151
|
+
});
|
|
152
|
+
vue.onUnmounted(() => {
|
|
153
|
+
refreshId += 1;
|
|
154
|
+
stopPolling();
|
|
155
|
+
void stopSubscription();
|
|
156
|
+
});
|
|
157
|
+
vue.watch(
|
|
158
|
+
() => vue.toValue(signature),
|
|
159
|
+
() => {
|
|
160
|
+
void refresh().catch(() => void 0);
|
|
161
|
+
resetIntervals();
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
status,
|
|
166
|
+
loading,
|
|
167
|
+
error,
|
|
168
|
+
refresh,
|
|
169
|
+
stopPolling,
|
|
170
|
+
stopSubscription
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function parseTransactionSignature(signature) {
|
|
174
|
+
let decodedSignature;
|
|
175
|
+
try {
|
|
176
|
+
decodedSignature = bs58__default.decode(signature);
|
|
177
|
+
} catch (cause) {
|
|
178
|
+
throw new TypeError("Invalid Solana transaction signature", { cause });
|
|
179
|
+
}
|
|
180
|
+
if (decodedSignature.length !== 64) {
|
|
181
|
+
throw new TypeError("Invalid Solana transaction signature");
|
|
182
|
+
}
|
|
183
|
+
return signature;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
exports.useSignatureStatus = useSignatureStatus;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const transaction = require('@vue-solana/core/transaction');
|
|
4
4
|
const vue = require('vue');
|
|
5
5
|
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
6
|
-
const useWallet = require('./vue.
|
|
6
|
+
const useWallet = require('./vue.BwipRa1w.cjs');
|
|
7
7
|
const useTransactionConfirmation = require('./vue.DHVYJk8P.cjs');
|
|
8
8
|
|
|
9
9
|
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
@@ -24,12 +24,17 @@ function useSignAndSendTransaction() {
|
|
|
24
24
|
loading.value = true;
|
|
25
25
|
error.value = null;
|
|
26
26
|
confirmation.value = null;
|
|
27
|
+
const activeWallet = wallet.value;
|
|
28
|
+
if (!activeWallet) {
|
|
29
|
+
const cause = new Error("No Solana wallet is configured");
|
|
30
|
+
error.value = cause;
|
|
31
|
+
status.value = "error";
|
|
32
|
+
loading.value = false;
|
|
33
|
+
throw cause;
|
|
34
|
+
}
|
|
27
35
|
try {
|
|
28
|
-
if (!wallet.value) {
|
|
29
|
-
throw new Error("No Solana wallet is configured");
|
|
30
|
-
}
|
|
31
36
|
const nextSignature = await withWalletTransactionTimeout(
|
|
32
|
-
transaction.signAndSendTransaction(connection,
|
|
37
|
+
transaction.signAndSendTransaction(connection, activeWallet, transaction$1, transactionOptions)
|
|
33
38
|
);
|
|
34
39
|
if (currentExecutionId === executionId) {
|
|
35
40
|
signature.value = nextSignature;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import bs58 from 'bs58';
|
|
2
|
+
import { shallowRef, onMounted, onUnmounted, watch, toValue } from 'vue';
|
|
3
|
+
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
|
+
import { t as tryUseSolana } from './vue.1M_c5FWA.mjs';
|
|
5
|
+
|
|
6
|
+
function useSignatureStatus(signature, options = {}) {
|
|
7
|
+
const solana = tryUseSolana();
|
|
8
|
+
const connection = solana?.connection ?? useConnection();
|
|
9
|
+
const status = shallowRef(null);
|
|
10
|
+
const loading = shallowRef(false);
|
|
11
|
+
const error = shallowRef(null);
|
|
12
|
+
let refreshId = 0;
|
|
13
|
+
let subscriptionStartId = 0;
|
|
14
|
+
let pollId = null;
|
|
15
|
+
let subscriptionId = null;
|
|
16
|
+
let manuallyStoppedPolling = false;
|
|
17
|
+
let manuallyStoppedSubscription = false;
|
|
18
|
+
async function refresh() {
|
|
19
|
+
const requestId = ++refreshId;
|
|
20
|
+
const value = toValue(signature);
|
|
21
|
+
if (!value || !solana) {
|
|
22
|
+
status.value = null;
|
|
23
|
+
loading.value = false;
|
|
24
|
+
error.value = null;
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
loading.value = true;
|
|
28
|
+
error.value = null;
|
|
29
|
+
try {
|
|
30
|
+
const validSignature = parseTransactionSignature(value);
|
|
31
|
+
const response = await connection.getSignatureStatuses([validSignature], {
|
|
32
|
+
searchTransactionHistory: options.searchTransactionHistory
|
|
33
|
+
});
|
|
34
|
+
const nextStatus = response.value[0] ?? null;
|
|
35
|
+
if (requestId === refreshId) {
|
|
36
|
+
status.value = nextStatus;
|
|
37
|
+
}
|
|
38
|
+
return nextStatus;
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
if (requestId === refreshId) {
|
|
41
|
+
status.value = null;
|
|
42
|
+
error.value = cause;
|
|
43
|
+
}
|
|
44
|
+
throw cause;
|
|
45
|
+
} finally {
|
|
46
|
+
if (requestId === refreshId) {
|
|
47
|
+
loading.value = false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function stopPolling() {
|
|
52
|
+
manuallyStoppedPolling = true;
|
|
53
|
+
stopCurrentPolling();
|
|
54
|
+
}
|
|
55
|
+
function stopCurrentPolling() {
|
|
56
|
+
if (pollId === null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
clearInterval(pollId);
|
|
60
|
+
pollId = null;
|
|
61
|
+
}
|
|
62
|
+
function startPolling() {
|
|
63
|
+
stopCurrentPolling();
|
|
64
|
+
const value = toValue(signature);
|
|
65
|
+
if (manuallyStoppedPolling || !options.pollIntervalMs || !value || !solana) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (options.pollIntervalMs <= 0) {
|
|
69
|
+
error.value = new RangeError("pollIntervalMs must be greater than 0");
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
parseTransactionSignature(value);
|
|
74
|
+
} catch (cause) {
|
|
75
|
+
error.value = cause;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
pollId = setInterval(() => {
|
|
79
|
+
void refresh().catch(() => void 0);
|
|
80
|
+
}, options.pollIntervalMs);
|
|
81
|
+
}
|
|
82
|
+
async function stopSubscription() {
|
|
83
|
+
manuallyStoppedSubscription = true;
|
|
84
|
+
subscriptionStartId += 1;
|
|
85
|
+
await stopCurrentSubscription();
|
|
86
|
+
}
|
|
87
|
+
async function stopCurrentSubscription() {
|
|
88
|
+
if (subscriptionId === null) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const currentSubscriptionId = subscriptionId;
|
|
92
|
+
subscriptionId = null;
|
|
93
|
+
try {
|
|
94
|
+
await connection.removeSignatureListener(currentSubscriptionId);
|
|
95
|
+
} catch (cause) {
|
|
96
|
+
error.value = cause;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function startSubscription() {
|
|
100
|
+
const requestId = ++subscriptionStartId;
|
|
101
|
+
await stopCurrentSubscription();
|
|
102
|
+
if (requestId !== subscriptionStartId) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const value = toValue(signature);
|
|
106
|
+
if (manuallyStoppedSubscription || !options.subscribe || !value || !solana) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const validSignature = parseTransactionSignature(value);
|
|
111
|
+
const nextSubscriptionId = connection.onSignature(
|
|
112
|
+
validSignature,
|
|
113
|
+
(notification, context) => {
|
|
114
|
+
if (requestId !== subscriptionStartId) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
status.value = {
|
|
118
|
+
slot: context.slot,
|
|
119
|
+
confirmations: null,
|
|
120
|
+
err: notification.err,
|
|
121
|
+
confirmationStatus: options.commitment ?? "confirmed"
|
|
122
|
+
};
|
|
123
|
+
error.value = null;
|
|
124
|
+
},
|
|
125
|
+
options.commitment
|
|
126
|
+
);
|
|
127
|
+
if (requestId !== subscriptionStartId) {
|
|
128
|
+
await connection.removeSignatureListener(nextSubscriptionId);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
subscriptionId = nextSubscriptionId;
|
|
132
|
+
} catch (cause) {
|
|
133
|
+
if (requestId === subscriptionStartId) {
|
|
134
|
+
error.value = cause;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function resetIntervals() {
|
|
139
|
+
startPolling();
|
|
140
|
+
void startSubscription();
|
|
141
|
+
}
|
|
142
|
+
onMounted(() => {
|
|
143
|
+
void refresh().catch(() => void 0);
|
|
144
|
+
resetIntervals();
|
|
145
|
+
});
|
|
146
|
+
onUnmounted(() => {
|
|
147
|
+
refreshId += 1;
|
|
148
|
+
stopPolling();
|
|
149
|
+
void stopSubscription();
|
|
150
|
+
});
|
|
151
|
+
watch(
|
|
152
|
+
() => toValue(signature),
|
|
153
|
+
() => {
|
|
154
|
+
void refresh().catch(() => void 0);
|
|
155
|
+
resetIntervals();
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
return {
|
|
159
|
+
status,
|
|
160
|
+
loading,
|
|
161
|
+
error,
|
|
162
|
+
refresh,
|
|
163
|
+
stopPolling,
|
|
164
|
+
stopSubscription
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function parseTransactionSignature(signature) {
|
|
168
|
+
let decodedSignature;
|
|
169
|
+
try {
|
|
170
|
+
decodedSignature = bs58.decode(signature);
|
|
171
|
+
} catch (cause) {
|
|
172
|
+
throw new TypeError("Invalid Solana transaction signature", { cause });
|
|
173
|
+
}
|
|
174
|
+
if (decodedSignature.length !== 64) {
|
|
175
|
+
throw new TypeError("Invalid Solana transaction signature");
|
|
176
|
+
}
|
|
177
|
+
return signature;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export { useSignatureStatus as u };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const address = require('@vue-solana/core/address');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
6
|
+
const useSolana = require('./vue.C4tLiG3R.cjs');
|
|
7
|
+
|
|
8
|
+
function useProgramAccounts(programId, options = {}) {
|
|
9
|
+
const solana = useSolana.tryUseSolana();
|
|
10
|
+
const connection = solana?.connection ?? useConnection.useConnection();
|
|
11
|
+
const accounts = vue.shallowRef([]);
|
|
12
|
+
const loading = vue.shallowRef(false);
|
|
13
|
+
const error = vue.shallowRef(null);
|
|
14
|
+
let refreshId = 0;
|
|
15
|
+
async function refresh() {
|
|
16
|
+
const requestId = ++refreshId;
|
|
17
|
+
const value = vue.toValue(programId);
|
|
18
|
+
if (!value || !solana) {
|
|
19
|
+
accounts.value = [];
|
|
20
|
+
loading.value = false;
|
|
21
|
+
error.value = null;
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
loading.value = true;
|
|
25
|
+
error.value = null;
|
|
26
|
+
try {
|
|
27
|
+
const publicKey = address.parsePublicKey(value);
|
|
28
|
+
if (!publicKey) {
|
|
29
|
+
accounts.value = [];
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
const nextAccounts = await connection.getProgramAccounts(publicKey, {
|
|
33
|
+
commitment: options.commitment,
|
|
34
|
+
dataSlice: options.dataSlice,
|
|
35
|
+
filters: options.filters
|
|
36
|
+
});
|
|
37
|
+
if (requestId === refreshId) {
|
|
38
|
+
accounts.value = nextAccounts;
|
|
39
|
+
}
|
|
40
|
+
return nextAccounts;
|
|
41
|
+
} catch (cause) {
|
|
42
|
+
if (requestId === refreshId) {
|
|
43
|
+
accounts.value = [];
|
|
44
|
+
error.value = cause;
|
|
45
|
+
}
|
|
46
|
+
throw cause;
|
|
47
|
+
} finally {
|
|
48
|
+
if (requestId === refreshId) {
|
|
49
|
+
loading.value = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
vue.onMounted(() => {
|
|
54
|
+
void refresh().catch(() => void 0);
|
|
55
|
+
});
|
|
56
|
+
vue.onUnmounted(() => {
|
|
57
|
+
refreshId += 1;
|
|
58
|
+
});
|
|
59
|
+
vue.watch(
|
|
60
|
+
() => vue.toValue(programId),
|
|
61
|
+
() => {
|
|
62
|
+
void refresh().catch(() => void 0);
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
return {
|
|
66
|
+
accounts,
|
|
67
|
+
loading,
|
|
68
|
+
error,
|
|
69
|
+
refresh
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.useProgramAccounts = useProgramAccounts;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const useAccountInfo = require('./shared/vue.BPnK_lsh.cjs');
|
|
4
|
+
require('@vue-solana/core/address');
|
|
5
|
+
require('vue');
|
|
6
|
+
require('./shared/vue.CwhEmATP.cjs');
|
|
7
|
+
require('./shared/vue.COyyrsQU.cjs');
|
|
8
|
+
require('./shared/vue.C4tLiG3R.cjs');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.useAccountInfo = useAccountInfo.useAccountInfo;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
import { PublicKeyInput } from '@vue-solana/core/address';
|
|
4
|
+
import { Commitment } from '@solana/web3-compat';
|
|
5
|
+
|
|
6
|
+
interface UseAccountInfoOptions {
|
|
7
|
+
commitment?: Commitment;
|
|
8
|
+
watch?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function useAccountInfo(address: MaybeRefOrGetter<PublicKeyInput>, options?: UseAccountInfoOptions): {
|
|
11
|
+
accountInfo: any;
|
|
12
|
+
loading: vue.ShallowRef<boolean, boolean>;
|
|
13
|
+
error: vue.ShallowRef<unknown, unknown>;
|
|
14
|
+
refresh: () => Promise<any>;
|
|
15
|
+
stopWatching: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useAccountInfo };
|
|
19
|
+
export type { UseAccountInfoOptions };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { MaybeRefOrGetter } from 'vue';
|
|
3
|
+
import { PublicKeyInput } from '@vue-solana/core/address';
|
|
4
|
+
import { Commitment } from '@solana/web3-compat';
|
|
5
|
+
|
|
6
|
+
interface UseAccountInfoOptions {
|
|
7
|
+
commitment?: Commitment;
|
|
8
|
+
watch?: boolean;
|
|
9
|
+
}
|
|
10
|
+
declare function useAccountInfo(address: MaybeRefOrGetter<PublicKeyInput>, options?: UseAccountInfoOptions): {
|
|
11
|
+
accountInfo: any;
|
|
12
|
+
loading: vue.ShallowRef<boolean, boolean>;
|
|
13
|
+
error: vue.ShallowRef<unknown, unknown>;
|
|
14
|
+
refresh: () => Promise<any>;
|
|
15
|
+
stopWatching: () => Promise<void>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { useAccountInfo };
|
|
19
|
+
export type { UseAccountInfoOptions };
|