Skip to content

SelectSubnet, SelectBlockchain, inputSubnetId & useAvaCloudSDK #2531

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5420897
initial component layout
navillanueva Jun 2, 2025
03eb2a8
improved UI - AvaCloud getSubnetById method missing data
navillanueva Jun 2, 2025
0e517eb
upgraded latest Avacloud SDK version + improved UI
navillanueva Jun 3, 2025
7ce6a2e
fixed Validator Manager latest Avacloud SDK version changes
navillanueva Jun 3, 2025
3a7486b
spacing on succesful subnet creation + fixed compilation errors
navillanueva Jun 3, 2025
f3dbb0b
created InputSubnetId component
navillanueva Jun 3, 2025
7479acf
fix build error
navillanueva Jun 3, 2025
2b9037a
`SelectBlockchain` and refactored ChainID to BlockchainId (#2557)
navillanueva Jun 11, 2025
5f89b2c
Merge remote-tracking branch 'origin/master' into refactor-selectSubn…
navillanueva Jun 11, 2025
9727a59
removed unused imports
navillanueva Jun 11, 2025
3ae6c84
merged main and resolved conflicts
navillanueva Jun 12, 2025
be65328
resolved AvacloudSDK v1.12.1 build errros
navillanueva Jun 12, 2025
8977c27
updating serverURL init for Avacloud SDK
navillanueva Jun 16, 2025
1a905bf
fetching VM ID and warning user - pending correctly creating docker c…
navillanueva May 31, 2025
0391636
fixed Ilya's comments
navillanueva Jun 17, 2025
cf9eb57
fixed build errors
navillanueva Jun 17, 2025
e6f2ede
added testing changes
navillanueva Jun 17, 2025
190a450
removed unused files
navillanueva Jun 17, 2025
f65740a
fixin component UI + input subnet ID on create chain
navillanueva Jun 18, 2025
e23d1a6
fix aggregate signature
navillanueva Jun 18, 2025
b4bb603
fix aggregate signature pending buffer issue
navillanueva Jun 18, 2025
fa48fe5
fix build errors
navillanueva Jun 19, 2025
8281f1d
fix build errors
navillanueva Jun 19, 2025
d1cf715
added justification to complete validator removal
navillanueva Jun 19, 2025
8422237
adding justification to the complete sign aggregate
navillanueva Jun 20, 2025
ad67d7e
Merge remote-tracking branch 'origin/master' into refactor-selectSubn…
navillanueva Jun 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/tools/common/api/validator-info.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Validator, SubnetInfo, L1ValidatorManagerDetails } from './types';
import { pChainEndpoint } from './consts';
import { AvaCloudSDK } from "@avalabs/avacloud-sdk";
import { useWalletStore } from "../../../../toolbox/src/stores/walletStore";
const { isTestnet } = useWalletStore();

export const avaCloudSDK = new AvaCloudSDK({
serverURL: isTestnet ? "https://api.avax-test.network" : "https://api.avax.network",
chainId: "43114",
network: "fuji",
});
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"postinstall": "prisma generate && fumadocs-mdx && cd toolbox && yarn"
},
"dependencies": {
"@avalabs/avacloud-sdk": "0.8.7",
"@avalabs/avacloud-sdk": "0.12.1",
"@avalabs/avalanchejs": "^5.0.0",
"@fumadocs/mdx-remote": "^1.2.0",
"@hookform/resolvers": "^4.1.3",
Expand Down Expand Up @@ -129,4 +129,4 @@
"typescript": "^5.8.2"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
}
4 changes: 2 additions & 2 deletions toolbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"postinstall": "node update_docker_tags.js"
},
"dependencies": {
"@avalabs/avacloud-sdk": "^0.9.0",
"@avalabs/avacloud-sdk": "^0.12.1",
"@avalabs/avalanchejs": "^4.1.2-alpha.4",
"@radix-ui/react-alert-dialog": "^1.1.13",
"@radix-ui/react-checkbox": "^1.2.3",
Expand Down Expand Up @@ -77,4 +77,4 @@
"vite": "^6.1.6",
"vite-plugin-dts": "^4.5.0"
}
}
}
347 changes: 347 additions & 0 deletions toolbox/src/components/BlockchainDetailsDisplay.tsx

Large diffs are not rendered by default.

150 changes: 150 additions & 0 deletions toolbox/src/components/InputSubnetId.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
"use client"

import { Input, type Suggestion } from "./Input";
import { useL1ListStore } from "../stores/l1ListStore";
import { useCreateChainStore } from "../stores/createChainStore";
import { useMemo, useState, useCallback, useEffect } from "react";
import { utils } from "@avalabs/avalanchejs";
import { useAvaCloudSDK } from "../stores/useAvaCloudSDK";

// Primary network subnet ID
export const PRIMARY_NETWORK_SUBNET_ID = "11111111111111111111111111111111LpoYY";

export default function InputSubnetId({
value,
onChange,
error,
label = "Subnet ID",
hidePrimaryNetwork = true,
helperText,
id,
validationDelayMs = 500,
readOnly = false,
hideSuggestions = false,
placeholder
}: {
value: string,
onChange: (value: string) => void,
error?: string | null,
label?: string,
hidePrimaryNetwork?: boolean
helperText?: string | null
id?: string
validationDelayMs?: number
readOnly?: boolean
hideSuggestions?: boolean
placeholder?: string
}) {
const createChainStoreSubnetId = useCreateChainStore()(state => state.subnetId);
const { l1List } = useL1ListStore()();
const { getSubnetById } = useAvaCloudSDK();

const [validationError, setValidationError] = useState<string | null>(null);

// Validate subnet ID format and checksum using Base58Check
const validateBase58Format = (subnetId: string): boolean => {
try {
// Validate Base58Check format and checksum (last 4 bytes)
utils.base58check.decode(subnetId);
return true;
} catch (error) {
return false;
}
};

// Validate subnet ID using AvaCloud SDK
const validateSubnetId = useCallback(async (subnetId: string) => {
if (!subnetId || subnetId.length < 10) {
setValidationError(null);
return;
}

// First validate Base58Check format and checksum
if (!validateBase58Format(subnetId)) {
setValidationError("Invalid subnet ID format or checksum");
return;
}

try {
setValidationError(null);

await getSubnetById({ subnetId });

// If we get here, the subnet exists
setValidationError(null);
} catch (error) {
// Show validation error for invalid subnet IDs
setValidationError("Subnet ID not found or invalid");
}
}, [getSubnetById]);

// Validate when value changes
useEffect(() => {
const timeoutId = setTimeout(() => {
if (value) {
validateSubnetId(value);
} else {
setValidationError(null);
}
}, validationDelayMs); // Wait for subnet to be available before validation

return () => clearTimeout(timeoutId);
}, [value, validateSubnetId, validationDelayMs]);

const subnetIdSuggestions: Suggestion[] = useMemo(() => {
const result: Suggestion[] = [];
const seen = new Set<string>();

// Add subnet from create chain store first
if (createChainStoreSubnetId && !(hidePrimaryNetwork && createChainStoreSubnetId === PRIMARY_NETWORK_SUBNET_ID)) {
result.push({
title: createChainStoreSubnetId,
value: createChainStoreSubnetId,
description: "The Subnet that you have just created in the \"Create Chain\" tool"
});
seen.add(createChainStoreSubnetId);
}

// Add subnets from L1 list
for (const l1 of l1List) {
const { subnetId, name } = l1;

if (!subnetId || seen.has(subnetId)) continue;

if (hidePrimaryNetwork && subnetId === PRIMARY_NETWORK_SUBNET_ID) {
continue;
}

result.push({
title: `${name} (${subnetId})`,
value: subnetId,
description: l1.description || "A subnet that was added to your L1 list.",
});

seen.add(subnetId);
}

return result;
}, [createChainStoreSubnetId, l1List, hidePrimaryNetwork]);

// Combine validation error with passed error
const combinedError = error || validationError;

return (
<Input
id={id}
label={label}
value={value}
onChange={onChange}
suggestions={readOnly || hideSuggestions ? [] : subnetIdSuggestions}
error={combinedError}
helperText={helperText}
placeholder={
readOnly
? "Automatically filled from Blockchain ID"
: placeholder || "Enter subnet ID"
}
disabled={readOnly}
/>
);
}
121 changes: 121 additions & 0 deletions toolbox/src/components/SelectBlockchain.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
"use client"

import SelectBlockchainId from "./SelectBlockchainId";
import { useState, useCallback } from "react";
import { useWalletStore } from "../stores/walletStore";
import { networkIDs } from "@avalabs/avalanchejs";

// API Response type from AvaCloud - matches the official API response
export type BlockchainApiResponse = {
createBlockTimestamp: number;
createBlockNumber: string;
blockchainId: string;
vmId: string;
subnetId: string;
blockchainName: string;
evmChainId: number;
}

// Extended type with additional metadata
export type BlockchainInfo = BlockchainApiResponse & {
isTestnet: boolean;
}

export type BlockchainSelection = {
blockchainId: string;
blockchain: BlockchainInfo | null;
}

// Import the unified details display component
import BlockchainDetailsDisplay from "./BlockchainDetailsDisplay";

export default function SelectBlockchain({
value,
onChange,
error,
label = "Select Avalanche Blockchain ID"
}: {
value: string,
onChange: (selection: BlockchainSelection) => void,
error?: string | null,
label?: string
}) {
const { avalancheNetworkID } = useWalletStore();
const [blockchainDetails, setBlockchainDetails] = useState<Record<string, BlockchainInfo>>({});
const [isLoading, setIsLoading] = useState(false);

// Network names for API calls
const networkNames: Record<number, string> = {
[networkIDs.MainnetID]: "mainnet",
[networkIDs.FujiID]: "fuji",
};

// Fetch blockchain details when needed
const fetchBlockchainDetails = useCallback(async (blockchainId: string) => {
if (!blockchainId || blockchainDetails[blockchainId]) return;

try {
const network = networkNames[Number(avalancheNetworkID)];
if (!network) return;

setIsLoading(true);

// Use direct API call as shown in AvaCloud documentation
// https://developers.avacloud.io/data-api/primary-network/get-blockchain-details-by-id
const response = await fetch(`https://glacier-api.avax.network/v1/networks/${network}/blockchains/${blockchainId}`, {
method: 'GET',
headers: {
'accept': 'application/json',
},
});

if (!response.ok) {
throw new Error(`Failed to fetch blockchain details: ${response.statusText}`);
}

const blockchain: BlockchainApiResponse = await response.json();

setBlockchainDetails(prev => ({
...prev,
[blockchainId]: {
...blockchain,
isTestnet: network === "fuji"
}
}));
} catch (error) {
console.error(`Error fetching blockchain details for ${blockchainId}:`, error);
} finally {
setIsLoading(false);
}
}, [avalancheNetworkID, networkNames, blockchainDetails]);

// Handle value change and fetch details if needed
const handleValueChange = useCallback((newValue: string) => {
if (newValue && !blockchainDetails[newValue]) {
fetchBlockchainDetails(newValue);
}

onChange({
blockchainId: newValue,
blockchain: blockchainDetails[newValue] || null
});
}, [fetchBlockchainDetails, blockchainDetails, onChange]);

// Get current blockchain details for display
const currentBlockchain = value ? blockchainDetails[value] || null : null;
const isLoadingCurrent = value && !blockchainDetails[value] && isLoading;

return (
<div>
<SelectBlockchainId
value={value}
onChange={handleValueChange}
error={error}
label={label}
/>

{/* Display blockchain details when a blockchain is selected */}
{value && <BlockchainDetailsDisplay blockchain={currentBlockchain} isLoading={!!isLoadingCurrent} />}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { useMemo } from "react";
import { cn } from "../lib/utils";
import { Globe } from 'lucide-react';

interface ChainOption {
interface BlockchainOption {
id: string;
name: string;
description: string;
logoUrl?: string;
}

export default function SelectChainID({
export default function SelectBlockchainId({
value,
onChange,
error,
Expand All @@ -28,8 +28,8 @@ export default function SelectChainID({
const { l1List } = useL1ListStore()();
const selectId = useId();

const options: ChainOption[] = useMemo(() => {
const result: ChainOption[] = [];
const options: BlockchainOption[] = useMemo(() => {
const result: BlockchainOption[] = [];

if (createChainStorechainID) {
result.push({
Expand Down Expand Up @@ -90,7 +90,7 @@ export default function SelectChainID({
</div>
</div>
) : (
<div className="text-zinc-400 dark:text-zinc-500">Select a chain ID</div>
<div className="text-zinc-400 dark:text-zinc-500">Select a blockchain ID</div>
)}
</button>

Expand Down Expand Up @@ -129,4 +129,4 @@ export default function SelectChainID({
{error && <p className="text-xs text-red-500 mt-1">{error}</p>}
</div>
);
}
}
Loading