anymal-protocol 1.0.13 → 1.0.15

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.
@@ -1,63 +0,0 @@
1
- export function resizeImage(
2
- file: File,
3
- maxWidth = 800,
4
- maxHeight = 800,
5
- quality = 0.7
6
- ): Promise<Blob> {
7
- return new Promise((resolve, reject) => {
8
- const img = new Image();
9
- img.src = URL.createObjectURL(file);
10
- img.onload = () => {
11
- const canvas = document.createElement("canvas");
12
- const ctx = canvas.getContext("2d");
13
-
14
- if (!ctx) {
15
- reject(new Error("Failed to get canvas 2D context"));
16
- return;
17
- }
18
-
19
- let width = img.width;
20
- let height = img.height;
21
-
22
- if (width > height) {
23
- if (width > maxWidth) {
24
- height = Math.round((height *= maxWidth / width));
25
- width = maxWidth;
26
- }
27
- } else {
28
- if (height > maxHeight) {
29
- width = Math.round((width *= maxHeight / height));
30
- height = maxHeight;
31
- }
32
- }
33
-
34
- canvas.width = width;
35
- canvas.height = height;
36
- ctx.drawImage(img, 0, 0, width, height);
37
-
38
- canvas.toBlob(
39
- (blob) => {
40
- if (blob) resolve(blob);
41
- else reject(new Error("Image compression failed."));
42
- },
43
- "image/jpeg",
44
- quality
45
- );
46
- };
47
- img.onerror = () => reject(new Error("Failed to load image."));
48
- });
49
- }
50
-
51
- export async function prepareImage(imageFile: File): Promise<string> {
52
- const compressedFile = (await resizeImage(imageFile)) as Blob;
53
- return toBase64(compressedFile);
54
- }
55
-
56
- export function toBase64(file: Blob): Promise<string> {
57
- return new Promise((resolve, reject) => {
58
- const reader = new FileReader();
59
- reader.readAsDataURL(file);
60
- reader.onload = () => resolve((reader.result as string).split(",")[1]);
61
- reader.onerror = (error) => reject(error);
62
- });
63
- }
package/src/index.ts DELETED
@@ -1,20 +0,0 @@
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
- export * from "./utils/account/useUpdateUserAsVerified";
8
- export * from "./utils/account/useUpdateUserName";
9
-
10
- export * from "./utils/anymals/useMintAnymalNFT";
11
- export * from "./utils/anymals/useAddAnymalToDatabase";
12
- export * from "./utils/anymals/useDeleteAnymalFromDatabase";
13
- export * from "./utils/anymals/useSaveAnymalMetadata";
14
- export * from "./utils/anymals/useUpdateAnymalWithNFT";
15
- export * from "./utils/anymals/useUploadAnymalImage";
16
-
17
- export * from "./utils/application/useCreateUserAppData";
18
-
19
- export * from "./utils/balance/useFetchBalance";
20
- export * from "./types/Anymal";
@@ -1,8 +0,0 @@
1
- export interface CreateAnymalInputData {}
2
-
3
- export interface AnymalNftMetadataInputData {
4
- name: string;
5
- description: string;
6
- image: string;
7
- nft_id: string;
8
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,44 +0,0 @@
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
- name
13
- isVerified
14
- accountType
15
- }
16
- }
17
- `;
18
-
19
- const response = await fetch(endpoint, {
20
- method: "POST",
21
- headers: {
22
- "Content-Type": "application/json",
23
- Authorization: `Bearer ${dbAuthToken}`,
24
- },
25
- body: JSON.stringify({ query }),
26
- });
27
-
28
- if (!response.ok) {
29
- throw new Error(`HTTP error! Status: ${response.status}`);
30
- }
31
-
32
- const data = await response.json();
33
-
34
- if (data && data.data && data.data.User && data.data.User.length > 0) {
35
- return data.data.User[0];
36
- } else {
37
- return null;
38
- }
39
- } catch (error) {
40
- console.error("Error fetching user data:", error);
41
- return null;
42
- }
43
- }, []);
44
- }
@@ -1,52 +0,0 @@
1
- import { useCallback } from "react";
2
-
3
- export function useUpdateUserAsVerified() {
4
- return useCallback(
5
- async (
6
- recaptchaToken: string | null,
7
- docID: string,
8
- dbAuthToken: string,
9
- endpoint: string
10
- ) => {
11
- if (!docID || !dbAuthToken || recaptchaToken === null) return;
12
-
13
- try {
14
- const mutation = `
15
- mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
16
- update_User(docID: $docID, input: $input) {
17
- isVerified
18
- }
19
- }
20
- `;
21
-
22
- const variables = {
23
- docId: [docID],
24
- input: {
25
- isVerified: true,
26
- },
27
- };
28
-
29
- const response = await fetch(endpoint, {
30
- method: "POST",
31
- headers: {
32
- "Content-Type": "application/json",
33
- Authorization: `Bearer ${dbAuthToken}`,
34
- },
35
- body: JSON.stringify({
36
- query: mutation,
37
- variables,
38
- }),
39
- });
40
-
41
- const responseMessage = response.ok
42
- ? "Your account has been verified!"
43
- : "An error has occured, try again.";
44
-
45
- return { success: response.ok, message: responseMessage };
46
- } catch (error) {
47
- return { success: false, message: (error as Error).message };
48
- }
49
- },
50
- []
51
- );
52
- }
@@ -1,48 +0,0 @@
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
- }
@@ -1,55 +0,0 @@
1
- import { useCallback } from "react";
2
-
3
- export function useUpdateUserName() {
4
- return useCallback(
5
- async (
6
- dbAuthToken: string,
7
- docID: string,
8
- name: string,
9
- endpoint: string
10
- ) => {
11
- if (!name || !dbAuthToken || !docID || !endpoint) {
12
- return { success: false };
13
- }
14
-
15
- try {
16
- const mutation = `
17
- mutation Update_User($docID: [ID], $input: UserMutationInputArg) {
18
- update_User(docID: $docID, input: $input) {
19
- name
20
- }
21
- }
22
- `;
23
-
24
- const variables = {
25
- docId: [docID],
26
- input: {
27
- name: name,
28
- },
29
- };
30
-
31
- const response = await fetch(endpoint, {
32
- method: "POST",
33
- headers: {
34
- "Content-Type": "application/json",
35
- Authorization: `Bearer ${dbAuthToken}`,
36
- },
37
- body: JSON.stringify({
38
- query: mutation,
39
- variables,
40
- }),
41
- });
42
-
43
- if (!response.ok) {
44
- return { success: false };
45
- }
46
-
47
- return { success: true };
48
- } catch (error) {
49
- console.error("Error updating name:", error);
50
- return { success: false };
51
- }
52
- },
53
- []
54
- );
55
- }
@@ -1,48 +0,0 @@
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
- }
@@ -1,61 +0,0 @@
1
- import { useCallback } from "react";
2
- import { encodeFunctionData, parseGwei } from "viem";
3
- import { VERIFY_ACCOUNT_ABI } from "../../helpers/BlockchainAbiHelper";
4
-
5
- export function useVerifyAccount() {
6
- return useCallback(
7
- async (
8
- pid: string,
9
- dbAuthToken: string,
10
- bundlerClient: any,
11
- smartAccount: any,
12
- accountRewardsContractAddress: `0x${string}`
13
- ): Promise<{
14
- success: boolean;
15
- message: string;
16
- }> => {
17
- if (
18
- !dbAuthToken ||
19
- !bundlerClient ||
20
- !smartAccount ||
21
- !accountRewardsContractAddress ||
22
- !pid
23
- ) {
24
- return {
25
- success: false,
26
- message: "Missing crucial information",
27
- };
28
- }
29
-
30
- const callData = encodeFunctionData({
31
- abi: VERIFY_ACCOUNT_ABI,
32
- functionName: "claimRewardByName",
33
- args: ["petastic-signup-campaign-1", pid],
34
- });
35
-
36
- try {
37
- const userOpHash = await bundlerClient.sendUserOperation({
38
- account: smartAccount,
39
- calls: [
40
- {
41
- to: accountRewardsContractAddress,
42
- data: callData,
43
- },
44
- ],
45
- maxPriorityFeePerGas: parseGwei("0.099"),
46
- maxFeePerGas: parseGwei("0.099"),
47
- });
48
-
49
- await bundlerClient.waitForUserOperationReceipt({
50
- hash: userOpHash,
51
- });
52
-
53
- return { success: true, message: "Registration kibble awarded" };
54
- } catch (error) {
55
- console.error(error);
56
- return { success: false, message: (error as Error).message };
57
- }
58
- },
59
- []
60
- );
61
- }
@@ -1,24 +0,0 @@
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
- }
@@ -1,82 +0,0 @@
1
- import { useCallback } from "react";
2
- import { CreateAnymalInputData } from "../../types/Anymal";
3
-
4
- export function useAddAnymalToDatabase() {
5
- return useCallback(
6
- async (
7
- dbAuthToken: string,
8
- endpoint: string,
9
- anymalData: CreateAnymalInputData
10
- ): Promise<{
11
- _docID: string | null;
12
- success: boolean;
13
- message: string;
14
- }> => {
15
- if (!dbAuthToken) {
16
- return {
17
- success: false,
18
- message: "Authentication token is missing.",
19
- _docID: null,
20
- };
21
- }
22
-
23
- let anymalDocID: string | null = null;
24
-
25
- try {
26
- const mutation = `
27
- mutation Create_Anymal($input: [AnymalMutationInputArg!]) {
28
- create_Anymal(input: $input) {
29
- _docID
30
- name
31
- passportID
32
- }
33
- }
34
- `;
35
-
36
- const response = await fetch(endpoint, {
37
- method: "POST",
38
- headers: {
39
- "Content-Type": "application/json",
40
- Authorization: `Bearer ${dbAuthToken}`,
41
- },
42
- body: JSON.stringify({
43
- query: mutation,
44
- variables: { input: [anymalData] },
45
- }),
46
- });
47
-
48
- if (!response.ok) {
49
- throw new Error(
50
- `Failed to create pet. HTTP status ${response.status}`
51
- );
52
- }
53
-
54
- const { data, errors } = await response.json();
55
-
56
- if (errors) {
57
- const errorMessage = JSON.stringify(errors);
58
- if (errorMessage.includes("given ID already exists")) {
59
- console.warn("Duplicate document ID detected.");
60
- anymalDocID = data?.create_Anymal[0]?._docID || null; // Capture the petDocID if possible
61
- throw new Error("Document with the given ID already exists.");
62
- }
63
- throw new Error(`GraphQL error: ${errorMessage}`);
64
- }
65
-
66
- anymalDocID = data.create_Anymal[0]._docID;
67
- return {
68
- success: true,
69
- _docID: anymalDocID,
70
- message: "Anymal added to account",
71
- };
72
- } catch (error) {
73
- return {
74
- success: false,
75
- _docID: null,
76
- message: "Error adding anymal to account",
77
- };
78
- }
79
- },
80
- []
81
- );
82
- }
@@ -1,47 +0,0 @@
1
- import { useCallback } from "react";
2
-
3
- export function useDeleteAnymalFromDatabase() {
4
- return useCallback(
5
- async (
6
- dbAuthToken: string,
7
- endpoint: string,
8
- anymalDocID: string
9
- ): Promise<void> => {
10
- if (!dbAuthToken || !endpoint || !anymalDocID) return;
11
-
12
- try {
13
- const mutation = `
14
- mutation Delete_Anymal($docId: [ID]) {
15
- delete_Anymal(docID: $docId) {
16
- _docID
17
- }
18
- }
19
- `;
20
-
21
- const response = await fetch(endpoint, {
22
- method: "POST",
23
- headers: {
24
- "Content-Type": "application/json",
25
- Authorization: `Bearer ${dbAuthToken}`,
26
- },
27
- body: JSON.stringify({
28
- query: mutation,
29
- variables: { docId: [anymalDocID] },
30
- }),
31
- });
32
-
33
- if (!response.ok)
34
- throw new Error(
35
- `Failed to delete anymal. HTTP status ${response.status}`
36
- );
37
-
38
- const { errors } = await response.json();
39
- if (errors) throw new Error(`GraphQL error: ${JSON.stringify(errors)}`);
40
- } catch (error) {
41
- console.error("Error deleting anymal from database:", error);
42
- throw error;
43
- }
44
- },
45
- []
46
- );
47
- }
@@ -1,63 +0,0 @@
1
- import { encodeFunctionData, parseGwei } from "viem";
2
- import { PET_NFT_ABI } from "../../helpers/BlockchainAbiHelper";
3
- import { useCallback } from "react";
4
-
5
- export function useMintAnymalNFT() {
6
- return useCallback(
7
- async (
8
- pid: string,
9
- nftId: string,
10
- dbAuthToken: string,
11
- validationContractAddress: string,
12
- smartAccount: any,
13
- bundlerClient: any
14
- ): Promise<{
15
- success: boolean;
16
- message: string;
17
- }> => {
18
- if (
19
- !dbAuthToken ||
20
- !nftId ||
21
- !bundlerClient ||
22
- !smartAccount ||
23
- !pid ||
24
- !validationContractAddress
25
- ) {
26
- return {
27
- success: false,
28
- message: "Missing authentication token OR NFT ID.",
29
- };
30
- }
31
-
32
- const callData = encodeFunctionData({
33
- abi: PET_NFT_ABI,
34
- functionName: "submitMetadataByCampaignName",
35
- args: [
36
- pid,
37
- nftId,
38
- `https://dev-nft.petastic.com/metadata/${nftId}`,
39
- "petastic-signup-campaign-1",
40
- ],
41
- });
42
-
43
- const userOpHash = await bundlerClient.sendUserOperation({
44
- account: smartAccount,
45
- calls: [
46
- {
47
- to: validationContractAddress,
48
- data: callData,
49
- },
50
- ],
51
- maxPriorityFeePerGas: parseGwei("0.001"),
52
- maxFeePerGas: parseGwei("0.001"),
53
- });
54
-
55
- await bundlerClient.waitForUserOperationReceipt({
56
- hash: userOpHash,
57
- });
58
-
59
- return { success: true, message: "Pet Passport Created!" };
60
- },
61
- []
62
- );
63
- }
@@ -1,37 +0,0 @@
1
- import { useCallback } from "react";
2
- import { AnymalNftMetadataInputData } from "../../types/Anymal";
3
-
4
- export function useSaveAnymalMetadata() {
5
- return useCallback(
6
- async (
7
- idToken: string,
8
- publicKey: string,
9
- nftMetadataInput: AnymalNftMetadataInputData,
10
- authServiceBaseUrl: string
11
- ) => {
12
- const response = await fetch(`${authServiceBaseUrl}/process-nft`, {
13
- method: "POST",
14
- headers: {
15
- "Content-Type": "application/json",
16
- Authorization: "Bearer " + idToken,
17
- },
18
- body: JSON.stringify({
19
- appPubKey: publicKey,
20
- nftMetadataInput: nftMetadataInput,
21
- }),
22
- });
23
-
24
- const data = await response.json();
25
-
26
- if (data.errors) {
27
- throw new Error(`GraphQL error: ${JSON.stringify(data.errors)}`);
28
- }
29
-
30
- return {
31
- success: true,
32
- message: data[0],
33
- };
34
- },
35
- []
36
- );
37
- }