Skip to content

Commit a8f9c01

Browse files
committed
dashboard: cleanup deps
1 parent 62d7c46 commit a8f9c01

12 files changed

+322
-4301
lines changed

common/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"version": "0.0.1",
44
"private": true,
55
"main": "dist/index.js",
6-
"types": "dist/index.d.ts"
6+
"types": "dist/index.d.ts",
7+
"devDependencies": {
8+
"@types/bs58": "^4.0.4"
9+
}
710
}

common/src/explorer.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
chainToChainId,
55
chainToPlatform,
66
} from '@wormhole-foundation/sdk-base';
7+
import { Buffer } from 'buffer';
78
import { base58 } from 'ethers/lib/utils';
89
import { Environment } from './consts';
910

dashboard/config-overrides.js

-70
This file was deleted.

dashboard/package.json

+6-31
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
"license": "Apache-2.0",
66
"dependencies": {
77
"@certusone/wormhole-sdk-proto-web": "^0.0.7",
8-
"@cosmjs/cosmwasm-stargate": "^0.29.5",
98
"@emotion/react": "^11.10.0",
109
"@emotion/styled": "^11.10.0",
11-
"@metaplex/js": "^4.12.0",
1210
"@mui/icons-material": "^5.8.4",
1311
"@mui/material": "^5.9.3",
1412
"@tanstack/react-table": "^8.5.11",
15-
"@terra-money/terra.js": "^3.1.3",
1613
"@testing-library/jest-dom": "^5.16.5",
1714
"@testing-library/react": "^13.3.0",
1815
"@testing-library/user-event": "^13.5.0",
@@ -21,9 +18,6 @@
2118
"@types/react": "^18.0.15",
2219
"@types/react-dom": "^18.0.6",
2320
"axios": "^0.27.2",
24-
"coingecko-api": "^1.0.10",
25-
"dotenv": "^16.0.2",
26-
"ethers": "^5.6.9",
2721
"numeral": "^2.0.6",
2822
"react": "^18.2.0",
2923
"react-dom": "^18.2.0",
@@ -32,13 +26,13 @@
3226
"react-timeago": "^7.1.0",
3327
"typescript": "^4.7.4",
3428
"use-debounce": "^10.0.0",
35-
"web-vitals": "^2.1.4",
36-
"web3": "^1.7.5"
29+
"webpack-bundle-analyzer": "^4.10.1"
3730
},
3831
"scripts": {
39-
"start": "react-app-rewired start",
40-
"build": "react-app-rewired --max_old_space_size=8192 build",
41-
"eject": "react-app-rewired eject"
32+
"start": "GENERATE_SOURCEMAP=false react-scripts start",
33+
"build": "GENERATE_SOURCEMAP=false react-scripts build",
34+
"eject": "react-scripts eject",
35+
"analyze": "npm run build -- --stats && npx webpack-bundle-analyzer ./build/bundle-stats.json"
4236
},
4337
"eslintConfig": {
4438
"extends": [
@@ -64,25 +58,6 @@
6458
"@types/numeral": "^2.0.2",
6559
"@types/react-router-dom": "^5.3.3",
6660
"@types/react-timeago": "^4.1.3",
67-
"assert": "^2.0.0",
68-
"browserify-zlib": "^0.2.0",
69-
"buffer": "^6.0.3",
70-
"console-browserify": "^1.2.0",
71-
"constants-browserify": "^1.0.0",
72-
"crypto-browserify": "^3.12.0",
73-
"https-browserify": "^1.0.0",
74-
"os-browserify": "^0.3.0",
75-
"path-browserify": "^1.0.1",
76-
"prettier": "^2.3.2",
77-
"process": "^0.11.10",
78-
"react-app-rewired": "^2.2.1",
79-
"readable-stream": "^3.6.0",
80-
"stream-browserify": "^3.0.0",
81-
"stream-http": "^3.2.0",
82-
"timers-browserify": "^2.0.12",
83-
"tty-browserify": "^0.0.1",
84-
"url": "^0.11.0",
85-
"util": "^0.12.4",
86-
"vm-browserify": "^1.1.2"
61+
"prettier": "^2.3.2"
8762
}
8863
}

dashboard/src/components/Accountant.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@ import {
2525
getSortedRowModel,
2626
useReactTable,
2727
} from '@tanstack/react-table';
28+
import chainIdToName from '@wormhole-foundation/wormhole-monitor-common/dist/chainIdToName';
29+
import { Buffer } from 'buffer';
30+
import numeral from 'numeral';
2831
import { memo, useCallback, useEffect, useMemo, useState } from 'react';
32+
import { useDebounce } from 'use-debounce';
2933
import { CloudGovernorInfo } from '../hooks/useCloudGovernorInfo';
3034
import useGetAccountantAccounts, { Account } from '../hooks/useGetAccountantAccounts';
3135
import useGetAccountantPendingTransfers, {
3236
PendingTransfer,
3337
} from '../hooks/useGetAccountantPendingTransfers';
38+
import useTokenData, { TokenDataEntry } from '../hooks/useTokenData';
3439
import {
3540
ACCOUNTANT_CONTRACT_ADDRESS,
3641
CHAIN_ICON_MAP,
3742
GUARDIAN_SET_3,
3843
WORMCHAIN_URL,
3944
} from '../utils/consts';
45+
import { queryContractSmart } from '../utils/queryContractSmart';
4046
import CollapsibleSection from './CollapsibleSection';
41-
import Table from './Table';
42-
import useTokenData, { TokenDataEntry } from '../hooks/useTokenData';
43-
import numeral from 'numeral';
4447
import { ExplorerTxHash } from './ExplorerTxHash';
45-
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
46-
import { useDebounce } from 'use-debounce';
47-
import chainIdToName from '@wormhole-foundation/wormhole-monitor-common/dist/chainIdToName';
48+
import Table from './Table';
4849

4950
type PendingTransferForAcct = PendingTransfer & { isEnqueuedInGov: boolean };
5051
type AccountWithTokenData = Account & {
@@ -315,8 +316,7 @@ function AccountantSearch() {
315316
let cancelled = false;
316317
(async () => {
317318
try {
318-
const cosmWasmClient = await CosmWasmClient.connect(WORMCHAIN_URL);
319-
const response = await cosmWasmClient.queryContractSmart(ACCOUNTANT_CONTRACT_ADDRESS, {
319+
const response = await queryContractSmart(WORMCHAIN_URL, ACCOUNTANT_CONTRACT_ADDRESS, {
320320
transfer_status: {
321321
emitter_chain,
322322
emitter_address,

dashboard/src/hooks/useGetAccountantAccounts.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
21
import { useEffect, useState } from 'react';
32
import { useNetworkContext } from '../contexts/NetworkContext';
43
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';
4+
import { queryContractSmart } from '../utils/queryContractSmart';
55

66
const POLL_INTERVAL_MS = 1 * 60 * 1000;
77
const PAGE_LIMIT = 2000; // throws a gas limit error over this
@@ -27,19 +27,20 @@ const useGetAccountantAccounts = (contractAddress: string): Account[] => {
2727
(async () => {
2828
while (!cancelled) {
2929
try {
30-
const cosmWasmClient = await CosmWasmClient.connect(
31-
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
32-
);
3330
let accounts: Account[] = [];
3431
let response;
3532
let start_after = undefined;
3633
do {
37-
response = await cosmWasmClient.queryContractSmart(contractAddress, {
38-
all_accounts: {
39-
limit: PAGE_LIMIT,
40-
start_after,
41-
},
42-
});
34+
response = await queryContractSmart(
35+
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL,
36+
contractAddress,
37+
{
38+
all_accounts: {
39+
limit: PAGE_LIMIT,
40+
start_after,
41+
},
42+
}
43+
);
4344
accounts = [...accounts, ...response.accounts];
4445
start_after =
4546
response.accounts.length && response.accounts[response.accounts.length - 1].key;

dashboard/src/hooks/useGetAccountantPendingTransfers.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
21
import { useEffect, useState } from 'react';
32
import { useNetworkContext } from '../contexts/NetworkContext';
43
import { TESTNET_WORMCHAIN_URL, WORMCHAIN_URL } from '../utils/consts';
4+
import { queryContractSmart } from '../utils/queryContractSmart';
55

66
const POLL_INTERVAL_MS = 10 * 1000;
77
const PAGE_LIMIT = 2000; // throws a gas limit error over this
@@ -37,19 +37,20 @@ const useGetAccountantPendingTransfers = (contractAddress: string): PendingTrans
3737
(async () => {
3838
while (!cancelled) {
3939
try {
40-
const cosmWasmClient = await CosmWasmClient.connect(
41-
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL
42-
);
4340
let pending: PendingTransfer[] = [];
4441
let response;
4542
let start_after = undefined;
4643
do {
47-
response = await cosmWasmClient.queryContractSmart(contractAddress, {
48-
all_pending_transfers: {
49-
limit: PAGE_LIMIT,
50-
start_after,
51-
},
52-
});
44+
response = await queryContractSmart(
45+
currentNetwork.name === 'Mainnet' ? WORMCHAIN_URL : TESTNET_WORMCHAIN_URL,
46+
contractAddress,
47+
{
48+
all_pending_transfers: {
49+
limit: PAGE_LIMIT,
50+
start_after,
51+
},
52+
}
53+
);
5354
pending = [...pending, ...response.pending];
5455
start_after =
5556
response.pending.length && response.pending[response.pending.length - 1].key;

dashboard/src/index.tsx

-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom/client';
33
import App from './App';
4-
import reportWebVitals from './reportWebVitals';
54

65
const root = ReactDOM.createRoot(document.getElementById('root') as any);
76
root.render(
87
<React.StrictMode>
98
<App />
109
</React.StrictMode>
1110
);
12-
13-
// If you want to start measuring performance in your app, pass a function
14-
// to log results (for example: reportWebVitals(console.log))
15-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
16-
reportWebVitals();

dashboard/src/reportWebVitals.js

-13
This file was deleted.

dashboard/src/utils/consts.ts

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import terra2Icon from '../images/terra2.svg';
3838
import wormchainIcon from '../images/wormchain.svg';
3939
import xplaIcon from '../images/xpla.svg';
4040

41-
require('dotenv').config();
42-
4341
export const WORMCHAIN_URL = 'https://tncnt-eu-wormchain-main-01.rpc.p2p.world';
4442
export const TESTNET_WORMCHAIN_URL = `https://corsproxy.io/?${encodeURIComponent(
4543
'https://gateway.testnet.xlabs.xyz'
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import axios from 'axios';
2+
import { Buffer } from 'buffer';
3+
4+
type QueryContractSmartResponse = {
5+
jsonrpc: '2.0';
6+
id: number;
7+
result: {
8+
response: {
9+
code: number;
10+
log: string;
11+
info: string;
12+
index: string;
13+
key: null;
14+
value: string;
15+
proofOps: null;
16+
height: string;
17+
codespace: string;
18+
};
19+
};
20+
};
21+
22+
// adapted from cosmjs-types/binary.js and cosmjs-types/varint.js
23+
export function uint32ToString(val: number): string {
24+
const num = val < 128 ? 1 : val < 16384 ? 2 : val < 2097152 ? 3 : val < 268435456 ? 4 : 5;
25+
const buf: number[] = new Array(num);
26+
let pos = 0;
27+
while (val > 127) {
28+
buf[pos++] = (val & 127) | 128;
29+
val >>>= 7;
30+
}
31+
buf[pos] = val;
32+
return Buffer.from(buf).toString('hex');
33+
}
34+
35+
export async function queryContractSmart(
36+
rpc: string,
37+
address: string,
38+
query: Object
39+
): Promise<any> {
40+
const addressHex = Buffer.from(address).toString('hex');
41+
const addressHexLen = uint32ToString(addressHex.length / 2);
42+
const queryHex = Buffer.from(JSON.stringify(query)).toString('hex');
43+
const queryStrLen = uint32ToString(queryHex.length / 2);
44+
const data = `0a${addressHexLen}${addressHex}12${queryStrLen}${queryHex}`;
45+
const response = await axios.post<QueryContractSmartResponse>(rpc, {
46+
jsonrpc: '2.0',
47+
id: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
48+
method: 'abci_query',
49+
params: {
50+
path: '/cosmwasm.wasm.v1.Query/SmartContractState',
51+
data,
52+
prove: false,
53+
},
54+
});
55+
if (!response.data.result.response.value) {
56+
if (response.data.result.response.code && response.data.result.response.log) {
57+
throw new Error(
58+
`Query failed with (${response.data.result.response.code}) ${response.data.result.response.log}`
59+
);
60+
} else {
61+
throw new Error(`Query failed with unknown error`);
62+
}
63+
}
64+
const asciiResponse = Buffer.from(response.data.result.response.value, 'base64').toString(
65+
'ascii'
66+
);
67+
return JSON.parse(
68+
asciiResponse.substring(asciiResponse.indexOf('{') || asciiResponse.indexOf('['))
69+
);
70+
}

0 commit comments

Comments
 (0)