Skip to content
This repository was archived by the owner on Aug 12, 2023. It is now read-only.

Commit ebb14d0

Browse files
committed
Fix empty asset data parsing
1 parent 8068897 commit ebb14d0

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/util/parse-asset-data.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,26 @@ const extractERC1155Assets = assetData => {
7575
}));
7676
};
7777

78-
const parseAssetData = (encodedData, amount) => {
78+
/**
79+
* Determine whether encoded asset data is empty.
80+
* @param {string} encodedData
81+
*/
82+
const isEmptyData = encodedData => {
7983
if (encodedData === '0x') {
84+
return true;
85+
}
86+
87+
if (!encodedData.startsWith('0x')) {
88+
return false;
89+
}
90+
91+
const valuesAfterX = encodedData.substr(2);
92+
93+
return valuesAfterX === '0'.repeat(valuesAfterX.length);
94+
};
95+
96+
const parseAssetData = (encodedData, amount) => {
97+
if (isEmptyData(encodedData)) {
8098
return [];
8199
}
82100

src/util/parse-asset-data.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const parseAssetData = require('./parse-asset-data');
2+
3+
describe('utils/parseAssetData', () => {
4+
it('should return empty array when asset data is 0x', () => {
5+
const assets = parseAssetData('0x', 0);
6+
7+
expect(assets).toEqual([]);
8+
});
9+
10+
it('should return empty array when asset data is 0x0', () => {
11+
const assets = parseAssetData('0x0', 0);
12+
13+
expect(assets).toEqual([]);
14+
});
15+
16+
it('should return empty array when asset data is 0x00000', () => {
17+
const assets = parseAssetData('0x00000', 0);
18+
19+
expect(assets).toEqual([]);
20+
});
21+
22+
it('should return empty array when asset data is 0x0000000000', () => {
23+
const assets = parseAssetData('0x0000000000', 0);
24+
25+
expect(assets).toEqual([]);
26+
});
27+
});

0 commit comments

Comments
 (0)