@@ -10,7 +10,7 @@ export interface UniqueIdentifier {
1010 address : string ;
1111}
1212
13- function isUniqueIdentifier ( identifier : any ) : identifier is UniqueIdentifier {
13+ function isUniqueIdentifiers ( identifier : any ) : identifier is UniqueIdentifier {
1414 const { address } = identifier ;
1515
1616 return typeof address === 'string' ;
@@ -28,7 +28,7 @@ export class Wallet extends Entity<Params> {
2828 public static unserialize ( serialized : string ) {
2929 const unserialized = unserialize ( serialized ) ;
3030
31- if ( ! isUniqueIdentifier ( unserialized ) ) {
31+ if ( ! isUniqueIdentifiers ( unserialized ) ) {
3232 throw new PolymathError ( {
3333 code : ErrorCode . InvalidUuid ,
3434 message : 'Wrong Wallet ID format.' ,
@@ -42,16 +42,15 @@ export class Wallet extends Entity<Params> {
4242
4343 public address : string ;
4444
45- private contractWrappers : PolymathBase ;
45+ protected context : Context ;
4646
4747 constructor ( params : Params , context : Context ) {
4848 super ( ) ;
4949
5050 const { address } = params ;
51- const { contractWrappers } = context ;
5251
5352 this . address = address ;
54- this . contractWrappers = contractWrappers ;
53+ this . context = context ;
5554 this . uid = Wallet . generateId ( {
5655 address,
5756 } ) ;
@@ -74,21 +73,33 @@ export class Wallet extends Entity<Params> {
7473 }
7574 }
7675
76+ /**
77+ * Retrieve the POLY balance of this particular wallet address
78+ */
7779 public getPolyBalance = async ( ) : Promise < BigNumber > => {
78- const { address } = this ;
79- return await this . contractWrappers . getBalance ( { address } ) ;
80+ const { address, context } = this ;
81+ return await context . contractWrappers . polyToken . balanceOf ( { owner : address } ) ;
8082 } ;
8183
84+ /**
85+ * Retrieve the ETH balance of this particular wallet address
86+ */
8287 public getEthBalance = async ( ) : Promise < BigNumber > => {
83- return await this . contractWrappers . polyToken . balanceOf ( ) ;
88+ const { address, context } = this ;
89+ return await context . contractWrappers . getBalance ( { address } ) ;
8490 } ;
8591
86- public getErc20Balance = async ( tokenAddress : string ) : Promise < BigNumber > => {
87- const erc20Wrapper = await this . contractWrappers . getERC20TokenWrapper ( {
92+ /**
93+ * Retrieve the ERC20 balance of this particular wallet address
94+ *
95+ * @param tokenAddress address of the ERC20 token contract
96+ */
97+ public getErc20Balance = async ( args : { tokenAddress : string } ) : Promise < BigNumber > => {
98+ const { context, address } = this ;
99+ const { tokenAddress } = args ;
100+ const erc20Wrapper = await context . contractWrappers . getERC20TokenWrapper ( {
88101 address : tokenAddress ,
89102 } ) ;
90-
91- const { address } = this ;
92103 return await erc20Wrapper . balanceOf ( { owner : address } ) ;
93104 } ;
94105}
0 commit comments