anymal-protocol 1.0.10 → 1.0.12

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,7 +18,9 @@ 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<void>;
21
+ declare function useUpdateUserName(): (dbAuthToken: string, docID: string, name: string, endpoint: string) => Promise<{
22
+ success: boolean;
23
+ }>;
22
24
 
23
25
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
24
26
  success: boolean;
@@ -58,6 +60,8 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
58
60
  type: string;
59
61
  }>;
60
62
 
63
+ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<any>;
64
+
61
65
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
62
66
 
63
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
67
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.d.ts CHANGED
@@ -18,7 +18,9 @@ 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<void>;
21
+ declare function useUpdateUserName(): (dbAuthToken: string, docID: string, name: string, endpoint: string) => Promise<{
22
+ success: boolean;
23
+ }>;
22
24
 
23
25
  declare function useMintAnymalNFT(): (pid: string, nftId: string, dbAuthToken: string, validationContractAddress: string, smartAccount: any, bundlerClient: any) => Promise<{
24
26
  success: boolean;
@@ -58,6 +60,8 @@ declare function useUploadAnymalImage(): (imageFile: File, type: string, idToken
58
60
  type: string;
59
61
  }>;
60
62
 
63
+ declare function useCreateUserAppData(): (appId: string, pid: string, dbAuthToken: string, endpoint: string) => Promise<any>;
64
+
61
65
  declare function useFetchBalance(): (publicClient: any, walletAddress: string, kibbleTokenAddress: string) => Promise<number | undefined>;
62
66
 
63
- export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
67
+ export { type AnymalNftMetadataInputData, type CreateAnymalInputData, useAddAnymalToDatabase, useCreateUserAppData, useCreateWeb3Account, useDeleteAnymalFromDatabase, useFetchBalance, useFetchUserData, useMintAnymalNFT, useSaveAnymalMetadata, useUpdateAnymalWithNFT, useUpdateUserAsVerified, useUpdateUserEmail, useUpdateUserName, useUpdateUserPid, useUploadAnymalImage, useVerifyAccount, useVerifyWeb3AuthSession };
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  useAddAnymalToDatabase: () => useAddAnymalToDatabase,
24
+ useCreateUserAppData: () => useCreateUserAppData,
24
25
  useCreateWeb3Account: () => useCreateWeb3Account,
25
26
  useDeleteAnymalFromDatabase: () => useDeleteAnymalFromDatabase,
26
27
  useFetchBalance: () => useFetchBalance,
@@ -854,6 +855,9 @@ var import_react8 = require("react");
854
855
  function useUpdateUserName() {
855
856
  return (0, import_react8.useCallback)(
856
857
  async (dbAuthToken, docID, name, endpoint) => {
858
+ if (!name || !dbAuthToken || !docID || !endpoint) {
859
+ return { success: false };
860
+ }
857
861
  try {
858
862
  const mutation = `
859
863
  mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
@@ -880,10 +884,12 @@ function useUpdateUserName() {
880
884
  })
881
885
  });
882
886
  if (!response.ok) {
883
- throw new Error(`HTTP error! Status: ${response.status}`);
887
+ return { success: false };
884
888
  }
889
+ return { success: true };
885
890
  } catch (error) {
886
891
  console.error("Error updating name:", error);
892
+ return { success: false };
887
893
  }
888
894
  },
889
895
  []
@@ -1229,11 +1235,65 @@ function useUploadAnymalImage() {
1229
1235
  );
1230
1236
  }
1231
1237
 
1232
- // src/utils/balance/useFetchBalance.ts
1238
+ // src/utils/application/useCreateUserAppData.ts
1233
1239
  var import_react15 = require("react");
1240
+ var import_uuid = require("uuid");
1241
+ function useCreateUserAppData() {
1242
+ return (0, import_react15.useCallback)(
1243
+ async (appId, pid, dbAuthToken, endpoint) => {
1244
+ if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
1245
+ const appValues = {
1246
+ id: (0, import_uuid.v4)(),
1247
+ userPid: pid,
1248
+ appId,
1249
+ settings: {
1250
+ darkMode: false
1251
+ }
1252
+ };
1253
+ try {
1254
+ const mutation = `
1255
+ mutation Create_UserAppSettings($input: [UserAppSettingsMutationInputArg!]) {
1256
+ create_UserAppSettings (input: $input) {
1257
+ id
1258
+ userPid
1259
+ appId
1260
+ settings
1261
+ }
1262
+ }
1263
+ `;
1264
+ const variables = {
1265
+ input: [appValues]
1266
+ };
1267
+ const response = await fetch(endpoint, {
1268
+ method: "POST",
1269
+ headers: {
1270
+ "Content-Type": "application/json",
1271
+ Authorization: `Bearer ${dbAuthToken}`
1272
+ },
1273
+ body: JSON.stringify({ query: mutation, variables })
1274
+ });
1275
+ if (!response.ok) {
1276
+ throw new Error(`HTTP error! Status: ${response.status}`);
1277
+ }
1278
+ const { data, errors } = await response.json();
1279
+ if (errors) {
1280
+ return [];
1281
+ }
1282
+ return data.create_UserAppSettings[0];
1283
+ } catch (error) {
1284
+ console.error("Error creating application:", error);
1285
+ return [];
1286
+ }
1287
+ },
1288
+ []
1289
+ );
1290
+ }
1291
+
1292
+ // src/utils/balance/useFetchBalance.ts
1293
+ var import_react16 = require("react");
1234
1294
  var import_viem3 = require("viem");
1235
1295
  function useFetchBalance() {
1236
- return (0, import_react15.useCallback)(
1296
+ return (0, import_react16.useCallback)(
1237
1297
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1238
1298
  try {
1239
1299
  const balance = await publicClient.readContract({
@@ -1253,6 +1313,7 @@ function useFetchBalance() {
1253
1313
  // Annotate the CommonJS export names for ESM import in node:
1254
1314
  0 && (module.exports = {
1255
1315
  useAddAnymalToDatabase,
1316
+ useCreateUserAppData,
1256
1317
  useCreateWeb3Account,
1257
1318
  useDeleteAnymalFromDatabase,
1258
1319
  useFetchBalance,
package/dist/index.mjs CHANGED
@@ -814,6 +814,9 @@ import { useCallback as useCallback8 } from "react";
814
814
  function useUpdateUserName() {
815
815
  return useCallback8(
816
816
  async (dbAuthToken, docID, name, endpoint) => {
817
+ if (!name || !dbAuthToken || !docID || !endpoint) {
818
+ return { success: false };
819
+ }
817
820
  try {
818
821
  const mutation = `
819
822
  mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
@@ -840,10 +843,12 @@ function useUpdateUserName() {
840
843
  })
841
844
  });
842
845
  if (!response.ok) {
843
- throw new Error(`HTTP error! Status: ${response.status}`);
846
+ return { success: false };
844
847
  }
848
+ return { success: true };
845
849
  } catch (error) {
846
850
  console.error("Error updating name:", error);
851
+ return { success: false };
847
852
  }
848
853
  },
849
854
  []
@@ -1189,11 +1194,65 @@ function useUploadAnymalImage() {
1189
1194
  );
1190
1195
  }
1191
1196
 
1192
- // src/utils/balance/useFetchBalance.ts
1197
+ // src/utils/application/useCreateUserAppData.ts
1193
1198
  import { useCallback as useCallback15 } from "react";
1199
+ import { v4 as uuid } from "uuid";
1200
+ function useCreateUserAppData() {
1201
+ return useCallback15(
1202
+ async (appId, pid, dbAuthToken, endpoint) => {
1203
+ if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
1204
+ const appValues = {
1205
+ id: uuid(),
1206
+ userPid: pid,
1207
+ appId,
1208
+ settings: {
1209
+ darkMode: false
1210
+ }
1211
+ };
1212
+ try {
1213
+ const mutation = `
1214
+ mutation Create_UserAppSettings($input: [UserAppSettingsMutationInputArg!]) {
1215
+ create_UserAppSettings (input: $input) {
1216
+ id
1217
+ userPid
1218
+ appId
1219
+ settings
1220
+ }
1221
+ }
1222
+ `;
1223
+ const variables = {
1224
+ input: [appValues]
1225
+ };
1226
+ const response = await fetch(endpoint, {
1227
+ method: "POST",
1228
+ headers: {
1229
+ "Content-Type": "application/json",
1230
+ Authorization: `Bearer ${dbAuthToken}`
1231
+ },
1232
+ body: JSON.stringify({ query: mutation, variables })
1233
+ });
1234
+ if (!response.ok) {
1235
+ throw new Error(`HTTP error! Status: ${response.status}`);
1236
+ }
1237
+ const { data, errors } = await response.json();
1238
+ if (errors) {
1239
+ return [];
1240
+ }
1241
+ return data.create_UserAppSettings[0];
1242
+ } catch (error) {
1243
+ console.error("Error creating application:", error);
1244
+ return [];
1245
+ }
1246
+ },
1247
+ []
1248
+ );
1249
+ }
1250
+
1251
+ // src/utils/balance/useFetchBalance.ts
1252
+ import { useCallback as useCallback16 } from "react";
1194
1253
  import { erc20Abi, getAddress } from "viem";
1195
1254
  function useFetchBalance() {
1196
- return useCallback15(
1255
+ return useCallback16(
1197
1256
  async (publicClient, walletAddress, kibbleTokenAddress) => {
1198
1257
  try {
1199
1258
  const balance = await publicClient.readContract({
@@ -1212,6 +1271,7 @@ function useFetchBalance() {
1212
1271
  }
1213
1272
  export {
1214
1273
  useAddAnymalToDatabase,
1274
+ useCreateUserAppData,
1215
1275
  useCreateWeb3Account,
1216
1276
  useDeleteAnymalFromDatabase,
1217
1277
  useFetchBalance,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anymal-protocol",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -15,6 +15,7 @@
15
15
  "dependencies": {
16
16
  "react": "^19.0.0",
17
17
  "react-dom": "^19.0.0",
18
+ "uuid": "^11.0.5",
18
19
  "viem": "^2.22.8"
19
20
  },
20
21
  "devDependencies": {
package/src/index.ts CHANGED
@@ -14,5 +14,7 @@ export * from "./utils/anymals/useSaveAnymalMetadata";
14
14
  export * from "./utils/anymals/useUpdateAnymalWithNFT";
15
15
  export * from "./utils/anymals/useUploadAnymalImage";
16
16
 
17
+ export * from "./utils/application/useCreateUserAppData";
18
+
17
19
  export * from "./utils/balance/useFetchBalance";
18
20
  export * from "./types/Anymal";
@@ -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
  []
@@ -0,0 +1,66 @@
1
+ import { useCallback } from "react";
2
+ import { v4 as uuid } from "uuid";
3
+
4
+ export function useCreateUserAppData() {
5
+ return useCallback(
6
+ async (
7
+ appId: string,
8
+ pid: string,
9
+ dbAuthToken: string,
10
+ endpoint: string
11
+ ) => {
12
+ if (!dbAuthToken || !pid || !dbAuthToken || !endpoint) return;
13
+
14
+ const appValues = {
15
+ id: uuid(),
16
+ userPid: pid,
17
+ appId: appId,
18
+ settings: {
19
+ darkMode: false,
20
+ },
21
+ };
22
+
23
+ try {
24
+ const mutation = `
25
+ mutation Create_UserAppSettings($input: [UserAppSettingsMutationInputArg!]) {
26
+ create_UserAppSettings (input: $input) {
27
+ id
28
+ userPid
29
+ appId
30
+ settings
31
+ }
32
+ }
33
+ `;
34
+
35
+ const variables = {
36
+ input: [appValues],
37
+ };
38
+
39
+ const response = await fetch(endpoint, {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json",
43
+ Authorization: `Bearer ${dbAuthToken}`,
44
+ },
45
+ body: JSON.stringify({ query: mutation, variables }),
46
+ });
47
+
48
+ if (!response.ok) {
49
+ throw new Error(`HTTP error! Status: ${response.status}`);
50
+ }
51
+
52
+ const { data, errors } = await response.json();
53
+
54
+ if (errors) {
55
+ return [];
56
+ }
57
+
58
+ return data.create_UserAppSettings[0];
59
+ } catch (error) {
60
+ console.error("Error creating application:", error);
61
+ return [];
62
+ }
63
+ },
64
+ []
65
+ );
66
+ }