Skip to content

Commit

Permalink
dashboard: cleanup deps
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-gray committed Apr 3, 2024
1 parent 62d7c46 commit a8f9c01
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 4,301 deletions.
5 changes: 4 additions & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"version": "0.0.1",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts"
"types": "dist/index.d.ts",
"devDependencies": {
"@types/bs58": "^4.0.4"
}
}
1 change: 1 addition & 0 deletions common/src/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
chainToChainId,
chainToPlatform,
} from '@wormhole-foundation/sdk-base';
import { Buffer } from 'buffer';
import { base58 } from 'ethers/lib/utils';
import { Environment } from './consts';

Expand Down
70 changes: 0 additions & 70 deletions dashboard/config-overrides.js

This file was deleted.

37 changes: 6 additions & 31 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
"license": "Apache-2.0",
"dependencies": {
"@certusone/wormhole-sdk-proto-web": "^0.0.7",
"@cosmjs/cosmwasm-stargate": "^0.29.5",
"@emotion/react": "^11.10.0",
"@emotion/styled": "^11.10.0",
"@metaplex/js": "^4.12.0",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.3",
"@tanstack/react-table": "^8.5.11",
"@terra-money/terra.js": "^3.1.3",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
Expand All @@ -21,9 +18,6 @@
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.6",
"axios": "^0.27.2",
"coingecko-api": "^1.0.10",
"dotenv": "^16.0.2",
"ethers": "^5.6.9",
"numeral": "^2.0.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand All @@ -32,13 +26,13 @@
"react-timeago": "^7.1.0",
"typescript": "^4.7.4",
"use-debounce": "^10.0.0",
"web-vitals": "^2.1.4",
"web3": "^1.7.5"
"webpack-bundle-analyzer": "^4.10.1"
},
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired --max_old_space_size=8192 build",
"eject": "react-app-rewired eject"
"start": "GENERATE_SOURCEMAP=false react-scripts start",
"build": "GENERATE_SOURCEMAP=false react-scripts build",
"eject": "react-scripts eject",
"analyze": "npm run build -- --stats && npx webpack-bundle-analyzer ./build/bundle-stats.json"
},
"eslintConfig": {
"extends": [
Expand All @@ -64,25 +58,6 @@
"@types/numeral": "^2.0.2",
"@types/react-router-dom": "^5.3.3",
"@types/react-timeago": "^4.1.3",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
"console-browserify": "^1.2.0",
"constants-browserify": "^1.0.0",
"crypto-browserify": "^3.12.0",
"https-browserify": "^1.0.0",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"prettier": "^2.3.2",
"process": "^0.11.10",
"react-app-rewired": "^2.2.1",
"readable-stream": "^3.6.0",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"timers-browserify": "^2.0.12",
"tty-browserify": "^0.0.1",
"url": "^0.11.0",
"util": "^0.12.4",
"vm-browserify": "^1.1.2"
"prettier": "^2.3.2"
}
}
16 changes: 8 additions & 8 deletions dashboard/src/components/Accountant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,27 @@ import {
getSortedRowModel,
useReactTable,
} from '@tanstack/react-table';
import chainIdToName from '@wormhole-foundation/wormhole-monitor-common/dist/chainIdToName';
import { Buffer } from 'buffer';
import numeral from 'numeral';
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
import { useDebounce } from 'use-debounce';
import { CloudGovernorInfo } from '../hooks/useCloudGovernorInfo';
import useGetAccountantAccounts, { Account } from '../hooks/useGetAccountantAccounts';
import useGetAccountantPendingTransfers, {
PendingTransfer,
} from '../hooks/useGetAccountantPendingTransfers';
import useTokenData, { TokenDataEntry } from '../hooks/useTokenData';
import {
ACCOUNTANT_CONTRACT_ADDRESS,
CHAIN_ICON_MAP,
GUARDIAN_SET_3,
WORMCHAIN_URL,
} from '../utils/consts';
import { queryContractSmart } from '../utils/queryContractSmart';
import CollapsibleSection from './CollapsibleSection';
import Table from './Table';
import useTokenData, { TokenDataEntry } from '../hooks/useTokenData';
import numeral from 'numeral';
import { ExplorerTxHash } from './ExplorerTxHash';
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { useDebounce } from 'use-debounce';
import chainIdToName from '@wormhole-foundation/wormhole-monitor-common/dist/chainIdToName';
import Table from './Table';

type PendingTransferForAcct = PendingTransfer & { isEnqueuedInGov: boolean };
type AccountWithTokenData = Account & {
Expand Down Expand Up @@ -315,8 +316,7 @@ function AccountantSearch() {
let cancelled = false;
(async () => {
try {
const cosmWasmClient = await CosmWasmClient.connect(WORMCHAIN_URL);
const response = await cosmWasmClient.queryContractSmart(ACCOUNTANT_CONTRACT_ADDRESS, {
const response = await queryContractSmart(WORMCHAIN_URL, ACCOUNTANT_CONTRACT_ADDRESS, {
transfer_status: {
emitter_chain,
emitter_address,
Expand Down
21 changes: 11 additions & 10 deletions dashboard/src/hooks/useGetAccountantAccounts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { useEffect, useState } from 'react';
import { useNetworkContext } from '../contexts/NetworkContext';
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';
import { queryContractSmart } from '../utils/queryContractSmart';

const POLL_INTERVAL_MS = 1 * 60 * 1000;
const PAGE_LIMIT = 2000; // throws a gas limit error over this
Expand All @@ -27,19 +27,20 @@ const useGetAccountantAccounts = (contractAddress: string): Account[] => {
(async () => {
while (!cancelled) {
try {
const cosmWasmClient = await CosmWasmClient.connect(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
);
let accounts: Account[] = [];
let response;
let start_after = undefined;
do {
response = await cosmWasmClient.queryContractSmart(contractAddress, {
all_accounts: {
limit: PAGE_LIMIT,
start_after,
},
});
response = await queryContractSmart(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL,
contractAddress,
{
all_accounts: {
limit: PAGE_LIMIT,
start_after,
},
}
);
accounts = [...accounts, ...response.accounts];
start_after =
response.accounts.length && response.accounts[response.accounts.length - 1].key;
Expand Down
21 changes: 11 additions & 10 deletions dashboard/src/hooks/useGetAccountantPendingTransfers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
import { useEffect, useState } from 'react';
import { useNetworkContext } from '../contexts/NetworkContext';
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';
import { queryContractSmart } from '../utils/queryContractSmart';

const POLL_INTERVAL_MS = 10 * 1000;
const PAGE_LIMIT = 2000; // throws a gas limit error over this
Expand Down Expand Up @@ -37,19 +37,20 @@ const useGetAccountantPendingTransfers = (contractAddress: string): PendingTrans
(async () => {
while (!cancelled) {
try {
const cosmWasmClient = await CosmWasmClient.connect(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
);
let pending: PendingTransfer[] = [];
let response;
let start_after = undefined;
do {
response = await cosmWasmClient.queryContractSmart(contractAddress, {
all_pending_transfers: {
limit: PAGE_LIMIT,
start_after,
},
});
response = await queryContractSmart(
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL,
contractAddress,
{
all_pending_transfers: {
limit: PAGE_LIMIT,
start_after,
},
}
);
pending = [...pending, ...response.pending];
start_after =
response.pending.length && response.pending[response.pending.length - 1].key;
Expand Down
6 changes: 0 additions & 6 deletions dashboard/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root') as any);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
13 changes: 0 additions & 13 deletions dashboard/src/reportWebVitals.js

This file was deleted.

2 changes: 0 additions & 2 deletions dashboard/src/utils/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import terra2Icon from '../images/terra2.svg';
import wormchainIcon from '../images/wormchain.svg';
import xplaIcon from '../images/xpla.svg';

require('dotenv').config();

export const WORMCHAIN_URL = 'https://tncnt-eu-wormchain-main-01.rpc.p2p.world';
export const TESTNET_WORMCHAIN_URL = `https://corsproxy.io/?${encodeURIComponent(
'https://gateway.testnet.xlabs.xyz'
Expand Down
70 changes: 70 additions & 0 deletions dashboard/src/utils/queryContractSmart.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import axios from 'axios';
import { Buffer } from 'buffer';

type QueryContractSmartResponse = {
jsonrpc: '2.0';
id: number;
result: {
response: {
code: number;
log: string;
info: string;
index: string;
key: null;
value: string;
proofOps: null;
height: string;
codespace: string;
};
};
};

// adapted from cosmjs-types/binary.js and cosmjs-types/varint.js
export function uint32ToString(val: number): string {
const num = val < 128 ? 1 : val < 16384 ? 2 : val < 2097152 ? 3 : val < 268435456 ? 4 : 5;
const buf: number[] = new Array(num);
let pos = 0;
while (val > 127) {
buf[pos++] = (val & 127) | 128;
val >>>= 7;
}
buf[pos] = val;
return Buffer.from(buf).toString('hex');
}

export async function queryContractSmart(
rpc: string,
address: string,
query: Object
): Promise<any> {
const addressHex = Buffer.from(address).toString('hex');
const addressHexLen = uint32ToString(addressHex.length / 2);
const queryHex = Buffer.from(JSON.stringify(query)).toString('hex');
const queryStrLen = uint32ToString(queryHex.length / 2);
const data = `0a${addressHexLen}${addressHex}12${queryStrLen}${queryHex}`;
const response = await axios.post<QueryContractSmartResponse>(rpc, {
jsonrpc: '2.0',
id: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
method: 'abci_query',
params: {
path: '/cosmwasm.wasm.v1.Query/SmartContractState',
data,
prove: false,
},
});
if (!response.data.result.response.value) {
if (response.data.result.response.code && response.data.result.response.log) {
throw new Error(
`Query failed with (${response.data.result.response.code}) ${response.data.result.response.log}`
);
} else {
throw new Error(`Query failed with unknown error`);
}
}
const asciiResponse = Buffer.from(response.data.result.response.value, 'base64').toString(
'ascii'
);
return JSON.parse(
asciiResponse.substring(asciiResponse.indexOf('{') || asciiResponse.indexOf('['))
);
}
Loading

0 comments on commit a8f9c01

Please sign in to comment.