@vue-solana/vue 0.5.0 → 0.6.1
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 +56 -4
- package/dist/index.cjs +12 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +7 -1
- package/dist/shared/vue.7TzeDJZX.mjs +127 -0
- package/dist/shared/vue.BPnK_lsh.cjs +129 -0
- package/dist/shared/vue.CUTLu1Gf.mjs +71 -0
- package/dist/shared/vue.DEQJ23UM.cjs +92 -0
- package/dist/shared/vue.DHVYJk8P.cjs +72 -0
- package/dist/shared/vue.DUufwq8y.cjs +186 -0
- package/dist/shared/vue.JC5FdU2O.mjs +180 -0
- package/dist/shared/vue.RQ9fETnm.mjs +90 -0
- package/dist/shared/vue.dmuispJ3.cjs +73 -0
- package/dist/shared/vue.jOsz34kz.mjs +69 -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 +3 -3
- package/dist/useSignAndSendTransaction.d.cts +19 -2
- package/dist/useSignAndSendTransaction.d.mts +19 -2
- package/dist/useSignAndSendTransaction.d.ts +19 -2
- package/dist/useSignAndSendTransaction.mjs +3 -3
- 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/useTransactionConfirmation.cjs +13 -0
- package/dist/useTransactionConfirmation.d.cts +26 -0
- package/dist/useTransactionConfirmation.d.mts +26 -0
- package/dist/useTransactionConfirmation.d.ts +26 -0
- package/dist/useTransactionConfirmation.mjs +6 -0
- package/package.json +23 -2
- package/dist/shared/vue.DJ42Zrow.mjs +0 -24
- package/dist/shared/vue.DQmAPXVB.cjs +0 -26
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const transaction = require('@vue-solana/core/transaction');
|
|
4
|
+
const vue = require('vue');
|
|
5
|
+
const useConnection = require('./vue.CwhEmATP.cjs');
|
|
6
|
+
|
|
7
|
+
function getConfirmedTransactionStatus(confirmation) {
|
|
8
|
+
if (confirmation.commitment === "finalized") {
|
|
9
|
+
return "finalized";
|
|
10
|
+
}
|
|
11
|
+
return confirmation.commitment === "processed" ? "processed" : "confirmed";
|
|
12
|
+
}
|
|
13
|
+
function useTransactionConfirmation(defaultOptions = {}) {
|
|
14
|
+
const connection = useConnection.useConnection();
|
|
15
|
+
const signature = vue.ref(null);
|
|
16
|
+
const confirmation = vue.ref(null);
|
|
17
|
+
const status = vue.ref("idle");
|
|
18
|
+
const loading = vue.ref(false);
|
|
19
|
+
const error = vue.ref(null);
|
|
20
|
+
let executionId = 0;
|
|
21
|
+
async function confirm(nextSignature, options = {}) {
|
|
22
|
+
const currentExecutionId = ++executionId;
|
|
23
|
+
const confirmationOptions = { ...defaultOptions, ...options };
|
|
24
|
+
signature.value = nextSignature;
|
|
25
|
+
confirmation.value = null;
|
|
26
|
+
status.value = "confirming";
|
|
27
|
+
loading.value = true;
|
|
28
|
+
error.value = null;
|
|
29
|
+
try {
|
|
30
|
+
const nextConfirmation = await transaction.confirmTransactionSignature(
|
|
31
|
+
connection,
|
|
32
|
+
nextSignature,
|
|
33
|
+
confirmationOptions
|
|
34
|
+
);
|
|
35
|
+
if (currentExecutionId === executionId) {
|
|
36
|
+
confirmation.value = nextConfirmation;
|
|
37
|
+
status.value = getConfirmedTransactionStatus(nextConfirmation);
|
|
38
|
+
}
|
|
39
|
+
return nextConfirmation;
|
|
40
|
+
} catch (cause) {
|
|
41
|
+
if (currentExecutionId === executionId) {
|
|
42
|
+
error.value = cause;
|
|
43
|
+
status.value = "error";
|
|
44
|
+
}
|
|
45
|
+
throw cause;
|
|
46
|
+
} finally {
|
|
47
|
+
if (currentExecutionId === executionId) {
|
|
48
|
+
loading.value = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function reset() {
|
|
53
|
+
executionId += 1;
|
|
54
|
+
signature.value = null;
|
|
55
|
+
confirmation.value = null;
|
|
56
|
+
status.value = "idle";
|
|
57
|
+
loading.value = false;
|
|
58
|
+
error.value = null;
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
signature,
|
|
62
|
+
confirmation,
|
|
63
|
+
status,
|
|
64
|
+
loading,
|
|
65
|
+
error,
|
|
66
|
+
confirm,
|
|
67
|
+
reset
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.getConfirmedTransactionStatus = getConfirmedTransactionStatus;
|
|
72
|
+
exports.useTransactionConfirmation = useTransactionConfirmation;
|
|
@@ -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;
|
|
@@ -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,90 @@
|
|
|
1
|
+
import { signAndSendTransaction, confirmTransactionSignature } from '@vue-solana/core/transaction';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
|
+
import { u as useWallet } from './vue.DYf_CRDv.mjs';
|
|
5
|
+
import { g as getConfirmedTransactionStatus } from './vue.jOsz34kz.mjs';
|
|
6
|
+
|
|
7
|
+
const SIGN_AND_SEND_TIMEOUT_MS = 12e4;
|
|
8
|
+
function useSignAndSendTransaction() {
|
|
9
|
+
const connection = useConnection();
|
|
10
|
+
const { wallet } = useWallet();
|
|
11
|
+
const signature = ref(null);
|
|
12
|
+
const confirmation = ref(null);
|
|
13
|
+
const status = ref("idle");
|
|
14
|
+
const loading = ref(false);
|
|
15
|
+
const error = ref(null);
|
|
16
|
+
let executionId = 0;
|
|
17
|
+
async function execute(transaction, options) {
|
|
18
|
+
const currentExecutionId = ++executionId;
|
|
19
|
+
const { confirm, confirmation: confirmationOptions, ...sendOptions } = options ?? {};
|
|
20
|
+
const transactionOptions = Object.keys(sendOptions).length > 0 ? sendOptions : void 0;
|
|
21
|
+
status.value = "sending";
|
|
22
|
+
loading.value = true;
|
|
23
|
+
error.value = null;
|
|
24
|
+
confirmation.value = null;
|
|
25
|
+
try {
|
|
26
|
+
if (!wallet.value) {
|
|
27
|
+
throw new Error("No Solana wallet is configured");
|
|
28
|
+
}
|
|
29
|
+
const nextSignature = await withWalletTransactionTimeout(
|
|
30
|
+
signAndSendTransaction(connection, wallet.value, transaction, transactionOptions)
|
|
31
|
+
);
|
|
32
|
+
if (currentExecutionId === executionId) {
|
|
33
|
+
signature.value = nextSignature;
|
|
34
|
+
status.value = confirm ? "confirming" : "sent";
|
|
35
|
+
}
|
|
36
|
+
if (!confirm) {
|
|
37
|
+
return nextSignature;
|
|
38
|
+
}
|
|
39
|
+
const nextConfirmation = await confirmTransactionSignature(
|
|
40
|
+
connection,
|
|
41
|
+
nextSignature,
|
|
42
|
+
confirmationOptions
|
|
43
|
+
);
|
|
44
|
+
if (currentExecutionId === executionId) {
|
|
45
|
+
confirmation.value = nextConfirmation;
|
|
46
|
+
status.value = getConfirmedTransactionStatus(nextConfirmation);
|
|
47
|
+
}
|
|
48
|
+
return nextSignature;
|
|
49
|
+
} catch (cause) {
|
|
50
|
+
if (currentExecutionId === executionId) {
|
|
51
|
+
error.value = cause;
|
|
52
|
+
status.value = "error";
|
|
53
|
+
}
|
|
54
|
+
throw cause;
|
|
55
|
+
} finally {
|
|
56
|
+
if (currentExecutionId === executionId) {
|
|
57
|
+
loading.value = false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
signature,
|
|
63
|
+
confirmation,
|
|
64
|
+
status,
|
|
65
|
+
loading,
|
|
66
|
+
error,
|
|
67
|
+
execute
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async function withWalletTransactionTimeout(promise) {
|
|
71
|
+
let timeoutId;
|
|
72
|
+
try {
|
|
73
|
+
const timeout = new Promise((_, reject) => {
|
|
74
|
+
timeoutId = setTimeout(() => {
|
|
75
|
+
reject(
|
|
76
|
+
new Error(
|
|
77
|
+
"Wallet transaction did not return a result. Check your wallet or explorer for the final status."
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
}, SIGN_AND_SEND_TIMEOUT_MS);
|
|
81
|
+
});
|
|
82
|
+
return await Promise.race([promise, timeout]);
|
|
83
|
+
} finally {
|
|
84
|
+
if (timeoutId) {
|
|
85
|
+
clearTimeout(timeoutId);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export { useSignAndSendTransaction 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,69 @@
|
|
|
1
|
+
import { confirmTransactionSignature } from '@vue-solana/core/transaction';
|
|
2
|
+
import { ref } from 'vue';
|
|
3
|
+
import { u as useConnection } from './vue.DlEAL2G8.mjs';
|
|
4
|
+
|
|
5
|
+
function getConfirmedTransactionStatus(confirmation) {
|
|
6
|
+
if (confirmation.commitment === "finalized") {
|
|
7
|
+
return "finalized";
|
|
8
|
+
}
|
|
9
|
+
return confirmation.commitment === "processed" ? "processed" : "confirmed";
|
|
10
|
+
}
|
|
11
|
+
function useTransactionConfirmation(defaultOptions = {}) {
|
|
12
|
+
const connection = useConnection();
|
|
13
|
+
const signature = ref(null);
|
|
14
|
+
const confirmation = ref(null);
|
|
15
|
+
const status = ref("idle");
|
|
16
|
+
const loading = ref(false);
|
|
17
|
+
const error = ref(null);
|
|
18
|
+
let executionId = 0;
|
|
19
|
+
async function confirm(nextSignature, options = {}) {
|
|
20
|
+
const currentExecutionId = ++executionId;
|
|
21
|
+
const confirmationOptions = { ...defaultOptions, ...options };
|
|
22
|
+
signature.value = nextSignature;
|
|
23
|
+
confirmation.value = null;
|
|
24
|
+
status.value = "confirming";
|
|
25
|
+
loading.value = true;
|
|
26
|
+
error.value = null;
|
|
27
|
+
try {
|
|
28
|
+
const nextConfirmation = await confirmTransactionSignature(
|
|
29
|
+
connection,
|
|
30
|
+
nextSignature,
|
|
31
|
+
confirmationOptions
|
|
32
|
+
);
|
|
33
|
+
if (currentExecutionId === executionId) {
|
|
34
|
+
confirmation.value = nextConfirmation;
|
|
35
|
+
status.value = getConfirmedTransactionStatus(nextConfirmation);
|
|
36
|
+
}
|
|
37
|
+
return nextConfirmation;
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
if (currentExecutionId === executionId) {
|
|
40
|
+
error.value = cause;
|
|
41
|
+
status.value = "error";
|
|
42
|
+
}
|
|
43
|
+
throw cause;
|
|
44
|
+
} finally {
|
|
45
|
+
if (currentExecutionId === executionId) {
|
|
46
|
+
loading.value = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function reset() {
|
|
51
|
+
executionId += 1;
|
|
52
|
+
signature.value = null;
|
|
53
|
+
confirmation.value = null;
|
|
54
|
+
status.value = "idle";
|
|
55
|
+
loading.value = false;
|
|
56
|
+
error.value = null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
signature,
|
|
60
|
+
confirmation,
|
|
61
|
+
status,
|
|
62
|
+
loading,
|
|
63
|
+
error,
|
|
64
|
+
confirm,
|
|
65
|
+
reset
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { getConfirmedTransactionStatus as g, useTransactionConfirmation as u };
|
|
@@ -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 };
|