Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 22 additions & 17 deletions src/components/shared/allocator-card.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Image from 'next/image';
import type { Address } from 'viem';
import { AccountIdentity } from './account-identity';
import { useConnection } from 'wagmi';
import { SupportedNetworks } from '@/utils/networks';
import { getSlicedAddress } from '@/utils/address';

type AllocatorCardProps = {
name: string;
address: Address;
description: string;
image?: string;
isSelected?: boolean;
onSelect?: () => void;
disabled?: boolean;
Expand All @@ -16,29 +16,41 @@ export function AllocatorCard({
name,
address,
description,
image,
isSelected = false,
onSelect,
disabled = false,
}: AllocatorCardProps): JSX.Element {
const { chainId } = useConnection();
return (
<button
type="button"
onClick={onSelect}
disabled={disabled}
className={`w-full rounded border p-4 text-left transition-all duration-200 ease-in-out ${
className={`w-full rounded border px-3 py-2.5 text-left transition-all duration-200 ease-in-out ${
isSelected
? 'border-primary bg-primary/10 dark:bg-primary/20'
: 'border-gray-100 bg-gray-50/50 hover:border-gray-300 dark:border-gray-700 dark:bg-gray-900/50 dark:hover:border-gray-600'
} ${disabled ? 'cursor-not-allowed opacity-50' : 'cursor-pointer'}`}
>
<div className="flex flex-col gap-3">
<div className="flex flex-col gap-1">
<div className="flex items-center justify-between">
<h4 className="font-medium text-primary">{name}</h4>
<div className="flex items-center gap-2">
{image && (
<Image
src={image}
alt={name}
width={20}
height={20}
className="rounded-full"
/>
)}
<span className="text-sm font-medium text-primary">{name}</span>
<span className="text-xs text-tertiary">{getSlicedAddress(address)}</span>
</div>
{isSelected && (
<div className="flex h-5 w-5 items-center justify-center rounded-full bg-primary">
<div className="flex h-4 w-4 shrink-0 items-center justify-center rounded-full bg-primary">
<svg
className="h-3 w-3 text-white"
className="h-2.5 w-2.5 text-white"
fill="none"
strokeLinecap="round"
strokeLinejoin="round"
Expand All @@ -51,14 +63,7 @@ export function AllocatorCard({
</div>
)}
</div>
<div className="text-xs text-secondary">
<AccountIdentity
address={address}
chainId={chainId ?? SupportedNetworks.Mainnet}
variant="full"
/>
</div>
<p className="text-sm text-secondary">{description}</p>
<p className="text-xs text-secondary">{description}</p>
</div>
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useMorphoMarketV1Adapters } from '@/hooks/useMorphoMarketV1Adapters';
import { v2AgentsBase } from '@/utils/monarch-agent';
import { getMorphoAddress } from '@/utils/morpho';
import { ALL_SUPPORTED_NETWORKS, SupportedNetworks, getNetworkConfig } from '@/utils/networks';
import { startVaultIndexing } from '@/utils/vault-indexing';
import { useVaultIndexingStore } from '@/stores/vault-indexing-store';
import { useVaultInitializationModalStore } from '@/stores/vault-initialization-modal-store';

const ZERO_ADDRESS = zeroAddress;
Expand Down Expand Up @@ -63,13 +63,7 @@ function DeployAdapterStep({
<div className="space-y-2">
<div className="flex items-center gap-2 text-xs text-secondary">
{isDeploying && <Spinner size={12} />}
<span>
{adapterDetected
? `Adapter detected: ${shortenAddress(adapterAddress)}`
: isDeploying
? 'Deploying adapter...'
: 'Adapter not detected yet. Click deploy to create one.'}
</span>
<span>{adapterDetected ? `Adapter detected: ${shortenAddress(adapterAddress)}` : isDeploying ? 'Deploying adapter...' : ''}</span>
</div>
</div>
</div>
Expand Down Expand Up @@ -165,14 +159,17 @@ function AgentSelectionStep({
}) {
return (
<div className="space-y-4 font-zen">
<p className="text-sm text-secondary">Choose an agent to automate your vault's allocations. You can change this later in settings.</p>
<p className="text-sm text-secondary">
Choose an allocator to automate your vault's allocations. You can change this later in settings.
</p>
<div className="space-y-3">
{v2AgentsBase.map((agent) => (
<AllocatorCard
key={agent.address}
name={agent.name}
address={agent.address as Address}
description={agent.strategyDescription}
image={agent.image}
isSelected={selectedAgent === (agent.address as Address)}
onSelect={() => onSelectAgent(selectedAgent === (agent.address as Address) ? null : (agent.address as Address))}
/>
Expand All @@ -194,6 +191,7 @@ const MAX_SYMBOL_LENGTH = 16;
export function VaultInitializationModal() {
// Modal state from Zustand (UI state)
const { isOpen, close } = useVaultInitializationModalStore();
const { startIndexing } = useVaultIndexingStore();

// Get vault address and chain ID from URL params
const { chainId: chainIdParam, vaultAddress } = useParams<{
Expand Down Expand Up @@ -238,7 +236,7 @@ export function VaultInitializationModal() {
});

const [stepIndex, setStepIndex] = useState(0);
const [selectedAgent, setSelectedAgent] = useState<Address | null>((v2AgentsBase.at(0)?.address as Address) || null);
const [selectedAgent, setSelectedAgent] = useState<Address | null>((v2AgentsBase.at(0)?.address as Address) ?? null);
const [vaultName, setVaultName] = useState<string>('');
const [vaultSymbol, setVaultSymbol] = useState<string>('');
const [deployedAdapter, setDeployedAdapter] = useState<Address>(ZERO_ADDRESS);
Expand Down Expand Up @@ -331,7 +329,7 @@ export function VaultInitializationModal() {
}

// Start indexing mode - vault page will handle retry logic
startVaultIndexing(vaultAddress, chainId);
startIndexing(vaultAddressValue, chainId);

// Trigger initial refetch
void vaultDataQuery.refetch();
Expand All @@ -348,20 +346,22 @@ export function VaultInitializationModal() {
vaultContract,
refetchAdapter,
close,
startIndexing,
registryAddress,
selectedAgent,
adapterAddress,
vaultName,
vaultSymbol,
vaultAddress,
vaultAddressValue,
chainId,
]);

// Reset state when modal closes
useEffect(() => {
if (!isOpen) {
setStepIndex(0);
setSelectedAgent(null);
setSelectedAgent((v2AgentsBase.at(0)?.address as Address) ?? null);
setVaultName('');
setVaultSymbol('');
setDeployedAdapter(ZERO_ADDRESS);
Expand All @@ -382,7 +382,7 @@ export function VaultInitializationModal() {
case 'metadata':
return 'Set vault name & symbol';
case 'agents':
return 'Choose an agent';
return 'Choose an Allocator';
case 'finalize':
return 'Review & finalize';
default:
Expand Down Expand Up @@ -480,7 +480,7 @@ export function VaultInitializationModal() {
mainIcon={<FiZap className="h-5 w-5" />}
onClose={close}
/>
<ModalBody className="space-y-6 px-8 py-6">
<ModalBody className="space-y-6 px-6 py-8">
{currentStep === 'deploy' && (
<DeployAdapterStep
isDeploying={isDeploying}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function CurrentCaps({ existingCaps, isOwner, onStartEdit, chainId, vault

try {
const capBigInt = BigInt(cap);
if (capBigInt >= maxUint128) {
if (capBigInt === 0n || capBigInt >= maxUint128) {
return 'No limit';
}
const value = Number(capBigInt) / 10 ** vaultAssetDecimals;
Expand Down Expand Up @@ -109,7 +109,7 @@ export function CurrentCaps({ existingCaps, isOwner, onStartEdit, chainId, vault
sharedMarketCount,
};
})
.filter((item) => item.market !== undefined) ?? []
.filter((item) => item.market !== undefined && item.effectiveCap > 0) ?? []
);
}, [existingCaps, markets, collateralCapMap, marketCountByCollateral]);

Expand Down
Loading