anymal-protocol 1.0.4 → 1.0.5
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 +13 -3
- package/dist/index.d.ts +13 -3
- package/dist/index.js +215 -36
- package/dist/index.mjs +209 -35
- package/package.json +1 -1
- package/src/index.ts +8 -1
- package/src/utils/account/useCreateWeb3Account.ts +24 -0
- package/src/utils/account/useFetchUserData.ts +43 -0
- package/src/utils/account/useUpdateUserEmail.ts +48 -0
- package/src/utils/account/useUpdateUserPid.ts +48 -0
- package/src/utils/account/useVerifyWeb3AuthSession.ts +24 -0
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -632,11 +637,180 @@ function useVerifyAccount() {
|
|
|
632
637
|
);
|
|
633
638
|
}
|
|
634
639
|
|
|
640
|
+
// src/utils/account/useVerifyWeb3AuthSession.ts
|
|
641
|
+
var import_react2 = require("react");
|
|
642
|
+
function useVerifyWeb3AuthSession() {
|
|
643
|
+
return (0, import_react2.useCallback)(
|
|
644
|
+
async (idToken, publicKey, authServiceBaseUrl) => {
|
|
645
|
+
const response = await fetch(
|
|
646
|
+
`${authServiceBaseUrl}/verify-web3-session`,
|
|
647
|
+
{
|
|
648
|
+
method: "POST",
|
|
649
|
+
headers: {
|
|
650
|
+
"Content-Type": "application/json",
|
|
651
|
+
Authorization: "Bearer " + idToken
|
|
652
|
+
},
|
|
653
|
+
body: JSON.stringify({ appPubKey: publicKey })
|
|
654
|
+
}
|
|
655
|
+
);
|
|
656
|
+
const { jwt } = await response.json();
|
|
657
|
+
return jwt;
|
|
658
|
+
},
|
|
659
|
+
[]
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// src/utils/account/useCreateWeb3Account.ts
|
|
664
|
+
var import_react3 = require("react");
|
|
665
|
+
function useCreateWeb3Account() {
|
|
666
|
+
return (0, import_react3.useCallback)(
|
|
667
|
+
async (idToken, publicKey, authServiceBaseUrl) => {
|
|
668
|
+
try {
|
|
669
|
+
const response = await fetch(`${authServiceBaseUrl}/create-account`, {
|
|
670
|
+
method: "POST",
|
|
671
|
+
headers: {
|
|
672
|
+
"Content-Type": "application/json",
|
|
673
|
+
Authorization: "Bearer " + idToken
|
|
674
|
+
},
|
|
675
|
+
body: JSON.stringify({ appPubKey: publicKey })
|
|
676
|
+
});
|
|
677
|
+
return await response.json();
|
|
678
|
+
} catch (error) {
|
|
679
|
+
console.error(error);
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
[]
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// src/utils/account/useFetchUserData.ts
|
|
688
|
+
var import_react4 = require("react");
|
|
689
|
+
function useFetchUserData() {
|
|
690
|
+
return (0, import_react4.useCallback)(async (dbAuthToken, endpoint) => {
|
|
691
|
+
try {
|
|
692
|
+
const query = `
|
|
693
|
+
query User {
|
|
694
|
+
User {
|
|
695
|
+
_docID
|
|
696
|
+
pid
|
|
697
|
+
email
|
|
698
|
+
isVerified
|
|
699
|
+
accountType
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
`;
|
|
703
|
+
const response = await fetch(endpoint, {
|
|
704
|
+
method: "POST",
|
|
705
|
+
headers: {
|
|
706
|
+
"Content-Type": "application/json",
|
|
707
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
708
|
+
},
|
|
709
|
+
body: JSON.stringify({ query })
|
|
710
|
+
});
|
|
711
|
+
if (!response.ok) {
|
|
712
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
713
|
+
}
|
|
714
|
+
const data = await response.json();
|
|
715
|
+
if (data && data.data && data.data.User && data.data.User.length > 0) {
|
|
716
|
+
return data.data.User[0];
|
|
717
|
+
} else {
|
|
718
|
+
return null;
|
|
719
|
+
}
|
|
720
|
+
} catch (error) {
|
|
721
|
+
console.error("Error fetching user data:", error);
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
}, []);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// src/utils/account/useUpdateUserEmail.ts
|
|
728
|
+
var import_react5 = require("react");
|
|
729
|
+
function useUpdateUserEmail() {
|
|
730
|
+
return (0, import_react5.useCallback)(
|
|
731
|
+
async (dbAuthToken, docID, email, endpoint) => {
|
|
732
|
+
try {
|
|
733
|
+
const mutation = `
|
|
734
|
+
mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
|
|
735
|
+
update_User(docID: $docID, input: $input) {
|
|
736
|
+
email
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
`;
|
|
740
|
+
const variables = {
|
|
741
|
+
docId: [docID],
|
|
742
|
+
input: {
|
|
743
|
+
email
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
const response = await fetch(endpoint, {
|
|
747
|
+
method: "POST",
|
|
748
|
+
headers: {
|
|
749
|
+
"Content-Type": "application/json",
|
|
750
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
751
|
+
},
|
|
752
|
+
body: JSON.stringify({
|
|
753
|
+
query: mutation,
|
|
754
|
+
variables
|
|
755
|
+
})
|
|
756
|
+
});
|
|
757
|
+
if (!response.ok) {
|
|
758
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
759
|
+
}
|
|
760
|
+
} catch (error) {
|
|
761
|
+
console.error("Error updating email:", error);
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
[]
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/utils/account/useUpdateUserPid.ts
|
|
769
|
+
var import_react6 = require("react");
|
|
770
|
+
function useUpdateUserPid() {
|
|
771
|
+
return (0, import_react6.useCallback)(
|
|
772
|
+
async (dbAuthToken, docID, pid, endpoint) => {
|
|
773
|
+
try {
|
|
774
|
+
const mutation = `
|
|
775
|
+
mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
|
|
776
|
+
update_User(docID: $docID, input: $input) {
|
|
777
|
+
pid
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
`;
|
|
781
|
+
const variables = {
|
|
782
|
+
docId: [docID],
|
|
783
|
+
input: {
|
|
784
|
+
pid
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
const response = await fetch(endpoint, {
|
|
788
|
+
method: "POST",
|
|
789
|
+
headers: {
|
|
790
|
+
"Content-Type": "application/json",
|
|
791
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
792
|
+
},
|
|
793
|
+
body: JSON.stringify({
|
|
794
|
+
query: mutation,
|
|
795
|
+
variables
|
|
796
|
+
})
|
|
797
|
+
});
|
|
798
|
+
if (!response.ok) {
|
|
799
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
800
|
+
}
|
|
801
|
+
} catch (error) {
|
|
802
|
+
console.error("Error updating email:", error);
|
|
803
|
+
}
|
|
804
|
+
},
|
|
805
|
+
[]
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
|
|
635
809
|
// src/utils/anymals/useMintAnymalNFT.ts
|
|
636
810
|
var import_viem2 = require("viem");
|
|
637
|
-
var
|
|
811
|
+
var import_react7 = require("react");
|
|
638
812
|
function useMintAnymalNFT() {
|
|
639
|
-
return (0,
|
|
813
|
+
return (0, import_react7.useCallback)(
|
|
640
814
|
async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
|
|
641
815
|
if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
|
|
642
816
|
return {
|
|
@@ -675,9 +849,9 @@ function useMintAnymalNFT() {
|
|
|
675
849
|
}
|
|
676
850
|
|
|
677
851
|
// src/utils/anymals/useAddAnymalToDatabase.ts
|
|
678
|
-
var
|
|
852
|
+
var import_react8 = require("react");
|
|
679
853
|
function useAddAnymalToDatabase() {
|
|
680
|
-
return (0,
|
|
854
|
+
return (0, import_react8.useCallback)(
|
|
681
855
|
async (dbAuthToken, endpoint, anymalData) => {
|
|
682
856
|
if (!dbAuthToken) {
|
|
683
857
|
return {
|
|
@@ -742,9 +916,9 @@ function useAddAnymalToDatabase() {
|
|
|
742
916
|
}
|
|
743
917
|
|
|
744
918
|
// src/utils/anymals/useDeleteAnymalFromDatabase.ts
|
|
745
|
-
var
|
|
919
|
+
var import_react9 = require("react");
|
|
746
920
|
function useDeleteAnymalFromDatabase() {
|
|
747
|
-
return (0,
|
|
921
|
+
return (0, import_react9.useCallback)(
|
|
748
922
|
async (dbAuthToken, endpoint, anymalDocID) => {
|
|
749
923
|
if (!dbAuthToken || !endpoint || !anymalDocID) return;
|
|
750
924
|
try {
|
|
@@ -782,9 +956,9 @@ function useDeleteAnymalFromDatabase() {
|
|
|
782
956
|
}
|
|
783
957
|
|
|
784
958
|
// src/utils/anymals/useSaveAnymalMetadata.ts
|
|
785
|
-
var
|
|
959
|
+
var import_react10 = require("react");
|
|
786
960
|
function useSaveAnymalMetadata() {
|
|
787
|
-
return (0,
|
|
961
|
+
return (0, import_react10.useCallback)(
|
|
788
962
|
async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
|
|
789
963
|
const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
|
|
790
964
|
method: "POST",
|
|
@@ -811,9 +985,9 @@ function useSaveAnymalMetadata() {
|
|
|
811
985
|
}
|
|
812
986
|
|
|
813
987
|
// src/utils/anymals/useUpdateAnymalWithNFT.ts
|
|
814
|
-
var
|
|
988
|
+
var import_react11 = require("react");
|
|
815
989
|
function useUpdateAnymalWithNFT() {
|
|
816
|
-
return (0,
|
|
990
|
+
return (0, import_react11.useCallback)(
|
|
817
991
|
async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
|
|
818
992
|
if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
|
|
819
993
|
return {
|
|
@@ -859,30 +1033,8 @@ function useUpdateAnymalWithNFT() {
|
|
|
859
1033
|
);
|
|
860
1034
|
}
|
|
861
1035
|
|
|
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
1036
|
// src/utils/anymals/useUploadAnymalImage.ts
|
|
885
|
-
var
|
|
1037
|
+
var import_react12 = require("react");
|
|
886
1038
|
|
|
887
1039
|
// src/helpers/UploadImageHelper.tsx
|
|
888
1040
|
function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
|
|
@@ -939,7 +1091,7 @@ function toBase64(file) {
|
|
|
939
1091
|
|
|
940
1092
|
// src/utils/anymals/useUploadAnymalImage.ts
|
|
941
1093
|
function useUploadAnymalImage() {
|
|
942
|
-
return (0,
|
|
1094
|
+
return (0, import_react12.useCallback)(
|
|
943
1095
|
async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
|
|
944
1096
|
if (!imageFile || !idToken) {
|
|
945
1097
|
return {
|
|
@@ -992,14 +1144,41 @@ function useUploadAnymalImage() {
|
|
|
992
1144
|
[]
|
|
993
1145
|
);
|
|
994
1146
|
}
|
|
1147
|
+
|
|
1148
|
+
// src/utils/balance/useFetchBalance.ts
|
|
1149
|
+
var import_react13 = require("react");
|
|
1150
|
+
var import_viem3 = require("viem");
|
|
1151
|
+
function useFetchBalance() {
|
|
1152
|
+
return (0, import_react13.useCallback)(
|
|
1153
|
+
async (publicClient, walletAddress, kibbleTokenAddress) => {
|
|
1154
|
+
try {
|
|
1155
|
+
const balance = await publicClient.readContract({
|
|
1156
|
+
address: (0, import_viem3.getAddress)(kibbleTokenAddress),
|
|
1157
|
+
abi: import_viem3.erc20Abi,
|
|
1158
|
+
functionName: "balanceOf",
|
|
1159
|
+
args: [(0, import_viem3.getAddress)(walletAddress)]
|
|
1160
|
+
});
|
|
1161
|
+
return Number(balance);
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
console.error("Failed to fetch token balance:", error);
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
[]
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
995
1169
|
// Annotate the CommonJS export names for ESM import in node:
|
|
996
1170
|
0 && (module.exports = {
|
|
997
1171
|
useAddAnymalToDatabase,
|
|
1172
|
+
useCreateWeb3Account,
|
|
998
1173
|
useDeleteAnymalFromDatabase,
|
|
999
1174
|
useFetchBalance,
|
|
1175
|
+
useFetchUserData,
|
|
1000
1176
|
useMintAnymalNFT,
|
|
1001
1177
|
useSaveAnymalMetadata,
|
|
1002
1178
|
useUpdateAnymalWithNFT,
|
|
1179
|
+
useUpdateUserEmail,
|
|
1180
|
+
useUpdateUserPid,
|
|
1003
1181
|
useUploadAnymalImage,
|
|
1004
|
-
useVerifyAccount
|
|
1182
|
+
useVerifyAccount,
|
|
1183
|
+
useVerifyWeb3AuthSession
|
|
1005
1184
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -599,11 +599,180 @@ function useVerifyAccount() {
|
|
|
599
599
|
);
|
|
600
600
|
}
|
|
601
601
|
|
|
602
|
+
// src/utils/account/useVerifyWeb3AuthSession.ts
|
|
603
|
+
import { useCallback as useCallback2 } from "react";
|
|
604
|
+
function useVerifyWeb3AuthSession() {
|
|
605
|
+
return useCallback2(
|
|
606
|
+
async (idToken, publicKey, authServiceBaseUrl) => {
|
|
607
|
+
const response = await fetch(
|
|
608
|
+
`${authServiceBaseUrl}/verify-web3-session`,
|
|
609
|
+
{
|
|
610
|
+
method: "POST",
|
|
611
|
+
headers: {
|
|
612
|
+
"Content-Type": "application/json",
|
|
613
|
+
Authorization: "Bearer " + idToken
|
|
614
|
+
},
|
|
615
|
+
body: JSON.stringify({ appPubKey: publicKey })
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
const { jwt } = await response.json();
|
|
619
|
+
return jwt;
|
|
620
|
+
},
|
|
621
|
+
[]
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// src/utils/account/useCreateWeb3Account.ts
|
|
626
|
+
import { useCallback as useCallback3 } from "react";
|
|
627
|
+
function useCreateWeb3Account() {
|
|
628
|
+
return useCallback3(
|
|
629
|
+
async (idToken, publicKey, authServiceBaseUrl) => {
|
|
630
|
+
try {
|
|
631
|
+
const response = await fetch(`${authServiceBaseUrl}/create-account`, {
|
|
632
|
+
method: "POST",
|
|
633
|
+
headers: {
|
|
634
|
+
"Content-Type": "application/json",
|
|
635
|
+
Authorization: "Bearer " + idToken
|
|
636
|
+
},
|
|
637
|
+
body: JSON.stringify({ appPubKey: publicKey })
|
|
638
|
+
});
|
|
639
|
+
return await response.json();
|
|
640
|
+
} catch (error) {
|
|
641
|
+
console.error(error);
|
|
642
|
+
return null;
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
[]
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// src/utils/account/useFetchUserData.ts
|
|
650
|
+
import { useCallback as useCallback4 } from "react";
|
|
651
|
+
function useFetchUserData() {
|
|
652
|
+
return useCallback4(async (dbAuthToken, endpoint) => {
|
|
653
|
+
try {
|
|
654
|
+
const query = `
|
|
655
|
+
query User {
|
|
656
|
+
User {
|
|
657
|
+
_docID
|
|
658
|
+
pid
|
|
659
|
+
email
|
|
660
|
+
isVerified
|
|
661
|
+
accountType
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
`;
|
|
665
|
+
const response = await fetch(endpoint, {
|
|
666
|
+
method: "POST",
|
|
667
|
+
headers: {
|
|
668
|
+
"Content-Type": "application/json",
|
|
669
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
670
|
+
},
|
|
671
|
+
body: JSON.stringify({ query })
|
|
672
|
+
});
|
|
673
|
+
if (!response.ok) {
|
|
674
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
675
|
+
}
|
|
676
|
+
const data = await response.json();
|
|
677
|
+
if (data && data.data && data.data.User && data.data.User.length > 0) {
|
|
678
|
+
return data.data.User[0];
|
|
679
|
+
} else {
|
|
680
|
+
return null;
|
|
681
|
+
}
|
|
682
|
+
} catch (error) {
|
|
683
|
+
console.error("Error fetching user data:", error);
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
}, []);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/utils/account/useUpdateUserEmail.ts
|
|
690
|
+
import { useCallback as useCallback5 } from "react";
|
|
691
|
+
function useUpdateUserEmail() {
|
|
692
|
+
return useCallback5(
|
|
693
|
+
async (dbAuthToken, docID, email, endpoint) => {
|
|
694
|
+
try {
|
|
695
|
+
const mutation = `
|
|
696
|
+
mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
|
|
697
|
+
update_User(docID: $docID, input: $input) {
|
|
698
|
+
email
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
`;
|
|
702
|
+
const variables = {
|
|
703
|
+
docId: [docID],
|
|
704
|
+
input: {
|
|
705
|
+
email
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
const response = await fetch(endpoint, {
|
|
709
|
+
method: "POST",
|
|
710
|
+
headers: {
|
|
711
|
+
"Content-Type": "application/json",
|
|
712
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
713
|
+
},
|
|
714
|
+
body: JSON.stringify({
|
|
715
|
+
query: mutation,
|
|
716
|
+
variables
|
|
717
|
+
})
|
|
718
|
+
});
|
|
719
|
+
if (!response.ok) {
|
|
720
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
721
|
+
}
|
|
722
|
+
} catch (error) {
|
|
723
|
+
console.error("Error updating email:", error);
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
[]
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
// src/utils/account/useUpdateUserPid.ts
|
|
731
|
+
import { useCallback as useCallback6 } from "react";
|
|
732
|
+
function useUpdateUserPid() {
|
|
733
|
+
return useCallback6(
|
|
734
|
+
async (dbAuthToken, docID, pid, endpoint) => {
|
|
735
|
+
try {
|
|
736
|
+
const mutation = `
|
|
737
|
+
mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
|
|
738
|
+
update_User(docID: $docID, input: $input) {
|
|
739
|
+
pid
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
`;
|
|
743
|
+
const variables = {
|
|
744
|
+
docId: [docID],
|
|
745
|
+
input: {
|
|
746
|
+
pid
|
|
747
|
+
}
|
|
748
|
+
};
|
|
749
|
+
const response = await fetch(endpoint, {
|
|
750
|
+
method: "POST",
|
|
751
|
+
headers: {
|
|
752
|
+
"Content-Type": "application/json",
|
|
753
|
+
Authorization: `Bearer ${dbAuthToken}`
|
|
754
|
+
},
|
|
755
|
+
body: JSON.stringify({
|
|
756
|
+
query: mutation,
|
|
757
|
+
variables
|
|
758
|
+
})
|
|
759
|
+
});
|
|
760
|
+
if (!response.ok) {
|
|
761
|
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
762
|
+
}
|
|
763
|
+
} catch (error) {
|
|
764
|
+
console.error("Error updating email:", error);
|
|
765
|
+
}
|
|
766
|
+
},
|
|
767
|
+
[]
|
|
768
|
+
);
|
|
769
|
+
}
|
|
770
|
+
|
|
602
771
|
// src/utils/anymals/useMintAnymalNFT.ts
|
|
603
772
|
import { encodeFunctionData as encodeFunctionData2, parseGwei as parseGwei2 } from "viem";
|
|
604
|
-
import { useCallback as
|
|
773
|
+
import { useCallback as useCallback7 } from "react";
|
|
605
774
|
function useMintAnymalNFT() {
|
|
606
|
-
return
|
|
775
|
+
return useCallback7(
|
|
607
776
|
async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
|
|
608
777
|
if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
|
|
609
778
|
return {
|
|
@@ -642,9 +811,9 @@ function useMintAnymalNFT() {
|
|
|
642
811
|
}
|
|
643
812
|
|
|
644
813
|
// src/utils/anymals/useAddAnymalToDatabase.ts
|
|
645
|
-
import { useCallback as
|
|
814
|
+
import { useCallback as useCallback8 } from "react";
|
|
646
815
|
function useAddAnymalToDatabase() {
|
|
647
|
-
return
|
|
816
|
+
return useCallback8(
|
|
648
817
|
async (dbAuthToken, endpoint, anymalData) => {
|
|
649
818
|
if (!dbAuthToken) {
|
|
650
819
|
return {
|
|
@@ -709,9 +878,9 @@ function useAddAnymalToDatabase() {
|
|
|
709
878
|
}
|
|
710
879
|
|
|
711
880
|
// src/utils/anymals/useDeleteAnymalFromDatabase.ts
|
|
712
|
-
import { useCallback as
|
|
881
|
+
import { useCallback as useCallback9 } from "react";
|
|
713
882
|
function useDeleteAnymalFromDatabase() {
|
|
714
|
-
return
|
|
883
|
+
return useCallback9(
|
|
715
884
|
async (dbAuthToken, endpoint, anymalDocID) => {
|
|
716
885
|
if (!dbAuthToken || !endpoint || !anymalDocID) return;
|
|
717
886
|
try {
|
|
@@ -749,9 +918,9 @@ function useDeleteAnymalFromDatabase() {
|
|
|
749
918
|
}
|
|
750
919
|
|
|
751
920
|
// src/utils/anymals/useSaveAnymalMetadata.ts
|
|
752
|
-
import { useCallback as
|
|
921
|
+
import { useCallback as useCallback10 } from "react";
|
|
753
922
|
function useSaveAnymalMetadata() {
|
|
754
|
-
return
|
|
923
|
+
return useCallback10(
|
|
755
924
|
async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
|
|
756
925
|
const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
|
|
757
926
|
method: "POST",
|
|
@@ -778,9 +947,9 @@ function useSaveAnymalMetadata() {
|
|
|
778
947
|
}
|
|
779
948
|
|
|
780
949
|
// src/utils/anymals/useUpdateAnymalWithNFT.ts
|
|
781
|
-
import { useCallback as
|
|
950
|
+
import { useCallback as useCallback11 } from "react";
|
|
782
951
|
function useUpdateAnymalWithNFT() {
|
|
783
|
-
return
|
|
952
|
+
return useCallback11(
|
|
784
953
|
async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
|
|
785
954
|
if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
|
|
786
955
|
return {
|
|
@@ -826,30 +995,8 @@ function useUpdateAnymalWithNFT() {
|
|
|
826
995
|
);
|
|
827
996
|
}
|
|
828
997
|
|
|
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
998
|
// src/utils/anymals/useUploadAnymalImage.ts
|
|
852
|
-
import { useCallback as
|
|
999
|
+
import { useCallback as useCallback12 } from "react";
|
|
853
1000
|
|
|
854
1001
|
// src/helpers/UploadImageHelper.tsx
|
|
855
1002
|
function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
|
|
@@ -906,7 +1053,7 @@ function toBase64(file) {
|
|
|
906
1053
|
|
|
907
1054
|
// src/utils/anymals/useUploadAnymalImage.ts
|
|
908
1055
|
function useUploadAnymalImage() {
|
|
909
|
-
return
|
|
1056
|
+
return useCallback12(
|
|
910
1057
|
async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
|
|
911
1058
|
if (!imageFile || !idToken) {
|
|
912
1059
|
return {
|
|
@@ -959,13 +1106,40 @@ function useUploadAnymalImage() {
|
|
|
959
1106
|
[]
|
|
960
1107
|
);
|
|
961
1108
|
}
|
|
1109
|
+
|
|
1110
|
+
// src/utils/balance/useFetchBalance.ts
|
|
1111
|
+
import { useCallback as useCallback13 } from "react";
|
|
1112
|
+
import { erc20Abi, getAddress } from "viem";
|
|
1113
|
+
function useFetchBalance() {
|
|
1114
|
+
return useCallback13(
|
|
1115
|
+
async (publicClient, walletAddress, kibbleTokenAddress) => {
|
|
1116
|
+
try {
|
|
1117
|
+
const balance = await publicClient.readContract({
|
|
1118
|
+
address: getAddress(kibbleTokenAddress),
|
|
1119
|
+
abi: erc20Abi,
|
|
1120
|
+
functionName: "balanceOf",
|
|
1121
|
+
args: [getAddress(walletAddress)]
|
|
1122
|
+
});
|
|
1123
|
+
return Number(balance);
|
|
1124
|
+
} catch (error) {
|
|
1125
|
+
console.error("Failed to fetch token balance:", error);
|
|
1126
|
+
}
|
|
1127
|
+
},
|
|
1128
|
+
[]
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
962
1131
|
export {
|
|
963
1132
|
useAddAnymalToDatabase,
|
|
1133
|
+
useCreateWeb3Account,
|
|
964
1134
|
useDeleteAnymalFromDatabase,
|
|
965
1135
|
useFetchBalance,
|
|
1136
|
+
useFetchUserData,
|
|
966
1137
|
useMintAnymalNFT,
|
|
967
1138
|
useSaveAnymalMetadata,
|
|
968
1139
|
useUpdateAnymalWithNFT,
|
|
1140
|
+
useUpdateUserEmail,
|
|
1141
|
+
useUpdateUserPid,
|
|
969
1142
|
useUploadAnymalImage,
|
|
970
|
-
useVerifyAccount
|
|
1143
|
+
useVerifyAccount,
|
|
1144
|
+
useVerifyWeb3AuthSession
|
|
971
1145
|
};
|
package/package.json
CHANGED
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
|
+
}
|
|
@@ -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
|
+
}
|