Skip to content

Commit

Permalink
Merge pull request #31 from subsquid/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
belopash authored Jun 11, 2024
2 parents 8a5fe74 + 754dccd commit b16adc5
Show file tree
Hide file tree
Showing 35 changed files with 1,420 additions and 825 deletions.
39 changes: 21 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { WagmiProvider } from 'wagmi';

import { queryClient } from '@api/client';
import { Alert } from '@components/Alert';
import { SquidHeightProvider } from '@hooks/useSquidNetworkHeightHooks';
import { wagmiConfig } from '@network/config';

import { AppRoutes } from './AppRoutes';
Expand All @@ -22,24 +23,26 @@ function App() {
return (
<WagmiProvider config={wagmiConfig}>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<RainbowKitProvider modalSize="compact" theme={rainbowkitTheme}>
<SnackbarProvider
hideIconVariant
preventDuplicate
maxSnack={3}
Components={{
subsquid: Alert,
}}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
>
<CssBaseline />
<BrowserRouter>
<AppRoutes />
</BrowserRouter>
</SnackbarProvider>
</RainbowKitProvider>
</ThemeProvider>
<SquidHeightProvider>
<ThemeProvider theme={theme}>
<RainbowKitProvider modalSize="compact" theme={rainbowkitTheme}>
<SnackbarProvider
hideIconVariant
preventDuplicate
maxSnack={3}
Components={{
subsquid: Alert,
}}
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
>
<CssBaseline />
<BrowserRouter>
<AppRoutes />
</BrowserRouter>
</SnackbarProvider>
</RainbowKitProvider>
</ThemeProvider>
</SquidHeightProvider>
</QueryClientProvider>
</WagmiProvider>
);
Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useWriteContract, useClient } from 'wagmi';
import { REWARD_TREASURY_CONTRACT_ABI } from '@api/contracts/reaward-treasury.abi';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount.ts';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -67,7 +67,7 @@ function useClaimFromVestingContract() {

export function useClaim() {
const client = useClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/gateway-registration/useRegisterGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { encodeFunctionData } from 'viem';
import { usePublicClient, useWriteContract } from 'wagmi';

import { AccountType } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -82,7 +82,7 @@ export function useRegisterGateway() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setLoading] = useState(false);

const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const registerGatewayFromWallet = useRegisterGatewayFromWallet();
const registerGatewayFromVestingContract = useRegisterGatewayFromVestingContract();

Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/gateway-registration/useStakeGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { encodeFunctionData } from 'viem';
import { usePublicClient, useWriteContract } from 'wagmi';

import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -105,7 +105,7 @@ function useStakeFromVestingContract() {

export function useStakeGateway() {
const client = usePublicClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useWriteContract, usePublicClient } from 'wagmi';

import { AccountType } from '@api/subsquid-network-squid';
import { BlockchainGateway } from '@api/subsquid-network-squid/gateways-graphql';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -78,7 +78,7 @@ export function useUnregisterGateway() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setLoading] = useState(false);

const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const unregisterGatewayFromWallet = useUnregisterGatewayFromWallet();
const unregisterGatewayFromVestingContract = useUnregisterGatewayFromVestingContract();

Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/gateway-registration/useUnstakeGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { encodeFunctionData } from 'viem';
import { useWriteContract, usePublicClient } from 'wagmi';

import { AccountType, GatewayStakeFragmentFragment } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -65,7 +65,7 @@ function useUnstakeFromVestingContract() {

export function useUnstakeGateway() {
const client = usePublicClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand Down
12 changes: 6 additions & 6 deletions src/api/contracts/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {

import { useApproveSqd } from '@api/contracts/sqd';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType, BlockchainApiWorker, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { AccountType, Worker, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand All @@ -25,7 +25,7 @@ import { STAKING_CONTRACT_ABI } from './staking.abi';
import { errorMessage, TxResult, isApproveRequiredError, WriteContractRes } from './utils';

type WorkerDepositRequest = {
worker: BlockchainApiWorker;
worker: Pick<Worker, 'id'>;
amount: string;
wallet: Pick<SourceWallet, 'id' | 'type'>;
};
Expand Down Expand Up @@ -104,7 +104,7 @@ function useDepositFromVestingContract() {

export function useWorkerDelegate() {
const client = useClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand Down Expand Up @@ -195,7 +195,7 @@ function useUndelegateFromVestingContract() {

export function useWorkerUndelegate() {
const client = usePublicClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);

Expand Down Expand Up @@ -238,7 +238,7 @@ export function useWorkerUndelegate() {

export function useCapedStake({ workerId }: { workerId?: string }) {
const contracts = useContracts();
const { currentHeight, isLoading: isHeightLoading } = useSquidNetworkHeightHooks();
const { currentHeight, isLoading: isHeightLoading } = useSquidNetworkHeight();

const { data, isLoading } = useReadContract({
address: contracts.SOFT_CAP,
Expand Down
14 changes: 9 additions & 5 deletions src/api/contracts/vesting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { erc20Abi, MulticallResponse } from 'viem';
import { waitForTransactionReceipt } from 'viem/actions';
import { useReadContracts, useWriteContract, useClient } from 'wagmi';

import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useContracts } from '@network/useContracts';

import { errorMessage, WriteContractRes } from './utils';
import { VESTING_CONTRACT_ABI } from './vesting.abi';

export function useVestingContracts({ addresses }: { addresses: `0x${string}`[] }) {
const contracts = useContracts();
const { currentHeight, isLoading: isSquidHeightLoading } = useSquidNetworkHeightHooks();
const { currentHeight, isLoading: isSquidHeightLoading } = useSquidNetworkHeight();

const { data, isLoading } = useReadContracts({
contracts: addresses.flatMap(address => {
Expand Down Expand Up @@ -60,7 +60,7 @@ export function useVestingContracts({ addresses }: { addresses: `0x${string}`[]
allowFailure: true,
blockNumber: BigInt(currentHeight),
query: {
enabled: !isSquidHeightLoading && !!addresses.length,
enabled: !isSquidHeightLoading,
select: r => {
if (r?.some(r => r.status === 'success')) {
return chunk(r, 8).map(ch => ({
Expand Down Expand Up @@ -94,7 +94,11 @@ export function useVestingContracts({ addresses }: { addresses: `0x${string}`[]
| undefined
>(undefined);
useEffect(() => {
if (!addresses.length) res.current = [];
if (!addresses.length) {
res.current = [];
return;
}

if (!isLoading) res.current = data;
}, [addresses, data, isLoading]);

Expand All @@ -119,7 +123,7 @@ function unwrapResult<T>(result?: MulticallResponse<T>): T | undefined {

export function useVestingContractRelease() {
const client = useClient();
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const { SQD } = useContracts();
Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/worker-registration/useRegisterWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useWriteContract, usePublicClient, useClient } from 'wagmi';
import { useApproveSqd } from '@api/contracts/sqd';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -120,7 +120,7 @@ export function useRegisterWorker() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setLoading] = useState(false);

const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const registerWorkerContract = useRegisterFromWallet();
const registerVestingContract = useRegisterWorkerFromVestingContract();

Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/worker-registration/useUnregisterWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useWriteContract, useClient } from 'wagmi';

import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { AccountType } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -76,7 +76,7 @@ export function useUnregisterWorker() {
const client = useClient();
const { address } = useAccount();
const [isLoading, setLoading] = useState(false);
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [error, setError] = useState<string | null>(null);

const unregisterWorkerFromWallet = useUnregisterWorkerFromWallet();
Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/worker-registration/useUpdateWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { waitForTransactionReceipt } from 'viem/actions';
import { useWriteContract, useClient } from 'wagmi';

import { AccountType } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -79,7 +79,7 @@ export function useUpdateWorker() {
const [error, setError] = useState<string | null>(null);
const [isLoading, setLoading] = useState(false);

const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const updateWorkerFromWallet = useUpdateWorkerFromWallet();
const updateWorkerFromVestingContract = useUpdateWorkerFromVestingContract();

Expand Down
4 changes: 2 additions & 2 deletions src/api/contracts/worker-registration/useWithdrawWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useWriteContract, useClient } from 'wagmi';
import { VESTING_CONTRACT_ABI } from '@api/contracts/vesting.abi';
import { UnregisterWorkerRequest } from '@api/contracts/worker-registration/useUnregisterWorker';
import { AccountType } from '@api/subsquid-network-squid';
import { useSquidNetworkHeightHooks } from '@hooks/useSquidNetworkHeightHooks.ts';
import { useSquidNetworkHeight } from '@hooks/useSquidNetworkHeightHooks';
import { useAccount } from '@network/useAccount';
import { useContracts } from '@network/useContracts.ts';

Expand Down Expand Up @@ -69,7 +69,7 @@ export function useWithdrawWorker() {
const client = useClient();
const { address } = useAccount();
const [isLoading, setLoading] = useState(false);
const { setWaitHeight } = useSquidNetworkHeightHooks();
const { setWaitHeight } = useSquidNetworkHeight();
const [error, setError] = useState<string | null>(null);

const withdrawWorkerFromWallet = useWithdrawWorkerFromWallet();
Expand Down
Loading

0 comments on commit b16adc5

Please sign in to comment.