Skip to content

Commit 51bbb15

Browse files
committed
showing custom tokens in swap history
1 parent d37ee6a commit 51bbb15

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/hooks/useTransactionHistory.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import {
2020
USER_TRANSACTIONS_V2_WITH_POOL,
2121
} from 'src/modules/history/v2-user-history-query';
2222
import { USER_TRANSACTIONS_V3 } from 'src/modules/history/v3-user-history-query';
23+
import { ERC20Service } from 'src/services/Erc20Service';
2324
import { useRootStore } from 'src/store/root';
2425
import { queryKeysFactory } from 'src/ui-config/queries';
2526
import { TOKEN_LIST } from 'src/ui-config/TokenList';
27+
import { getProvider } from 'src/utils/marketsAndNetworksConfig';
2628
import { useShallow } from 'zustand/shallow';
2729

2830
export const applyTxHistoryFilters = ({
@@ -221,17 +223,44 @@ export const useTransactionHistory = ({ isFilterActive }: { isFilterActive: bool
221223
)
222224
).filter((order) => order !== null);
223225

224-
return filteredCowAaveOrders
225-
.map<TransactionHistoryItemUnion | null>((order) => {
226-
const srcToken = TOKEN_LIST.tokens.find(
226+
return Promise.all(
227+
filteredCowAaveOrders.map<Promise<TransactionHistoryItemUnion | null>>(async (order) => {
228+
const erc20Service = new ERC20Service(getProvider);
229+
230+
let srcToken:
231+
| { address: string; name: string; symbol: string; decimals: number }
232+
| undefined = TOKEN_LIST.tokens.find(
227233
(token) =>
228234
token.chainId == chainId && token.address.toLowerCase() == order.sellToken.toLowerCase()
229235
);
230-
const destToken = TOKEN_LIST.tokens.find(
236+
237+
let destToken:
238+
| { address: string; name: string; symbol: string; decimals: number }
239+
| undefined = TOKEN_LIST.tokens.find(
231240
(token) =>
232241
token.chainId == chainId && token.address.toLowerCase() == order.buyToken.toLowerCase()
233242
);
234243

244+
// Custom tokens - only if erc20Service is available
245+
if (!srcToken && erc20Service) {
246+
srcToken = await erc20Service
247+
.getTokenInfo(order.sellToken, chainId)
248+
.then((token) => ({ ...token, underlyingAsset: token.address }))
249+
.catch(() => undefined);
250+
}
251+
252+
if (!destToken && erc20Service) {
253+
console.log('Fetching custom token', order.buyToken);
254+
destToken = await erc20Service
255+
.getTokenInfo(order.buyToken, chainId)
256+
.then((token) => ({ ...token, underlyingAsset: token.address }))
257+
.catch(() => {
258+
console.log('Error fetching custom token', order.buyToken);
259+
return undefined;
260+
});
261+
}
262+
263+
// Otherwise, we can not display it
235264
if (!srcToken || !destToken) {
236265
return null;
237266
}
@@ -265,7 +294,7 @@ export const useTransactionHistory = ({ isFilterActive }: { isFilterActive: bool
265294
chainId: chainId,
266295
};
267296
})
268-
.filter((txn) => txn !== null);
297+
).then((txns) => txns.filter((txn) => txn !== null));
269298
};
270299

271300
const PAGE_SIZE = 100;

0 commit comments

Comments
 (0)