anymal-protocol 1.0.9 → 1.0.11

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
@@ -18,6 +18,10 @@ declare function useUpdateUserAsVerified(): (recaptchaToken: string | null, docI
18
18
  message: string;
19
19
  } | undefined>;
20
20
 
21
+ declare function useUpdateUserName(): (dbAuthToken: string, docID: string, name: string, endpoint: string) => Promise<{
22
+ success: boolean;
23
+ }>;
24
+
21
25
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
22
26
  success: boolean;
23
27
  message: string;
@@ -58,4 +62,4 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
58
62
 
59
63
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
60
64
 
61
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
65
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -18,6 +18,10 @@ declare function useUpdateUserAsVerified(): (recaptchaToken: string | null, docI
18
18
  message: string;
19
19
  } | undefined>;
20
20
 
21
+ declare function useUpdateUserName(): (dbAuthToken: string, docID: string, name: string, endpoint: string) => Promise<{
22
+ success: boolean;
23
+ }>;
24
+
21
25
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
22
26
  success: boolean;
23
27
  message: string;
@@ -58,4 +62,4 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
58
62
 
59
63
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
60
64
 
61
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
65
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ __export(index_exports, {
30
30
  useUpdateAnymalWithNFT: () => useUpdateAnymalWithNFT,
31
31
  useUpdateUserAsVerified: () => useUpdateUserAsVerified,
32
32
  useUpdateUserEmail: () => useUpdateUserEmail,
33
+ useUpdateUserName: () => useUpdateUserName,
33
34
  useUpdateUserPid: () => useUpdateUserPid,
34
35
  useUploadAnymalImage: () => useUploadAnymalImage,
35
36
  useVerifyAccount: () => useVerifyAccount,
@@ -848,11 +849,57 @@ function useUpdateUserAsVerified() {
848
849
  );
849
850
  }
850
851
 
852
+ // src/utils/account/useUpdateUserName.ts
853
+ var import_react8 = require("react");
854
+ function useUpdateUserName() {
855
+ return (0, import_react8.useCallback)(
856
+ async (dbAuthToken, docID, name, endpoint) => {
857
+ if (!name || !dbAuthToken || !docID || !endpoint) {
858
+ return { success: false };
859
+ }
860
+ try {
861
+ const mutation = `
862
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
863
+ update_User(docID: $docID, input: $input) {
864
+ name
865
+ }
866
+ }
867
+ `;
868
+ const variables = {
869
+ docId: [docID],
870
+ input: {
871
+ name
872
+ }
873
+ };
874
+ const response = await fetch(endpoint, {
875
+ method: "POST",
876
+ headers: {
877
+ "Content-Type": "application/json",
878
+ Authorization: `Bearer ${dbAuthToken}`
879
+ },
880
+ body: JSON.stringify({
881
+ query: mutation,
882
+ variables
883
+ })
884
+ });
885
+ if (!response.ok) {
886
+ return { success: false };
887
+ }
888
+ return { success: true };
889
+ } catch (error) {
890
+ console.error("Error updating name:", error);
891
+ return { success: false };
892
+ }
893
+ },
894
+ []
895
+ );
896
+ }
897
+
851
898
  // src/utils/anymals/useMintAnymalNFT.ts
852
899
  var import_viem2 = require("viem");
853
- var import_react8 = require("react");
900
+ var import_react9 = require("react");
854
901
  function useMintAnymalNFT() {
855
- return (0, import_react8.useCallback)(
902
+ return (0, import_react9.useCallback)(
856
903
  async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
857
904
  if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
858
905
  return {
@@ -891,9 +938,9 @@ function useMintAnymalNFT() {
891
938
  }
892
939
 
893
940
  // src/utils/anymals/useAddAnymalToDatabase.ts
894
- var import_react9 = require("react");
941
+ var import_react10 = require("react");
895
942
  function useAddAnymalToDatabase() {
896
- return (0, import_react9.useCallback)(
943
+ return (0, import_react10.useCallback)(
897
944
  async (dbAuthToken, endpoint, anymalData) => {
898
945
  if (!dbAuthToken) {
899
946
  return {
@@ -958,9 +1005,9 @@ function useAddAnymalToDatabase() {
958
1005
  }
959
1006
 
960
1007
  // src/utils/anymals/useDeleteAnymalFromDatabase.ts
961
- var import_react10 = require("react");
1008
+ var import_react11 = require("react");
962
1009
  function useDeleteAnymalFromDatabase() {
963
- return (0, import_react10.useCallback)(
1010
+ return (0, import_react11.useCallback)(
964
1011
  async (dbAuthToken, endpoint, anymalDocID) => {
965
1012
  if (!dbAuthToken || !endpoint || !anymalDocID) return;
966
1013
  try {
@@ -998,9 +1045,9 @@ function useDeleteAnymalFromDatabase() {
998
1045
  }
999
1046
 
1000
1047
  // src/utils/anymals/useSaveAnymalMetadata.ts
1001
- var import_react11 = require("react");
1048
+ var import_react12 = require("react");
1002
1049
  function useSaveAnymalMetadata() {
1003
- return (0, import_react11.useCallback)(
1050
+ return (0, import_react12.useCallback)(
1004
1051
  async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
1005
1052
  const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
1006
1053
  method: "POST",
@@ -1027,9 +1074,9 @@ function useSaveAnymalMetadata() {
1027
1074
  }
1028
1075
 
1029
1076
  // src/utils/anymals/useUpdateAnymalWithNFT.ts
1030
- var import_react12 = require("react");
1077
+ var import_react13 = require("react");
1031
1078
  function useUpdateAnymalWithNFT() {
1032
- return (0, import_react12.useCallback)(
1079
+ return (0, import_react13.useCallback)(
1033
1080
  async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
1034
1081
  if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
1035
1082
  return {
@@ -1076,7 +1123,7 @@ function useUpdateAnymalWithNFT() {
1076
1123
  }
1077
1124
 
1078
1125
  // src/utils/anymals/useUploadAnymalImage.ts
1079
- var import_react13 = require("react");
1126
+ var import_react14 = require("react");
1080
1127
 
1081
1128
  // src/helpers/UploadImageHelper.tsx
1082
1129
  function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
@@ -1133,7 +1180,7 @@ function toBase64(file) {
1133
1180
 
1134
1181
  // src/utils/anymals/useUploadAnymalImage.ts
1135
1182
  function useUploadAnymalImage() {
1136
- return (0, import_react13.useCallback)(
1183
+ return (0, import_react14.useCallback)(
1137
1184
  async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
1138
1185
  if (!imageFile || !idToken) {
1139
1186
  return {
@@ -1188,10 +1235,10 @@ function useUploadAnymalImage() {
1188
1235
  }
1189
1236
 
1190
1237
  // src/utils/balance/useFetchBalance.ts
1191
- var import_react14 = require("react");
1238
+ var import_react15 = require("react");
1192
1239
  var import_viem3 = require("viem");
1193
1240
  function useFetchBalance() {
1194
- return (0, import_react14.useCallback)(
1241
+ return (0, import_react15.useCallback)(
1195
1242
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1196
1243
  try {
1197
1244
  const balance = await publicClient.readContract({
@@ -1220,6 +1267,7 @@ function useFetchBalance() {
1220
1267
  useUpdateAnymalWithNFT,
1221
1268
  useUpdateUserAsVerified,
1222
1269
  useUpdateUserEmail,
1270
+ useUpdateUserName,
1223
1271
  useUpdateUserPid,
1224
1272
  useUploadAnymalImage,
1225
1273
  useVerifyAccount,
package/dist/index.mjs CHANGED
@@ -809,11 +809,57 @@ function useUpdateUserAsVerified() {
809
809
  );
810
810
  }
811
811
 
812
+ // src/utils/account/useUpdateUserName.ts
813
+ import { useCallback as useCallback8 } from "react";
814
+ function useUpdateUserName() {
815
+ return useCallback8(
816
+ async (dbAuthToken, docID, name, endpoint) => {
817
+ if (!name || !dbAuthToken || !docID || !endpoint) {
818
+ return { success: false };
819
+ }
820
+ try {
821
+ const mutation = `
822
+ mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
823
+ update_User(docID: $docID, input: $input) {
824
+ name
825
+ }
826
+ }
827
+ `;
828
+ const variables = {
829
+ docId: [docID],
830
+ input: {
831
+ name
832
+ }
833
+ };
834
+ const response = await fetch(endpoint, {
835
+ method: "POST",
836
+ headers: {
837
+ "Content-Type": "application/json",
838
+ Authorization: `Bearer ${dbAuthToken}`
839
+ },
840
+ body: JSON.stringify({
841
+ query: mutation,
842
+ variables
843
+ })
844
+ });
845
+ if (!response.ok) {
846
+ return { success: false };
847
+ }
848
+ return { success: true };
849
+ } catch (error) {
850
+ console.error("Error updating name:", error);
851
+ return { success: false };
852
+ }
853
+ },
854
+ []
855
+ );
856
+ }
857
+
812
858
  // src/utils/anymals/useMintAnymalNFT.ts
813
859
  import { encodeFunctionData as encodeFunctionData2, parseGwei as parseGwei2 } from "viem";
814
- import { useCallback as useCallback8 } from "react";
860
+ import { useCallback as useCallback9 } from "react";
815
861
  function useMintAnymalNFT() {
816
- return useCallback8(
862
+ return useCallback9(
817
863
  async (pid, nftId, dbAuthToken, validationContractAddress, smartAccount, bundlerClient) => {
818
864
  if (!dbAuthToken || !nftId || !bundlerClient || !smartAccount || !pid || !validationContractAddress) {
819
865
  return {
@@ -852,9 +898,9 @@ function useMintAnymalNFT() {
852
898
  }
853
899
 
854
900
  // src/utils/anymals/useAddAnymalToDatabase.ts
855
- import { useCallback as useCallback9 } from "react";
901
+ import { useCallback as useCallback10 } from "react";
856
902
  function useAddAnymalToDatabase() {
857
- return useCallback9(
903
+ return useCallback10(
858
904
  async (dbAuthToken, endpoint, anymalData) => {
859
905
  if (!dbAuthToken) {
860
906
  return {
@@ -919,9 +965,9 @@ function useAddAnymalToDatabase() {
919
965
  }
920
966
 
921
967
  // src/utils/anymals/useDeleteAnymalFromDatabase.ts
922
- import { useCallback as useCallback10 } from "react";
968
+ import { useCallback as useCallback11 } from "react";
923
969
  function useDeleteAnymalFromDatabase() {
924
- return useCallback10(
970
+ return useCallback11(
925
971
  async (dbAuthToken, endpoint, anymalDocID) => {
926
972
  if (!dbAuthToken || !endpoint || !anymalDocID) return;
927
973
  try {
@@ -959,9 +1005,9 @@ function useDeleteAnymalFromDatabase() {
959
1005
  }
960
1006
 
961
1007
  // src/utils/anymals/useSaveAnymalMetadata.ts
962
- import { useCallback as useCallback11 } from "react";
1008
+ import { useCallback as useCallback12 } from "react";
963
1009
  function useSaveAnymalMetadata() {
964
- return useCallback11(
1010
+ return useCallback12(
965
1011
  async (idToken, publicKey, nftMetadataInput, authServiceBaseUrl) => {
966
1012
  const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
967
1013
  method: "POST",
@@ -988,9 +1034,9 @@ function useSaveAnymalMetadata() {
988
1034
  }
989
1035
 
990
1036
  // src/utils/anymals/useUpdateAnymalWithNFT.ts
991
- import { useCallback as useCallback12 } from "react";
1037
+ import { useCallback as useCallback13 } from "react";
992
1038
  function useUpdateAnymalWithNFT() {
993
- return useCallback12(
1039
+ return useCallback13(
994
1040
  async (anymalPassportId, anymalDocId, dbAuthToken, endpoint) => {
995
1041
  if (!dbAuthToken || !anymalPassportId || !anymalDocId || !endpoint) {
996
1042
  return {
@@ -1037,7 +1083,7 @@ function useUpdateAnymalWithNFT() {
1037
1083
  }
1038
1084
 
1039
1085
  // src/utils/anymals/useUploadAnymalImage.ts
1040
- import { useCallback as useCallback13 } from "react";
1086
+ import { useCallback as useCallback14 } from "react";
1041
1087
 
1042
1088
  // src/helpers/UploadImageHelper.tsx
1043
1089
  function resizeImage(file, maxWidth = 800, maxHeight = 800, quality = 0.7) {
@@ -1094,7 +1140,7 @@ function toBase64(file) {
1094
1140
 
1095
1141
  // src/utils/anymals/useUploadAnymalImage.ts
1096
1142
  function useUploadAnymalImage() {
1097
- return useCallback13(
1143
+ return useCallback14(
1098
1144
  async (imageFile, type, idToken, publicKey, authServiceBaseUrl) => {
1099
1145
  if (!imageFile || !idToken) {
1100
1146
  return {
@@ -1149,10 +1195,10 @@ function useUploadAnymalImage() {
1149
1195
  }
1150
1196
 
1151
1197
  // src/utils/balance/useFetchBalance.ts
1152
- import { useCallback as useCallback14 } from "react";
1198
+ import { useCallback as useCallback15 } from "react";
1153
1199
  import { erc20Abi, getAddress } from "viem";
1154
1200
  function useFetchBalance() {
1155
- return useCallback14(
1201
+ return useCallback15(
1156
1202
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1157
1203
  try {
1158
1204
  const balance = await publicClient.readContract({
@@ -1180,6 +1226,7 @@ export {
1180
1226
  useUpdateAnymalWithNFT,
1181
1227
  useUpdateUserAsVerified,
1182
1228
  useUpdateUserEmail,
1229
+ useUpdateUserName,
1183
1230
  useUpdateUserPid,
1184
1231
  useUploadAnymalImage,
1185
1232
  useVerifyAccount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export * from "./utils/account/useFetchUserData";
5
5
  export * from "./utils/account/useUpdateUserEmail";
6
6
  export * from "./utils/account/useUpdateUserPid";
7
7
  export * from "./utils/account/useUpdateUserAsVerified";
8
+ export * from "./utils/account/useUpdateUserName";
8
9
 
9
10
  export * from "./utils/anymals/useMintAnymalNFT";
10
11
  export * from "./utils/anymals/useAddAnymalToDatabase";
@@ -8,6 +8,10 @@ export function useUpdateUserName() {
8
8
  name: string,
9
9
  endpoint: string
10
10
  ) => {
11
+ if (!name || !dbAuthToken || !docID || !endpoint) {
12
+ return { success: false };
13
+ }
14
+
11
15
  try {
12
16
  const mutation = `
13
17
  mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
@@ -37,10 +41,13 @@ export function useUpdateUserName() {
37
41
  });
38
42
 
39
43
  if (!response.ok) {
40
- throw new Error(`HTTP error! Status: ${response.status}`);
44
+ return { success: false };
41
45
  }
46
+
47
+ return { success: true };
42
48
  } catch (error) {
43
49
  console.error("Error updating name:", error);
50
+ return { success: false };
44
51
  }
45
52
  },
46
53
  []