Skip to content
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

add past rinkeby data on dashboard #222

Merged
merged 2 commits into from
Feb 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import PolygonIcon from '../Icons/PolygonIcon';
interface IEscrowContainer {}

const NETWORK_ICONS: { [chainId in ChainId]?: ReactElement } = {
[ChainId.RINKEBY]: <EthereumIcon />,
[ChainId.GOERLI]: <EthereumIcon />,
[ChainId.POLYGON]: <PolygonIcon />,
[ChainId.POLYGON_MUMBAI]: <PolygonIcon />,
Expand Down
117 changes: 64 additions & 53 deletions packages/apps/escrow-dashboard/src/components/Escrow/EscrowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,68 +141,79 @@ export const EscrowView = () => {
</Box>
)}
<Box>
<Typography
color="primary"
variant="body2"
fontWeight={600}
sx={{ mb: 2 }}
>
Contract Address
</Typography>
<Typography
color="primary"
variant="caption"
component="p"
sx={{ mb: 1 }}
>
Escrow
</Typography>
<TextBox sx={{ mb: 2 }}>
<Link
sx={{ overflow: 'hidden', textDecoration: 'none' }}
href={`${ESCROW_NETWORKS[chainId]?.scanUrl}/address/${ESCROW_NETWORKS[chainId]?.factoryAddress}`}
target="_blank"
{(ESCROW_NETWORKS[chainId]?.factoryAddress ||
ESCROW_NETWORKS[chainId]?.hmtAddress) && (
<Typography
color="primary"
variant="body2"
fontWeight={600}
sx={{ mb: 2 }}
>
Contract Address
</Typography>
)}
{ESCROW_NETWORKS[chainId]?.factoryAddress && (
<>
<Typography
variant="body2"
fontWeight={600}
color="primary"
sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
variant="caption"
component="p"
sx={{ mb: 1 }}
>
{ESCROW_NETWORKS[chainId]?.factoryAddress}
Escrow
</Typography>
</Link>
<CopyAddressButton
address={ESCROW_NETWORKS[chainId]?.factoryAddress}
/>
</TextBox>
<Typography
color="primary"
variant="caption"
component="p"
sx={{ mb: 1 }}
>
Token
</Typography>
<TextBox sx={{ mb: 2 }}>
<Link
sx={{ overflow: 'hidden', textDecoration: 'none' }}
href={`${ESCROW_NETWORKS[chainId]?.scanUrl}/address/${ESCROW_NETWORKS[chainId]?.hmtAddress}`}
target="_blank"
>
<TextBox sx={{ mb: 2 }}>
<Link
sx={{ overflow: 'hidden', textDecoration: 'none' }}
href={`${ESCROW_NETWORKS[chainId]?.scanUrl}/address/${ESCROW_NETWORKS[chainId]?.factoryAddress}`}
target="_blank"
>
<Typography
variant="body2"
fontWeight={600}
color="primary"
sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
>
{ESCROW_NETWORKS[chainId]?.factoryAddress}
</Typography>
</Link>
<CopyAddressButton
address={ESCROW_NETWORKS[chainId]?.factoryAddress}
/>
</TextBox>
</>
)}
{ESCROW_NETWORKS[chainId]?.hmtAddress && (
<>
<Typography
variant="body2"
fontWeight={600}
color="primary"
sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
variant="caption"
component="p"
sx={{ mb: 1 }}
>
{ESCROW_NETWORKS[chainId]?.hmtAddress}
Token
</Typography>
</Link>
<CopyAddressButton
address={ESCROW_NETWORKS[chainId]?.hmtAddress}
/>
</TextBox>
<TextBox sx={{ mb: 2 }}>
<Link
sx={{ overflow: 'hidden', textDecoration: 'none' }}
href={`${ESCROW_NETWORKS[chainId]?.scanUrl}/address/${ESCROW_NETWORKS[chainId]?.hmtAddress}`}
target="_blank"
>
<Typography
variant="body2"
fontWeight={600}
color="primary"
sx={{ overflow: 'hidden', textOverflow: 'ellipsis' }}
>
{ESCROW_NETWORKS[chainId]?.hmtAddress}
</Typography>
</Link>
<CopyAddressButton
address={ESCROW_NETWORKS[chainId]?.hmtAddress}
/>
</TextBox>
</>
)}
</Box>
</Grid>
</>
Expand Down
12 changes: 12 additions & 0 deletions packages/apps/escrow-dashboard/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum ChainId {
ALL = -1,
MAINNET = 1,
RINKEBY = 4,
GOERLI = 5,
BSC_MAINNET = 56,
BSC_TESTNET = 97,
Expand Down Expand Up @@ -28,6 +29,7 @@ export interface IEscrowNetwork {
}

export const SUPPORTED_CHAIN_IDS = [
ChainId.RINKEBY,
ChainId.GOERLI,
ChainId.BSC_MAINNET,
ChainId.BSC_TESTNET,
Expand All @@ -39,6 +41,7 @@ export const SUPPORTED_CHAIN_IDS = [
];

export const TESTNET_CHAIN_IDS = [
ChainId.RINKEBY,
ChainId.GOERLI,
ChainId.BSC_TESTNET,
ChainId.POLYGON_MUMBAI,
Expand All @@ -48,6 +51,15 @@ export const TESTNET_CHAIN_IDS = [
export const ESCROW_NETWORKS: {
[chainId in ChainId]?: IEscrowNetwork;
} = {
[ChainId.RINKEBY]: {
chainId: ChainId.RINKEBY,
title: 'Ethereum Rinkeby',
scanUrl: 'https://rinkeby.etherscan.io',
rpcUrl: 'https://rinkeby.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161',
subgraphUrl: '',
factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
hmtAddress: '',
},
[ChainId.GOERLI]: {
chainId: ChainId.GOERLI,
title: 'Ethereum Goerli',
Expand Down
123 changes: 71 additions & 52 deletions packages/apps/escrow-dashboard/src/state/escrow/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
} from '@reduxjs/toolkit/dist/matchers';
import { Contract, providers } from 'ethers';
import stringify from 'fast-json-stable-stringify';
import rinkebyEscrowEvents from 'src/history-data/rinkeby_EscrowEvents.json';
import rinkebyEscrowStats from 'src/history-data/rinkeby_EscrowStats.json';
import rinkebyEscrowAmount from 'src/history-data/rinkeby_EscrowAmount.json';
import { ChainId, SUPPORTED_CHAIN_IDS, ESCROW_NETWORKS } from 'src/constants';
import { RAW_ESCROW_STATS_QUERY, RAW_EVENT_DAY_DATA_QUERY } from 'src/queries';
import { AppState } from 'src/state';
Expand Down Expand Up @@ -55,27 +58,31 @@ export const fetchEscrowEventsAsync = createAsyncThunk<
let escrowEvents: EscrowEventsType = {};
await Promise.all(
SUPPORTED_CHAIN_IDS.map(async (chainId) => {
const eventDayDatas = await gqlFetch(
ESCROW_NETWORKS[chainId]?.subgraphUrl!,
RAW_EVENT_DAY_DATA_QUERY
)
.then((res) => res.json())
.then((json) =>
json.data.eventDayDatas.map((d: EscrowEventDayData) => ({
...d,
dailyBulkTransferEvents: Number(d.dailyBulkTransferEvents),
dailyIntermediateStorageEvents: Number(
d.dailyIntermediateStorageEvents
),
dailyPendingEvents: Number(d.dailyPendingEvents),
dailyTotalEvents:
Number(d.dailyBulkTransferEvents) +
Number(d.dailyIntermediateStorageEvents) +
Number(d.dailyPendingEvents),
dailyEscrowAmounts: Number(d.dailyEscrowAmounts),
}))
);
escrowEvents[chainId] = eventDayDatas;
if (chainId === ChainId.RINKEBY) {
escrowEvents[chainId] = rinkebyEscrowEvents as any;
} else {
const eventDayDatas = await gqlFetch(
ESCROW_NETWORKS[chainId]?.subgraphUrl!,
RAW_EVENT_DAY_DATA_QUERY
)
.then((res) => res.json())
.then((json) =>
json.data.eventDayDatas.map((d: EscrowEventDayData) => ({
...d,
dailyBulkTransferEvents: Number(d.dailyBulkTransferEvents),
dailyIntermediateStorageEvents: Number(
d.dailyIntermediateStorageEvents
),
dailyPendingEvents: Number(d.dailyPendingEvents),
dailyTotalEvents:
Number(d.dailyBulkTransferEvents) +
Number(d.dailyIntermediateStorageEvents) +
Number(d.dailyPendingEvents),
dailyEscrowAmounts: Number(d.dailyEscrowAmounts),
}))
);
escrowEvents[chainId] = eventDayDatas;
}
})
);

Expand All @@ -90,31 +97,35 @@ export const fetchEscrowStatsAsync = createAsyncThunk<
let escrowStats: EscrowStatsType = {};
await Promise.all(
SUPPORTED_CHAIN_IDS.map(async (chainId) => {
const stats = await gqlFetch(
ESCROW_NETWORKS[chainId]?.subgraphUrl!,
RAW_ESCROW_STATS_QUERY
)
.then((res) => res.json())
.then((json) => {
const {
intermediateStorageEventCount,
pendingEventCount,
bulkTransferEventCount,
} = json.data.escrowStatistics;

return {
intermediateStorageEventCount: Number(
intermediateStorageEventCount
),
pendingEventCount: Number(pendingEventCount),
bulkTransferEventCount: Number(bulkTransferEventCount),
totalEventCount:
Number(intermediateStorageEventCount) +
Number(pendingEventCount) +
Number(bulkTransferEventCount),
};
});
escrowStats[chainId] = stats;
if (chainId === ChainId.RINKEBY) {
escrowStats[chainId] = rinkebyEscrowStats;
} else {
const stats = await gqlFetch(
ESCROW_NETWORKS[chainId]?.subgraphUrl!,
RAW_ESCROW_STATS_QUERY
)
.then((res) => res.json())
.then((json) => {
const {
intermediateStorageEventCount,
pendingEventCount,
bulkTransferEventCount,
} = json.data.escrowStatistics;

return {
intermediateStorageEventCount: Number(
intermediateStorageEventCount
),
pendingEventCount: Number(pendingEventCount),
bulkTransferEventCount: Number(bulkTransferEventCount),
totalEventCount:
Number(intermediateStorageEventCount) +
Number(pendingEventCount) +
Number(bulkTransferEventCount),
};
});
escrowStats[chainId] = stats;
}
})
);

Expand All @@ -129,12 +140,20 @@ export const fetchEscrowAmountsAsync = createAsyncThunk<
let escrowAmounts: EscrowAmountsType = {};
await Promise.all(
SUPPORTED_CHAIN_IDS.map(async (chainId) => {
const rpcUrl = ESCROW_NETWORKS[chainId]?.rpcUrl!;
const factoryAddress = ESCROW_NETWORKS[chainId]?.factoryAddress!;
const provider = new providers.JsonRpcProvider(rpcUrl);
const contract = new Contract(factoryAddress, EscrowFactoryABI, provider);
const escrowAmount = await contract.counter();
escrowAmounts[chainId] = Number(escrowAmount);
if (chainId === ChainId.RINKEBY) {
escrowAmounts[chainId] = rinkebyEscrowAmount;
} else {
const rpcUrl = ESCROW_NETWORKS[chainId]?.rpcUrl!;
const factoryAddress = ESCROW_NETWORKS[chainId]?.factoryAddress!;
const provider = new providers.JsonRpcProvider(rpcUrl);
const contract = new Contract(
factoryAddress,
EscrowFactoryABI,
provider
);
const escrowAmount = await contract.counter();
escrowAmounts[chainId] = Number(escrowAmount);
}
})
);

Expand Down
9 changes: 9 additions & 0 deletions packages/apps/escrow-dashboard/src/state/token/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ export const fetchTokenStatsAsync = createAsyncThunk<
let tokenStats: TokenStatsType = {};
await Promise.all(
SUPPORTED_CHAIN_IDS.map(async (chainId) => {
if (chainId === ChainId.RINKEBY) {
return {
totalApprovalEventCount: 0,
totalTransferEventCount: 0,
totalValueTransfered: 0,
holders: 0,
totalSupply: 0,
};
}
const stats = await gqlFetch(
ESCROW_NETWORKS[chainId]?.subgraphUrl!,
RAW_TOKEN_STATS_QUERY
Expand Down