Skip to content

Commit de14af4

Browse files
authored
Fix useIsTransferLimited hook to use token origin chain (#1398)
Previously the hook was using the token destination chain to check if the token was transfer limited. This would not work for tokens where the origin chain was different from the destination chain. Also prefer to fetch the governor limits from wormholescan Co-authored-by: Kevin Peters <kevin@wormholelabs.xyz>
1 parent 5bbb2bf commit de14af4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

wormhole-connect/src/hooks/useIsTransferLimited.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ChainId } from '@wormhole-foundation/wormhole-connect-sdk';
22
import axios from 'axios';
3-
import { TOKENS } from 'config';
3+
import { TOKENS, WORMHOLE_API } from 'config';
44
import { hexlify } from 'ethers/lib/utils.js';
55
import { useEffect, useMemo, useRef, useState } from 'react';
66
import { useSelector } from 'react-redux';
@@ -10,6 +10,13 @@ import { getWrappedTokenId } from 'utils';
1010
import { WORMHOLE_RPC_HOSTS } from 'config';
1111

1212
const REMAINING_NOTIONAL_TOLERANCE = 0.98;
13+
14+
const GOVERNOR_API_BASE_URLS = [
15+
// prefer to use the wormholescan api first
16+
WORMHOLE_API,
17+
...WORMHOLE_RPC_HOSTS,
18+
];
19+
1320
interface TokenListEntry {
1421
originAddress: string;
1522
originChainId: number;
@@ -73,12 +80,13 @@ const useIsTransferLimited = (): IsTransferLimitedResult => {
7380
try {
7481
const tokenConfig = TOKENS[token];
7582
const tokenId = getWrappedTokenId(tokenConfig);
83+
const tokenChain = wh.toChainId(tokenId.chain);
7684
const formatted = hexlify(
77-
await formatAssetAddress(fromChain, tokenId.address),
85+
await formatAssetAddress(tokenChain, tokenId.address),
7886
);
7987
if (!cancelled) {
8088
setAssetAddress(formatted);
81-
setAssetChain(wh.toChainId(tokenId.chain));
89+
setAssetChain(tokenChain);
8290
}
8391
} catch (e) {
8492
if (!cancelled) {
@@ -96,9 +104,11 @@ const useIsTransferLimited = (): IsTransferLimitedResult => {
96104
if (!fetchedTokenList.current) {
97105
let cancelled = false;
98106
(async () => {
99-
for (const rpcHost of WORMHOLE_RPC_HOSTS) {
107+
for (const rpcHost of GOVERNOR_API_BASE_URLS) {
100108
try {
101-
const baseUrl = `${rpcHost}/v1/governor`;
109+
const baseUrl = `${rpcHost}${
110+
rpcHost.endsWith('/') ? '' : '/'
111+
}v1/governor`;
102112
const [tokenListResponse, availableNotionalByChainResponse] =
103113
await Promise.all([
104114
axios.get<TokenList>(`${baseUrl}/token_list`),

0 commit comments

Comments
 (0)