1
- using System ;
2
1
using System . Collections . Generic ;
3
2
using System . Numerics ;
4
3
using System . Threading . Tasks ;
@@ -20,8 +19,7 @@ public class Pack : Routable
20
19
/// <summary>
21
20
/// Interact with a Marketplace contract.
22
21
/// </summary>
23
- public Pack ( string chain , string address )
24
- : base ( $ "{ address } { subSeparator } pack")
22
+ public Pack ( string chain , string address ) : base ( $ "{ address } { subSeparator } pack")
25
23
{
26
24
this . chain = chain ;
27
25
this . contractAddress = address ;
@@ -193,14 +191,17 @@ public async Task<PackContents> GetPackContents(string packId)
193
191
var erc20R = new List < ERC20Contents > ( ) ;
194
192
var erc721R = new List < ERC721Contents > ( ) ;
195
193
var erc1155R = new List < ERC1155Contents > ( ) ;
196
- foreach ( var tokenReward in packContents . Contents )
194
+ for ( int i = 0 ; i < packContents . Contents . Count ; i ++ )
197
195
{
196
+ var tokenReward = packContents . Contents [ i ] ;
197
+ var amount = packContents . PerUnitAmounts [ i ] ;
198
198
switch ( tokenReward . TokenType )
199
199
{
200
200
case 0 :
201
201
var tempERC20 = new ERC20Contents ( ) ;
202
202
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 ) ;
204
205
erc20R . Add ( tempERC20 ) ;
205
206
break ;
206
207
case 1 :
@@ -213,17 +214,18 @@ public async Task<PackContents> GetPackContents(string packId)
213
214
var tempERC1155 = new ERC1155Contents ( ) ;
214
215
tempERC1155 . contractAddress = tokenReward . AssetContract ;
215
216
tempERC1155 . tokenId = tokenReward . TokenId . ToString ( ) ;
216
- tempERC1155 . quantityPerReward = tokenReward . TotalAmount . ToString ( ) ;
217
+ tempERC1155 . quantityPerReward = amount . ToString ( ) ;
218
+ tempERC1155 . totalRewards = ( tokenReward . TotalAmount / amount ) . ToString ( ) ;
217
219
erc1155R . Add ( tempERC1155 ) ;
218
220
break ;
219
221
default :
220
222
break ;
221
223
}
222
224
}
223
225
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 ;
227
229
return contents ;
228
230
}
229
231
}
@@ -406,20 +408,20 @@ public override string ToString()
406
408
[ System . Serializable ]
407
409
public class PackContents
408
410
{
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 ;
412
414
413
415
public override string ToString ( )
414
416
{
415
- string erc20str = "ERC20 Contents: \n " ;
416
- foreach ( var content in erc20Contents )
417
+ string erc20str = "\n " ;
418
+ foreach ( var content in erc20Rewards )
417
419
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 )
420
422
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 )
423
425
erc1155str += content . ToString ( ) ;
424
426
return "PackContents:\n " + erc20str + erc721str + erc1155str ;
425
427
}
@@ -462,7 +464,7 @@ public class ERC20Contents : ERC20Reward
462
464
463
465
public override string ToString ( )
464
466
{
465
- return "ERC20Contents: \n " + $ "totalRewards: { totalRewards . ToString ( ) } \n " + base . ToString ( ) ;
467
+ return base . ToString ( ) + $ "totalRewards: { totalRewards . ToString ( ) } \n ";
466
468
}
467
469
}
468
470
@@ -504,7 +506,7 @@ public class ERC1155Reward
504
506
505
507
public override string ToString ( )
506
508
{
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 ";
508
510
}
509
511
}
510
512
@@ -515,7 +517,7 @@ public class ERC1155Contents : ERC1155Reward
515
517
516
518
public override string ToString ( )
517
519
{
518
- return "ERC1155Contents: \n " + $ "totalRewards: { totalRewards . ToString ( ) } \n " + base . ToString ( ) ;
520
+ return base . ToString ( ) + $ "totalRewards: { totalRewards . ToString ( ) } \n ";
519
521
}
520
522
}
521
523
}
0 commit comments