1
+ // tslint:disable-next-line
2
+ import Web3 from 'web3'
3
+
1
4
import {
2
5
LoanTransactionResponse ,
3
6
LoanMetadataResponse ,
4
7
LoanRequestResponse ,
5
8
LoanAddressesByBorrowerResponse ,
6
9
LoansAddressesResponse ,
7
10
LoanAPIInstance ,
8
- BaseResponse ,
9
- BaseLoanModel
11
+ BaseLoanModel ,
12
+ MaxLoanAmountResponse
10
13
} from '../types'
11
-
12
14
import BaseService from './BaseService'
13
15
14
16
export default class LoanRequest extends BaseService implements LoanAPIInstance {
15
- constructor ( token : string , apiUrl ?: string ) {
16
- super ( token , apiUrl )
17
- }
18
-
19
- private async apiRequest (
20
- endpoint : string ,
21
- resourceType : string ,
22
- errorParam : string = '' ,
23
- method : 'get' | 'post' = 'get' ,
24
- params ?: object
25
- ) : Promise < BaseResponse > {
26
- const api = method === 'post' ? this . api . post : this . api . get
27
-
28
- try {
29
- const { data } = await api ( endpoint , params )
30
-
31
- return { data, code : 200 }
32
- } catch ( e ) {
33
- return LoanRequest . errorHandler ( e , resourceType , errorParam )
34
- }
17
+ constructor ( token : string , web3 ?: Web3 , apiUrl ?: string ) {
18
+ super ( token , web3 , apiUrl )
35
19
}
36
20
37
- public async create ( creatorWalletAddress : string , params : BaseLoanModel ) : Promise < LoanTransactionResponse > {
38
- BaseService . checkAddressChecksum ( creatorWalletAddress )
21
+ public async create ( borrowerWalletAddress : string , params : BaseLoanModel ) : Promise < LoanTransactionResponse > {
22
+ BaseService . checkAddressChecksum ( borrowerWalletAddress )
39
23
40
- return await this . apiRequest ( `/request/create/${ creatorWalletAddress } ` , 'loan request creation' , '' , 'post' , params )
24
+ return await this . apiRequest ( '/request' , 'loan requests creation' , '' , 'post' , {
25
+ borrower : borrowerWalletAddress ,
26
+ ...params
27
+ } )
41
28
}
42
29
43
30
public async placeCollateral ( loanAddress : string , borrowerAddress : string ) : Promise < LoanTransactionResponse > {
@@ -46,7 +33,7 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
46
33
47
34
return await this . apiRequest (
48
35
`/request/placecollateral/${ loanAddress } /${ borrowerAddress } ` ,
49
- 'placing loan request collateral' ,
36
+ 'placing loan requests collateral' ,
50
37
loanAddress ,
51
38
'post'
52
39
)
@@ -58,7 +45,7 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
58
45
59
46
return await this . apiRequest (
60
47
`/request/fund/${ loanAddress } /${ lenderAddress } /${ amount } ` ,
61
- 'funding loan request ' ,
48
+ 'funding loan requests ' ,
62
49
loanAddress ,
63
50
'post'
64
51
)
@@ -70,29 +57,46 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
70
57
71
58
return await this . apiRequest (
72
59
`/request/payback/${ loanAddress } /${ borrowerAddress } ` ,
73
- 'placing loan request payback' ,
60
+ 'placing loan requests payback' ,
74
61
loanAddress ,
75
62
'post'
76
63
)
77
64
}
65
+ public async getMaxLoanAmountFromCollateral (
66
+ collateralAmount : number ,
67
+ collateralType : string ,
68
+ moe : string ,
69
+ ltv ?: number
70
+ ) : Promise < MaxLoanAmountResponse > {
71
+ return await this . apiRequest ( '/request/maxamount/' , 'getting max loan amount' , collateralType , 'post' , {
72
+ collateralAmount,
73
+ collateralType,
74
+ moe,
75
+ ltv
76
+ } )
77
+ }
78
78
79
79
public async getLoanData ( loanAddress : string ) : Promise < LoanRequestResponse > {
80
80
BaseService . checkAddressChecksum ( loanAddress )
81
81
82
- return await this . apiRequest ( `/request/${ loanAddress } ` , 'loan request ' , loanAddress )
82
+ return await this . apiRequest ( `/request/getone/ ${ loanAddress } ` , 'loan requests ' , loanAddress )
83
83
}
84
84
85
85
public async getAllAddresses ( ) : Promise < LoansAddressesResponse > {
86
- return await this . apiRequest ( '/requests ' , 'loan request addresses' )
86
+ return await this . apiRequest ( '/request ' , 'loan requests addresses' )
87
87
}
88
88
89
89
public async getLoansByBorrower ( borrowerAddress : string ) : Promise < LoanAddressesByBorrowerResponse > {
90
90
BaseService . checkAddressChecksum ( borrowerAddress )
91
91
92
- return await this . apiRequest ( `/requests/${ borrowerAddress } ` , 'loan addresses by borrower' , borrowerAddress )
92
+ return await this . apiRequest (
93
+ `/request/getlistbyborrower/${ borrowerAddress } ` ,
94
+ 'loan addresses by borrower' ,
95
+ borrowerAddress
96
+ )
93
97
}
94
98
95
99
public async getMetadata ( ) : Promise < LoanMetadataResponse > {
96
- return await this . apiRequest ( '/requests /metadata' , 'loan requests metadata' )
100
+ return await this . apiRequest ( '/request /metadata' , 'loan requests metadata' )
97
101
}
98
102
}
0 commit comments