Skip to content

Commit 594ecfd

Browse files
committed
dashboard: governor token list pagination fix
1 parent af5b937 commit 594ecfd

File tree

6 files changed

+63
-16
lines changed

6 files changed

+63
-16
lines changed

dashboard/src/components/ExplorerAssetURL.tsx

-4
This file was deleted.

dashboard/src/components/Governor.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ import {
2626
getSortedRowModel,
2727
useReactTable,
2828
} from '@tanstack/react-table';
29+
import { chainIdToName } from '@wormhole-foundation/wormhole-monitor-common';
2930
import numeral from 'numeral';
3031
import { useCallback, useMemo, useState } from 'react';
3132
import useGovernorInfo from '../hooks/useGovernorInfo';
3233
import { CHAIN_ICON_MAP, WORMHOLE_RPC_HOSTS } from '../utils/consts';
3334
import CollapsibleSection from './CollapsibleSection';
3435
import EnqueuedVAAChecker from './EnqueuedVAAChecker';
35-
import { ExplorerAssetURL } from './ExplorerAssetURL';
3636
import { ExplorerTxHash } from './ExplorerTxHash';
3737
import Table from './Table';
38-
import { chainIdToName } from '@wormhole-foundation/wormhole-monitor-common';
3938

4039
const calculatePercent = (notional: GovernorGetAvailableNotionalByChainResponse_Entry): number => {
4140
try {
@@ -146,9 +145,6 @@ const tokenColumns = [
146145
}),
147146
tokenColumnHelper.accessor('originAddress', {
148147
header: () => 'Token',
149-
cell: (info) => (
150-
<ExplorerAssetURL chain={info.row.original.originChainId} assetAddr={info.getValue()} />
151-
),
152148
}),
153149
tokenColumnHelper.accessor('price', {
154150
header: () => <Box order="1">Price</Box>,
@@ -329,7 +325,7 @@ function Governor() {
329325
}}
330326
placeholder="Search Address"
331327
/>
332-
<Table<GovernorGetTokenListResponse_Entry> table={tokenTable} />
328+
<Table<GovernorGetTokenListResponse_Entry> table={tokenTable} paginated />
333329
</AccordionDetails>
334330
</Accordion>
335331
</Card>

dashboard/src/components/MainnetGovernor.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { CHAIN_ICON_MAP, WORMHOLE_RPC_HOSTS } from '../utils/consts';
4343
import { getQuorumLossCount } from './Alerts';
4444
import CollapsibleSection from './CollapsibleSection';
4545
import EnqueuedVAAChecker from './EnqueuedVAAChecker';
46-
import { ExplorerAssetURL } from './ExplorerAssetURL';
4746
import { ExplorerTxHash } from './ExplorerTxHash';
4847
import Table from './Table';
4948

@@ -272,9 +271,6 @@ const tokenColumns = [
272271
}),
273272
tokenColumnHelper.accessor('originAddress', {
274273
header: () => 'Token',
275-
cell: (info) => (
276-
<ExplorerAssetURL chain={info.row.original.originChainId} assetAddr={info.getValue()} />
277-
),
278274
}),
279275
tokenColumnHelper.accessor('price', {
280276
header: () => <Box order="1">Price</Box>,

dashboard/src/hooks/useCloudGovernorInfo.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useEffect, useState } from 'react';
33
import { useNetworkContext } from '../contexts/NetworkContext';
44
import { getQuorumCount } from '../components/Alerts';
55
import { GUARDIAN_SET_4 } from '@wormhole-foundation/wormhole-monitor-common';
6+
import { tryHexToNativeAssetString } from '../utils/nativeAsset';
67

78
export interface AvailableNotionalByChain {
89
guardianName?: string;
@@ -192,7 +193,16 @@ const getInfo = async (endpoint: string): Promise<CloudGovernorInfo> => {
192193
});
193194
}
194195

195-
const tokens = firstConfig?.tokens || [];
196+
const tokens =
197+
firstConfig?.tokens?.map((entry) => {
198+
try {
199+
return {
200+
...entry,
201+
originAddress: tryHexToNativeAssetString(entry.originAddress, entry.originChainId),
202+
};
203+
} catch (e) {}
204+
return entry;
205+
}) || [];
196206

197207
const vaaById: { [key: string]: EnqueuedVAA } = {};
198208
const totalEnqueuedVaas: TotalEnqueuedVaasByGuardianByChain = {};

dashboard/src/hooks/useGovernorInfo.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useNetworkContext } from '../contexts/NetworkContext';
88
import { getGovernorAvailableNotionalByChain } from '../utils/getGovernorAvailableNotionalByChain';
99
import { getGovernorEnqueuedVAAs } from '../utils/getGovernorEnqueuedVAAs';
1010
import { getGovernorTokenList } from '../utils/getGovernorTokenList';
11+
import { tryHexToNativeAssetString } from '../utils/nativeAsset';
1112

1213
type GovernorInfo = {
1314
notionals: GovernorGetAvailableNotionalByChainResponse_Entry[];
@@ -51,7 +52,21 @@ function useGovernorInfo(): GovernorInfo {
5152
while (!cancelled && currentNetwork.type === 'guardian') {
5253
const response = await getGovernorTokenList(currentNetwork);
5354
if (!cancelled) {
54-
setGovernorInfo((info) => ({ ...info, tokens: response.entries }));
55+
setGovernorInfo((info) => ({
56+
...info,
57+
tokens: response.entries.map((entry) => {
58+
try {
59+
return {
60+
...entry,
61+
originAddress: tryHexToNativeAssetString(
62+
entry.originAddress,
63+
entry.originChainId
64+
),
65+
};
66+
} catch (e) {}
67+
return entry;
68+
}),
69+
}));
5570
await new Promise((resolve) => setTimeout(resolve, TIMEOUT));
5671
}
5772
}

dashboard/src/utils/nativeAsset.ts

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { chainToChainId, chainToPlatform, toChain } from '@wormhole-foundation/sdk-base';
2+
import base58 from 'bs58';
3+
import { Buffer } from 'buffer';
4+
5+
// ported from @certusone/wormhole-sdk
6+
7+
const hexToUint8Array = (h: string): Uint8Array => {
8+
if (h.startsWith('0x')) h = h.slice(2);
9+
return new Uint8Array(Buffer.from(h, 'hex'));
10+
};
11+
12+
function hexToNativeAssetStringAlgorand(s: string): string {
13+
return BigInt(s.startsWith('0x') ? s : `0x${s}`).toString();
14+
}
15+
16+
const tryUint8ArrayToNative = (a: Uint8Array, chain: number): string => {
17+
const platform = chainToPlatform(toChain(chain));
18+
if (platform === 'Evm') {
19+
console.log('here', `0x${Buffer.from(a).toString('hex')}`);
20+
return `0x${Buffer.from(a).toString('hex').substring(24)}`;
21+
} else if (platform === 'Solana') {
22+
return base58.encode(a);
23+
}
24+
return `0x${Buffer.from(a).toString('hex')}`;
25+
};
26+
27+
const tryHexToNativeString = (h: string, c: number): string =>
28+
tryUint8ArrayToNative(hexToUint8Array(h), c);
29+
30+
export const tryHexToNativeAssetString = (h: string, c: number): string =>
31+
c === chainToChainId('Algorand')
32+
? // Algorand assets are represented by their asset ids, not an address
33+
hexToNativeAssetStringAlgorand(h)
34+
: tryHexToNativeString(h, c);

0 commit comments

Comments
 (0)