This repository was archived by the owner on Aug 12, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments