cilantro-react 0.1.1 → 0.1.2
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/dist/index.d.mts +57 -24
- package/dist/index.d.ts +57 -24
- package/dist/index.js +190 -126
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +184 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -194,25 +194,34 @@ function CilantroAuthProvider({
|
|
|
194
194
|
const login = async (usernameOrEmail, password) => {
|
|
195
195
|
try {
|
|
196
196
|
const result = await cilantroLogin({ usernameOrEmail, password });
|
|
197
|
-
const
|
|
198
|
-
if (!
|
|
199
|
-
const jwt =
|
|
200
|
-
const userType =
|
|
197
|
+
const data = result && typeof result === "object" && "data" in result ? result.data : void 0;
|
|
198
|
+
if (!data?.jwt) throw new Error("No JWT token received from server");
|
|
199
|
+
const jwt = data.jwt;
|
|
200
|
+
const userType = data.userType;
|
|
201
201
|
setToken(jwt);
|
|
202
202
|
setSdkAuth(jwt);
|
|
203
203
|
if (typeof window !== "undefined") {
|
|
204
204
|
localStorage.setItem(jwtStorageKey, jwt);
|
|
205
205
|
document.cookie = `cilantro_jwt=${jwt}; path=/; max-age=${60 * 60 * 24 * 7}`;
|
|
206
206
|
}
|
|
207
|
-
|
|
208
|
-
const
|
|
207
|
+
if (data.user && typeof data.user === "object") {
|
|
208
|
+
const u = data.user;
|
|
209
209
|
setUser({
|
|
210
|
-
username:
|
|
211
|
-
email:
|
|
212
|
-
userType: userType ??
|
|
210
|
+
username: u.username,
|
|
211
|
+
email: u.email,
|
|
212
|
+
userType: userType ?? u.userType
|
|
213
213
|
});
|
|
214
|
-
}
|
|
215
|
-
|
|
214
|
+
} else {
|
|
215
|
+
try {
|
|
216
|
+
const payload = JSON.parse(atob(jwt.split(".")[1]));
|
|
217
|
+
setUser({
|
|
218
|
+
username: payload.username,
|
|
219
|
+
email: payload.email,
|
|
220
|
+
userType: userType ?? payload.userType
|
|
221
|
+
});
|
|
222
|
+
} catch {
|
|
223
|
+
setUser({ userType });
|
|
224
|
+
}
|
|
216
225
|
}
|
|
217
226
|
onLoginSuccess?.();
|
|
218
227
|
} catch (error) {
|
|
@@ -295,12 +304,12 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
295
304
|
setSelectedWallet(wallet);
|
|
296
305
|
} else {
|
|
297
306
|
setSelectedWallet(wallets[0]);
|
|
298
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id);
|
|
307
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id ?? wallets[0].walletId);
|
|
299
308
|
}
|
|
300
309
|
} else {
|
|
301
310
|
if (wallets.length > 0) {
|
|
302
311
|
setSelectedWallet(wallets[0]);
|
|
303
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id);
|
|
312
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallets[0].id ?? wallets[0].walletId);
|
|
304
313
|
}
|
|
305
314
|
}
|
|
306
315
|
} else if (wallets.length === 0) {
|
|
@@ -314,19 +323,13 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
314
323
|
if (token) setSdkAuth(token);
|
|
315
324
|
const result = await findAllWallets();
|
|
316
325
|
const walletsList = extractResponseData(result) ?? [];
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
walletAddress: w.walletAddress ?? w.address ?? "",
|
|
325
|
-
chain: w.chain ?? "solana",
|
|
326
|
-
active: w.active !== false,
|
|
327
|
-
...w
|
|
328
|
-
};
|
|
329
|
-
}) : [];
|
|
326
|
+
const list = Array.isArray(walletsList) ? walletsList : [];
|
|
327
|
+
const formattedWallets = list.map((w) => ({
|
|
328
|
+
...w,
|
|
329
|
+
id: w.walletId,
|
|
330
|
+
address: w.walletAddress,
|
|
331
|
+
active: w.isActive
|
|
332
|
+
}));
|
|
330
333
|
setWallets(formattedWallets);
|
|
331
334
|
} catch (error) {
|
|
332
335
|
console.error("Failed to load wallets:", error);
|
|
@@ -339,7 +342,7 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
|
|
|
339
342
|
const wallet = wallets.find((w) => w.id === walletId || w.walletId === walletId);
|
|
340
343
|
if (wallet) {
|
|
341
344
|
setSelectedWallet(wallet);
|
|
342
|
-
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallet.id);
|
|
345
|
+
if (typeof window !== "undefined") localStorage.setItem(storageKey, wallet.id ?? wallet.walletId);
|
|
343
346
|
}
|
|
344
347
|
};
|
|
345
348
|
const refreshWallets = async () => {
|
|
@@ -582,6 +585,52 @@ function useSigners(options = {}) {
|
|
|
582
585
|
return { signers, isLoading, error, refresh };
|
|
583
586
|
}
|
|
584
587
|
|
|
588
|
+
// src/hooks/useSignersRaw.ts
|
|
589
|
+
import { useState as useState4, useEffect as useEffect5, useCallback as useCallback2 } from "react";
|
|
590
|
+
import { listSigners as listSigners2 } from "cilantro-sdk/wallet";
|
|
591
|
+
function useSignersRaw(options = {}) {
|
|
592
|
+
const { walletId } = options;
|
|
593
|
+
const { token } = useCilantroAuth();
|
|
594
|
+
const [signersRaw, setSignersRaw] = useState4(null);
|
|
595
|
+
const [isLoading, setIsLoading] = useState4(false);
|
|
596
|
+
const [error, setError] = useState4(null);
|
|
597
|
+
const load = useCallback2(async () => {
|
|
598
|
+
if (!walletId) {
|
|
599
|
+
setSignersRaw(null);
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
setIsLoading(true);
|
|
603
|
+
setError(null);
|
|
604
|
+
try {
|
|
605
|
+
if (token) setSdkAuth(token);
|
|
606
|
+
const result = await listSigners2(walletId);
|
|
607
|
+
setSignersRaw(result);
|
|
608
|
+
} catch (err) {
|
|
609
|
+
setSignersRaw(null);
|
|
610
|
+
setError(err instanceof Error ? err.message : String(err));
|
|
611
|
+
} finally {
|
|
612
|
+
setIsLoading(false);
|
|
613
|
+
}
|
|
614
|
+
}, [walletId, token]);
|
|
615
|
+
useEffect5(() => {
|
|
616
|
+
if (!walletId) {
|
|
617
|
+
setSignersRaw(null);
|
|
618
|
+
setError(null);
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
621
|
+
load();
|
|
622
|
+
}, [walletId, load]);
|
|
623
|
+
const refresh = useCallback2(async () => {
|
|
624
|
+
if (walletId) await load();
|
|
625
|
+
}, [walletId, load]);
|
|
626
|
+
return {
|
|
627
|
+
signersRaw: walletId ? signersRaw : null,
|
|
628
|
+
isLoading,
|
|
629
|
+
error,
|
|
630
|
+
refresh
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
585
634
|
// src/hooks/useSignersForSelectedWallet.ts
|
|
586
635
|
function useSignersForSelectedWallet(options = {}) {
|
|
587
636
|
const { walletId: walletIdOverride } = options;
|
|
@@ -591,28 +640,21 @@ function useSignersForSelectedWallet(options = {}) {
|
|
|
591
640
|
}
|
|
592
641
|
|
|
593
642
|
// src/hooks/useDelegatedKeys.ts
|
|
594
|
-
import { useState as
|
|
643
|
+
import { useState as useState5, useEffect as useEffect6, useCallback as useCallback3 } from "react";
|
|
595
644
|
import { findAll } from "cilantro-sdk/delegated-keys";
|
|
596
645
|
function normalizeKeys(list) {
|
|
597
|
-
return list.
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
name: k.name,
|
|
601
|
-
publicKey: String(k.publicKey ?? ""),
|
|
602
|
-
permissions: k.permissions ?? {},
|
|
603
|
-
isActive: k.isActive !== false,
|
|
604
|
-
createdAt: k.createdAt,
|
|
605
|
-
expiresAt: k.expiresAt,
|
|
606
|
-
...k
|
|
646
|
+
return list.map((k) => ({
|
|
647
|
+
...k,
|
|
648
|
+
id: k.delegatedKeyId
|
|
607
649
|
}));
|
|
608
650
|
}
|
|
609
651
|
function useDelegatedKeys(options = {}) {
|
|
610
652
|
const { walletId, filterActive = true } = options;
|
|
611
653
|
const { token } = useCilantroAuth();
|
|
612
|
-
const [keys, setKeys] =
|
|
613
|
-
const [isLoading, setIsLoading] =
|
|
614
|
-
const [error, setError] =
|
|
615
|
-
const loadKeys =
|
|
654
|
+
const [keys, setKeys] = useState5([]);
|
|
655
|
+
const [isLoading, setIsLoading] = useState5(false);
|
|
656
|
+
const [error, setError] = useState5(null);
|
|
657
|
+
const loadKeys = useCallback3(async () => {
|
|
616
658
|
if (!walletId) {
|
|
617
659
|
setKeys([]);
|
|
618
660
|
return;
|
|
@@ -624,12 +666,16 @@ function useDelegatedKeys(options = {}) {
|
|
|
624
666
|
const result = await findAll(walletId);
|
|
625
667
|
const keysData = extractResponseData(result) ?? [];
|
|
626
668
|
const list = Array.isArray(keysData) ? keysData : [];
|
|
627
|
-
|
|
669
|
+
const valid = list.filter(
|
|
670
|
+
(k) => k != null && typeof k === "object" && "delegatedKeyId" in k
|
|
671
|
+
);
|
|
672
|
+
let loaded = normalizeKeys(valid);
|
|
628
673
|
if (filterActive) {
|
|
629
674
|
const now = Date.now();
|
|
630
675
|
loaded = loaded.filter((key) => {
|
|
631
676
|
if (!key.isActive) return false;
|
|
632
|
-
const
|
|
677
|
+
const raw = key.expiresAt;
|
|
678
|
+
const exp = raw != null && (typeof raw === "string" || typeof raw === "number") ? new Date(raw).getTime() : null;
|
|
633
679
|
return exp === null || exp > now;
|
|
634
680
|
});
|
|
635
681
|
}
|
|
@@ -641,17 +687,17 @@ function useDelegatedKeys(options = {}) {
|
|
|
641
687
|
setIsLoading(false);
|
|
642
688
|
}
|
|
643
689
|
}, [walletId, token, filterActive]);
|
|
644
|
-
|
|
690
|
+
useEffect6(() => {
|
|
645
691
|
loadKeys();
|
|
646
692
|
}, [loadKeys]);
|
|
647
|
-
const refresh =
|
|
693
|
+
const refresh = useCallback3(async () => {
|
|
648
694
|
if (walletId) await loadKeys();
|
|
649
695
|
}, [walletId, loadKeys]);
|
|
650
696
|
return { keys, isLoading, error, refresh };
|
|
651
697
|
}
|
|
652
698
|
|
|
653
699
|
// src/hooks/useSignerSelection.ts
|
|
654
|
-
import { useState as
|
|
700
|
+
import { useState as useState6, useEffect as useEffect7, useCallback as useCallback4 } from "react";
|
|
655
701
|
function useSignerSelection(options = {}) {
|
|
656
702
|
const { walletId: walletIdOverride, signingMethod = "sdk-signer" } = options;
|
|
657
703
|
const { selectedWallet } = useWallets();
|
|
@@ -659,17 +705,17 @@ function useSignerSelection(options = {}) {
|
|
|
659
705
|
const { signers: availableSigners, isLoading: isLoadingSigners } = useSigners({
|
|
660
706
|
walletId: effectiveWalletId || null
|
|
661
707
|
});
|
|
662
|
-
const [selectedWalletId, setSelectedWalletId] =
|
|
663
|
-
const [selectedSigner, setSelectedSigner] =
|
|
664
|
-
|
|
708
|
+
const [selectedWalletId, setSelectedWalletId] = useState6(effectiveWalletId);
|
|
709
|
+
const [selectedSigner, setSelectedSigner] = useState6(null);
|
|
710
|
+
useEffect7(() => {
|
|
665
711
|
setSelectedWalletId(effectiveWalletId);
|
|
666
712
|
}, [effectiveWalletId]);
|
|
667
|
-
|
|
713
|
+
useEffect7(() => {
|
|
668
714
|
if (signingMethod !== "sdk-signer") {
|
|
669
715
|
setSelectedSigner(null);
|
|
670
716
|
}
|
|
671
717
|
}, [signingMethod]);
|
|
672
|
-
const reset =
|
|
718
|
+
const reset = useCallback4(() => {
|
|
673
719
|
setSelectedWalletId("");
|
|
674
720
|
setSelectedSigner(null);
|
|
675
721
|
}, []);
|
|
@@ -720,7 +766,7 @@ function useCanSign(options = {}) {
|
|
|
720
766
|
}
|
|
721
767
|
|
|
722
768
|
// src/hooks/useMessageSigning.ts
|
|
723
|
-
import { useState as
|
|
769
|
+
import { useState as useState7 } from "react";
|
|
724
770
|
|
|
725
771
|
// src/core/signer-signing/core.ts
|
|
726
772
|
import { PublicKey } from "@solana/web3.js";
|
|
@@ -800,7 +846,9 @@ import {
|
|
|
800
846
|
registerPasskeyComplete,
|
|
801
847
|
signWithPasskeySigner
|
|
802
848
|
} from "cilantro-sdk/helpers";
|
|
803
|
-
import {
|
|
849
|
+
import {
|
|
850
|
+
sendRawPasskeyTransaction
|
|
851
|
+
} from "cilantro-sdk/transactions";
|
|
804
852
|
import { createExternalWalletSigner, startPasskeyAuthentication } from "cilantro-sdk/wallet";
|
|
805
853
|
async function createEmailSignerHelper(walletId, email) {
|
|
806
854
|
const trimmedEmail = email.trim();
|
|
@@ -862,9 +910,10 @@ async function signAndSendPasskeyTransaction(walletId, signerId, transaction, op
|
|
|
862
910
|
});
|
|
863
911
|
}
|
|
864
912
|
const unsignedTransaction = transaction.serialize({ verifySignatures: false }).toString("base64");
|
|
865
|
-
const authOptions = await startPasskeyAuthentication(
|
|
866
|
-
|
|
867
|
-
|
|
913
|
+
const authOptions = await startPasskeyAuthentication(
|
|
914
|
+
walletId,
|
|
915
|
+
{ credentialId: options?.credentialId }
|
|
916
|
+
);
|
|
868
917
|
const authData = extractResponseData(authOptions);
|
|
869
918
|
if (!authData) throw new Error("Failed to get authentication options");
|
|
870
919
|
const authDataValue = authData && typeof authData === "object" && "data" in authData ? authData.data : authData;
|
|
@@ -883,7 +932,10 @@ async function signAndSendPasskeyTransaction(walletId, signerId, transaction, op
|
|
|
883
932
|
};
|
|
884
933
|
const result = await sendRawPasskeyTransaction(dto);
|
|
885
934
|
const resultData = extractResponseData(result);
|
|
886
|
-
return {
|
|
935
|
+
return {
|
|
936
|
+
signature: resultData?.signature ?? "",
|
|
937
|
+
status: resultData?.status
|
|
938
|
+
};
|
|
887
939
|
}
|
|
888
940
|
|
|
889
941
|
// src/core/signer-signing/errors.ts
|
|
@@ -954,10 +1006,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
954
1006
|
validateSignerActive(signer, signerType);
|
|
955
1007
|
const storageOptions = getStorageOptions();
|
|
956
1008
|
try {
|
|
957
|
-
const
|
|
1009
|
+
const signatureBytes = await signWithEmailSigner(walletId, signerId, message, storageOptions);
|
|
958
1010
|
const keypair = await getEmailSignerKeypair2(walletId, signerId, storageOptions);
|
|
959
1011
|
return {
|
|
960
|
-
signature: Buffer.from(
|
|
1012
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1013
|
+
message: messageText,
|
|
961
1014
|
publicKey: Buffer.from(keypair.publicKey).toString("hex"),
|
|
962
1015
|
signerType: SIGNER_TYPES.EMAIL
|
|
963
1016
|
};
|
|
@@ -969,10 +1022,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
969
1022
|
validateSignerActive(signer, signerType);
|
|
970
1023
|
const storageOptions = getStorageOptions();
|
|
971
1024
|
try {
|
|
972
|
-
const
|
|
1025
|
+
const signatureBytes = await signWithPhoneSigner(walletId, signerId, message, storageOptions);
|
|
973
1026
|
const keypair = await getPhoneSignerKeypair2(walletId, signerId, storageOptions);
|
|
974
1027
|
return {
|
|
975
|
-
signature: Buffer.from(
|
|
1028
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1029
|
+
message: messageText,
|
|
976
1030
|
publicKey: Buffer.from(keypair.publicKey).toString("hex"),
|
|
977
1031
|
signerType: SIGNER_TYPES.PHONE
|
|
978
1032
|
};
|
|
@@ -982,8 +1036,10 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
982
1036
|
}
|
|
983
1037
|
if (signerType === SIGNER_TYPES.PASSKEY) {
|
|
984
1038
|
const signResult = await signWithPasskey(walletId, signerId, messageText, { useBrowserAutofill: false });
|
|
1039
|
+
const signatureBase64 = Buffer.from(signResult.signature, "hex").toString("base64");
|
|
985
1040
|
return {
|
|
986
|
-
signature:
|
|
1041
|
+
signature: signatureBase64,
|
|
1042
|
+
message: messageText,
|
|
987
1043
|
signerType: SIGNER_TYPES.PASSKEY,
|
|
988
1044
|
signer: signResult.signer
|
|
989
1045
|
};
|
|
@@ -991,10 +1047,11 @@ async function signMessageWithSigner(walletId, signer, messageText) {
|
|
|
991
1047
|
if (signerType === SIGNER_TYPES.EXTERNAL || signerType === SIGNER_TYPES.API_KEY) {
|
|
992
1048
|
validateSignerActive(signer, signerType);
|
|
993
1049
|
const storageOptions = getStorageOptions();
|
|
994
|
-
const
|
|
1050
|
+
const signatureBytes = await signWithSigner(walletId, signerId, signerType, message, storageOptions);
|
|
995
1051
|
const keypair = await deriveSignerKeypair2(walletId, signerId, signerType, storageOptions);
|
|
996
1052
|
return {
|
|
997
|
-
signature: Buffer.from(
|
|
1053
|
+
signature: Buffer.from(signatureBytes).toString("base64"),
|
|
1054
|
+
message: messageText,
|
|
998
1055
|
publicKey: Buffer.from(keypair.publicKey).toString("base64"),
|
|
999
1056
|
signerType
|
|
1000
1057
|
};
|
|
@@ -1121,9 +1178,11 @@ async function submitSignedTransaction(walletId, signedTransactionBase64) {
|
|
|
1121
1178
|
});
|
|
1122
1179
|
const resultData = extractResponseData(submitResult);
|
|
1123
1180
|
if (!resultData?.signature) throw new Error("Server did not return a transaction signature");
|
|
1181
|
+
const status = resultData.status ?? "pending";
|
|
1124
1182
|
return {
|
|
1125
1183
|
signature: resultData.signature,
|
|
1126
|
-
|
|
1184
|
+
status,
|
|
1185
|
+
confirmationStatus: status
|
|
1127
1186
|
};
|
|
1128
1187
|
}
|
|
1129
1188
|
async function handlePasskeyTransaction(walletId, signerId, transaction, connection) {
|
|
@@ -1136,7 +1195,7 @@ async function handlePasskeyTransaction(walletId, signerId, transaction, connect
|
|
|
1136
1195
|
const result = await signAndSendPasskeyTransaction(walletId, signerId, transaction, {
|
|
1137
1196
|
useBrowserAutofill: false
|
|
1138
1197
|
});
|
|
1139
|
-
let
|
|
1198
|
+
let status = "confirmed";
|
|
1140
1199
|
try {
|
|
1141
1200
|
await connection.confirmTransaction({
|
|
1142
1201
|
signature: result.signature,
|
|
@@ -1146,12 +1205,12 @@ async function handlePasskeyTransaction(walletId, signerId, transaction, connect
|
|
|
1146
1205
|
} catch (error) {
|
|
1147
1206
|
const errorMsg = extractErrorMessage(error);
|
|
1148
1207
|
if (errorMsg.includes("block height exceeded") || errorMsg.includes("expired") || errorMsg.includes("timeout")) {
|
|
1149
|
-
|
|
1208
|
+
status = "pending";
|
|
1150
1209
|
} else {
|
|
1151
1210
|
throw new Error(`Transaction confirmation failed: ${errorMsg}. Signature: ${result.signature}`);
|
|
1152
1211
|
}
|
|
1153
1212
|
}
|
|
1154
|
-
return { signature: result.signature, confirmationStatus };
|
|
1213
|
+
return { signature: result.signature, status, confirmationStatus: status };
|
|
1155
1214
|
}
|
|
1156
1215
|
async function handleEmailOrPhoneTransaction(walletId, signer, signerType, signerId, transaction) {
|
|
1157
1216
|
validateSignerActive(signer, signerType);
|
|
@@ -1268,19 +1327,12 @@ async function getWalletData(walletId) {
|
|
|
1268
1327
|
const walletDataResponse = await findOneWallet(walletId);
|
|
1269
1328
|
const walletData = extractResponseData(walletDataResponse);
|
|
1270
1329
|
if (!walletData) throw new Error("Wallet data is empty");
|
|
1271
|
-
const address = String(
|
|
1272
|
-
|
|
1273
|
-
).trim();
|
|
1274
|
-
if (!address) throw new Error(`No wallet address found. Available fields: ${Object.keys(walletData).join(", ")}`);
|
|
1330
|
+
const address = String(walletData.walletAddress ?? "").trim();
|
|
1331
|
+
if (!address) throw new Error("No wallet address found (walletAddress is empty).");
|
|
1275
1332
|
const walletPublicKey = new PublicKey4(address);
|
|
1276
|
-
const
|
|
1277
|
-
const adminPubkey = String(
|
|
1278
|
-
walletData.adminSignerPubkey ?? walletData.adminSigner ?? adminData?.publicKey ?? ""
|
|
1279
|
-
).trim();
|
|
1333
|
+
const adminPubkey = String(walletData.adminSignerPubkey ?? "").trim();
|
|
1280
1334
|
if (!adminPubkey) {
|
|
1281
|
-
throw new Error(
|
|
1282
|
-
`adminSignerPubkey not found in wallet data. Available fields: ${Object.keys(walletData).join(", ")}`
|
|
1283
|
-
);
|
|
1335
|
+
throw new Error("adminSignerPubkey not found in wallet data.");
|
|
1284
1336
|
}
|
|
1285
1337
|
const adminSignerPubkey = new PublicKey4(adminPubkey);
|
|
1286
1338
|
return { walletPublicKey, adminSignerPubkey };
|
|
@@ -1296,9 +1348,9 @@ function useMessageSigning(options) {
|
|
|
1296
1348
|
walletAdapterSignMessage,
|
|
1297
1349
|
walletAdapterPublicKey
|
|
1298
1350
|
} = options;
|
|
1299
|
-
const [messageText, setMessageText] =
|
|
1300
|
-
const [signResultState, setSignResultState] =
|
|
1301
|
-
const [isSigning, setIsSigning] =
|
|
1351
|
+
const [messageText, setMessageText] = useState7("Hello, Solana!");
|
|
1352
|
+
const [signResultState, setSignResultState] = useState7({ status: "idle" });
|
|
1353
|
+
const [isSigning, setIsSigning] = useState7(false);
|
|
1302
1354
|
const handleSign = async () => {
|
|
1303
1355
|
setIsSigning(true);
|
|
1304
1356
|
setSignResultState({ status: "loading" });
|
|
@@ -1328,7 +1380,7 @@ function useMessageSigning(options) {
|
|
|
1328
1380
|
setSignResultState({
|
|
1329
1381
|
status: "success",
|
|
1330
1382
|
message: `Message signed successfully with ${signerType} signer!`,
|
|
1331
|
-
detail: {
|
|
1383
|
+
detail: { ...result }
|
|
1332
1384
|
});
|
|
1333
1385
|
} catch (error) {
|
|
1334
1386
|
const errorMsg = extractErrorMessage(error);
|
|
@@ -1356,7 +1408,7 @@ function useMessageSigning(options) {
|
|
|
1356
1408
|
}
|
|
1357
1409
|
|
|
1358
1410
|
// src/hooks/useTransactionSigning.ts
|
|
1359
|
-
import { useState as
|
|
1411
|
+
import { useState as useState8 } from "react";
|
|
1360
1412
|
function useTransactionSigning(options) {
|
|
1361
1413
|
const {
|
|
1362
1414
|
token,
|
|
@@ -1367,9 +1419,9 @@ function useTransactionSigning(options) {
|
|
|
1367
1419
|
walletAdapterPublicKey,
|
|
1368
1420
|
connection
|
|
1369
1421
|
} = options;
|
|
1370
|
-
const [transactionResultState, setTransactionResultState] =
|
|
1371
|
-
const [isSigningTransaction, setIsSigningTransaction] =
|
|
1372
|
-
const [isSendingTransaction, setIsSendingTransaction] =
|
|
1422
|
+
const [transactionResultState, setTransactionResultState] = useState8({ status: "idle" });
|
|
1423
|
+
const [isSigningTransaction, setIsSigningTransaction] = useState8(false);
|
|
1424
|
+
const [isSendingTransaction, setIsSendingTransaction] = useState8(false);
|
|
1373
1425
|
const signTransaction = async (transaction) => {
|
|
1374
1426
|
setIsSigningTransaction(true);
|
|
1375
1427
|
setTransactionResultState({ status: "loading" });
|
|
@@ -1447,6 +1499,7 @@ function useTransactionSigning(options) {
|
|
|
1447
1499
|
message: `Transaction sent with ${signerType} signer!`,
|
|
1448
1500
|
detail: {
|
|
1449
1501
|
signature: result.signature,
|
|
1502
|
+
status: result.status,
|
|
1450
1503
|
confirmationStatus: result.confirmationStatus,
|
|
1451
1504
|
explorerUrl: `https://solscan.io/tx/${result.signature}?cluster=devnet`
|
|
1452
1505
|
}
|
|
@@ -1581,8 +1634,9 @@ function WalletSelector(props) {
|
|
|
1581
1634
|
const effectiveValue = value ?? selectedWallet?.id ?? selectedWallet?.walletId ?? "";
|
|
1582
1635
|
const selected = wallets.find((w) => w.id === effectiveValue || w.walletId === effectiveValue) ?? selectedWallet;
|
|
1583
1636
|
const handleSelect = (wallet) => {
|
|
1584
|
-
|
|
1585
|
-
|
|
1637
|
+
const id = wallet.id ?? wallet.walletId;
|
|
1638
|
+
selectWallet(id);
|
|
1639
|
+
onWalletChange?.(id, wallet);
|
|
1586
1640
|
};
|
|
1587
1641
|
const handleValueChange = (id) => {
|
|
1588
1642
|
selectWallet(id);
|
|
@@ -1630,7 +1684,10 @@ function WalletSelector(props) {
|
|
|
1630
1684
|
}
|
|
1631
1685
|
return /* @__PURE__ */ jsx6("div", { className: cn(className, classNames?.root), "data-cilantro-wallet-selector": true, children: /* @__PURE__ */ jsxs2(Select, { value: effectiveValue || void 0, onValueChange: handleValueChange, disabled: isLoading, children: [
|
|
1632
1686
|
/* @__PURE__ */ jsx6(SelectTrigger, { className: classNames?.trigger, "aria-label": "Select wallet", children: /* @__PURE__ */ jsx6(SelectValue, { placeholder: isLoading ? "Loading..." : placeholder }) }),
|
|
1633
|
-
/* @__PURE__ */ jsx6(SelectContent, { className: classNames?.content, children: wallets.map((w) =>
|
|
1687
|
+
/* @__PURE__ */ jsx6(SelectContent, { className: classNames?.content, children: wallets.map((w) => {
|
|
1688
|
+
const id = w.id ?? w.walletId;
|
|
1689
|
+
return /* @__PURE__ */ jsx6(SelectItem, { value: id, className: classNames?.item, children: w.walletName || id }, id);
|
|
1690
|
+
}) })
|
|
1634
1691
|
] }) });
|
|
1635
1692
|
}
|
|
1636
1693
|
|
|
@@ -1766,10 +1823,11 @@ function DelegatedKeySelector(props) {
|
|
|
1766
1823
|
filterActive
|
|
1767
1824
|
});
|
|
1768
1825
|
const onSelect = (key) => {
|
|
1769
|
-
|
|
1826
|
+
const id = key.id ?? key.delegatedKeyId;
|
|
1827
|
+
onChange?.(id, key);
|
|
1770
1828
|
};
|
|
1771
1829
|
const handleValueChange = (id) => {
|
|
1772
|
-
const key = keys.find((k) => k.id === id) ?? null;
|
|
1830
|
+
const key = keys.find((k) => (k.id ?? k.delegatedKeyId) === id) ?? null;
|
|
1773
1831
|
onChange?.(id, key);
|
|
1774
1832
|
};
|
|
1775
1833
|
if (children) {
|
|
@@ -1808,7 +1866,13 @@ function DelegatedKeySelector(props) {
|
|
|
1808
1866
|
"aria-live": "polite",
|
|
1809
1867
|
children: isLoading ? /* @__PURE__ */ jsx9("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "Loading delegated keys..." }) : error ? /* @__PURE__ */ jsx9("p", { className: cn("text-sm text-destructive", classNames?.message), role: "alert", children: error }) : keys.length === 0 ? /* @__PURE__ */ jsx9("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "No delegated keys found." }) : /* @__PURE__ */ jsxs4(Select, { value: (value ?? "") || void 0, onValueChange: handleValueChange, children: [
|
|
1810
1868
|
/* @__PURE__ */ jsx9(SelectTrigger, { className: classNames?.trigger, "aria-label": "Select delegated key", children: /* @__PURE__ */ jsx9(SelectValue, { placeholder }) }),
|
|
1811
|
-
/* @__PURE__ */ jsx9(SelectContent, { className: classNames?.content, children: keys.map((k) =>
|
|
1869
|
+
/* @__PURE__ */ jsx9(SelectContent, { className: classNames?.content, children: keys.map((k) => {
|
|
1870
|
+
const id = k.id ?? k.delegatedKeyId;
|
|
1871
|
+
return /* @__PURE__ */ jsxs4(SelectItem, { value: id, className: classNames?.item, children: [
|
|
1872
|
+
k.publicKey.slice(0, 8),
|
|
1873
|
+
"..."
|
|
1874
|
+
] }, id);
|
|
1875
|
+
}) })
|
|
1812
1876
|
] })
|
|
1813
1877
|
}
|
|
1814
1878
|
);
|
|
@@ -2123,7 +2187,7 @@ function TransactionSigningForm({
|
|
|
2123
2187
|
}
|
|
2124
2188
|
|
|
2125
2189
|
// src/components/LoginForm.tsx
|
|
2126
|
-
import { useState as
|
|
2190
|
+
import { useState as useState9 } from "react";
|
|
2127
2191
|
|
|
2128
2192
|
// src/ui/input.tsx
|
|
2129
2193
|
import * as React7 from "react";
|
|
@@ -2159,9 +2223,9 @@ function LoginForm({
|
|
|
2159
2223
|
renderSwitchToRegister
|
|
2160
2224
|
}) {
|
|
2161
2225
|
const { login, isLoading } = useCilantroAuth();
|
|
2162
|
-
const [usernameOrEmail, setUsernameOrEmail] =
|
|
2163
|
-
const [password, setPassword] =
|
|
2164
|
-
const [error, setError] =
|
|
2226
|
+
const [usernameOrEmail, setUsernameOrEmail] = useState9("");
|
|
2227
|
+
const [password, setPassword] = useState9("");
|
|
2228
|
+
const [error, setError] = useState9(null);
|
|
2165
2229
|
const handleSubmit = async (e) => {
|
|
2166
2230
|
e.preventDefault();
|
|
2167
2231
|
setError(null);
|
|
@@ -2241,7 +2305,7 @@ function LoginForm({
|
|
|
2241
2305
|
}
|
|
2242
2306
|
|
|
2243
2307
|
// src/components/RegisterForm.tsx
|
|
2244
|
-
import { useState as
|
|
2308
|
+
import { useState as useState10 } from "react";
|
|
2245
2309
|
import { jsx as jsx17, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2246
2310
|
function RegisterForm({
|
|
2247
2311
|
className,
|
|
@@ -2255,10 +2319,10 @@ function RegisterForm({
|
|
|
2255
2319
|
renderSwitchToLogin
|
|
2256
2320
|
}) {
|
|
2257
2321
|
const { register, isLoading } = useCilantroAuth();
|
|
2258
|
-
const [username, setUsername] =
|
|
2259
|
-
const [email, setEmail] =
|
|
2260
|
-
const [password, setPassword] =
|
|
2261
|
-
const [error, setError] =
|
|
2322
|
+
const [username, setUsername] = useState10("");
|
|
2323
|
+
const [email, setEmail] = useState10("");
|
|
2324
|
+
const [password, setPassword] = useState10("");
|
|
2325
|
+
const [error, setError] = useState10(null);
|
|
2262
2326
|
const handleSubmit = async (e) => {
|
|
2263
2327
|
e.preventDefault();
|
|
2264
2328
|
setError(null);
|
|
@@ -2355,7 +2419,7 @@ function RegisterForm({
|
|
|
2355
2419
|
}
|
|
2356
2420
|
|
|
2357
2421
|
// src/components/AuthForm.tsx
|
|
2358
|
-
import { useState as
|
|
2422
|
+
import { useState as useState11 } from "react";
|
|
2359
2423
|
import { Fragment as Fragment4, jsx as jsx18, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2360
2424
|
function AuthForm({
|
|
2361
2425
|
defaultMode = "login",
|
|
@@ -2374,12 +2438,12 @@ function AuthForm({
|
|
|
2374
2438
|
isActive = true
|
|
2375
2439
|
}) {
|
|
2376
2440
|
const { login, register, isLoading } = useCilantroAuth();
|
|
2377
|
-
const [mode, setMode] =
|
|
2378
|
-
const [usernameOrEmail, setUsernameOrEmail] =
|
|
2379
|
-
const [username, setUsername] =
|
|
2380
|
-
const [email, setEmail] =
|
|
2381
|
-
const [password, setPassword] =
|
|
2382
|
-
const [error, setError] =
|
|
2441
|
+
const [mode, setMode] = useState11(defaultMode);
|
|
2442
|
+
const [usernameOrEmail, setUsernameOrEmail] = useState11("");
|
|
2443
|
+
const [username, setUsername] = useState11("");
|
|
2444
|
+
const [email, setEmail] = useState11("");
|
|
2445
|
+
const [password, setPassword] = useState11("");
|
|
2446
|
+
const [error, setError] = useState11(null);
|
|
2383
2447
|
const isLogin = mode === "login";
|
|
2384
2448
|
const handleSubmit = async (e) => {
|
|
2385
2449
|
e.preventDefault();
|
|
@@ -2566,7 +2630,7 @@ function AuthGuard({
|
|
|
2566
2630
|
}
|
|
2567
2631
|
|
|
2568
2632
|
// src/components/AddSignerForm.tsx
|
|
2569
|
-
import { useState as
|
|
2633
|
+
import { useState as useState12 } from "react";
|
|
2570
2634
|
|
|
2571
2635
|
// src/ui/dialog.tsx
|
|
2572
2636
|
import * as React8 from "react";
|
|
@@ -2644,12 +2708,12 @@ function AddSignerForm({
|
|
|
2644
2708
|
classNames,
|
|
2645
2709
|
asDialog = true
|
|
2646
2710
|
}) {
|
|
2647
|
-
const [signerType, setSignerType] =
|
|
2648
|
-
const [email, setEmail] =
|
|
2649
|
-
const [phone, setPhone] =
|
|
2650
|
-
const [address, setAddress] =
|
|
2651
|
-
const [isSubmitting, setIsSubmitting] =
|
|
2652
|
-
const [error, setError] =
|
|
2711
|
+
const [signerType, setSignerType] = useState12(null);
|
|
2712
|
+
const [email, setEmail] = useState12("");
|
|
2713
|
+
const [phone, setPhone] = useState12("");
|
|
2714
|
+
const [address, setAddress] = useState12("");
|
|
2715
|
+
const [isSubmitting, setIsSubmitting] = useState12(false);
|
|
2716
|
+
const [error, setError] = useState12(null);
|
|
2653
2717
|
const resetForm = () => {
|
|
2654
2718
|
setSignerType(null);
|
|
2655
2719
|
setEmail("");
|
|
@@ -2922,7 +2986,7 @@ function AddSignerForm({
|
|
|
2922
2986
|
}
|
|
2923
2987
|
|
|
2924
2988
|
// src/components/SignerList.tsx
|
|
2925
|
-
import { useState as
|
|
2989
|
+
import { useState as useState13 } from "react";
|
|
2926
2990
|
import { Fragment as Fragment7, jsx as jsx22, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
2927
2991
|
function SignerList({
|
|
2928
2992
|
walletId,
|
|
@@ -2933,7 +2997,7 @@ function SignerList({
|
|
|
2933
2997
|
children
|
|
2934
2998
|
}) {
|
|
2935
2999
|
const { signers, isLoading, error, refresh } = useSigners({ walletId });
|
|
2936
|
-
const [addSignerOpen, setAddSignerOpen] =
|
|
3000
|
+
const [addSignerOpen, setAddSignerOpen] = useState13(false);
|
|
2937
3001
|
const handleAddSuccess = () => {
|
|
2938
3002
|
refresh();
|
|
2939
3003
|
onSignerAdded?.();
|
|
@@ -3112,6 +3176,7 @@ export {
|
|
|
3112
3176
|
useSignerSelection,
|
|
3113
3177
|
useSigners,
|
|
3114
3178
|
useSignersForSelectedWallet,
|
|
3179
|
+
useSignersRaw,
|
|
3115
3180
|
useTransactionSigning,
|
|
3116
3181
|
useWalletAddress,
|
|
3117
3182
|
useWallets
|