@@ -10,7 +10,7 @@ export interface UniqueIdentifier {
10
10
address : string ;
11
11
}
12
12
13
- function isUniqueIdentifier ( identifier : any ) : identifier is UniqueIdentifier {
13
+ function isUniqueIdentifiers ( identifier : any ) : identifier is UniqueIdentifier {
14
14
const { address } = identifier ;
15
15
16
16
return typeof address === 'string' ;
@@ -28,7 +28,7 @@ export class Wallet extends Entity<Params> {
28
28
public static unserialize ( serialized : string ) {
29
29
const unserialized = unserialize ( serialized ) ;
30
30
31
- if ( ! isUniqueIdentifier ( unserialized ) ) {
31
+ if ( ! isUniqueIdentifiers ( unserialized ) ) {
32
32
throw new PolymathError ( {
33
33
code : ErrorCode . InvalidUuid ,
34
34
message : 'Wrong Wallet ID format.' ,
@@ -42,16 +42,15 @@ export class Wallet extends Entity<Params> {
42
42
43
43
public address : string ;
44
44
45
- private contractWrappers : PolymathBase ;
45
+ protected context : Context ;
46
46
47
47
constructor ( params : Params , context : Context ) {
48
48
super ( ) ;
49
49
50
50
const { address } = params ;
51
- const { contractWrappers } = context ;
52
51
53
52
this . address = address ;
54
- this . contractWrappers = contractWrappers ;
53
+ this . context = context ;
55
54
this . uid = Wallet . generateId ( {
56
55
address,
57
56
} ) ;
@@ -74,21 +73,33 @@ export class Wallet extends Entity<Params> {
74
73
}
75
74
}
76
75
76
+ /**
77
+ * Retrieve the POLY balance of this particular wallet address
78
+ */
77
79
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 } ) ;
80
82
} ;
81
83
84
+ /**
85
+ * Retrieve the ETH balance of this particular wallet address
86
+ */
82
87
public getEthBalance = async ( ) : Promise < BigNumber > => {
83
- return await this . contractWrappers . polyToken . balanceOf ( ) ;
88
+ const { address, context } = this ;
89
+ return await context . contractWrappers . getBalance ( { address } ) ;
84
90
} ;
85
91
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 ( {
88
101
address : tokenAddress ,
89
102
} ) ;
90
-
91
- const { address } = this ;
92
103
return await erc20Wrapper . balanceOf ( { owner : address } ) ;
93
104
} ;
94
105
}
0 commit comments