Skip to content

Commit afb44b1

Browse files
authored
Merge pull request #1459 from crypto-com/dev
Internal Release 1.5.1
2 parents caf10aa + e3aab49 commit afb44b1

File tree

9 files changed

+252
-148
lines changed

9 files changed

+252
-148
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
99
### Additions
1010
- Security enhancement
1111
- web3 library dependencies bump
12+
- Transit to upgraded indexing services
1213
## [v1.5.0] - 2024-03-12
1314
### Additions
1415
- Security enhancement on DApp Browser

src/config/StaticAssets.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { TestNetCroeseid5Config, MainNetConfig } from './StaticConfig';
1111
export const STATIC_ASSET_COUNT = 4;
1212

1313
// Update Explorer Url - https://cronoscan.com
14-
export const MAINNET_EVM_EXPLORER_URL = 'https://cronoscan.com';
14+
export const MAINNET_EVM_EXPLORER_URL = 'https://explorer.cronos.org';
1515
// There's no testnet explorer on cronoscan.com. Use cronos.org/explorer instead.
16-
export const TESTNET_EVM_EXPLORER_URL = 'https://cronos.org/explorer/testnet3';
16+
export const TESTNET_EVM_EXPLORER_URL = 'https://explorer.cronos.org/testnet';
1717

1818
export const MAINNET_ETHEREUM_EXPLORER_URL = 'https://etherscan.io';
1919
export const ROPSTEN_ETHEREUM_EXPLORER_URL = 'https://ropsten.etherscan.io';
@@ -235,8 +235,8 @@ export const ETH_ASSET = (walletConfig: WalletConfig) => {
235235

236236
fee: { gasLimit: '50000', networkFee: '20000000000' },
237237
indexingUrl: isTestnet
238-
? 'https://eth-indexing.crypto.org/ethereum/goerli/api/v1'
239-
: 'https://eth-indexing.crypto.org/ethereum/mainnet/api/v1',
238+
? 'https://eth-indexing.crypto.org/ethereum/goerli/api/v2'
239+
: 'https://eth-indexing.crypto.org/ethereum/mainnet/api/v2',
240240
isLedgerSupportDisabled: false,
241241
isStakingDisabled: false,
242242
nodeUrl: isTestnet

src/layouts/home/home.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,6 @@ function HomeLayout(props: HomeLayoutProps) {
345345
: MAINNET_ETHEREUM_EXPLORER_URL;
346346

347347
setTimeout(async () => {
348-
349-
console.log('checkCorrectExplorerUrl', cronosTendermintAsset?.config?.explorerUrl, checkDefaultCronosPosExplorerUrl);
350348
if (
351349
!walletSession.activeAsset?.config?.explorer ||
352350
// Check if explorerUrl has been updated with latest default

src/service/TransactionHistoryService.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { croMarketPriceApi } from './rpc/MarketApi';
4040
import { CronosNftIndexingAPI } from './rpc/indexing/nft/cronos/CronosNftIndexingAPI';
4141
import {
4242
checkIfTestnet,
43+
getAllERC20WhiteListedAddress,
4344
getCronosEvmAsset,
4445
isCRC20AssetWhitelisted,
4546
isERC20AssetWhitelisted,
@@ -334,18 +335,19 @@ export class TransactionHistoryService {
334335
const txList = await ethClient.getTxsByAddress(currentAsset.address);
335336

336337
const loadedTxList = txList
337-
.filter(
338-
tx =>
339-
tx.token_symbol === 'ETH' &&
340-
(tx.type?.toLowerCase() === EthereumTransactionType.TRANSFER ||
341-
tx.type?.toLowerCase() === EthereumTransactionType.UTF8TRANSFER),
342-
)
338+
// .filter(
339+
// tx =>
340+
// tx.method_id === ''
341+
// // tx.token_symbol === 'ETH' &&
342+
// // (tx.type?.toLowerCase() === EthereumTransactionType.TRANSFER ||
343+
// // tx.type?.toLowerCase() === EthereumTransactionType.UTF8TRANSFER),
344+
// )
343345
.map(tx => {
344346
const transferTx: TransferTransactionData = {
345-
amount: tx.amount,
346-
assetSymbol: tx.token_symbol,
347+
amount: tx.value,
348+
assetSymbol: 'ETH',
347349
date: new Date(Number(tx.timestamp) * 1000).toISOString(),
348-
hash: tx.transaction_hash,
350+
hash: tx.hash,
349351
memo: '',
350352
receiverAddress: tx.to,
351353
senderAddress: tx.from,
@@ -356,7 +358,7 @@ export class TransactionHistoryService {
356358
walletId: walletIdentifier,
357359
assetId: currentAsset.identifier,
358360
assetType: currentAsset.assetType,
359-
txHash: tx.transaction_hash,
361+
txHash: tx.hash,
360362
txType: EthereumTransactionType.TRANSFER,
361363
txData: transferTx,
362364
// TODO: add messageTypeName
@@ -860,9 +862,9 @@ export class TransactionHistoryService {
860862

861863
const ethClient = new EthClient(ethEvmAsset.config?.nodeUrl, ethEvmAsset.config?.indexingUrl);
862864

863-
// const allWhiteListedTokens = getAllERC20WhiteListedAddress();
865+
const allWhiteListedTokens = getAllERC20WhiteListedAddress();
864866
const tokensListResponse = await ethClient.getBalanceByAddress(address, {
865-
// token: allWhiteListedTokens.slice(0, 20).join(','),
867+
contract_addresses: allWhiteListedTokens.slice(0, 20).join(','),
866868
});
867869
const newlyLoadedTokens = await tokensListResponse
868870
.filter(token => token.balance > 0 && token.token_addr !== 'ETH')
@@ -941,9 +943,9 @@ export class TransactionHistoryService {
941943
if (asset.name.includes('Cronos')) {
942944
await this.fetchCurrentWalletCRC20Tokens(asset, currentSession);
943945
}
944-
if (asset.name.includes('Ethereum')) {
945-
await this.fetchCurrentWalletERC20Tokens(asset, currentSession);
946-
}
946+
// if (asset.name.includes('Ethereum')) {
947+
// await this.fetchCurrentWalletERC20Tokens(asset, currentSession);
948+
// }
947949
break;
948950
default:
949951
break;

src/service/ethereum/EthClient.spec.ts

Lines changed: 0 additions & 51 deletions
This file was deleted.

src/service/ethereum/EthClient.ts

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
4141
getETHBalanceByAddress = async (address: string): Promise<string> => {
4242
const balanceResponse: AxiosResponse<BalancesByAddressResponse> = await axios({
4343
baseURL: this.indexingBaseUrl,
44-
url: `/address/${address.toLowerCase()}/balance`,
44+
url: `/addresses/${address.toLowerCase()}/native_balance`,
4545
});
4646

4747
if (balanceResponse.status !== 200) {
@@ -62,7 +62,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
6262
getBalanceByAddress = async (address: string, options?: balanceQueryBaseParams) => {
6363
const balanceResponse: AxiosResponse<BalancesByAddressResponse> = await axios({
6464
baseURL: this.indexingBaseUrl,
65-
url: `/address/${address.toLowerCase()}/balance`,
65+
url: `/addresses/${address.toLowerCase()}/token_balance`,
6666
params: { ...options },
6767
});
6868

@@ -79,7 +79,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
7979

8080
getTxsByAddress = async (address: string, options?: txQueryBaseParams) => {
8181
// Pagination params
82-
let currentPage = options?.page || 0;
82+
let currentPage = options?.page || 1;
8383
const limit = options?.pageSize || 100;
8484

8585
// Result
@@ -91,7 +91,6 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
9191
const txDataList = await this.getTxsByAddressPaginated(address, {
9292
pageSize: limit,
9393
page: currentPage,
94-
sort: 'timestamp:desc',
9594
});
9695

9796
// Append TxData list to the final response array
@@ -111,7 +110,7 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
111110
private getTxsByAddressPaginated = async (address: string, options?: txQueryBaseParams) => {
112111
const txListResponse: AxiosResponse<TransactionsByAddressResponse> = await axios({
113112
baseURL: this.indexingBaseUrl,
114-
url: `/address/${address.toLowerCase()}/normal`,
113+
url: `/addresses/${address.toLowerCase()}/transactions`,
115114
params: { ...options },
116115
});
117116

@@ -134,4 +133,54 @@ export class EthClient extends EVMClient implements IEthChainIndexAPI {
134133
getInternalTxsByAddress(address: string, options?: any) {
135134
throw new Error('Method not implemented.');
136135
}
136+
137+
138+
getERC20TransfersByAddress = async (address: string, options?: txQueryBaseParams) => {
139+
// Pagination params
140+
let currentPage = options?.page || 1;
141+
const limit = options?.pageSize || 100;
142+
143+
// Result
144+
const finalList: TransactionData[] = [];
145+
146+
// eslint-disable-next-line no-constant-condition
147+
while (true) {
148+
// eslint-disable-next-line
149+
const txDataList = await this.getERC20TransfersByAddressPaginated(address, {
150+
pageSize: limit,
151+
page: currentPage,
152+
sort: 'timestamp:desc',
153+
});
154+
155+
// Append TxData list to the final response array
156+
finalList.push(...txDataList);
157+
158+
// Increment pagination params
159+
currentPage += 1;
160+
161+
if (txDataList.length < 1 || txDataList.length < limit) {
162+
break;
163+
}
164+
}
165+
166+
return finalList;
167+
};
168+
169+
private getERC20TransfersByAddressPaginated = async (address: string, options?: txQueryBaseParams) => {
170+
const txListResponse: AxiosResponse<TransactionsByAddressResponse> = await axios({
171+
baseURL: this.indexingBaseUrl,
172+
url: `/addresses/${address.toLowerCase()}/transfers`,
173+
params: { ...options },
174+
});
175+
176+
if (txListResponse.status !== 200) {
177+
return [];
178+
}
179+
180+
if (!txListResponse.data.data) {
181+
return [];
182+
}
183+
184+
return txListResponse.data.data as TransactionData[];
185+
};
137186
}

0 commit comments

Comments
 (0)