anymal-protocol 1.0.4 → 1.0.6

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 CHANGED
@@ -3,6 +3,16 @@ declare function useVerifyAccount(): (pid: string, dbAuthToken: string, bundlerC
3
3
  message: string;
4
4
  }>;
5
5
 
6
+ declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
7
+
8
+ declare function useCreateWeb3Account(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
9
+
10
+ declare function useFetchUserData(): (dbAuthToken: string, endpoint: string) => Promise<any>;
11
+
12
+ declare function useUpdateUserEmail(): (dbAuthToken: string, docID: string, email: string, endpoint: string) => Promise<void>;
13
+
14
+ declare function useUpdateUserPid(): (dbAuthToken: string, docID: string, pid: string, endpoint: string) => Promise<void>;
15
+
6
16
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
7
17
  success: boolean;
8
18
  message: string;
@@ -34,8 +44,6 @@ declare function useUpdateAnymalWithNFT(): (anymalPassportId: string, anymalDocI
34
44
  success: boolean;
35
45
  }>;
36
46
 
37
- declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
38
-
39
47
  declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<{
40
48
  success: boolean;
41
49
  message: string;
@@ -43,4 +51,6 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
43
51
  type: string;
44
52
  }>;
45
53
 
46
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useDeleteAnymalFromDatabase, useFetchBalance, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUploadAnymalImage, useVerifyAccount };
54
+ declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
55
+
56
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserEmail, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -3,6 +3,16 @@ declare function useVerifyAccount(): (pid: string, dbAuthToken: string, bundlerC
3
3
  message: string;
4
4
  }>;
5
5
 
6
+ declare function useVerifyWeb3AuthSession(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
7
+
8
+ declare function useCreateWeb3Account(): (idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<any>;
9
+
10
+ declare function useFetchUserData(): (dbAuthToken: string, endpoint: string) => Promise<any>;
11
+
12
+ declare function useUpdateUserEmail(): (dbAuthToken: string, docID: string, email: string, endpoint: string) => Promise<void>;
13
+
14
+ declare function useUpdateUserPid(): (dbAuthToken: string, docID: string, pid: string, endpoint: string) => Promise<void>;
15
+
6
16
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
7
17
  success: boolean;
8
18
  message: string;
@@ -34,8 +44,6 @@ declare function useUpdateAnymalWithNFT(): (anymalPassportId: string, anymalDocI
34
44
  success: boolean;
35
45
  }>;
36
46
 
37
- declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
38
-
39
47
  declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken: string, publicKey: string, authServiceBaseUrl: string) => Promise<{
40
48
  success: boolean;
41
49
  message: string;
@@ -43,4 +51,6 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
43
51
  type: string;
44
52
  }>;
45
53
 
46
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useDeleteAnymalFromDatabase, useFetchBalance, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUploadAnymalImage, useVerifyAccount };
54
+ declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
55
+
56
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserEmail, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -21,13 +21,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  useAddAnymalToDatabase: () => useAddAnymalToDatabase,
24
+ useCreateWeb3Account: () => useCreateWeb3Account,
24
25
  useDeleteAnymalFromDatabase: () => useDeleteAnymalFromDatabase,
25
26
  useFetchBalance: () => useFetchBalance,
27
+ useFetchUserData: () => useFetchUserData,
26
28
  useMintAnymalNFT: () => useMintAnymalNFT,
27
29
  useSaveAnymalMetadata: () => useSaveAnymalMetadata,
28
30
  useUpdateAnymalWithNFT: () => useUpdateAnymalWithNFT,
31
+ useUpdateUserEmail: () => useUpdateUserEmail,
32
+ useUpdateUserPid: () => useUpdateUserPid,
29
33
  useUploadAnymalImage: () => useUploadAnymalImage,
30
- useVerifyAccount: () => useVerifyAccount
34
+ useVerifyAccount: () => useVerifyAccount,
35
+ useVerifyWeb3AuthSession: () => useVerifyWeb3AuthSession
31
36
  });
32
37
  module.exports = __toCommonJS(index_exports);
33
38
 
@@ -597,9 +602,16 @@ function useVerifyAccount() {
597
602
  return (0, import_react.useCallback)(
598
603
  async (pid, dbAuthToken, bundlerClient, smartAccount, accountRewardsContractAddress) => {
599
604
  if (!dbAuthToken || !bundlerClient || !smartAccount || !accountRewardsContractAddress || !pid) {
605
+ console.log({
606
+ dbAuthToken,
607
+ bundlerClient,
608
+ smartAccount,
609
+ accountRewardsContractAddress,
610
+ pid
611
+ });
600
612
  return {
601
613
  success: false,
602
- message: "Missing authentication token OR NFT ID."
614
+ message: "Missing crucial information"
603
615
  };
604
616
  }
605
617
  const callData = (0, import_viem.encodeFunctionData)({
@@ -632,11 +644,180 @@ function useVerifyAccount() {
632
644
  );
633
645
  }
634
646
 
647
+ // src/utils/account/useVerifyWeb3AuthSession.ts
648
+ var import_react2 = require("react");
649
+ function useVerifyWeb3AuthSession() {
650
+ return (0, import_react2.useCallback)(
651
+ async (idToken, publicKey, authServiceBaseUrl) => {
652
+ const response = await fetch(
653
+ `${authServiceBaseUrl}/verify-web3-session`,
654
+ {
655
+ method: "POST",
656
+ headers: {
657
+ "Content-Type": "application/json",
658
+ Authorization: "Bearer " + idToken
659
+ },
660
+ body: JSON.stringify({ appPubKey: publicKey })
661
+ }
662
+ );
663
+ const { jwt } = await response.json();
664
+ return jwt;
665
+ },
666
+ []
667
+ );
668
+ }
669
+
670
+ // src/utils/account/useCreateWeb3Account.ts
671
+ var import_react3 = require("react");
672
+ function useCreateWeb3Account() {
673
+ return (0, import_react3.useCallback)(
674
+ async (idToken, publicKey, authServiceBaseUrl) => {
675
+ try {
676
+ const response = await fetch(`${authServiceBaseUrl}/create-account`, {
677
+ method: "POST",
678
+ headers: {
679
+ "Content-Type": "application/json",
680
+ Authorization: "Bearer " + idToken
681
+ },
682
+ body: JSON.stringify({ appPubKey: publicKey })
683
+ });
684
+ return await response.json();
685
+ } catch (error) {
686
+ console.error(error);
687
+ return null;
688
+ }
689
+ },
690
+ []
691
+ );
692
+ }
693
+
694
+ // src/utils/account/useFetchUserData.ts
695
+ var import_react4 = require("react");
696
+ function useFetchUserData() {
697
+ return (0, import_react4.useCallback)(async (dbAuthToken, endpoint) => {
698
+ try {
699
+ const query = `
700
+ query User {
701
+ User {
702
+ _docID
703
+ pid
704
+ email
705
+ isVerified
706
+ accountType
707
+ }
708
+ }
709
+ `;
710
+ const response = await fetch(endpoint, {
711
+ method: "POST",
712
+ headers: {
713
+ "Content-Type": "application/json",
714
+ Authorization: `Bearer ${dbAuthToken}`
715
+ },
716
+ body: JSON.stringify({ query })
717
+ });
718
+ if (!response.ok) {
719
+ throw new Error(`HTTP error! Status: ${response.status}`);
720
+ }
721
+ const data = await response.json();
722
+ if (data && data.data && data.data.User && data.data.User.length > 0) {
723
+ return data.data.User[0];
724
+ } else {
725
+ return null;
726
+ }
727
+ } catch (error) {
728
+ console.error("Error fetching user data:", error);
729
+ return null;
730
+ }
731
+ }, []);
732
+ }
733
+
734
+ // src/utils/account/useUpdateUserEmail.ts
735
+ var import_react5 = require("react");
736
+ function useUpdateUserEmail() {
737
+ return (0, import_react5.useCallback)(
738
+ async (dbAuthToken, docID, email, endpoint) => {
739
+ try {
740
+ const mutation = `
741
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
742
+ update_User(docID: $docID, input: $input) {
743
+ email
744
+ }
745
+ }
746
+ `;
747
+ const variables = {
748
+ docId: [docID],
749
+ input: {
750
+ email
751
+ }
752
+ };
753
+ const response = await fetch(endpoint, {
754
+ method: "POST",
755
+ headers: {
756
+ "Content-Type": "application/json",
757
+ Authorization: `Bearer ${dbAuthToken}`
758
+ },
759
+ body: JSON.stringify({
760
+ query: mutation,
761
+ variables
762
+ })
763
+ });
764
+ if (!response.ok) {
765
+ throw new Error(`HTTP error! Status: ${response.status}`);
766
+ }
767
+ } catch (error) {
768
+ console.error("Error updating email:", error);
769
+ }
770
+ },
771
+ []
772
+ );
773
+ }
774
+
775
+ // src/utils/account/useUpdateUserPid.ts
776
+ var import_react6 = require("react");
777
+ function useUpdateUserPid() {
778
+ return (0, import_react6.useCallback)(
779
+ async (dbAuthToken, docID, pid, endpoint) => {
780
+ try {
781
+ const mutation = `
782
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
783
+ update_User(docID: $docID, input: $input) {
784
+ pid
785
+ }
786
+ }
787
+ `;
788
+ const variables = {
789
+ docId: [docID],
790
+ input: {
791
+ pid
792
+ }
793
+ };
794
+ const response = await fetch(endpoint, {
795
+ method: "POST",
796
+ headers: {
797
+ "Content-Type": "application/json",
798
+ Authorization: `Bearer ${dbAuthToken}`
799
+ },
800
+ body: JSON.stringify({
801
+ query: mutation,
802
+ variables
803
+ })
804
+ });
805
+ if (!response.ok) {
806
+ throw new Error(`HTTP error! Status: ${response.status}`);
807
+ }
808
+ } catch (error) {
809
+ console.error("Error updating email:", error);
810
+ }
811
+ },
812
+ []
813
+ );
814
+ }
815
+
635
816
  // src/utils/anymals/useMintAnymalNFT.ts
636
817
  var import_viem2 = require("viem");
637
- var import_react2 = require("react");
818
+ var import_react7 = require("react");
638
819
  function useMintAnymalNFT() {
639
- return (0, import_react2.useCallback)(
820
+ return (0, import_react7.useCallback)(
640
821
  async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
641
822
  if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
642
823
  return {
@@ -675,9 +856,9 @@ function useMintAnymalNFT() {
675
856
  }
676
857
 
677
858
  // src/utils/anymals/useAddAnymalToDatabase.ts
678
- var import_react3 = require("react");
859
+ var import_react8 = require("react");
679
860
  function useAddAnymalToDatabase() {
680
- return (0, import_react3.useCallback)(
861
+ return (0, import_react8.useCallback)(
681
862
  async (dbAuthToken, endpoint, anymalData) => {
682
863
  if (!dbAuthToken) {
683
864
  return {
@@ -742,9 +923,9 @@ function useAddAnymalToDatabase() {
742
923
  }
743
924
 
744
925
  // src/utils/anymals/useDeleteAnymalFromDatabase.ts
745
- var import_react4 = require("react");
926
+ var import_react9 = require("react");
746
927
  function useDeleteAnymalFromDatabase() {
747
- return (0, import_react4.useCallback)(
928
+ return (0, import_react9.useCallback)(
748
929
  async (dbAuthToken, endpoint, anymalDocID) => {
749
930
  if (!dbAuthToken || !endpoint || !anymalDocID) return;
750
931
  try {
@@ -782,9 +963,9 @@ function useDeleteAnymalFromDatabase() {
782
963
  }
783
964
 
784
965
  // src/utils/anymals/useSaveAnymalMetadata.ts
785
- var import_react5 = require("react");
966
+ var import_react10 = require("react");
786
967
  function useSaveAnymalMetadata() {
787
- return (0, import_react5.useCallback)(
968
+ return (0, import_react10.useCallback)(
788
969
  async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
789
970
  const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
790
971
  method: "POST",
@@ -811,9 +992,9 @@ function useSaveAnymalMetadata() {
811
992
  }
812
993
 
813
994
  // src/utils/anymals/useUpdateAnymalWithNFT.ts
814
- var import_react6 = require("react");
995
+ var import_react11 = require("react");
815
996
  function useUpdateAnymalWithNFT() {
816
- return (0, import_react6.useCallback)(
997
+ return (0, import_react11.useCallback)(
817
998
  async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
818
999
  if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
819
1000
  return {
@@ -859,30 +1040,8 @@ function useUpdateAnymalWithNFT() {
859
1040
  );
860
1041
  }
861
1042
 
862
- // src/utils/balance/useFetchBalance.ts
863
- var import_react7 = require("react");
864
- var import_viem3 = require("viem");
865
- function useFetchBalance() {
866
- return (0, import_react7.useCallback)(
867
- async (publicClient, walletAddress, kibbleTokenAddress) => {
868
- try {
869
- const balance = await publicClient.readContract({
870
- address: (0, import_viem3.getAddress)(kibbleTokenAddress),
871
- abi: import_viem3.erc20Abi,
872
- functionName: "balanceOf",
873
- args: [(0, import_viem3.getAddress)(walletAddress)]
874
- });
875
- return Number(balance);
876
- } catch (error) {
877
- console.error("Failed to fetch token balance:", error);
878
- }
879
- },
880
- []
881
- );
882
- }
883
-
884
1043
  // src/utils/anymals/useUploadAnymalImage.ts
885
- var import_react8 = require("react");
1044
+ var import_react12 = require("react");
886
1045
 
887
1046
  // src/helpers/UploadImageHelper.tsx
888
1047
  function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
@@ -939,7 +1098,7 @@ function toBase64(file) {
939
1098
 
940
1099
  // src/utils/anymals/useUploadAnymalImage.ts
941
1100
  function useUploadAnymalImage() {
942
- return (0, import_react8.useCallback)(
1101
+ return (0, import_react12.useCallback)(
943
1102
  async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
944
1103
  if (!imageFile || !idToken) {
945
1104
  return {
@@ -992,14 +1151,41 @@ function useUploadAnymalImage() {
992
1151
  []
993
1152
  );
994
1153
  }
1154
+
1155
+ // src/utils/balance/useFetchBalance.ts
1156
+ var import_react13 = require("react");
1157
+ var import_viem3 = require("viem");
1158
+ function useFetchBalance() {
1159
+ return (0, import_react13.useCallback)(
1160
+ async (publicClient, walletAddress, kibbleTokenAddress) => {
1161
+ try {
1162
+ const balance = await publicClient.readContract({
1163
+ address: (0, import_viem3.getAddress)(kibbleTokenAddress),
1164
+ abi: import_viem3.erc20Abi,
1165
+ functionName: "balanceOf",
1166
+ args: [(0, import_viem3.getAddress)(walletAddress)]
1167
+ });
1168
+ return Number(balance);
1169
+ } catch (error) {
1170
+ console.error("Failed to fetch token balance:", error);
1171
+ }
1172
+ },
1173
+ []
1174
+ );
1175
+ }
995
1176
  // Annotate the CommonJS export names for ESM import in node:
996
1177
  0 && (module.exports = {
997
1178
  useAddAnymalToDatabase,
1179
+ useCreateWeb3Account,
998
1180
  useDeleteAnymalFromDatabase,
999
1181
  useFetchBalance,
1182
+ useFetchUserData,
1000
1183
  useMintAnymalNFT,
1001
1184
  useSaveAnymalMetadata,
1002
1185
  useUpdateAnymalWithNFT,
1186
+ useUpdateUserEmail,
1187
+ useUpdateUserPid,
1003
1188
  useUploadAnymalImage,
1004
- useVerifyAccount
1189
+ useVerifyAccount,
1190
+ useVerifyWeb3AuthSession
1005
1191
  });
package/dist/index.mjs CHANGED
@@ -564,9 +564,16 @@ function useVerifyAccount() {
564
564
  return useCallback(
565
565
  async (pid, dbAuthToken, bundlerClient, smartAccount, accountRewardsContractAddress) => {
566
566
  if (!dbAuthToken || !bundlerClient || !smartAccount || !accountRewardsContractAddress || !pid) {
567
+ console.log({
568
+ dbAuthToken,
569
+ bundlerClient,
570
+ smartAccount,
571
+ accountRewardsContractAddress,
572
+ pid
573
+ });
567
574
  return {
568
575
  success: false,
569
- message: "Missing authentication token OR NFT ID."
576
+ message: "Missing crucial information"
570
577
  };
571
578
  }
572
579
  const callData = encodeFunctionData({
@@ -599,11 +606,180 @@ function useVerifyAccount() {
599
606
  );
600
607
  }
601
608
 
609
+ // src/utils/account/useVerifyWeb3AuthSession.ts
610
+ import { useCallback as useCallback2 } from "react";
611
+ function useVerifyWeb3AuthSession() {
612
+ return useCallback2(
613
+ async (idToken, publicKey, authServiceBaseUrl) => {
614
+ const response = await fetch(
615
+ `${authServiceBaseUrl}/verify-web3-session`,
616
+ {
617
+ method: "POST",
618
+ headers: {
619
+ "Content-Type": "application/json",
620
+ Authorization: "Bearer " + idToken
621
+ },
622
+ body: JSON.stringify({ appPubKey: publicKey })
623
+ }
624
+ );
625
+ const { jwt } = await response.json();
626
+ return jwt;
627
+ },
628
+ []
629
+ );
630
+ }
631
+
632
+ // src/utils/account/useCreateWeb3Account.ts
633
+ import { useCallback as useCallback3 } from "react";
634
+ function useCreateWeb3Account() {
635
+ return useCallback3(
636
+ async (idToken, publicKey, authServiceBaseUrl) => {
637
+ try {
638
+ const response = await fetch(`${authServiceBaseUrl}/create-account`, {
639
+ method: "POST",
640
+ headers: {
641
+ "Content-Type": "application/json",
642
+ Authorization: "Bearer " + idToken
643
+ },
644
+ body: JSON.stringify({ appPubKey: publicKey })
645
+ });
646
+ return await response.json();
647
+ } catch (error) {
648
+ console.error(error);
649
+ return null;
650
+ }
651
+ },
652
+ []
653
+ );
654
+ }
655
+
656
+ // src/utils/account/useFetchUserData.ts
657
+ import { useCallback as useCallback4 } from "react";
658
+ function useFetchUserData() {
659
+ return useCallback4(async (dbAuthToken, endpoint) => {
660
+ try {
661
+ const query = `
662
+ query User {
663
+ User {
664
+ _docID
665
+ pid
666
+ email
667
+ isVerified
668
+ accountType
669
+ }
670
+ }
671
+ `;
672
+ const response = await fetch(endpoint, {
673
+ method: "POST",
674
+ headers: {
675
+ "Content-Type": "application/json",
676
+ Authorization: `Bearer ${dbAuthToken}`
677
+ },
678
+ body: JSON.stringify({ query })
679
+ });
680
+ if (!response.ok) {
681
+ throw new Error(`HTTP error! Status: ${response.status}`);
682
+ }
683
+ const data = await response.json();
684
+ if (data && data.data && data.data.User && data.data.User.length > 0) {
685
+ return data.data.User[0];
686
+ } else {
687
+ return null;
688
+ }
689
+ } catch (error) {
690
+ console.error("Error fetching user data:", error);
691
+ return null;
692
+ }
693
+ }, []);
694
+ }
695
+
696
+ // src/utils/account/useUpdateUserEmail.ts
697
+ import { useCallback as useCallback5 } from "react";
698
+ function useUpdateUserEmail() {
699
+ return useCallback5(
700
+ async (dbAuthToken, docID, email, endpoint) => {
701
+ try {
702
+ const mutation = `
703
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
704
+ update_User(docID: $docID, input: $input) {
705
+ email
706
+ }
707
+ }
708
+ `;
709
+ const variables = {
710
+ docId: [docID],
711
+ input: {
712
+ email
713
+ }
714
+ };
715
+ const response = await fetch(endpoint, {
716
+ method: "POST",
717
+ headers: {
718
+ "Content-Type": "application/json",
719
+ Authorization: `Bearer ${dbAuthToken}`
720
+ },
721
+ body: JSON.stringify({
722
+ query: mutation,
723
+ variables
724
+ })
725
+ });
726
+ if (!response.ok) {
727
+ throw new Error(`HTTP error! Status: ${response.status}`);
728
+ }
729
+ } catch (error) {
730
+ console.error("Error updating email:", error);
731
+ }
732
+ },
733
+ []
734
+ );
735
+ }
736
+
737
+ // src/utils/account/useUpdateUserPid.ts
738
+ import { useCallback as useCallback6 } from "react";
739
+ function useUpdateUserPid() {
740
+ return useCallback6(
741
+ async (dbAuthToken, docID, pid, endpoint) => {
742
+ try {
743
+ const mutation = `
744
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
745
+ update_User(docID: $docID, input: $input) {
746
+ pid
747
+ }
748
+ }
749
+ `;
750
+ const variables = {
751
+ docId: [docID],
752
+ input: {
753
+ pid
754
+ }
755
+ };
756
+ const response = await fetch(endpoint, {
757
+ method: "POST",
758
+ headers: {
759
+ "Content-Type": "application/json",
760
+ Authorization: `Bearer ${dbAuthToken}`
761
+ },
762
+ body: JSON.stringify({
763
+ query: mutation,
764
+ variables
765
+ })
766
+ });
767
+ if (!response.ok) {
768
+ throw new Error(`HTTP error! Status: ${response.status}`);
769
+ }
770
+ } catch (error) {
771
+ console.error("Error updating email:", error);
772
+ }
773
+ },
774
+ []
775
+ );
776
+ }
777
+
602
778
  // src/utils/anymals/useMintAnymalNFT.ts
603
779
  import { encodeFunctionData as encodeFunctionData2, parseGwei as parseGwei2 } from "viem";
604
- import { useCallback as useCallback2 } from "react";
780
+ import { useCallback as useCallback7 } from "react";
605
781
  function useMintAnymalNFT() {
606
- return useCallback2(
782
+ return useCallback7(
607
783
  async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
608
784
  if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
609
785
  return {
@@ -642,9 +818,9 @@ function useMintAnymalNFT() {
642
818
  }
643
819
 
644
820
  // src/utils/anymals/useAddAnymalToDatabase.ts
645
- import { useCallback as useCallback3 } from "react";
821
+ import { useCallback as useCallback8 } from "react";
646
822
  function useAddAnymalToDatabase() {
647
- return useCallback3(
823
+ return useCallback8(
648
824
  async (dbAuthToken, endpoint, anymalData) => {
649
825
  if (!dbAuthToken) {
650
826
  return {
@@ -709,9 +885,9 @@ function useAddAnymalToDatabase() {
709
885
  }
710
886
 
711
887
  // src/utils/anymals/useDeleteAnymalFromDatabase.ts
712
- import { useCallback as useCallback4 } from "react";
888
+ import { useCallback as useCallback9 } from "react";
713
889
  function useDeleteAnymalFromDatabase() {
714
- return useCallback4(
890
+ return useCallback9(
715
891
  async (dbAuthToken, endpoint, anymalDocID) => {
716
892
  if (!dbAuthToken || !endpoint || !anymalDocID) return;
717
893
  try {
@@ -749,9 +925,9 @@ function useDeleteAnymalFromDatabase() {
749
925
  }
750
926
 
751
927
  // src/utils/anymals/useSaveAnymalMetadata.ts
752
- import { useCallback as useCallback5 } from "react";
928
+ import { useCallback as useCallback10 } from "react";
753
929
  function useSaveAnymalMetadata() {
754
- return useCallback5(
930
+ return useCallback10(
755
931
  async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
756
932
  const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
757
933
  method: "POST",
@@ -778,9 +954,9 @@ function useSaveAnymalMetadata() {
778
954
  }
779
955
 
780
956
  // src/utils/anymals/useUpdateAnymalWithNFT.ts
781
- import { useCallback as useCallback6 } from "react";
957
+ import { useCallback as useCallback11 } from "react";
782
958
  function useUpdateAnymalWithNFT() {
783
- return useCallback6(
959
+ return useCallback11(
784
960
  async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
785
961
  if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
786
962
  return {
@@ -826,30 +1002,8 @@ function useUpdateAnymalWithNFT() {
826
1002
  );
827
1003
  }
828
1004
 
829
- // src/utils/balance/useFetchBalance.ts
830
- import { useCallback as useCallback7 } from "react";
831
- import { erc20Abi, getAddress } from "viem";
832
- function useFetchBalance() {
833
- return useCallback7(
834
- async (publicClient, walletAddress, kibbleTokenAddress) => {
835
- try {
836
- const balance = await publicClient.readContract({
837
- address: getAddress(kibbleTokenAddress),
838
- abi: erc20Abi,
839
- functionName: "balanceOf",
840
- args: [getAddress(walletAddress)]
841
- });
842
- return Number(balance);
843
- } catch (error) {
844
- console.error("Failed to fetch token balance:", error);
845
- }
846
- },
847
- []
848
- );
849
- }
850
-
851
1005
  // src/utils/anymals/useUploadAnymalImage.ts
852
- import { useCallback as useCallback8 } from "react";
1006
+ import { useCallback as useCallback12 } from "react";
853
1007
 
854
1008
  // src/helpers/UploadImageHelper.tsx
855
1009
  function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
@@ -906,7 +1060,7 @@ function toBase64(file) {
906
1060
 
907
1061
  // src/utils/anymals/useUploadAnymalImage.ts
908
1062
  function useUploadAnymalImage() {
909
- return useCallback8(
1063
+ return useCallback12(
910
1064
  async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
911
1065
  if (!imageFile || !idToken) {
912
1066
  return {
@@ -959,13 +1113,40 @@ function useUploadAnymalImage() {
959
1113
  []
960
1114
  );
961
1115
  }
1116
+
1117
+ // src/utils/balance/useFetchBalance.ts
1118
+ import { useCallback as useCallback13 } from "react";
1119
+ import { erc20Abi, getAddress } from "viem";
1120
+ function useFetchBalance() {
1121
+ return useCallback13(
1122
+ async (publicClient, walletAddress, kibbleTokenAddress) => {
1123
+ try {
1124
+ const balance = await publicClient.readContract({
1125
+ address: getAddress(kibbleTokenAddress),
1126
+ abi: erc20Abi,
1127
+ functionName: "balanceOf",
1128
+ args: [getAddress(walletAddress)]
1129
+ });
1130
+ return Number(balance);
1131
+ } catch (error) {
1132
+ console.error("Failed to fetch token balance:", error);
1133
+ }
1134
+ },
1135
+ []
1136
+ );
1137
+ }
962
1138
  export {
963
1139
  useAddAnymalToDatabase,
1140
+ useCreateWeb3Account,
964
1141
  useDeleteAnymalFromDatabase,
965
1142
  useFetchBalance,
1143
+ useFetchUserData,
966
1144
  useMintAnymalNFT,
967
1145
  useSaveAnymalMetadata,
968
1146
  useUpdateAnymalWithNFT,
1147
+ useUpdateUserEmail,
1148
+ useUpdateUserPid,
969
1149
  useUploadAnymalImage,
970
- useVerifyAccount
1150
+ useVerifyAccount,
1151
+ useVerifyWeb3AuthSession
971
1152
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
package/src/index.ts CHANGED
@@ -1,9 +1,16 @@
1
1
  export * from "./utils/account/useVerifyAccount";
2
+ export * from "./utils/account/useVerifyWeb3AuthSession";
3
+ export * from "./utils/account/useCreateWeb3Account";
4
+ export * from "./utils/account/useFetchUserData";
5
+ export * from "./utils/account/useUpdateUserEmail";
6
+ export * from "./utils/account/useUpdateUserPid";
7
+
2
8
  export * from "./utils/anymals/useMintAnymalNFT";
3
9
  export * from "./utils/anymals/useAddAnymalToDatabase";
4
10
  export * from "./utils/anymals/useDeleteAnymalFromDatabase";
5
11
  export * from "./utils/anymals/useSaveAnymalMetadata";
6
12
  export * from "./utils/anymals/useUpdateAnymalWithNFT";
7
- export * from "./utils/balance/useFetchBalance";
8
13
  export * from "./utils/anymals/useUploadAnymalImage";
14
+
15
+ export * from "./utils/balance/useFetchBalance";
9
16
  export * from "./types/Anymal";
@@ -0,0 +1,24 @@
1
+ import { useCallback } from "react";
2
+
3
+ export function useCreateWeb3Account() {
4
+ return useCallback(
5
+ async (idToken: string, publicKey: string, authServiceBaseUrl: string) => {
6
+ try {
7
+ const response = await fetch(`${authServiceBaseUrl}/create-account`, {
8
+ method: "POST",
9
+ headers: {
10
+ "Content-Type": "application/json",
11
+ Authorization: "Bearer " + idToken,
12
+ },
13
+ body: JSON.stringify({ appPubKey: publicKey }),
14
+ });
15
+
16
+ return await response.json();
17
+ } catch (error) {
18
+ console.error(error);
19
+ return null;
20
+ }
21
+ },
22
+ []
23
+ );
24
+ }
@@ -0,0 +1,43 @@
1
+ import { useCallback } from "react";
2
+
3
+ export function useFetchUserData() {
4
+ return useCallback(async (dbAuthToken: string, endpoint: string) => {
5
+ try {
6
+ const query = `
7
+ query User {
8
+ User {
9
+ _docID
10
+ pid
11
+ email
12
+ isVerified
13
+ accountType
14
+ }
15
+ }
16
+ `;
17
+
18
+ const response = await fetch(endpoint, {
19
+ method: "POST",
20
+ headers: {
21
+ "Content-Type": "application/json",
22
+ Authorization: `Bearer ${dbAuthToken}`,
23
+ },
24
+ body: JSON.stringify({ query }),
25
+ });
26
+
27
+ if (!response.ok) {
28
+ throw new Error(`HTTP error! Status: ${response.status}`);
29
+ }
30
+
31
+ const data = await response.json();
32
+
33
+ if (data && data.data && data.data.User && data.data.User.length > 0) {
34
+ return data.data.User[0];
35
+ } else {
36
+ return null;
37
+ }
38
+ } catch (error) {
39
+ console.error("Error fetching user data:", error);
40
+ return null;
41
+ }
42
+ }, []);
43
+ }
@@ -0,0 +1,48 @@
1
+ import { useCallback } from "react";
2
+
3
+ export function useUpdateUserEmail() {
4
+ return useCallback(
5
+ async (
6
+ dbAuthToken: string,
7
+ docID: string,
8
+ email: string,
9
+ endpoint: string
10
+ ) => {
11
+ try {
12
+ const mutation = `
13
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
14
+ update_User(docID: $docID, input: $input) {
15
+ email
16
+ }
17
+ }
18
+ `;
19
+
20
+ const variables = {
21
+ docId: [docID],
22
+ input: {
23
+ email: email,
24
+ },
25
+ };
26
+
27
+ const response = await fetch(endpoint, {
28
+ method: "POST",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ Authorization: `Bearer ${dbAuthToken}`,
32
+ },
33
+ body: JSON.stringify({
34
+ query: mutation,
35
+ variables,
36
+ }),
37
+ });
38
+
39
+ if (!response.ok) {
40
+ throw new Error(`HTTP error! Status: ${response.status}`);
41
+ }
42
+ } catch (error) {
43
+ console.error("Error updating email:", error);
44
+ }
45
+ },
46
+ []
47
+ );
48
+ }
@@ -0,0 +1,48 @@
1
+ import { useCallback } from "react";
2
+
3
+ export function useUpdateUserPid() {
4
+ return useCallback(
5
+ async (
6
+ dbAuthToken: string,
7
+ docID: string,
8
+ pid: string,
9
+ endpoint: string
10
+ ) => {
11
+ try {
12
+ const mutation = `
13
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
14
+ update_User(docID: $docID, input: $input) {
15
+ pid
16
+ }
17
+ }
18
+ `;
19
+
20
+ const variables = {
21
+ docId: [docID],
22
+ input: {
23
+ pid: pid,
24
+ },
25
+ };
26
+
27
+ const response = await fetch(endpoint, {
28
+ method: "POST",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ Authorization: `Bearer ${dbAuthToken}`,
32
+ },
33
+ body: JSON.stringify({
34
+ query: mutation,
35
+ variables,
36
+ }),
37
+ });
38
+
39
+ if (!response.ok) {
40
+ throw new Error(`HTTP error! Status: ${response.status}`);
41
+ }
42
+ } catch (error) {
43
+ console.error("Error updating email:", error);
44
+ }
45
+ },
46
+ []
47
+ );
48
+ }
@@ -21,9 +21,16 @@ export function useVerifyAccount() {
21
21
  !accountRewardsContractAddress ||
22
22
  !pid
23
23
  ) {
24
+ console.log({
25
+ dbAuthToken,
26
+ bundlerClient,
27
+ smartAccount,
28
+ accountRewardsContractAddress,
29
+ pid,
30
+ });
24
31
  return {
25
32
  success: false,
26
- message: "Missing authentication token OR NFT ID.",
33
+ message: "Missing crucial information",
27
34
  };
28
35
  }
29
36
 
@@ -0,0 +1,24 @@
1
+ import { useCallback } from "react";
2
+
3
+ export function useVerifyWeb3AuthSession() {
4
+ return useCallback(
5
+ async (idToken: string, publicKey: string, authServiceBaseUrl: string) => {
6
+ const response = await fetch(
7
+ `${authServiceBaseUrl}/verify-web3-session`,
8
+ {
9
+ method: "POST",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ Authorization: "Bearer " + idToken,
13
+ },
14
+ body: JSON.stringify({ appPubKey: publicKey }),
15
+ }
16
+ );
17
+
18
+ const { jwt } = await response.json();
19
+
20
+ return jwt;
21
+ },
22
+ []
23
+ );
24
+ }