Skip to content

Commit

Permalink
Merge pull request #27 from subsquid/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
belopash authored Jun 3, 2024
2 parents c3e956e + 295f162 commit 47614ef
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 70 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
echo "::set-output name=enable_demo_features::false"
else
echo "::set-output name=app_env::dev"
echo "::set-output name=testnet_squid_api_url::https://subsquid.squids.live/subsquid-network-testnet/v/v1/graphql"
echo "::set-output name=testnet_squid_api_url::https://subsquid.squids.live/subsquid-network-testnet/v/v3/graphql"
echo "::set-output name=mainnet_squid_api_url::https://subsquid.squids.live/subsquid-network-mainnet/v/v3/graphql"
echo "::set-output name=enable_demo_features::true"
fi
Expand Down
13 changes: 10 additions & 3 deletions src/api/subsquid-network-squid/accounts-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
export type SourceWallet = {
id: string;
type: AccountType;
};

export type SourceWalletWithBalance = SourceWallet & {
balance: string;
};

Expand All @@ -35,7 +38,7 @@ export function useMySources({ enabled }: { enabled?: boolean } = {}) {

const wallet = data?.accountById;

const res = useMemo((): SourceWallet[] => {
const res = useMemo((): SourceWalletWithBalance[] => {
return !wallet
? [
{
Expand Down Expand Up @@ -85,14 +88,18 @@ export function useMyAssets() {
let bonded = new Decimal(0);
let claimable = new Decimal(0);
let delegated = new Decimal(0);
const vestings: { address: string; balance: string }[] = [];
const vestings: SourceWalletWithBalance[] = [];

for (const a of accounts) {
balance = balance.add(a.balance);

for (const o of a.owned) {
locked = locked.add(o.balance);
vestings.push({ address: o.id, balance: new Decimal(o.balance).toFixed(0) });
vestings.push({
id: o.id,
type: AccountType.Vesting,
balance: new Decimal(o.balance).toFixed(0),
});
}
}
for (const w of workers) {
Expand Down
5 changes: 5 additions & 0 deletions src/api/subsquid-network-squid/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ fragment GatewayFragment on Gateway {
id
type
}
operator {
stake {
locked
}
}
createdAt
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/subsquid-network-squid/gateways-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function useMyGatewayStakes() {
},
{
select: res => {
return res.gatewayOperators[0];
return res.gatewayOperators.filter(o => o.pendingStake || o.stake);
},
enabled,
},
Expand Down
17 changes: 17 additions & 0 deletions src/api/subsquid-network-squid/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5478,6 +5478,10 @@ export type GatewayFragmentFragment = {
website?: string;
createdAt: any;
owner?: { __typename?: 'Account'; id: string; type: AccountType };
operator?: {
__typename?: 'GatewayOperator';
stake?: { __typename?: 'GatewayStake'; locked: boolean };
};
};

export type MyGatewaysQueryVariables = Exact<{
Expand All @@ -5497,6 +5501,10 @@ export type MyGatewaysQuery = {
website?: string;
createdAt: any;
owner?: { __typename?: 'Account'; id: string; type: AccountType };
operator?: {
__typename?: 'GatewayOperator';
stake?: { __typename?: 'GatewayStake'; locked: boolean };
};
}>;
};

Expand All @@ -5517,6 +5525,10 @@ export type GatewayByPeerIdQuery = {
website?: string;
createdAt: any;
owner?: { __typename?: 'Account'; id: string; type: AccountType };
operator?: {
__typename?: 'GatewayOperator';
stake?: { __typename?: 'GatewayStake'; locked: boolean };
};
};
};

Expand Down Expand Up @@ -5656,6 +5668,11 @@ export const GatewayFragmentFragmentDoc = `
id
type
}
operator {
stake {
locked
}
}
createdAt
}
`;
Expand Down
6 changes: 2 additions & 4 deletions src/components/SourceWallet/SourceWalletOption.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react';

import { addressFormatter } from '@lib/formatters/formatters';
import { Box, Stack, styled, useMediaQuery, useTheme } from '@mui/material';

import { formatSqd } from '@api/contracts/utils';
import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { AccountType, SourceWalletWithBalance } from '@api/subsquid-network-squid';
import { useContracts } from '@network/useContracts';

const SourceWalletOptionWrapper = styled(Box, {
Expand Down Expand Up @@ -35,7 +33,7 @@ const SourceWalletBalance = styled(Stack, {
textAlign: 'right',
}));

export const SourceWalletOption = ({ source }: { source: SourceWallet }) => {
export const SourceWalletOption = ({ source }: { source: SourceWalletWithBalance }) => {
const { SQD_TOKEN } = useContracts();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
Expand Down
4 changes: 2 additions & 2 deletions src/components/SourceWallet/useMySourceOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';

import { SourceWallet, useMySources } from '@api/subsquid-network-squid';
import { SourceWalletWithBalance, useMySources } from '@api/subsquid-network-squid';

import { SourceWalletOption } from './SourceWalletOption';

export function useMySourceOptions({
enabled = true,
sourceDisabled,
}: { enabled?: boolean; sourceDisabled?: (w: SourceWallet) => boolean } = {}) {
}: { enabled?: boolean; sourceDisabled?: (w: SourceWalletWithBalance) => boolean } = {}) {
const { sources, isPending } = useMySources({ enabled });

const options = sources.map(s => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/AssetsPage/Assets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,13 @@ export function MyAssets() {
</TokenBalanceItem>

{d.vestings?.map(v => (
<TokenBalanceItem key={d.name + '-' + v.address} sx={{ ml: 2.5 }}>
<TokenBalanceItem key={d.name + '-' + v.id} sx={{ ml: 2.5 }}>
<TokenBalanceLabel
sx={{ background: d.background, color: d.color }}
value={
<CopyToClipboard
text={v.address}
content={addressFormatter(v.address, true)}
text={v.id}
content={addressFormatter(v.id, true)}
></CopyToClipboard>
}
/>
Expand Down
13 changes: 7 additions & 6 deletions src/pages/AssetsPage/ReleaseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import * as yup from 'yup';

import { formatSqd, fromSqd } from '@api/contracts/utils';
import { useVestingContract, useVestingContractRelease } from '@api/contracts/vesting';
import { SourceWallet } from '@api/subsquid-network-squid';
import { BlockchainContractError } from '@components/BlockchainContractError';
import { ContractCallDialog } from '@components/ContractCallDialog';
import { Form } from '@components/Form';
import { Loader } from '@components/Loader';
import { TableList } from '@components/Table/TableList';
import { useContracts } from '@network/useContracts';

import { VestingName } from './VestingName';
import { SourceWalletName } from './VestingName';

export const claimSchema = yup.object({
source: yup.string().label('Source').trim().required('Source is required'),
Expand All @@ -23,18 +24,18 @@ export function ReleaseButton({
vesting,
disabled,
}: {
vesting: { address: string };
vesting: SourceWallet;
disabled?: boolean;
}) {
const { release, error, isLoading } = useVestingContractRelease();
const { data, isLoading: isVestingLoading } = useVestingContract({
address: vesting.address as `0x${string}`,
address: vesting.id as `0x${string}`,
});
const { SQD_TOKEN } = useContracts();

const formik = useFormik({
initialValues: {
source: vesting.address,
source: vesting.id,
amount: 0,
},
validationSchema: claimSchema,
Expand All @@ -44,7 +45,7 @@ export function ReleaseButton({

onSubmit: async () => {
const { failedReason } = await release({
address: vesting.address as `0x${string}`,
address: vesting.id as `0x${string}`,
});

if (!failedReason) {
Expand Down Expand Up @@ -87,7 +88,7 @@ export function ReleaseButton({
<TableBody>
<TableRow>
<TableCell>
<VestingName vesting={vesting} />
<SourceWalletName source={vesting} />
</TableCell>
<TableCell>Vesting</TableCell>
<TableCell align="right">{formatSqd(SQD_TOKEN, data?.releasable, 8)}</TableCell>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/AssetsPage/Vesting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function Vesting({ backPath }: { backPath: string }) {
<CenteredPageWrapper className="wide">
<NetworkPageTitle
backPath={searchParams.get('backPath') || backPath}
endAdornment={vesting?.isOwn() ? <ReleaseButton vesting={{ address }} /> : null}
endAdornment={vesting?.isOwn() ? <ReleaseButton vesting={vesting} /> : null}
/>
<Card>
<Stack spacing={3} divider={<Divider orientation="horizontal" flexItem />}>
Expand Down
11 changes: 6 additions & 5 deletions src/pages/AssetsPage/VestingName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { addressFormatter } from '@lib/formatters/formatters';
import { Box, Stack, styled } from '@mui/material';
import { Link } from 'react-router-dom';

import { AccountType, SourceWallet } from '@api/subsquid-network-squid';
import { Avatar } from '@components/Avatar';
import { CopyToClipboard } from '@components/CopyToClipboard';

Expand All @@ -15,16 +16,16 @@ const Name = styled(Box, {
whiteSpace: 'nowrap',
}));

export function VestingName({ vesting, to }: { vesting: { address: string }; to?: string }) {
export function SourceWalletName({ source, to }: { source: SourceWallet; to?: string }) {
return (
<Stack direction="row" spacing={2}>
<Avatar name={vesting.address.slice(2)} colorDiscriminator={vesting.address} />
<Avatar name={source.id.slice(2)} colorDiscriminator={source.id} />
<Box>
<Name>Vesting contract</Name>
<Name>{source.type === AccountType.Vesting ? 'Vesting contract' : 'Wallet'}</Name>
<Box sx={{ opacity: 0.8 }}>
<CopyToClipboard
text={vesting.address}
content={<Link to={to || ''}>{addressFormatter(vesting.address, true)}</Link>}
text={source.id}
content={<Link to={to || '#'}>{addressFormatter(source.id, true)}</Link>}
/>
</Box>
</Box>
Expand Down
8 changes: 4 additions & 4 deletions src/pages/AssetsPage/Vestings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { NetworkPageTitle } from '@layouts/NetworkLayout';
import { useContracts } from '@network/useContracts';

import { ReleaseButton } from './ReleaseButton';
import { VestingName } from './VestingName';
import { SourceWalletName } from './VestingName';

export function MyVestings() {
const { assets, isLoading } = useMyAssets();
const { data, isLoading: isVestingsLoading } = useVestingContracts({
addresses: assets.vestings.map(v => v.address as `0x${string}`),
addresses: assets.vestings.map(v => v.id as `0x${string}`),
});
const { SQD_TOKEN } = useContracts();

Expand All @@ -40,9 +40,9 @@ export function MyVestings() {
{assets.vestings.map((vesting, i) => {
const d = data?.[i];
return (
<TableRow className="hoverable" key={vesting.address}>
<TableRow className="hoverable" key={vesting.id}>
<TableCell>
<VestingName vesting={vesting} to={`vestings/${vesting.address}`} />
<SourceWalletName source={vesting} to={`vestings/${vesting.id}`} />
</TableCell>
<TableCell>{formatSqd(SQD_TOKEN, fromSqd(d?.balance))}</TableCell>
<TableCell>{formatSqd(SQD_TOKEN, d?.releasable)}</TableCell>
Expand Down
4 changes: 1 addition & 3 deletions src/pages/GatewaysPage/AddNewGateway.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useFormik } from 'formik';
import { useNavigate } from 'react-router-dom';

import { useRegisterGateway } from '@api/contracts/gateway-registration/useRegisterGateway';
import { AccountType, useMySources } from '@api/subsquid-network-squid';
import { useMySources } from '@api/subsquid-network-squid';
import { BlockchainContractError } from '@components/BlockchainContractError';
import { Card } from '@components/Card';
import { Form, FormikSwitch, FormikTextInput, FormRow } from '@components/Form';
Expand Down Expand Up @@ -81,13 +81,11 @@ function AddGatewayForm() {
<FormRow>
<FormikSelect
id="source"
disabled
showErrorOnlyOfTouched
options={sources.map(s => {
return {
label: <SourceWalletOption source={s} />,
value: s.id,
disabled: s.type === AccountType.Vesting,
};
})}
formik={formik}
Expand Down
9 changes: 7 additions & 2 deletions src/pages/GatewaysPage/GatewayName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';

import { Stack, styled } from '@mui/material';
import { Box } from '@mui/system';
import { Link } from 'react-router-dom';

import { BlockchainGateway } from '@api/subsquid-network-squid/gateways-graphql';
import { Avatar } from '@components/Avatar';
Expand All @@ -15,7 +16,7 @@ const Name = styled(Box, {
fontWeight: 500,
}));

export const GatewayName = ({ gateway }: { gateway: BlockchainGateway }) => {
export const GatewayName = ({ gateway, to }: { gateway: BlockchainGateway; to?: string }) => {
return (
<Stack spacing={2} direction="row">
<Avatar colorDiscriminator={gateway.id} name={gateway.name || gateway.id} />
Expand All @@ -25,7 +26,11 @@ export const GatewayName = ({ gateway }: { gateway: BlockchainGateway }) => {
<Box>
<CopyToClipboard
text={gateway.id}
content={<PeerIdShort>{shortPeerId(gateway.id)}</PeerIdShort>}
content={
<PeerIdShort>
<Link to={to || ''}>{shortPeerId(gateway.id)}</Link>
</PeerIdShort>
}
/>
</Box>
</Stack>
Expand Down
Loading

0 comments on commit 47614ef

Please sign in to comment.