1- using System ;
21using System . Collections . Generic ;
32using System . Numerics ;
43using System . Threading . Tasks ;
@@ -20,8 +19,7 @@ public class Pack : Routable
2019 /// <summary>
2120 /// Interact with a Marketplace contract.
2221 /// </summary>
23- public Pack ( string chain , string address )
24- : base ( $ "{ address } { subSeparator } pack")
22+ public Pack ( string chain , string address ) : base ( $ "{ address } { subSeparator } pack")
2523 {
2624 this . chain = chain ;
2725 this . contractAddress = address ;
@@ -193,14 +191,17 @@ public async Task<PackContents> GetPackContents(string packId)
193191 var erc20R = new List < ERC20Contents > ( ) ;
194192 var erc721R = new List < ERC721Contents > ( ) ;
195193 var erc1155R = new List < ERC1155Contents > ( ) ;
196- foreach ( var tokenReward in packContents . Contents )
194+ for ( int i = 0 ; i < packContents . Contents . Count ; i ++ )
197195 {
196+ var tokenReward = packContents . Contents [ i ] ;
197+ var amount = packContents . PerUnitAmounts [ i ] ;
198198 switch ( tokenReward . TokenType )
199199 {
200200 case 0 :
201201 var tempERC20 = new ERC20Contents ( ) ;
202202 tempERC20 . contractAddress = tokenReward . AssetContract ;
203- tempERC20 . quantityPerReward = tokenReward . TotalAmount . ToString ( ) ;
203+ tempERC20 . quantityPerReward = amount . ToString ( ) . ToEth ( 18 ) ;
204+ tempERC20 . totalRewards = ( tokenReward . TotalAmount / amount ) . ToString ( ) . ToEth ( 18 ) ;
204205 erc20R . Add ( tempERC20 ) ;
205206 break ;
206207 case 1 :
@@ -213,17 +214,18 @@ public async Task<PackContents> GetPackContents(string packId)
213214 var tempERC1155 = new ERC1155Contents ( ) ;
214215 tempERC1155 . contractAddress = tokenReward . AssetContract ;
215216 tempERC1155 . tokenId = tokenReward . TokenId . ToString ( ) ;
216- tempERC1155 . quantityPerReward = tokenReward . TotalAmount . ToString ( ) ;
217+ tempERC1155 . quantityPerReward = amount . ToString ( ) ;
218+ tempERC1155 . totalRewards = ( tokenReward . TotalAmount / amount ) . ToString ( ) ;
217219 erc1155R . Add ( tempERC1155 ) ;
218220 break ;
219221 default :
220222 break ;
221223 }
222224 }
223225 PackContents contents = new PackContents ( ) ;
224- contents . erc20Contents = erc20R ;
225- contents . erc721Contents = erc721R ;
226- contents . erc1155Contents = erc1155R ;
226+ contents . erc20Rewards = erc20R ;
227+ contents . erc721Rewards = erc721R ;
228+ contents . erc1155Rewards = erc1155R ;
227229 return contents ;
228230 }
229231 }
@@ -406,20 +408,20 @@ public override string ToString()
406408 [ System . Serializable ]
407409 public class PackContents
408410 {
409- public List < ERC20Contents > erc20Contents ;
410- public List < ERC721Contents > erc721Contents ;
411- public List < ERC1155Contents > erc1155Contents ;
411+ public List < ERC20Contents > erc20Rewards ;
412+ public List < ERC721Contents > erc721Rewards ;
413+ public List < ERC1155Contents > erc1155Rewards ;
412414
413415 public override string ToString ( )
414416 {
415- string erc20str = "ERC20 Contents: \n " ;
416- foreach ( var content in erc20Contents )
417+ string erc20str = "\n " ;
418+ foreach ( var content in erc20Rewards )
417419 erc20str += content . ToString ( ) ;
418- string erc721str = "ERC721 Contents: \n " ;
419- foreach ( var content in erc721Contents )
420+ string erc721str = "\n " ;
421+ foreach ( var content in erc721Rewards )
420422 erc721str += content . ToString ( ) ;
421- string erc1155str = "ERC1155 Contents: \n " ;
422- foreach ( var content in erc1155Contents )
423+ string erc1155str = "\n " ;
424+ foreach ( var content in erc1155Rewards )
423425 erc1155str += content . ToString ( ) ;
424426 return "PackContents:\n " + erc20str + erc721str + erc1155str ;
425427 }
@@ -462,7 +464,7 @@ public class ERC20Contents : ERC20Reward
462464
463465 public override string ToString ( )
464466 {
465- return "ERC20Contents: \n " + $ "totalRewards: { totalRewards . ToString ( ) } \n " + base . ToString ( ) ;
467+ return base . ToString ( ) + $ "totalRewards: { totalRewards . ToString ( ) } \n ";
466468 }
467469 }
468470
@@ -504,7 +506,7 @@ public class ERC1155Reward
504506
505507 public override string ToString ( )
506508 {
507- return "ERC1155Reward:\n " + $ "contractAddress: { contractAddress . ToString ( ) } \n " + $ "tokenId: { tokenId . ToString ( ) } \n " + $ "contractAddress : { tokenId . ToString ( ) } \n ";
509+ return "ERC1155Reward:\n " + $ "contractAddress: { contractAddress . ToString ( ) } \n " + $ "tokenId: { tokenId . ToString ( ) } \n " + $ "quantityPerReward : { quantityPerReward . ToString ( ) } \n ";
508510 }
509511 }
510512
@@ -515,7 +517,7 @@ public class ERC1155Contents : ERC1155Reward
515517
516518 public override string ToString ( )
517519 {
518- return "ERC1155Contents: \n " + $ "totalRewards: { totalRewards . ToString ( ) } \n " + base . ToString ( ) ;
520+ return base . ToString ( ) + $ "totalRewards: { totalRewards . ToString ( ) } \n ";
519521 }
520522 }
521523}
0 commit comments