@compilot/react-sdk 2.3.9-dev → 2.3.10-dev
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/compilot-react-sdk.cjs.dev.js +284 -217
- package/dist/compilot-react-sdk.cjs.prod.js +284 -217
- package/dist/compilot-react-sdk.esm.js +285 -219
- package/dist/declarations/src/hooks/index.d.ts +3 -2
- package/dist/declarations/src/hooks/index.d.ts.map +1 -1
- package/dist/declarations/src/hooks/useIdentityWallets.d.ts +12 -0
- package/dist/declarations/src/hooks/useIdentityWallets.d.ts.map +1 -0
- package/dist/package.json +1 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect, useState, useCallback, useMemo, createContext, useContext } from 'react';
|
|
2
|
-
import { load,
|
|
2
|
+
import { load, authenticate, isAuthenticated, watchIsAuthenticated, watchCustomerStatus, getCustomerStatus, disconnect, getTxAuthDataSignature, getIdentityWallets, attachWalletToIdentity, openWidget, isOpen, watchWidgetVisibleState } from '@compilot/web-sdk';
|
|
3
3
|
export * from '@compilot/web-sdk';
|
|
4
4
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
|
|
@@ -741,223 +741,6 @@ var useAsyncMutationState = function useAsyncMutationState(_ref) {
|
|
|
741
741
|
return _objectSpread2(_objectSpread2({}, globalState), {}, _defineProperty(_defineProperty(_defineProperty({}, mutationName, mutateAsync), "setData", setData), "setPending", setPending));
|
|
742
742
|
};
|
|
743
743
|
|
|
744
|
-
/**
|
|
745
|
-
* A hook that returns a function that opens the ComPilot ID widget.
|
|
746
|
-
*
|
|
747
|
-
* @param loginParams - The login parameters to use when opening the widget.
|
|
748
|
-
* @returns The async mutation state of the widget opening.
|
|
749
|
-
*
|
|
750
|
-
* @category Hook
|
|
751
|
-
*/
|
|
752
|
-
var useOpenWidget = function useOpenWidget(loginParams) {
|
|
753
|
-
var config = useComPilotConfig();
|
|
754
|
-
var mutationFn = useCallback(function () {
|
|
755
|
-
return openWidget(config, loginParams);
|
|
756
|
-
}, [config]);
|
|
757
|
-
var mutationState = useAsyncMutationState({
|
|
758
|
-
mutationName: "openWidget",
|
|
759
|
-
mutationKey: ["openWidget", config._internal.identifier],
|
|
760
|
-
mutationFn: mutationFn,
|
|
761
|
-
defaultValue: isOpen(config)
|
|
762
|
-
});
|
|
763
|
-
useEffect(function () {
|
|
764
|
-
var unsubscribe = watchWidgetVisibleState(config, {
|
|
765
|
-
onChange: function onChange(isVisible) {
|
|
766
|
-
mutationState.setData(isVisible);
|
|
767
|
-
},
|
|
768
|
-
onIsLoadingChange: mutationState.setPending
|
|
769
|
-
});
|
|
770
|
-
return unsubscribe;
|
|
771
|
-
}, [config, mutationState.setData, mutationState.setPending]);
|
|
772
|
-
return mutationState;
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
/**
|
|
776
|
-
* A callback that returns a transaction authorization data signature.
|
|
777
|
-
*
|
|
778
|
-
* @category Callback
|
|
779
|
-
*/
|
|
780
|
-
|
|
781
|
-
/**
|
|
782
|
-
* A hook that returns a function that returns a transaction authorization data signature.
|
|
783
|
-
*
|
|
784
|
-
* @returns A function that returns a transaction authorization data signature.
|
|
785
|
-
*
|
|
786
|
-
* @category Hook
|
|
787
|
-
*
|
|
788
|
-
* @example
|
|
789
|
-
*
|
|
790
|
-
* ##### EIP-155 Transaction Wagmi Example
|
|
791
|
-
*
|
|
792
|
-
* ```tsx
|
|
793
|
-
* import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
|
|
794
|
-
* import { waitForTransactionReceipt } from "viem/actions";
|
|
795
|
-
* import { encodeFunctionData } from "viem";
|
|
796
|
-
* import { usePublicClient, useWalletClient } from "wagmi";
|
|
797
|
-
*
|
|
798
|
-
* const MyComponent = () => {
|
|
799
|
-
*
|
|
800
|
-
* const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
|
|
801
|
-
* const walletClient = useWalletClient();
|
|
802
|
-
* const publicClient = usePublicClient();
|
|
803
|
-
*
|
|
804
|
-
* const gatedNftMint = async () => {
|
|
805
|
-
*
|
|
806
|
-
* // Get signature for the given parameters
|
|
807
|
-
* const signatureResponse = await getTxAuthDataSignature({
|
|
808
|
-
* namespace: "eip155",
|
|
809
|
-
* contractAbi,
|
|
810
|
-
* contractAddress,
|
|
811
|
-
* functionName: "mintNFTGated",
|
|
812
|
-
* args: [account.address],
|
|
813
|
-
* userAddress: account.address,
|
|
814
|
-
* chainId: EvmChainId.parse(chainId),
|
|
815
|
-
* });
|
|
816
|
-
*
|
|
817
|
-
* if (!signatureResponse.isAuthorized) {
|
|
818
|
-
* throw new Error("User is not authorized");
|
|
819
|
-
* }
|
|
820
|
-
*
|
|
821
|
-
* // Mint Gated Nft with signature
|
|
822
|
-
* const unsignedTx = encodeFunctionData({
|
|
823
|
-
* abi: contractAbi,
|
|
824
|
-
* functionName: "mintNFTGated",
|
|
825
|
-
* args: [account.address],
|
|
826
|
-
* });
|
|
827
|
-
*
|
|
828
|
-
* // Build the raw transaction data with the signature
|
|
829
|
-
* const txData = (unsignedTx + signatureResponse.payload) as `0x${string}`;
|
|
830
|
-
*
|
|
831
|
-
* // try to mint nft
|
|
832
|
-
* const tx = await walletClient.data.sendTransaction({
|
|
833
|
-
* to: contractAddress,
|
|
834
|
-
* data: txData,
|
|
835
|
-
* });
|
|
836
|
-
*
|
|
837
|
-
* const receipt = await waitForTransactionReceipt(publicClient, {
|
|
838
|
-
* hash: tx,
|
|
839
|
-
* });
|
|
840
|
-
*
|
|
841
|
-
* return receipt;
|
|
842
|
-
* };
|
|
843
|
-
*
|
|
844
|
-
* return <button onClick={gatedNftMint}>Mint Gated NFT</button>;
|
|
845
|
-
* };
|
|
846
|
-
* ```
|
|
847
|
-
*
|
|
848
|
-
* ### Tezos Transaction Example
|
|
849
|
-
*
|
|
850
|
-
* ```tsx
|
|
851
|
-
* import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
|
|
852
|
-
* import { packDataBytes, Parser } from "@taquito/michel-codec";
|
|
853
|
-
* import type { MichelsonData, MichelsonType } from "@taquito/michel-codec";
|
|
854
|
-
* import { RpcClient } from "@taquito/rpc";
|
|
855
|
-
*
|
|
856
|
-
* const MyComponent = () => {
|
|
857
|
-
* const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
|
|
858
|
-
* const wallet = useWallet();
|
|
859
|
-
*
|
|
860
|
-
* const signAndSend = async () => {
|
|
861
|
-
*
|
|
862
|
-
* // prepare the mint function call
|
|
863
|
-
* const storage: any = await claimerContract.storage();
|
|
864
|
-
* const lastAssetId = storage.siggated_extension.extension.lastMinted.toNumber() as number;
|
|
865
|
-
* const functionCallArgs = {
|
|
866
|
-
* owner: userAddress,
|
|
867
|
-
* token_id: (lastAssetId + 1).toString(), //"1",
|
|
868
|
-
* };
|
|
869
|
-
* const functionCallArgsBytes = convertMint(
|
|
870
|
-
* functionCallArgs.owner,
|
|
871
|
-
* functionCallArgs.token_id,
|
|
872
|
-
* );
|
|
873
|
-
*
|
|
874
|
-
* // Get signature for the given parameters
|
|
875
|
-
* const signatureResponse = await getTxAuthDataSignature({
|
|
876
|
-
* namespace: "tezos",
|
|
877
|
-
* contractAddress: "KT1JN7a2es4Ne8SuePZU7YrHKG49hfgCCyBK",
|
|
878
|
-
* functionName: "%mint_gated%",
|
|
879
|
-
* args: functionCallArgsBytes,
|
|
880
|
-
* chainID: TezosChainId.parse(currentChainId),
|
|
881
|
-
* userAddress: userAddress as TezosImplicitAddress,
|
|
882
|
-
* });
|
|
883
|
-
*
|
|
884
|
-
* // Check if the user is authorized
|
|
885
|
-
* if (!signatureResponse.isAuthorized) {
|
|
886
|
-
* return {
|
|
887
|
-
* signatureResponse: {
|
|
888
|
-
* isAuthorized: false,
|
|
889
|
-
* signature: "None",
|
|
890
|
-
* },
|
|
891
|
-
* };
|
|
892
|
-
* }
|
|
893
|
-
*
|
|
894
|
-
* // Mint Gated Nft with signature
|
|
895
|
-
* const op = await claimerContract.methodsObject
|
|
896
|
-
* .mint_gated({
|
|
897
|
-
* userAddress,
|
|
898
|
-
* expirationBlock: signatureResponse.blockExpiration,
|
|
899
|
-
* functionName,
|
|
900
|
-
* functionArgs: functionCallArgsBytes,
|
|
901
|
-
* signerPublicKey: COMPILOT_SIGNER_PK,
|
|
902
|
-
* signature: signatureResponse.signature,
|
|
903
|
-
* })
|
|
904
|
-
* .send();
|
|
905
|
-
* await op.confirmation(2);
|
|
906
|
-
* };
|
|
907
|
-
* return <button onClick={signAndSend}>Sign and Send</button>;
|
|
908
|
-
* };
|
|
909
|
-
*
|
|
910
|
-
*
|
|
911
|
-
* // Helper function to convert mint function to bytes
|
|
912
|
-
* function convertMint(owner_str: string, token_id: string) {
|
|
913
|
-
* const data = `(Pair "${owner_str}" ${token_id})`;
|
|
914
|
-
* const type = `(pair address nat)`;
|
|
915
|
-
* const p = new Parser();
|
|
916
|
-
* const dataJSON = p.parseMichelineExpression(data);
|
|
917
|
-
* const typeJSON = p.parseMichelineExpression(type);
|
|
918
|
-
* const packed = packDataBytes(
|
|
919
|
-
* dataJSON as MichelsonData,
|
|
920
|
-
* typeJSON as MichelsonType,
|
|
921
|
-
* );
|
|
922
|
-
* return packed.bytes;
|
|
923
|
-
* }
|
|
924
|
-
*
|
|
925
|
-
* // Tezos signer public key
|
|
926
|
-
* const COMPILOT_SIGNER_PK = "edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4";
|
|
927
|
-
* const client = new RpcClient("https://rpc.ghostnet.teztnets.com/");
|
|
928
|
-
* ```
|
|
929
|
-
*
|
|
930
|
-
*/
|
|
931
|
-
var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
932
|
-
var config = useComPilotConfig();
|
|
933
|
-
var mutationFn = useCallback(/*#__PURE__*/function () {
|
|
934
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
935
|
-
var res;
|
|
936
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
937
|
-
while (1) switch (_context.prev = _context.next) {
|
|
938
|
-
case 0:
|
|
939
|
-
_context.next = 2;
|
|
940
|
-
return getTxAuthDataSignature(config, params);
|
|
941
|
-
case 2:
|
|
942
|
-
res = _context.sent;
|
|
943
|
-
return _context.abrupt("return", res);
|
|
944
|
-
case 4:
|
|
945
|
-
case "end":
|
|
946
|
-
return _context.stop();
|
|
947
|
-
}
|
|
948
|
-
}, _callee);
|
|
949
|
-
}));
|
|
950
|
-
return function (_x) {
|
|
951
|
-
return _ref.apply(this, arguments);
|
|
952
|
-
};
|
|
953
|
-
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
954
|
-
return useAsyncMutationState({
|
|
955
|
-
mutationName: "getTxAuthDataSignature",
|
|
956
|
-
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
957
|
-
mutationFn: mutationFn
|
|
958
|
-
});
|
|
959
|
-
};
|
|
960
|
-
|
|
961
744
|
/**
|
|
962
745
|
* A hook that returns a function that authenticates the user without opening the ComPilot ID widget.
|
|
963
746
|
* This will authenticate the user only if they are not already authenticated.
|
|
@@ -1229,4 +1012,287 @@ var useDisconnect = function useDisconnect() {
|
|
|
1229
1012
|
});
|
|
1230
1013
|
};
|
|
1231
1014
|
|
|
1232
|
-
|
|
1015
|
+
/**
|
|
1016
|
+
* A callback that returns a transaction authorization data signature.
|
|
1017
|
+
*
|
|
1018
|
+
* @category Callback
|
|
1019
|
+
*/
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* A hook that returns a function that returns a transaction authorization data signature.
|
|
1023
|
+
*
|
|
1024
|
+
* @returns A function that returns a transaction authorization data signature.
|
|
1025
|
+
*
|
|
1026
|
+
* @category Hook
|
|
1027
|
+
*
|
|
1028
|
+
* @example
|
|
1029
|
+
*
|
|
1030
|
+
* ##### EIP-155 Transaction Wagmi Example
|
|
1031
|
+
*
|
|
1032
|
+
* ```tsx
|
|
1033
|
+
* import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
|
|
1034
|
+
* import { waitForTransactionReceipt } from "viem/actions";
|
|
1035
|
+
* import { encodeFunctionData } from "viem";
|
|
1036
|
+
* import { usePublicClient, useWalletClient } from "wagmi";
|
|
1037
|
+
*
|
|
1038
|
+
* const MyComponent = () => {
|
|
1039
|
+
*
|
|
1040
|
+
* const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
|
|
1041
|
+
* const walletClient = useWalletClient();
|
|
1042
|
+
* const publicClient = usePublicClient();
|
|
1043
|
+
*
|
|
1044
|
+
* const gatedNftMint = async () => {
|
|
1045
|
+
*
|
|
1046
|
+
* // Get signature for the given parameters
|
|
1047
|
+
* const signatureResponse = await getTxAuthDataSignature({
|
|
1048
|
+
* namespace: "eip155",
|
|
1049
|
+
* contractAbi,
|
|
1050
|
+
* contractAddress,
|
|
1051
|
+
* functionName: "mintNFTGated",
|
|
1052
|
+
* args: [account.address],
|
|
1053
|
+
* userAddress: account.address,
|
|
1054
|
+
* chainId: EvmChainId.parse(chainId),
|
|
1055
|
+
* });
|
|
1056
|
+
*
|
|
1057
|
+
* if (!signatureResponse.isAuthorized) {
|
|
1058
|
+
* throw new Error("User is not authorized");
|
|
1059
|
+
* }
|
|
1060
|
+
*
|
|
1061
|
+
* // Mint Gated Nft with signature
|
|
1062
|
+
* const unsignedTx = encodeFunctionData({
|
|
1063
|
+
* abi: contractAbi,
|
|
1064
|
+
* functionName: "mintNFTGated",
|
|
1065
|
+
* args: [account.address],
|
|
1066
|
+
* });
|
|
1067
|
+
*
|
|
1068
|
+
* // Build the raw transaction data with the signature
|
|
1069
|
+
* const txData = (unsignedTx + signatureResponse.payload) as `0x${string}`;
|
|
1070
|
+
*
|
|
1071
|
+
* // try to mint nft
|
|
1072
|
+
* const tx = await walletClient.data.sendTransaction({
|
|
1073
|
+
* to: contractAddress,
|
|
1074
|
+
* data: txData,
|
|
1075
|
+
* });
|
|
1076
|
+
*
|
|
1077
|
+
* const receipt = await waitForTransactionReceipt(publicClient, {
|
|
1078
|
+
* hash: tx,
|
|
1079
|
+
* });
|
|
1080
|
+
*
|
|
1081
|
+
* return receipt;
|
|
1082
|
+
* };
|
|
1083
|
+
*
|
|
1084
|
+
* return <button onClick={gatedNftMint}>Mint Gated NFT</button>;
|
|
1085
|
+
* };
|
|
1086
|
+
* ```
|
|
1087
|
+
*
|
|
1088
|
+
* ### Tezos Transaction Example
|
|
1089
|
+
*
|
|
1090
|
+
* ```tsx
|
|
1091
|
+
* import { useGetTxAuthDataSignature } from "@compilot/react-sdk";
|
|
1092
|
+
* import { packDataBytes, Parser } from "@taquito/michel-codec";
|
|
1093
|
+
* import type { MichelsonData, MichelsonType } from "@taquito/michel-codec";
|
|
1094
|
+
* import { RpcClient } from "@taquito/rpc";
|
|
1095
|
+
*
|
|
1096
|
+
* const MyComponent = () => {
|
|
1097
|
+
* const { getTxAuthDataSignature } = useGetTxAuthDataSignature();
|
|
1098
|
+
* const wallet = useWallet();
|
|
1099
|
+
*
|
|
1100
|
+
* const signAndSend = async () => {
|
|
1101
|
+
*
|
|
1102
|
+
* // prepare the mint function call
|
|
1103
|
+
* const storage: any = await claimerContract.storage();
|
|
1104
|
+
* const lastAssetId = storage.siggated_extension.extension.lastMinted.toNumber() as number;
|
|
1105
|
+
* const functionCallArgs = {
|
|
1106
|
+
* owner: userAddress,
|
|
1107
|
+
* token_id: (lastAssetId + 1).toString(), //"1",
|
|
1108
|
+
* };
|
|
1109
|
+
* const functionCallArgsBytes = convertMint(
|
|
1110
|
+
* functionCallArgs.owner,
|
|
1111
|
+
* functionCallArgs.token_id,
|
|
1112
|
+
* );
|
|
1113
|
+
*
|
|
1114
|
+
* // Get signature for the given parameters
|
|
1115
|
+
* const signatureResponse = await getTxAuthDataSignature({
|
|
1116
|
+
* namespace: "tezos",
|
|
1117
|
+
* contractAddress: "KT1JN7a2es4Ne8SuePZU7YrHKG49hfgCCyBK",
|
|
1118
|
+
* functionName: "%mint_gated%",
|
|
1119
|
+
* args: functionCallArgsBytes,
|
|
1120
|
+
* chainID: TezosChainId.parse(currentChainId),
|
|
1121
|
+
* userAddress: userAddress as TezosImplicitAddress,
|
|
1122
|
+
* });
|
|
1123
|
+
*
|
|
1124
|
+
* // Check if the user is authorized
|
|
1125
|
+
* if (!signatureResponse.isAuthorized) {
|
|
1126
|
+
* return {
|
|
1127
|
+
* signatureResponse: {
|
|
1128
|
+
* isAuthorized: false,
|
|
1129
|
+
* signature: "None",
|
|
1130
|
+
* },
|
|
1131
|
+
* };
|
|
1132
|
+
* }
|
|
1133
|
+
*
|
|
1134
|
+
* // Mint Gated Nft with signature
|
|
1135
|
+
* const op = await claimerContract.methodsObject
|
|
1136
|
+
* .mint_gated({
|
|
1137
|
+
* userAddress,
|
|
1138
|
+
* expirationBlock: signatureResponse.blockExpiration,
|
|
1139
|
+
* functionName,
|
|
1140
|
+
* functionArgs: functionCallArgsBytes,
|
|
1141
|
+
* signerPublicKey: COMPILOT_SIGNER_PK,
|
|
1142
|
+
* signature: signatureResponse.signature,
|
|
1143
|
+
* })
|
|
1144
|
+
* .send();
|
|
1145
|
+
* await op.confirmation(2);
|
|
1146
|
+
* };
|
|
1147
|
+
* return <button onClick={signAndSend}>Sign and Send</button>;
|
|
1148
|
+
* };
|
|
1149
|
+
*
|
|
1150
|
+
*
|
|
1151
|
+
* // Helper function to convert mint function to bytes
|
|
1152
|
+
* function convertMint(owner_str: string, token_id: string) {
|
|
1153
|
+
* const data = `(Pair "${owner_str}" ${token_id})`;
|
|
1154
|
+
* const type = `(pair address nat)`;
|
|
1155
|
+
* const p = new Parser();
|
|
1156
|
+
* const dataJSON = p.parseMichelineExpression(data);
|
|
1157
|
+
* const typeJSON = p.parseMichelineExpression(type);
|
|
1158
|
+
* const packed = packDataBytes(
|
|
1159
|
+
* dataJSON as MichelsonData,
|
|
1160
|
+
* typeJSON as MichelsonType,
|
|
1161
|
+
* );
|
|
1162
|
+
* return packed.bytes;
|
|
1163
|
+
* }
|
|
1164
|
+
*
|
|
1165
|
+
* // Tezos signer public key
|
|
1166
|
+
* const COMPILOT_SIGNER_PK = "edpkurPsQ8eUApnLUJ9ZPDvu98E8VNj4KtJa1aZr16Cr5ow5VHKnz4";
|
|
1167
|
+
* const client = new RpcClient("https://rpc.ghostnet.teztnets.com/");
|
|
1168
|
+
* ```
|
|
1169
|
+
*
|
|
1170
|
+
*/
|
|
1171
|
+
var useGetTxAuthDataSignature = function useGetTxAuthDataSignature() {
|
|
1172
|
+
var config = useComPilotConfig();
|
|
1173
|
+
var mutationFn = useCallback(/*#__PURE__*/function () {
|
|
1174
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
|
|
1175
|
+
var res;
|
|
1176
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1177
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1178
|
+
case 0:
|
|
1179
|
+
_context.next = 2;
|
|
1180
|
+
return getTxAuthDataSignature(config, params);
|
|
1181
|
+
case 2:
|
|
1182
|
+
res = _context.sent;
|
|
1183
|
+
return _context.abrupt("return", res);
|
|
1184
|
+
case 4:
|
|
1185
|
+
case "end":
|
|
1186
|
+
return _context.stop();
|
|
1187
|
+
}
|
|
1188
|
+
}, _callee);
|
|
1189
|
+
}));
|
|
1190
|
+
return function (_x) {
|
|
1191
|
+
return _ref.apply(this, arguments);
|
|
1192
|
+
};
|
|
1193
|
+
}(), [config._internal.widgetStateStore, config._internal.identifier]);
|
|
1194
|
+
return useAsyncMutationState({
|
|
1195
|
+
mutationName: "getTxAuthDataSignature",
|
|
1196
|
+
mutationKey: ["getTxAuthDataSignature", config._internal.identifier],
|
|
1197
|
+
mutationFn: mutationFn
|
|
1198
|
+
});
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
/**
|
|
1202
|
+
* A hook that returns the current identity wallets.
|
|
1203
|
+
*/
|
|
1204
|
+
var useIdentityWallets = function useIdentityWallets() {
|
|
1205
|
+
var config = useComPilotConfig();
|
|
1206
|
+
var auth = config._internal.widgetStateStore.select(function (state) {
|
|
1207
|
+
return state.auth;
|
|
1208
|
+
});
|
|
1209
|
+
var _useState = useState(0),
|
|
1210
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1211
|
+
queryCacheBuster = _useState2[0],
|
|
1212
|
+
setQueryCacheBuster = _useState2[1];
|
|
1213
|
+
var _useAsyncQueryState = useAsyncQueryState({
|
|
1214
|
+
queryKey: ["useIdentityWallets", config._internal.identifier, auth === "loading" || auth === "not_authenticated" ? "" : auth.token],
|
|
1215
|
+
defaultValue: null
|
|
1216
|
+
}),
|
|
1217
|
+
state = _useAsyncQueryState.state,
|
|
1218
|
+
setError = _useAsyncQueryState.setError,
|
|
1219
|
+
setResult = _useAsyncQueryState.setResult,
|
|
1220
|
+
startLoading = _useAsyncQueryState.startLoading;
|
|
1221
|
+
useEffect(function () {
|
|
1222
|
+
if (!config) {
|
|
1223
|
+
return;
|
|
1224
|
+
}
|
|
1225
|
+
startLoading();
|
|
1226
|
+
getIdentityWallets(config).then(function (wallets) {
|
|
1227
|
+
setResult(wallets);
|
|
1228
|
+
})["catch"](function (err) {
|
|
1229
|
+
config._internal.logger.error("Failed to fetch identity wallets", err);
|
|
1230
|
+
setError(err instanceof Error ? err : new Error("Unknown error"));
|
|
1231
|
+
});
|
|
1232
|
+
}, [config, queryCacheBuster]);
|
|
1233
|
+
var mutationFn = useCallback(/*#__PURE__*/function () {
|
|
1234
|
+
var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(wallet) {
|
|
1235
|
+
var res;
|
|
1236
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1237
|
+
while (1) switch (_context.prev = _context.next) {
|
|
1238
|
+
case 0:
|
|
1239
|
+
res = attachWalletToIdentity(config, {
|
|
1240
|
+
wallet: wallet
|
|
1241
|
+
});
|
|
1242
|
+
setQueryCacheBuster(function (prev) {
|
|
1243
|
+
return prev + 1;
|
|
1244
|
+
});
|
|
1245
|
+
return _context.abrupt("return", res);
|
|
1246
|
+
case 3:
|
|
1247
|
+
case "end":
|
|
1248
|
+
return _context.stop();
|
|
1249
|
+
}
|
|
1250
|
+
}, _callee);
|
|
1251
|
+
}));
|
|
1252
|
+
return function (_x) {
|
|
1253
|
+
return _ref.apply(this, arguments);
|
|
1254
|
+
};
|
|
1255
|
+
}(), [config]);
|
|
1256
|
+
var addWalletMutation = useAsyncMutationState({
|
|
1257
|
+
mutationName: "attachWalletToIdentity",
|
|
1258
|
+
mutationKey: ["attachWalletToIdentity", config._internal.identifier, auth === "loading" || auth === "not_authenticated" ? "" : auth.token],
|
|
1259
|
+
mutationFn: mutationFn
|
|
1260
|
+
});
|
|
1261
|
+
return {
|
|
1262
|
+
identityWallets: state,
|
|
1263
|
+
addWalletMutation: addWalletMutation
|
|
1264
|
+
};
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* A hook that returns a function that opens the ComPilot ID widget.
|
|
1269
|
+
*
|
|
1270
|
+
* @param loginParams - The login parameters to use when opening the widget.
|
|
1271
|
+
* @returns The async mutation state of the widget opening.
|
|
1272
|
+
*
|
|
1273
|
+
* @category Hook
|
|
1274
|
+
*/
|
|
1275
|
+
var useOpenWidget = function useOpenWidget(loginParams) {
|
|
1276
|
+
var config = useComPilotConfig();
|
|
1277
|
+
var mutationFn = useCallback(function () {
|
|
1278
|
+
return openWidget(config, loginParams);
|
|
1279
|
+
}, [config]);
|
|
1280
|
+
var mutationState = useAsyncMutationState({
|
|
1281
|
+
mutationName: "openWidget",
|
|
1282
|
+
mutationKey: ["openWidget", config._internal.identifier],
|
|
1283
|
+
mutationFn: mutationFn,
|
|
1284
|
+
defaultValue: isOpen(config)
|
|
1285
|
+
});
|
|
1286
|
+
useEffect(function () {
|
|
1287
|
+
var unsubscribe = watchWidgetVisibleState(config, {
|
|
1288
|
+
onChange: function onChange(isVisible) {
|
|
1289
|
+
mutationState.setData(isVisible);
|
|
1290
|
+
},
|
|
1291
|
+
onIsLoadingChange: mutationState.setPending
|
|
1292
|
+
});
|
|
1293
|
+
return unsubscribe;
|
|
1294
|
+
}, [config, mutationState.setData, mutationState.setPending]);
|
|
1295
|
+
return mutationState;
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
export { ComPilotProvider, useAuthenticate, useComPilotConfig, useCustomerStatus, useDisconnect, useGetTxAuthDataSignature, useIdentityWallets, useOpenWidget };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export * from "./useOpenWidget.js";
|
|
2
|
-
export * from "./useGetTxAuthDataSignature.js";
|
|
3
1
|
export * from "./useAuthenticate.js";
|
|
4
2
|
export * from "./useCustomerStatus.js";
|
|
5
3
|
export * from "./useDisconnect.js";
|
|
4
|
+
export * from "./useGetTxAuthDataSignature.js";
|
|
5
|
+
export * from "./useIdentityWallets.js";
|
|
6
|
+
export * from "./useOpenWidget.js";
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/hooks","sources":["index.ts"],"names":[],"mappings":"AAAA,mCAAgC;AAChC,+CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"../../../../src/hooks","sources":["index.ts"],"names":[],"mappings":"AAAA,qCAAkC;AAClC,uCAAoC;AACpC,mCAAgC;AAChC,+CAA4C;AAC5C,wCAAqC;AACrC,mCAAgC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Web3Wallet } from "@compilot/web-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* A hook that returns the current identity wallets.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useIdentityWallets: () => {
|
|
6
|
+
identityWallets: import("../utils/useAsyncQueryState.js").AsyncQueryState<{
|
|
7
|
+
address: string;
|
|
8
|
+
namespace: "cosmos" | "tezos" | "eip155" | "aptos" | "polkadot" | "starknet" | "solana" | "cardano";
|
|
9
|
+
}[] | null>;
|
|
10
|
+
addWalletMutation: import("../utils/useAsyncMutationState.js").AsyncMutationState<(wallet: Web3Wallet) => Promise<boolean>, "attachWalletToIdentity">;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=useIdentityWallets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIdentityWallets.d.ts","sourceRoot":"../../../../src/hooks","sources":["useIdentityWallets.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAQpD;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;+FAiCZ,UAAU;CAsB5B,CAAC"}
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compilot/react-sdk",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.10-dev",
|
|
4
4
|
"description": "ComPilot React SDK",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "ISC",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"pino": "^9.4.0",
|
|
29
29
|
"zod": "^3.23.8",
|
|
30
|
-
"@compilot/web-sdk": "2.3.
|
|
30
|
+
"@compilot/web-sdk": "2.3.9-dev",
|
|
31
31
|
"@nexeraid/identity-api-client": "2.3.0-dev",
|
|
32
|
-
"@nexeraid/identity-schemas": "2.3.
|
|
32
|
+
"@nexeraid/identity-schemas": "2.3.9-dev",
|
|
33
33
|
"@nexeraid/logger": "2.3.0-dev"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|