-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseVaults.ts
More file actions
27 lines (23 loc) · 939 Bytes
/
useVaults.ts
File metadata and controls
27 lines (23 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use client';
import { useState } from 'react';
import { container } from 'tsyringe';
import type { VaultModelDto } from '@shared/dto/models/vault.model.dto';
import type { GetMyVaultsDataDto } from '@shared/dto/output/data/get-my-vaults.data.dto';
import { VaultsGateway } from '@ui/gateways/vaults.gateway';
import { useApiFetch } from '@ui/hooks/api/useApiFetch';
export function useVaults(): {
vaults: VaultModelDto[];
loading: boolean;
error: Error | null;
refetch: () => Promise<void>;
} {
const gateway: VaultsGateway = container.resolve(VaultsGateway);
const [vaults, setVaults] = useState<VaultModelDto[]>([]);
const [error, setError] = useState<Error | null>(null);
const { loading, refetch } = useApiFetch<GetMyVaultsDataDto>({
request: () => gateway.getMyVaults(),
onSuccess: data => setVaults(data.myVaults),
onError: err => setError(err),
});
return { vaults, loading, error, refetch };
}