From 08d2f0250dd5169e1dccbf34290632c0c41c36a3 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 3 Mar 2025 07:11:30 +0100 Subject: [PATCH] fix(frontend): update contract modal validation --- frontend/openapi-docs.json | 407 ++- frontend/package-lock.json | 10 + frontend/package.json | 1 + .../dashboard/CreateContractModal.tsx | 77 +- .../dashboard/RegisterAgentModal.tsx | 18 +- .../components/dashboard/RegisteredAgents.tsx | 12 +- frontend/src/components/wallet/SwapDialog.tsx | 12 +- frontend/src/lib/api/api-keys.ts | 70 - frontend/src/lib/api/api-keys/create.ts | 59 - frontend/src/lib/api/api-keys/delete.ts | 49 - frontend/src/lib/api/api-keys/status.ts | 49 - frontend/src/lib/api/api-keys/update.ts | 52 - frontend/src/lib/api/client.ts | 16 - frontend/src/lib/api/create-payment-source.ts | 71 - frontend/src/lib/api/delete-payment-source.ts | 29 - frontend/src/lib/api/generated/api.ts | 2504 ----------------- frontend/src/lib/api/generated/sdk.gen.ts | 25 + frontend/src/lib/api/generated/types.gen.ts | 171 +- frontend/src/lib/api/get-registered-agents.ts | 83 - frontend/src/lib/api/health.ts | 31 - frontend/src/lib/api/payment-source.ts | 81 - frontend/src/lib/api/register-agent.ts | 73 - frontend/src/lib/api/transactions.ts | 209 -- frontend/src/lib/api/update-payment-source.ts | 72 - frontend/src/lib/api/wallet.ts | 85 - .../swagger-generator/openapi-docs.json | 31 +- 26 files changed, 607 insertions(+), 3690 deletions(-) delete mode 100644 frontend/src/lib/api/api-keys.ts delete mode 100644 frontend/src/lib/api/api-keys/create.ts delete mode 100644 frontend/src/lib/api/api-keys/delete.ts delete mode 100644 frontend/src/lib/api/api-keys/status.ts delete mode 100644 frontend/src/lib/api/api-keys/update.ts delete mode 100644 frontend/src/lib/api/client.ts delete mode 100644 frontend/src/lib/api/create-payment-source.ts delete mode 100644 frontend/src/lib/api/delete-payment-source.ts delete mode 100644 frontend/src/lib/api/generated/api.ts delete mode 100644 frontend/src/lib/api/get-registered-agents.ts delete mode 100644 frontend/src/lib/api/health.ts delete mode 100644 frontend/src/lib/api/payment-source.ts delete mode 100644 frontend/src/lib/api/register-agent.ts delete mode 100644 frontend/src/lib/api/transactions.ts delete mode 100644 frontend/src/lib/api/update-payment-source.ts delete mode 100644 frontend/src/lib/api/wallet.ts diff --git a/frontend/openapi-docs.json b/frontend/openapi-docs.json index 23a2f16..1b0b21e 100644 --- a/frontend/openapi-docs.json +++ b/frontend/openapi-docs.json @@ -1520,7 +1520,7 @@ "format": "date-time" } ], - "default": "2025-02-23T18:19:37.520Z", + "default": "2025-02-27T14:38:36.080Z", "description": "The time after which the payment has to be submitted to the smart contract" }, "unlockTime": { @@ -4154,7 +4154,7 @@ } } }, - "/registry/": { + "/registry/wallet": { "get": { "description": "Gets the agent metadata.", "summary": "REQUIRES API KEY Authentication (+READ)", @@ -4244,11 +4244,11 @@ "nullable": true, "maxLength": 250 }, - "api_url": { + "apiUrl": { "type": "string", "maxLength": 250 }, - "example_output": { + "exampleOutput": { "type": "string", "nullable": true, "maxLength": 250 @@ -4260,7 +4260,7 @@ "maxLength": 250 } }, - "requests_per_hour": { + "requestsPerHour": { "type": "string", "nullable": true, "maxLength": 250 @@ -4308,7 +4308,7 @@ "type": "object", "nullable": true, "properties": { - "privacy_policy": { + "privacyPolicy": { "type": "string", "nullable": true, "maxLength": 250 @@ -4350,7 +4350,7 @@ "type": "string", "maxLength": 250 }, - "metadata_version": { + "metadataVersion": { "type": "integer", "minimum": 1, "maximum": 1 @@ -4358,13 +4358,13 @@ }, "required": [ "name", - "api_url", + "apiUrl", "tags", "capability", "author", "pricing", "image", - "metadata_version" + "metadataVersion" ] } }, @@ -4397,8 +4397,8 @@ "metadata": { "name": "name", "description": "description", - "api_url": "api_url", - "example_output": "example_output", + "apiUrl": "api_url", + "exampleOutput": "example_output", "tags": [ "tag1", "tag2" @@ -4413,7 +4413,7 @@ "organization": "author_organization" }, "legal": { - "privacy_policy": "privacy_policy", + "privacyPolicy": "privacy_policy", "terms": "terms", "other": "other" }, @@ -4424,9 +4424,296 @@ "unit": "unit" } ], - "metadata_version": 1 + "metadataVersion": 1 + } + } + ] + } + } + } + } + } + } + } + } + }, + "/registry/": { + "get": { + "description": "Gets the agent metadata.", + "summary": "REQUIRES API KEY Authentication (+READ)", + "tags": [ + "registry" + ], + "security": [ + { + "API-Key": [] + } + ], + "parameters": [ + { + "schema": { + "type": "string", + "description": "The cursor id to paginate through the results" + }, + "required": false, + "description": "The cursor id to paginate through the results", + "name": "cursorId", + "in": "query" + }, + { + "schema": { + "type": "string", + "enum": [ + "Preprod", + "Mainnet" + ], + "description": "The Cardano network used to register the agent on" + }, + "required": true, + "description": "The Cardano network used to register the agent on", + "name": "network", + "in": "query" + }, + { + "schema": { + "type": "string", + "maxLength": 250, + "description": "The smart contract address of the payment source to which the registration belongs" + }, + "required": false, + "description": "The smart contract address of the payment source to which the registration belongs", + "name": "smartContractAddress", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Agent metadata", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "status": { + "type": "string" + }, + "data": { + "type": "object", + "properties": { + "assets": { + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string", + "nullable": true + }, + "apiUrl": { + "type": "string" + }, + "capabilityName": { + "type": "string" + }, + "capabilityVersion": { + "type": "string" + }, + "requestsPerHour": { + "type": "string", + "nullable": true + }, + "authorName": { + "type": "string" + }, + "authorContact": { + "type": "string", + "nullable": true + }, + "authorOrganization": { + "type": "string", + "nullable": true + }, + "privacyPolicy": { + "type": "string", + "nullable": true + }, + "terms": { + "type": "string", + "nullable": true + }, + "other": { + "type": "string", + "nullable": true + }, + "state": { + "type": "string", + "enum": [ + "RegistrationRequested", + "RegistrationInitiated", + "RegistrationConfirmed", + "RegistrationFailed", + "DeregistrationRequested", + "DeregistrationInitiated", + "DeregistrationConfirmed", + "DeregistrationFailed" + ] + }, + "tags": { + "type": "array", + "items": { + "type": "string" + } + }, + "createdAt": { + "type": "string" + }, + "updatedAt": { + "type": "string" + }, + "lastCheckedAt": { + "type": "string", + "nullable": true + }, + "agentIdentifier": { + "type": "string", + "nullable": true + }, + "Pricing": { + "type": "array", + "items": { + "type": "object", + "properties": { + "unit": { + "type": "string" + }, + "quantity": { + "type": "string" + } + }, + "required": [ + "unit", + "quantity" + ] + } + }, + "SmartContractWallet": { + "type": "object", + "properties": { + "walletVkey": { + "type": "string" + }, + "walletAddress": { + "type": "string" + } + }, + "required": [ + "walletVkey", + "walletAddress" + ] + }, + "CurrentTransaction": { + "type": "object", + "nullable": true, + "properties": { + "txHash": { + "type": "string" + }, + "status": { + "type": "string", + "enum": [ + "Pending", + "Confirmed", + "FailedViaTimeout" + ] + } + }, + "required": [ + "txHash", + "status" + ] + } + }, + "required": [ + "id", + "name", + "description", + "apiUrl", + "capabilityName", + "capabilityVersion", + "requestsPerHour", + "authorName", + "authorContact", + "authorOrganization", + "privacyPolicy", + "terms", + "other", + "state", + "tags", + "createdAt", + "updatedAt", + "lastCheckedAt", + "agentIdentifier", + "Pricing", + "SmartContractWallet", + "CurrentTransaction" + ] } } + }, + "required": [ + "assets" + ] + } + }, + "required": [ + "status", + "data" + ], + "example": { + "status": "success", + "data": { + "assets": [ + { + "id": "asset_id", + "name": "name", + "description": "description", + "apiUrl": "api_url", + "capabilityName": "capability_name", + "capabilityVersion": "capability_version", + "requestsPerHour": "100", + "authorName": "author_name", + "authorContact": "author_contact", + "authorOrganization": "author_organization", + "privacyPolicy": "link to privacy policy", + "terms": "link to terms", + "other": "link to other", + "state": "RegistrationRequested", + "tags": [ + "tag1", + "tag2" + ], + "createdAt": "1970-01-20T20:00:36.260Z", + "updatedAt": "1970-01-20T20:00:36.260Z", + "lastCheckedAt": "1970-01-20T20:00:36.260Z", + "agentIdentifier": "agent_identifier", + "Pricing": [ + { + "unit": "unit", + "quantity": "1000000" + } + ], + "SmartContractWallet": { + "walletVkey": "wallet_vkey", + "walletAddress": "wallet_address" + }, + "CurrentTransaction": null + } ] } } @@ -4472,7 +4759,7 @@ "maxLength": 250, "description": "The payment key of a specific wallet used for the registration" }, - "example_output": { + "exampleOutput": { "type": "string", "maxLength": 250, "description": "Link to a example output of the agent" @@ -4492,7 +4779,7 @@ "maxLength": 250, "description": "Name of the agent" }, - "api_url": { + "apiUrl": { "type": "string", "maxLength": 250, "description": "Base URL of the agent, to request interactions" @@ -4520,7 +4807,7 @@ ], "description": "Provide information about the used AI model and version" }, - "requests_per_hour": { + "requestsPerHour": { "type": "string", "maxLength": 250, "description": "The request the agent can handle per hour" @@ -4536,7 +4823,7 @@ }, "quantity": { "type": "string", - "maxLength": 55 + "maxLength": 25 } }, "required": [ @@ -4550,7 +4837,7 @@ "legal": { "type": "object", "properties": { - "privacy_policy": { + "privacyPolicy": { "type": "string", "maxLength": 250 }, @@ -4592,23 +4879,23 @@ "sellingWalletVkey", "tags", "name", - "api_url", + "apiUrl", "description", "capability", - "requests_per_hour", + "requestsPerHour", "pricing", "author" ], "example": { "network": "Preprod", "smartContractAddress": "addr_test1", - "example_output": "example_output", + "exampleOutput": "example_output", "tags": [ "tag1", "tag2" ], "name": "Agent Name", - "api_url": "https://api.example.com", + "apiUrl": "https://api.example.com", "description": "Agent Description", "author": { "name": "Author Name", @@ -4616,7 +4903,7 @@ "organization": "Author Organization" }, "legal": { - "privacy_policy": "Privacy Policy URL", + "privacyPolicy": "Privacy Policy URL", "terms": "Terms of Service URL", "other": "Other Legal Information URL" }, @@ -4625,7 +4912,7 @@ "name": "Capability Name", "version": "1.0.0" }, - "requests_per_hour": "100", + "requestsPerHour": "100", "pricing": [ { "unit": "usdm", @@ -4651,27 +4938,30 @@ "data": { "type": "object", "properties": { + "id": { + "type": "string" + }, "name": { "type": "string" }, - "api_url": { + "apiUrl": { "type": "string" }, - "capability_name": { + "capabilityName": { "type": "string" }, - "capability_version": { + "capabilityVersion": { "type": "string" }, "description": { "type": "string", "nullable": true }, - "requests_per_hour": { + "requestsPerHour": { "type": "string", "nullable": true }, - "privacy_policy": { + "privacyPolicy": { "type": "string", "nullable": true }, @@ -4737,13 +5027,14 @@ } }, "required": [ + "id", "name", - "api_url", - "capability_name", - "capability_version", + "apiUrl", + "capabilityName", + "capabilityVersion", "description", - "requests_per_hour", - "privacy_policy", + "requestsPerHour", + "privacyPolicy", "terms", "other", "tags", @@ -4760,14 +5051,15 @@ "example": { "status": "success", "data": { - "api_url": "api_url", + "id": "cuid2", + "apiUrl": "api_url", "tags": [ "tag1", "tag2" ], - "capability_name": "capability_name", - "capability_version": "capability_version", - "requests_per_hour": "100", + "capabilityName": "capability_name", + "capabilityVersion": "capability_version", + "requestsPerHour": "100", "Pricing": [ { "unit": "usdm", @@ -4781,7 +5073,7 @@ "state": "RegistrationRequested", "description": "description", "name": "name", - "privacy_policy": "link to privacy policy", + "privacyPolicy": "link to privacy policy", "terms": "link to terms", "other": "link to other" } @@ -4812,7 +5104,7 @@ }, "required": true, "description": "The identifier of the registration (asset) to be deregistered", - "name": "assetName", + "name": "agentIdentifier", "in": "query" }, { @@ -4855,27 +5147,30 @@ "data": { "type": "object", "properties": { + "id": { + "type": "string" + }, "name": { "type": "string" }, - "api_url": { + "apiUrl": { "type": "string" }, - "capability_name": { + "capabilityName": { "type": "string" }, - "capability_version": { + "capabilityVersion": { "type": "string" }, "description": { "type": "string", "nullable": true }, - "requests_per_hour": { + "requestsPerHour": { "type": "string", "nullable": true }, - "privacy_policy": { + "privacyPolicy": { "type": "string", "nullable": true }, @@ -4941,13 +5236,14 @@ } }, "required": [ + "id", "name", - "api_url", - "capability_name", - "capability_version", + "apiUrl", + "capabilityName", + "capabilityVersion", "description", - "requests_per_hour", - "privacy_policy", + "requestsPerHour", + "privacyPolicy", "terms", "other", "tags", @@ -4964,14 +5260,15 @@ "example": { "status": "success", "data": { - "api_url": "api_url", + "id": "cuid2", + "apiUrl": "api_url", "tags": [ "tag1", "tag2" ], - "capability_name": "capability_name", - "capability_version": "capability_version", - "requests_per_hour": "100", + "capabilityName": "capability_name", + "capabilityVersion": "capability_version", + "requestsPerHour": "100", "Pricing": [ { "unit": "usdm", @@ -4985,7 +5282,7 @@ "state": "RegistrationRequested", "description": "description", "name": "name", - "privacy_policy": "link to privacy policy", + "privacyPolicy": "link to privacy policy", "terms": "link to terms", "other": "link to other" } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index c49b617..0800e5f 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -9,6 +9,7 @@ "version": "0.1.0", "dependencies": { "@hey-api/client-axios": "^0.6.1", + "@hey-api/client-fetch": "^0.8.1", "@hey-api/openapi-ts": "^0.64.6", "@meshsdk/core": "^1.9.0-beta.4", "@radix-ui/react-dialog": "^1.0.4", @@ -1023,6 +1024,15 @@ "axios": ">= 1.0.0 < 2" } }, + "node_modules/@hey-api/client-fetch": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@hey-api/client-fetch/-/client-fetch-0.8.1.tgz", + "integrity": "sha512-AaVNVLBl7N9Fun7QDnb00YDubAFjB9ICi5U6kmzcJSnnQTQGRMsuBBRupQV5ERdMMFt71zjSDym7Z+gLVe8m3A==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/hey-api" + } + }, "node_modules/@hey-api/json-schema-ref-parser": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/@hey-api/json-schema-ref-parser/-/json-schema-ref-parser-1.0.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 0ddab5e..9b19dd9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@hey-api/client-axios": "^0.6.1", + "@hey-api/client-fetch": "^0.8.1", "@hey-api/openapi-ts": "^0.64.6", "@meshsdk/core": "^1.9.0-beta.4", "@radix-ui/react-dialog": "^1.0.4", diff --git a/frontend/src/components/dashboard/CreateContractModal.tsx b/frontend/src/components/dashboard/CreateContractModal.tsx index 22bff15..9bd0b20 100644 --- a/frontend/src/components/dashboard/CreateContractModal.tsx +++ b/frontend/src/components/dashboard/CreateContractModal.tsx @@ -3,16 +3,15 @@ import { Button } from "@/components/ui/button"; import { useState } from "react"; import { useAppContext } from "@/lib/contexts/AppContext"; import { X } from "lucide-react"; -import { createPaymentSource } from "@/lib/api/create-payment-source"; -import { getPaymentSources } from "@/lib/api/payment-source"; +import { postPaymentSource, getPaymentSource } from "@/lib/api/generated"; type CreateContractModalProps = { onClose: () => void; } type FormData = { - network: 'MAINNET' | 'PREPROD'; - paymentType: string; + network: 'Mainnet' | 'Preprod'; + paymentType: 'Web3CardanoV1'; blockfrostApiKey: string; adminWallets: { walletAddress: string }[]; feeReceiverWallet: { walletAddress: string }; @@ -32,8 +31,8 @@ type FormData = { } const initialFormData: FormData = { - network: 'PREPROD', - paymentType: 'WEB3_CARDANO_V1', + network: 'Preprod', + paymentType: 'Web3CardanoV1', blockfrostApiKey: '', adminWallets: [{ walletAddress: '' }], feeReceiverWallet: { walletAddress: '' }, @@ -44,15 +43,13 @@ const initialFormData: FormData = { }; export function CreateContractModal({ onClose }: CreateContractModalProps) { - const { state } = useAppContext(); - const [formData, setFormData] = useState({ ...initialFormData, }); - const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); const { dispatch } = useAppContext(); + const { apiClient } = useAppContext(); const handleAdd = async () => { setError(''); @@ -79,27 +76,52 @@ export function CreateContractModal({ onClose }: CreateContractModalProps) { return; } - const payload = { - network: formData.network, - paymentType: formData.paymentType, - blockfrostApiKey: formData.blockfrostApiKey, - AdminWallets: formData.adminWallets.filter(w => w.walletAddress.trim()), - FeeReceiverNetworkWallet: formData.feeReceiverWallet, - FeePermille: formData.feePermille, - CollectionWallet: formData.collectionWallet, - PurchasingWallets: formData.purchasingWallets.filter(w => w.walletMnemonic.trim()), - SellingWallets: formData.sellingWallets.filter(w => w.walletMnemonic.trim()) - }; - - await createPaymentSource(payload, state.apiKey!); - + if (formData.adminWallets.length != 3) { + setError('At least 3 admin wallets are required'); + return; + } + await postPaymentSource({ + client: apiClient, + body: { + AdminWallets: formData.adminWallets.filter(w => w.walletAddress.trim()).slice(0, 3) as [ + { walletAddress: string }, + { walletAddress: string }, + { walletAddress: string } + ], + network: formData.network, + paymentType: formData.paymentType, + feeRatePermille: formData.feePermille, + FeeReceiverNetworkWallet: formData.feeReceiverWallet, + PurchasingWallets: formData.purchasingWallets.filter(w => w.walletMnemonic.trim()).map(w => ({ + walletMnemonic: w.walletMnemonic, + collectionAddress: formData.collectionWallet.walletAddress.trim(), + note: w.note || '' + })), + SellingWallets: formData.sellingWallets.filter(w => w.walletMnemonic.trim()).map(w => ({ + walletMnemonic: w.walletMnemonic, + collectionAddress: formData.collectionWallet.walletAddress.trim(), + note: w.note || '' + })), + PaymentSourceConfig: { + rpcProviderApiKey: formData.blockfrostApiKey, + rpcProvider: 'Blockfrost' + }, + } + }); - const sourcesData = await getPaymentSources(state.apiKey!); + //TODO: refetch all + const sourcesData = await getPaymentSource({ + client: apiClient, + query: { + cursorId: undefined, + take: 100, + } + }); dispatch({ type: 'SET_PAYMENT_SOURCES', - payload: sourcesData?.data?.paymentSources || [] + payload: sourcesData?.data?.data?.paymentSources || [] }); onClose(); @@ -157,7 +179,7 @@ export function CreateContractModal({ onClose }: CreateContractModalProps) {