Skip to content

Commit a8ef501

Browse files
committed
use address_hash to fill out address field
1 parent 262f265 commit a8ef501

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

packages/checkout/sdk/src/api/blockscout/blockscout.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,22 @@ export class Blockscout {
107107

108108
const response = await this.httpClient.get(url); // success if 2XX response otherwise throw error
109109

110+
// Normalize the data by ensuring address field is always present
111+
// Map address_hash to address if address is not present
112+
const normalizedItems = response.data?.items?.map((item: BlockscoutToken) => {
113+
const normalizedToken = { ...item.token };
114+
if (!normalizedToken.address && normalizedToken.address_hash) {
115+
normalizedToken.address = normalizedToken.address_hash;
116+
}
117+
return { ...item, token: normalizedToken };
118+
}) || [];
119+
110120
// To get around an issue with native tokens being an ERC-20, there is the need
111121
// to remove IMX from `resp` and add it back in using getNativeTokenByWalletAddress.
112122
// This has affected some of the early wallets, and it might not be an issue in mainnet
113123
// however, let's enforce it.
114124
const data = {
115-
items: response.data?.items?.filter(
125+
items: normalizedItems.filter(
116126
(token: BlockscoutToken) => token.token.address && token.token.address !== this.nativeToken.address,
117127
),
118128
// eslint-disable-next-line @typescript-eslint/naming-convention

packages/checkout/sdk/src/api/blockscout/blockscoutType.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface BlockscoutToken {
2020

2121
export interface BlockscoutTokenData {
2222
address: string
23+
address_hash?: string
2324
decimals: string
2425
name: string
2526
symbol: string
@@ -34,6 +35,7 @@ export interface BlockscoutError {
3435

3536
export interface BlockscoutNativeTokenData {
3637
address: string
38+
address_hash?: string
3739
decimals: string
3840
name: string
3941
symbol: string

0 commit comments

Comments
 (0)