Skip to content

Commit 6fbd145

Browse files
authored
feat(checkout): use address_hash to fill out address field (#2678)
1 parent 262f265 commit 6fbd145

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

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 as any).address_hash) {
115+
normalizedToken.address = (normalizedToken as any).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

0 commit comments

Comments
 (0)